Give each build container its own machine identity

A target whose tests enrol a service identity could not be built at all.
CultLib's Linux protector binds the seed to /etc/machine-id, the build image
carries none, and the runner is --read-only, so Odin's suite failed every
step with "Linux machine-id is unavailable".

Mounting the host's machine-id would let a build container protect a seed
that unwraps on the host, which is exactly the property the binding exists to
deny. So each frozen workspace now gets its own identity, derived from the
workspace path and mounted read-only: stable for the life of a build, and
useless anywhere else including this host.

Also moves Idunn's topology store to /var/lib/gamecult/idunn-projection. It
is Idunn's published surface -- every managed target must read it to verify
its own Expected incarnation -- and it was sitting inside Idunn's private
0750 root where no workload could traverse to it. Odin's own daemon already
named that directory in its tests.

Odin's three roots become writable for the same reason Heimdall's are: a
target Idunn cannot write is a target it cannot deploy.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-07 00:24:59 +02:00
commit da7dcf4b2d
2 changed files with 79 additions and 9 deletions

View file

@ -40,9 +40,9 @@ ExecStart=/usr/local/bin/idunn serve \
--bindings-dir /etc/gamecult/idunn/bindings \
--source-root /var/lib/gamecult/idunn/sources \
--staging-root /var/lib/gamecult/idunn/staging \
--topology-store /var/lib/gamecult/idunn/topology.cc \
--topology-store /var/lib/gamecult/idunn-projection/topology.cc \
--idunn-identity-store /var/lib/gamecult/idunn/idunn-service-identity.cc \
--odin-correlation-store /var/lib/gamecult/odin/idunn-runtime-topology.cc \
--odin-correlation-store /var/lib/gamecult/odin/topology.cc \
--odin-trust-anchor /etc/gamecult/idunn/odin-topology-anchor.cc \
--deployment-brake-operator-anchor /etc/gamecult/idunn/deployment-brake-operator-anchor.cc \
--source-uid 986 \
@ -69,19 +69,26 @@ ProtectSystem=full
ReadWritePaths=/etc/gamecult/idunn
ReadWritePaths=/etc/nginx/idunn-stream-routes
ReadWritePaths=/etc/systemd/system
ReadWritePaths=/var/lib/gamecult/idunn /var/lib/gamecult/idunn-authority
# idunn-projection is deliberately outside Idunn's own 0750 directory: the
# topology store is Idunn's *published* surface, and every managed target must
# read it to verify its own Expected incarnation against the Idunn anchor. It
# was inside the private root, where no workload could traverse to it.
ReadWritePaths=/var/lib/gamecult/idunn /var/lib/gamecult/idunn-authority /var/lib/gamecult/idunn-projection
ReadWritePaths=/srv/build
# One entry per managed target: its runtime root, state root and release root.
# A target Idunn cannot write is a target it cannot deploy, so this list grows
# by exactly three paths per migration and is the honest blast radius.
ReadWritePaths=/etc/gamecult/heimdall /var/lib/gamecult/heimdall /srv/heimdall/app
# Odin's directory is a managed target's, and is read-only on purpose: Idunn
# consumes Odin's published topology correlation to gate *deployment* promotion
# and nothing else. Continuity never consults it -- see
# stale_odin_provider_receipt_cannot_gate_continuity_restart -- and an absent
# Odin is a managed target like any other now, so its three roots are writable
# on the same terms. This used to be ReadOnlyPaths, on the reasoning that Idunn
# only *reads* Odin's correlation store to gate promotion. That remains true of
# the correlation itself -- continuity never consults it, see
# stale_odin_provider_receipt_cannot_gate_continuity_restart, and an absent
# store yields None rather than an error, so Odin being down blocks promotions
# and leaves daemon survival untouched.
ReadOnlyPaths=/var/lib/gamecult/odin
# and leaves daemon survival untouched. But a target Idunn cannot write is a
# target it cannot deploy, and Odin has to be deployable: it is the bootstrap
# target every other target's warming presence is observed through.
ReadWritePaths=/etc/gamecult/odin /var/lib/gamecult/odin /srv/odin
[Install]
WantedBy=multi-user.target

