MINIMUM_SYSTEMD_VERSION = GenericVersion("254")
+MKOSI_AS_CALLER = (
+ "setpriv",
+ f"--reuid={INVOKING_USER.uid}",
+ f"--regid={INVOKING_USER.gid}",
+ "--clear-groups",
+)
@contextlib.contextmanager
def mount_base_trees(state: MkosiState) -> Iterator[None]:
"--setenv", "BUILDROOT", "/",
],
),
+ "mkosi-as-caller" : MKOSI_AS_CALLER,
}
hd = stack.enter_context(finalize_host_scripts(state, helpers))
*(["--setenv", "BUILDDIR", "/work/build"] if state.config.build_dir else []),
],
),
+ "mkosi-as-caller" : MKOSI_AS_CALLER,
}
cmdline = state.args.cmdline if state.args.verb == Verb.build else []
"--setenv", "BUILDROOT", "/",
],
),
+ "mkosi-as-caller" : MKOSI_AS_CALLER,
}
with (
"--setenv", "BUILDROOT", "/",
],
),
+ "mkosi-as-caller" : MKOSI_AS_CALLER,
}
with (
the host system. This means that from a script, you can do e.g.
`dnf install vim` to install vim into the image.
+* `mkosi-as-caller`: This script uses `setpriv` to switch from
+ the user `root` in the user namespace used for various build steps
+ back to the original user that called mkosi. This is useful when
+ we want to invoke build steps which will write to $BUILDDIR and
+ we want to have the files owned by the calling user.
+
+ For example, a complete `mkosi.build` script might be the following:
+
+ ```sh
+ set -ex
+
+ rm -rf "$BUILDDIR/build"
+ mkosi-as-caller meson setup "$BUILDDIR/build" "$SRCDIR"
+ mkosi-as-caller meson compile -C "$BUILDDIR/build"
+ meson install -C "$BUILDDIR/build" --no-rebuild
+ ```
+
When scripts are executed, any directories that are still writable are
also made read-only (`/home`, `/var`, `/root`, ...) and only the minimal set
of directories that need to be writable remain writable. This is to