Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/dracut/ignition-ostree: add ignition-ostree-sysusers service #774

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
#
# Needed to work around the initrd `rootfs` / filesystem not being a valid
# mount to pivot out of. For reference, see:
# - https://github.com/torvalds/linux/blob/26bc672134241a080a83b2ab9aa8abede8d30e1c/fs/namespace.c#L3605
# - https://gist.github.com/jlebon/fb6e7c6dcc3ce17d3e2a86f5938ec033
set -euo pipefail

TMP_CHROOT_DIR=""

main() {
setup_chroot_tmpdir
run_chrooted_bwrap "$@"
}

setup_chroot_tmpdir() {
TMP_CHROOT_DIR=$(mktemp --directory --tmpdir=/mnt '.coreos-sysroot-bwrap.tmp.XXXXXXXXXX')
mount --bind / "${TMP_CHROOT_DIR}"
mount --make-private "${TMP_CHROOT_DIR}"
mount --bind "${TMP_CHROOT_DIR}" "${TMP_CHROOT_DIR}"
for mnt in proc sys dev; do
mount --bind /$mnt "${TMP_CHROOT_DIR}"/$mnt
done
touch "${TMP_CHROOT_DIR}"/run/ostree-booted
mount --bind /sysroot "${TMP_CHROOT_DIR}"/sysroot
}

run_chrooted_bwrap() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would probably be a good thing to live in rdcore (and in theory in the future it could be a crate shared between rdcore and rpm-ostree).

Not a blocker though.

chroot "${TMP_CHROOT_DIR}" \
/usr/bin/env --chdir /sysroot \
bwrap \
--unshare-pid --unshare-uts --unshare-ipc --unshare-net \
--unshare-cgroup-try --dev /dev --proc /proc --chdir / \
--ro-bind usr /usr --bind etc /etc --dir /tmp --tmpfs /var/tmp \
--tmpfs /run --ro-bind /run/ostree-booted /run/ostree-booted \
--symlink usr/lib /lib \
--symlink usr/lib64 /lib64 \
--symlink usr/bin /bin \
--symlink usr/sbin /sbin -- "$@"
}

cleanup() {
if test -z "${TMP_CHROOT_DIR}"; then
return
fi

umount --lazy --recursive "${TMP_CHROOT_DIR}"
umount --recursive "${TMP_CHROOT_DIR}"
lucab marked this conversation as resolved.
Show resolved Hide resolved
rmdir "${TMP_CHROOT_DIR}"
}

trap cleanup EXIT
main "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Run systemd-sysusers for the target OSTree sysroot.

set -euo pipefail

main() {
coreos-sysroot-bwrap systemd-sysusers
travier marked this conversation as resolved.
Show resolved Hide resolved
coreos-relabel \
/etc/group \
/etc/group- \
/etc/gshadow \
/etc/gshadow- \
/etc/passwd \
/etc/passwd- \
/etc/shadow \
/etc/shadow-
}

main "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Populate OSTree sysusers
DefaultDependencies=false
ConditionKernelCommandLine=|ostree

# Need to do this with all mount points active
After=ignition-mount.service

# But *before* we start dumping files in there
Before=ignition-files.service
Before=ignition-ostree-populate-var.service

[Service]
Type=oneshot
RemainAfterExit=yes
MountFlags=slave
ExecStart=/usr/sbin/ignition-ostree-sysusers
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ install_ignition_unit() {

install() {
inst_multiple \
bwrap \
realpath \
rmdir \
setfiles \
systemd-sysusers \
systemd-tmpfiles \
Expand Down Expand Up @@ -56,6 +58,10 @@ install() {
sgdisk \
find

inst_script "$moddir/ignition-ostree-sysusers" \
"/usr/sbin/ignition-ostree-sysusers"
install_ignition_unit ignition-ostree-sysusers.service

for x in mount populate; do
install_ignition_unit ignition-ostree-${x}-var.service
inst_script "$moddir/ignition-ostree-${x}-var.sh" "/usr/sbin/ignition-ostree-${x}-var"
Expand Down Expand Up @@ -87,4 +93,5 @@ install() {
inst_script "$moddir/coreos-growpart" /usr/libexec/coreos-growpart

inst_script "$moddir/coreos-relabel" /usr/bin/coreos-relabel
inst_script "$moddir/coreos-sysroot-bwrap" /usr/bin/coreos-sysroot-bwrap
}
12 changes: 12 additions & 0 deletions tests/kola/ignition/sysusers/config.fcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
variant: fcos
version: 1.0.0
storage:
files:
- path: /etc/zincati/config.d/00-dummy-placeholder.toml
mode: 0644
user:
name: "zincati"
contents:
inline: |
# Dummy placeholder
20 changes: 20 additions & 0 deletions tests/kola/ignition/sysusers/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail

ok() {
echo "ok" "$@"
}

fatal() {
echo "$@" >&2
exit 1
}

TARGET="/etc/zincati/config.d/00-dummy-placeholder.toml"
OWNER=$(stat -c '%U' "${TARGET}")

# make sure the placeholder file is owned by the proper system user.
if test "${OWNER}" != 'zincati' ; then
fatal "unexpected owner of ${TARGET}: ${OWNER}"
fi
ok "placeholder file correctly owned by zincati user"