Image and initrd generators#
Four Bash scripts build the signed images and the initrd a target boots
with: shirudo-gen-image, shirudo-gen-runtime and
shirudo-gen-verity on the operator host, shirudo-gen-initrd on the
target.
Script |
Installed by, to |
Purpose |
|---|---|---|
|
operator package, |
Build a signed image from a directory. |
|
operator package, |
Build the signed runtime image and its |
|
operator package, |
Sign an existing ext4 image. |
|
target package, |
Build and check the initrd with the dracut module |
$(libexecdir) is /usr/libexec in the distribution packages and
/usr/local/libexec after make install. Every option of the scripts
takes its value as the next argument. None accepts --option=<value>.
A script that fails prints <script>: <reason> and exits with 1, or
with the status of the tool that failed. -h and --help print the
usage on standard output.
Runs on: as listed above. Requires: listed per script. Changes measured state: no. A target measures the images when it activates them.
shirudo-gen-image#
shirudo-gen-image --source <directory> --output <prefix> --keys-dir <dir>
[--kind config|runtime] [--size <mib>] [--builder <helper>]
Builds an ext4 file system of --size MiB from <directory> (owner
root, no journal, 4096-byte blocks) and signs it with
shirudo-gen-verity. It writes <prefix>.img, .verity,
.roothash and .p7s and replaces no existing file.
It refuses a source that contains a file named signing_key.pem, a
special file, a source that contains the keys directory, and for
--kind config any symbolic link. Files that do not fit --size
make it fail with <n> KiB of files do not fit an image of <size> MiB;
raise --size. Requires mkfs.ext4 and veritysetup.
Option |
Default |
Description |
|---|---|---|
|
required |
Directory that becomes the root of the image. |
|
required |
Output prefix. |
|
required |
Operator keys directory, outside |
|
|
|
|
1 |
File system size in MiB, 1 to 1048576. |
|
|
The helper that signs the root hash. |
shirudo-gen-runtime#
shirudo-gen-runtime --binary <shirudo> --bootstrap-conf <file>
--cert <certificate> --config-cert <certificate>
--output <prefix> --keys-dir <dir>
[--size <mib>] [--builder <helper>]
[--unit-output <file>] [--extra-binary <file>]...
[--config-cert <additional-certificate>]...
Builds the runtime image, the image whose root hash the bootstrap settings pin. It holds:
usr/bin/shirudo:--binary, the target binary without its symbols and debug sections, asllvm-stripwrites itetc/shirudo/shirudo.conf:--bootstrap-confkeys/cert.der:--cert, the initial BPF signing certificateetc/shirudo/config-cert.der: the first--config-cert; additional certificates areconfig-cert-2.der,config-cert-3.derand on. Any of them may sign a config imagefor a dynamically linked binary, its ELF interpreter and libraries under their own paths, found with
lddeach
--extra-binaryunderusr/bin/with its libraries
It prints the runtime invocation on standard error, for example
/run/shirudo/runtime/usr/bin/shirudo init for a static binary. With
--unit-output it writes a systemd drop-in for shirudo.service
that clears EnvironmentFile= and ExecStart= and runs the runtime
binary with init. No drop-in is written for the other units.
ldd runs the inputs’ dynamic loader on the operator host: pass only
trusted binaries. Requires readelf, ldd and llvm-strip.
Option |
Default |
Description |
|---|---|---|
|
required |
The |
|
required |
The bootstrap |
|
required |
The initial BPF signing certificate. |
|
required |
The config image verification certificate. Repeatable, at most 16.
With several certificates, the generator replaces the bootstrap’s
|
|
required |
Output prefix. |
|
required |
Operator keys directory that signs the image. |
|
15 |
File system size in MiB, 1 to 1048576. The default holds the
stripped static target binary and its certificates. A dynamic
binary with its libraries or an |
|
|
The signing helper. |
|
none |
Write the |
|
none |
A further trusted executable for the image. Repeatable. |
shirudo-gen-verity#
shirudo-gen-verity <filesystem-image> -o <prefix> [--kind config|runtime]
[--keys-dir <dir>] [--key <signing-key>]
[--cert <certificate>] [--salt <salt>]
[--builder <helper>]
Formats the dm-verity hash tree of an existing ext4 image with
veritysetup, signs the root hash, verifies the result and prints the
root hash. shirudo image describes it as shirudo image build, which
passes --builder itself.
Option |
Default |
Description |
|---|---|---|
|
required |
Output prefix. |
|
|
|
|
|
Directory of the signing key and certificate. |
|
from |
Signing key and certificate. |
|
chosen by |
64 hexadecimal characters. |
|
|
The signing helper. |
shirudo-gen-initrd#
shirudo-gen-initrd [--kver <release>] [--output <file>]
[--cert <certificate>] [--trusted-dir <dir>]
[--binary <file> --binary-path <path>]
[--unit <file>] [--bootstrap-conf <file>]
[--kmoddir <dir>] [--no-kernel] [--module-dir <dir>]
[-- <dracut-arguments>]
shirudo-gen-initrd --check [<file>] [--kver <release>] [--output <file>]
shirudo-gen-initrd --print-cmdline
Runs dracut --force --add shirudo for a kernel release, then checks
the result. It requires dracut, and root unless --output names
where to write: without it the initrd replaces the one the host boots.
Run as another user, dracut writes every member of the archive as owned
by root. The initrd holds the
binary at its root file system path, the primary certificate as
/etc/shirudo/keys/cert.der, the trusted certificates and their vouches
under /etc/shirudo/keys/trusted/, the bootstrap
/etc/shirudo/shirudo.conf and shirudo-initrd.service, enabled.
When --module-dir or the script’s own directory holds
module-setup.sh, dracut runs on a private copy of its base directory
whose modules.d/90shirudo is that module, and the host’s
/usr/lib/dracut is left as it is. Otherwise the module comes from
/usr/lib/dracut/modules.d/90shirudo. Paths given on the command line reach the module through a
generated dracut.conf that also leaves out the host’s drop-ins.
The check lists the archive with lsinitrd and fails unless it holds
the shirudo binary, etc/shirudo/keys/cert.der,
etc/shirudo/shirudo.conf, shirudo-initrd.service and its
enablement, systemd-pcrphase-initrd.service and
etc/initrd-release. After a build, the script warns when the running
kernel’s command line lacks bpf.keyring_unsealed=1 or
dm_verity.keyring_unsealed=1.
Option |
Default |
Description |
|---|---|---|
|
|
Kernel release. |
|
|
Initrd to write, or to check. |
|
the |
Only check an initrd. |
|
off |
Print the kernel parameters the initrd needs and exit. |
|
|
Primary certificate to embed. |
|
|
Further certificates and their vouches. |
|
the installed |
Binary to embed. Needs |
|
the binary’s path |
Where the binary lives on the root file system. |
|
the installed |
Unit to embed. |
|
|
Bootstrap settings to embed. The module fails without a readable file. |
|
dracut’s |
Take kernel modules from |
|
off |
Embed no kernel modules. |
|
the script’s directory |
The dracut module to build with. |
|
Pass the remaining arguments to |
Examples#
Build a config image from a directory:
operator$ /usr/libexec/shirudo/gen-image/shirudo-gen-image --source ./config-root --output ./config --keys-dir ~/shirudo-keys --kind config
Build the runtime image and its drop-in:
operator$ /usr/libexec/shirudo/gen-image/shirudo-gen-runtime --binary <target-binary> --bootstrap-conf bootstrap.conf --cert cert.der --config-cert config-cert.der --output ./runtime --keys-dir ~/shirudo-keys --unit-output ./runtime.conf
<target-binary> is the static shirudo of the target package.
Build the initrd for the running kernel and print the kernel parameters it needs:
target# shirudo-gen-initrd --bootstrap-conf <bootstrap-conf>
target# shirudo-gen-initrd --print-cmdline
bpf.keyring_unsealed=1 dm_verity.keyring_unsealed=1
<bootstrap-conf> is the bootstrap shirudo.conf that names the
runtime image (Configuration).