View file

@ -1245,6 +1245,8 @@ impl DockerRunnerDriver {
"/tmp:rw,nosuid,nodev,noexec,size={}m",
runner.tmpfs_mebibytes
)),
OsString::from("--mount"),
bind_mount(&build_machine_id_file(workspace)?, "/etc/machine-id", true)?,
];
if let Some(cache_root) = &runner.cache_root {
ensure_runner_cache_root(cache_root, identity)?;
@ -5867,6 +5869,47 @@ fn remove_exact_root_owned_file(path: &Path, mode: u32) -> Result<()> {
sync_parent_directory(path)
}
/// A build container's own machine identity, mounted read-only at
/// `/etc/machine-id`.
///
/// The image carries no machine-id, and code that binds a service identity to
/// the machine -- CultLib's Linux protector does exactly this -- cannot run
/// without one, so a target whose tests enrol an identity cannot be built at
/// all. The host's machine-id is not the answer: it would let a build container
/// protect a seed that unwraps on the host, which is precisely the property the
/// binding exists to deny.
///
/// So each frozen workspace gets its own identity, derived from the workspace
/// path. It is stable for the life of a build, and an identity enrolled inside
/// one is unusable anywhere else, including on this host.
fn build_machine_id(workspace: &Path) -> Result<String> {
let text = workspace
.to_str()
.context("frozen workspace path is not UTF-8")?;
// systemd machine-id format: exactly 32 lowercase hex digits.
let digest = sha256_id(text.as_bytes());
Ok(digest
.strip_prefix("sha256-")
.unwrap_or(&digest)
.chars()
.take(32)
.collect())
}
fn build_machine_id_file(workspace: &Path) -> Result<PathBuf> {
let root = PathBuf::from("/run/idunn/build-machine-ids");
fs::create_dir_all(&root).context("creating the build machine-id root")?;
let id = build_machine_id(workspace)?;
let path = root.join(&id);
if !path.exists() {
fs::write(&path, format!("{id}
")).context("writing the build machine-id")?;
fs::set_permissions(&path, std::os::unix::fs::PermissionsExt::from_mode(0o444))
.context("sealing the build machine-id")?;
}
Ok(path)
}
fn bind_mount(source: &Path, destination: &str, read_only: bool) -> Result<OsString> {
ensure!(source.is_absolute(), "Docker bind source is not absolute");
let text = source.to_str().context("Docker bind source is not UTF-8")?;
@ -6467,6 +6510,26 @@ fn apply_identity(command: &mut Command, identity: Option<ProcessIdentity>) -> R
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn build_machine_id_is_well_formed_per_workspace_and_never_the_host() {
let first = build_machine_id(Path::new("/var/lib/gamecult/idunn/staging/tx-a")).unwrap();
let second = build_machine_id(Path::new("/var/lib/gamecult/idunn/staging/tx-b")).unwrap();
assert_eq!(first.len(), 32);
assert!(first.chars().all(|c| c.is_ascii_hexdigit() && !c.is_uppercase()));
assert_ne!(first, second);
assert_eq!(
first,
build_machine_id(Path::new("/var/lib/gamecult/idunn/staging/tx-a")).unwrap(),
"a workspace's build identity must be stable for the life of the build"
);
// The point of the derived identity is that it is not this host's: an
// identity a build enrols must not unwrap anywhere but that build.
if let Ok(host) = std::fs::read_to_string("/etc/machine-id") {
assert_ne!(first, host.trim());
}
}
use cultnet_rs::{
GameCultProviderHealthIdentity, IDUNN_EXPECTED_INCARNATION_SCHEMA,
IDUNN_PROCESS_WRITE_LEASE_SCHEMA, IdunnServiceIdentity,