Skip to content

eBPF-based security platform

image: keep the generated runtime service in a template

KP Singh30b1f2f74cb7
diff --git a/tools/gen-image/README.md b/tools/gen-image/README.md
index 1b5267e7..ac493999 100644
--- a/tools/gen-image/README.md
+++ b/tools/gen-image/README.md
@@ -67,6 +67,10 @@ for `config.verification_key` in the bootstrap configuration. The initial
BPF certificate is `keys/cert.der` inside the image. Runtime images have no
shell or debugger unless the operator explicitly supplies one.
+The generated service content is kept in `runtime-service.conf.in` beside
+the scripts. Keep that template with the scripts when copying this directory.
+The generator substitutes only the interpreter and library paths.
+
Pass `--unit-output runtime-service.conf` to generate a systemd drop-in for
the root phase. Install it as
`/etc/systemd/system/shirudo.service.d/verity.conf`. It clears the writable
diff --git a/tools/gen-image/runtime-service.conf.in b/tools/gen-image/runtime-service.conf.in
new file mode 100644
index 00000000..14a3d2f2
--- /dev/null
+++ b/tools/gen-image/runtime-service.conf.in
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+[Service]
+EnvironmentFile=
+ExecStart=
+ExecStart=/run/shirudo/runtime@interpreter@ --inhibit-cache --library-path @library_path@ /run/shirudo/runtime/usr/bin/shirudo init
diff --git a/tools/gen-image/shirudo-gen-runtime b/tools/gen-image/shirudo-gen-runtime
index 04f3cdb5..b9198da5 100755
--- a/tools/gen-image/shirudo-gen-runtime
+++ b/tools/gen-image/shirudo-gen-runtime
@@ -115,13 +115,10 @@ if [ -n "$unit_output" ]; then
case "$interpreter$library_path" in *[[:space:]\\\"%]*) die 'runtime paths cannot be encoded in a systemd ExecStart' ;; esac
(
set -o noclobber
- cat >"$unit_output" <<EOF
-# SPDX-License-Identifier: BSD-2-Clause
-# Copyright (c) 2026 Authors of shirudo
-[Service]
-EnvironmentFile=
-ExecStart=
-ExecStart=/run/shirudo/runtime$interpreter --inhibit-cache --library-path $library_path /run/shirudo/runtime/usr/bin/shirudo init
-EOF
+ interpreter_escaped=$(printf '%s' "$interpreter" | sed 's/[\&|]/\\&/g')
+ library_path_escaped=$(printf '%s' "$library_path" | sed 's/[\&|]/\\&/g')
+ sed -e "s|@interpreter@|$interpreter_escaped|g" \
+ -e "s|@library_path@|$library_path_escaped|g" \
+ "$here/runtime-service.conf.in" >"$unit_output"
)
fi