Bind Idunn deployment and runtime admission

This commit is contained in:
Meta Vens 2026-09-02 13:53:07 +02:00
commit 32cbb5f028
9 changed files with 3608 additions and 217 deletions

File diff suppressed because it is too large Load diff

View file

@ -41,6 +41,14 @@ pub fn run(args: impl IntoIterator<Item = String>) -> Result<()> {
let command = args.next().ok_or_else(|| anyhow!(usage()))?;
let options = parse_options(args)?;
match command.as_str() {
"enroll-provider-health-identity" => {
let public_key = enroll_provider_health_identity(&options)?;
println!("{public_key}");
}
"provider-health-public-key" => {
let public_key = provider_health_public_key(&options)?;
println!("{public_key}");
}
"enroll-idunn-identity" => {
require_only(&options, &["private-store"])?;
enroll_service_identity_at::<IdunnServiceIdentity>(&path(&options, "private-store")?)?;
@ -76,6 +84,7 @@ pub fn run(args: impl IntoIterator<Item = String>) -> Result<()> {
"deployment-brake-status" => deployment_brake_status(&options)?,
"create-daemon-health-trust-binding" => create_health_binding(&options)?,
"add-daemon-health-trust-binding" => add_health_binding(&options)?,
"require-daemon-health-release-binding" => require_health_binding_release(&options)?,
"rotate-daemon-health-trust-signer" => rotate_health_binding_signer(&options)?,
"validate-daemon-health-trust-binding" => {
require_only(&options, &["input"])?;
@ -88,6 +97,24 @@ pub fn run(args: impl IntoIterator<Item = String>) -> Result<()> {
Ok(())
}
fn enroll_provider_health_identity(options: &BTreeMap<String, String>) -> Result<String> {
require_only(options, &["private-store"])?;
let signer = enroll_service_identity_at::<GameCultProviderHealthIdentity>(&path(
options,
"private-store",
)?)?;
encode_public_key(&signer.entry().public_key)
}
fn provider_health_public_key(options: &BTreeMap<String, String>) -> Result<String> {
require_only(options, &["private-store"])?;
let signer = open_service_identity_at::<GameCultProviderHealthIdentity>(&path(
options,
"private-store",
)?)?;
encode_public_key(&signer.entry().public_key)
}
fn deployment_brake_engage(options: &BTreeMap<String, String>) -> Result<()> {
require_only(
options,
@ -191,11 +218,24 @@ fn deployment_brake_status(options: &BTreeMap<String, String>) -> Result<()> {
"now-unix-millis",
],
)?;
let exact_actuation_fields = ["release-id", "deployment-id", "now-unix-millis"];
let exact_actuation_field_count = exact_actuation_fields
.into_iter()
.filter(|field| options.contains_key(*field))
.count();
if exact_actuation_field_count != 0
&& exact_actuation_field_count != exact_actuation_fields.len()
{
bail!("exact deployment-brake actuation validation requires release, deployment, and time");
}
let record = read_brake(&path(options, "store")?)?;
if record.runtime_id != required(options, "runtime-id")? {
bail!("deployment brake belongs to another runtime")
}
if record.status == "engaged" {
if exact_actuation_field_count != 0 {
bail!("engaged deployment brake denies exact actuation validation");
}
println!(
"engaged runtime={} scope={} owner={} reason={}",
record.runtime_id, record.scope, record.updated_by, record.reason
@ -288,11 +328,19 @@ fn read_operator_anchor(path: &Path) -> Result<ServiceIdentityTrustAnchor> {
fn validate_health_binding_store(path: &Path) -> Result<()> {
let entries = SingleFileMessagePackBackingStore::new(path).pull_all_read_only_snapshot()?;
validated_health_bindings(&entries)?;
Ok(())
}
fn validated_health_bindings(
entries: &[CultCacheEnvelope],
) -> Result<Vec<IdunnDaemonHealthTrustBindingRecord>> {
if entries.is_empty() {
bail!("daemon health trust store is empty");
}
let mut keys = BTreeSet::new();
let mut tuples = BTreeSet::new();
let mut bindings = Vec::with_capacity(entries.len());
for envelope in entries {
if envelope.r#type != IdunnDaemonHealthTrustBindingRecord::TYPE
|| envelope.schema_id.as_deref() != Some(IDUNN_DAEMON_HEALTH_TRUST_BINDING_SCHEMA)
@ -307,15 +355,16 @@ fn validate_health_binding_store(path: &Path) -> Result<()> {
binding.validate()?;
if !keys.insert(binding.binding_id.clone())
|| !tuples.insert((
binding.daemon_id,
binding.health_contract,
binding.source_runtime_id,
binding.daemon_id.clone(),
binding.health_contract.clone(),
binding.source_runtime_id.clone(),
))
{
bail!("trust store contains a duplicate binding id or tuple");
}
bindings.push(binding);
}
Ok(())
Ok(bindings)
}
fn create_health_binding(options: &BTreeMap<String, String>) -> Result<()> {
@ -431,6 +480,91 @@ fn add_health_binding(options: &BTreeMap<String, String>) -> Result<()> {
Ok(())
}
fn require_health_binding_release(options: &BTreeMap<String, String>) -> Result<()> {
require_only(
options,
&[
"store",
"binding-id",
"daemon",
"health-contract",
"source-runtime",
"signer-public-key-hex",
],
)?;
let store_path = path(options, "store")?;
let store = SingleFileMessagePackBackingStore::new(&store_path);
let entries = store.pull_all_read_only_snapshot()?;
let signer_public_key = decode_public_key(required(options, "signer-public-key-hex")?)?;
require_health_binding_release_from_snapshot(
&store,
entries,
required(options, "binding-id")?,
required(options, "daemon")?,
required(options, "health-contract")?,
required(options, "source-runtime")?,
&signer_public_key,
)
}
fn require_health_binding_release_from_snapshot(
store: &SingleFileMessagePackBackingStore,
entries: Vec<CultCacheEnvelope>,
binding_id: &str,
daemon_id: &str,
health_contract: &str,
source_runtime_id: &str,
signer_public_key: &[u8],
) -> Result<()> {
let bindings = validated_health_bindings(&entries)?;
let target_index = bindings
.iter()
.position(|binding| binding.binding_id == binding_id)
.ok_or_else(|| anyhow!("named daemon health trust binding does not exist"))?;
let current = &bindings[target_index];
if current.daemon_id != daemon_id
|| current.health_contract != health_contract
|| current.source_runtime_id != source_runtime_id
|| current.signer_public_key != signer_public_key
{
bail!("named daemon health trust binding does not match the expected immutable fields");
}
if current.release_binding_required {
return Ok(());
}
let mut next = current.clone();
next.release_binding_required = true;
next.validate()?;
let mut replacement = entries[target_index].clone();
replacement.payload = rmp_serde::to_vec(&next)?;
let expected = entries
.into_iter()
.map(|envelope| CultCacheExpectedEnvelope {
r#type: envelope.r#type.clone(),
key: envelope.key.clone(),
current: Some(envelope),
})
.collect::<Vec<_>>();
if !store.compare_exchange(&expected, &[replacement])? {
let latest_entries = store.pull_all_read_only_snapshot()?;
let latest_bindings = validated_health_bindings(&latest_entries)?;
if let Some(latest) = latest_bindings
.iter()
.find(|binding| binding.binding_id == binding_id)
&& latest.daemon_id == daemon_id
&& latest.health_contract == health_contract
&& latest.source_runtime_id == source_runtime_id
&& latest.signer_public_key == signer_public_key
&& latest.release_binding_required
{
return Ok(());
}
bail!("daemon health trust store changed during release-binding transition");
}
Ok(())
}
fn rotate_health_binding_signer(options: &BTreeMap<String, String>) -> Result<()> {
require_only(
options,
@ -723,6 +857,19 @@ fn decode_public_key(value: &str) -> Result<Vec<u8>> {
.collect()
}
fn encode_public_key(value: &[u8]) -> Result<String> {
if value.len() != 32 {
bail!("provider health public key must be exactly 32 bytes");
}
const HEX: &[u8; 16] = b"0123456789abcdef";
let mut encoded = String::with_capacity(64);
for byte in value {
encoded.push(HEX[(byte >> 4) as usize] as char);
encoded.push(HEX[(byte & 0x0f) as usize] as char);
}
Ok(encoded)
}
fn refuse_existing(path: &Path, label: &str) -> Result<()> {
if path.exists() {
bail!(
@ -760,7 +907,7 @@ fn normalized(path: &Path) -> Result<PathBuf> {
}
fn usage() -> &'static str {
"Usage: idunn-provision enroll-idunn-identity --private-store <path>\n idunn-provision export-idunn-public-anchor --private-store <path> --public-anchor <path>\n idunn-provision enroll-deployment-brake-operator --private-store <path>\n idunn-provision export-deployment-brake-operator-anchor --private-store <path> --public-anchor <path>\n idunn-provision deployment-brake-engage --store <path> --runtime-id <id> --owner <principal> --reason <text> --observed-at-unix-millis <u64>\n idunn-provision deployment-brake-release --store <path> --private-store <path> --runtime-id <id> --owner <principal> --reason <text> --authorization-id <id> --release-id <id> --deployment-id <id> --issued-at-unix-millis <u64> --expires-at-unix-millis <u64>\n idunn-provision deployment-brake-status --store <path> --operator-anchor <path> --runtime-id <id> [--release-id <id> --deployment-id <id> --now-unix-millis <u64>]\n idunn-provision create-daemon-health-trust-binding --output <path> --binding-id <id> --daemon <id> --health-contract <id> --source-runtime <id> --signer-public-key-hex <hex> --bound-at-unix-millis <u64> --release-binding-required <true|false>\n idunn-provision add-daemon-health-trust-binding --output <path> --binding-id <id> --daemon <id> --health-contract <id> --source-runtime <id> --signer-public-key-hex <hex> --bound-at-unix-millis <u64> --release-binding-required <true|false>\n idunn-provision rotate-daemon-health-trust-signer --output <path> --binding-id <id> --signer-public-key-hex <hex> --bound-at-unix-millis <u64>\n idunn-provision validate-daemon-health-trust-binding --input <path>\n idunn-provision create-provider-projection-trust-anchor --output <path> --trust-anchor-id <id> --runtime-id <id> --idunn-public-anchor <path> --bound-at-unix-millis <u64> --expires-at-unix-millis <u64>\n idunn-provision validate-provider-projection-trust-anchor --input <path> --idunn-public-anchor <path>"
"Usage: idunn-provision enroll-provider-health-identity --private-store <path>\n idunn-provision provider-health-public-key --private-store <path>\n idunn-provision enroll-idunn-identity --private-store <path>\n idunn-provision export-idunn-public-anchor --private-store <path> --public-anchor <path>\n idunn-provision enroll-deployment-brake-operator --private-store <path>\n idunn-provision export-deployment-brake-operator-anchor --private-store <path> --public-anchor <path>\n idunn-provision deployment-brake-engage --store <path> --runtime-id <id> --owner <principal> --reason <text> --observed-at-unix-millis <u64>\n idunn-provision deployment-brake-release --store <path> --private-store <path> --runtime-id <id> --owner <principal> --reason <text> --authorization-id <id> --release-id <id> --deployment-id <id> --issued-at-unix-millis <u64> --expires-at-unix-millis <u64>\n idunn-provision deployment-brake-status --store <path> --operator-anchor <path> --runtime-id <id> [--release-id <id> --deployment-id <id> --now-unix-millis <u64>]\n idunn-provision create-daemon-health-trust-binding --output <path> --binding-id <id> --daemon <id> --health-contract <id> --source-runtime <id> --signer-public-key-hex <hex> --bound-at-unix-millis <u64> --release-binding-required <true|false>\n idunn-provision add-daemon-health-trust-binding --output <path> --binding-id <id> --daemon <id> --health-contract <id> --source-runtime <id> --signer-public-key-hex <hex> --bound-at-unix-millis <u64> --release-binding-required <true|false>\n idunn-provision require-daemon-health-release-binding --store <path> --binding-id <id> --daemon <id> --health-contract <id> --source-runtime <id> --signer-public-key-hex <hex>\n idunn-provision rotate-daemon-health-trust-signer --output <path> --binding-id <id> --signer-public-key-hex <hex> --bound-at-unix-millis <u64>\n idunn-provision validate-daemon-health-trust-binding --input <path>\n idunn-provision create-provider-projection-trust-anchor --output <path> --trust-anchor-id <id> --runtime-id <id> --idunn-public-anchor <path> --bound-at-unix-millis <u64> --expires-at-unix-millis <u64>\n idunn-provision validate-provider-projection-trust-anchor --input <path> --idunn-public-anchor <path>"
}
#[cfg(test)]
@ -817,6 +964,50 @@ mod tests {
]
}
const TEST_SIGNER_HEX: &str =
"1111111111111111111111111111111111111111111111111111111111111111";
const WRONG_SIGNER_HEX: &str =
"2222222222222222222222222222222222222222222222222222222222222222";
fn write_test_binding(
command: &str,
store: &str,
id: &str,
daemon: &str,
runtime: &str,
) -> Result<()> {
invoke(&binding_args(command, store, id, daemon, runtime))
}
fn require_test_binding(
store: &str,
id: &str,
daemon: &str,
contract: &str,
runtime: &str,
signer: &str,
) -> Result<()> {
invoke(&[
"require-daemon-health-release-binding",
"--store",
store,
"--binding-id",
id,
"--daemon",
daemon,
"--health-contract",
contract,
"--source-runtime",
runtime,
"--signer-public-key-hex",
signer,
])
}
fn store_snapshot(path: &Path) -> Result<Vec<CultCacheEnvelope>> {
SingleFileMessagePackBackingStore::new(path).pull_all_read_only_snapshot()
}
#[test]
fn append_health_binding_preserves_existing_and_rejects_collisions_and_aliens() -> Result<()> {
let temp = TempDir::new()?;
@ -891,6 +1082,253 @@ mod tests {
Ok(())
}
#[test]
fn require_release_binding_changes_only_the_named_flag_and_is_idempotent() -> Result<()> {
let temp = TempDir::new()?;
let store = temp.path().join("trust.cc");
let path = store.to_str().unwrap();
write_test_binding(
"create-daemon-health-trust-binding",
path,
"one",
"daemon-one",
"runtime-one",
)?;
write_test_binding(
"add-daemon-health-trust-binding",
path,
"two",
"daemon-two",
"runtime-two",
)?;
let before = store_snapshot(&store)?;
require_test_binding(
path,
"one",
"daemon-one",
"provider.health",
"runtime-one",
TEST_SIGNER_HEX,
)?;
let after = store_snapshot(&store)?;
let before_target = before.iter().find(|entry| entry.key == "one").unwrap();
let after_target = after.iter().find(|entry| entry.key == "one").unwrap();
let mut expected: IdunnDaemonHealthTrustBindingRecord =
rmp_serde::from_slice(&before_target.payload)?;
expected.release_binding_required = true;
assert_eq!(
rmp_serde::from_slice::<IdunnDaemonHealthTrustBindingRecord>(&after_target.payload)?,
expected
);
let mut expected_envelope = before_target.clone();
expected_envelope.payload = after_target.payload.clone();
assert_eq!(after_target, &expected_envelope);
assert_eq!(
after.iter().find(|entry| entry.key == "two"),
before.iter().find(|entry| entry.key == "two")
);
require_test_binding(
path,
"one",
"daemon-one",
"provider.health",
"runtime-one",
TEST_SIGNER_HEX,
)?;
assert_eq!(store_snapshot(&store)?, after);
require_health_binding_release_from_snapshot(
&SingleFileMessagePackBackingStore::new(&store),
before,
"one",
"daemon-one",
"provider.health",
"runtime-one",
&decode_public_key(TEST_SIGNER_HEX)?,
)?;
Ok(())
}
#[test]
fn require_release_binding_refuses_wrong_identity_and_invalid_store_without_writing()
-> Result<()> {
let temp = TempDir::new()?;
let store = temp.path().join("trust.cc");
let path = store.to_str().unwrap();
write_test_binding(
"create-daemon-health-trust-binding",
path,
"one",
"daemon-one",
"runtime-one",
)?;
let before = store_snapshot(&store)?;
for (id, daemon, contract, runtime, signer) in [
(
"one",
"wrong",
"provider.health",
"runtime-one",
TEST_SIGNER_HEX,
),
("one", "daemon-one", "wrong", "runtime-one", TEST_SIGNER_HEX),
(
"one",
"daemon-one",
"provider.health",
"wrong",
TEST_SIGNER_HEX,
),
(
"one",
"daemon-one",
"provider.health",
"runtime-one",
WRONG_SIGNER_HEX,
),
(
"missing",
"daemon-one",
"provider.health",
"runtime-one",
TEST_SIGNER_HEX,
),
] {
assert!(require_test_binding(path, id, daemon, contract, runtime, signer).is_err());
}
assert!(
invoke(&[
"require-daemon-health-release-binding",
"--store",
path,
"--binding-id",
"one",
"--daemon",
"daemon-one",
"--health-contract",
"provider.health",
"--signer-public-key-hex",
TEST_SIGNER_HEX,
])
.is_err()
);
assert_eq!(store_snapshot(&store)?, before);
SingleFileMessagePackBackingStore::new(&store).push(&CultCacheEnvelope {
key: "alien".into(),
r#type: "alien".into(),
payload: vec![],
stored_at: "2026-07-19T20:00:00Z".into(),
schema_id: Some("alien.v0".into()),
})?;
let foreign = store_snapshot(&store)?;
assert!(
require_test_binding(
path,
"one",
"daemon-one",
"provider.health",
"runtime-one",
TEST_SIGNER_HEX,
)
.is_err()
);
assert_eq!(store_snapshot(&store)?, foreign);
let ambiguous = temp.path().join("ambiguous.cc");
let ambiguous_path = ambiguous.to_str().unwrap();
write_test_binding(
"create-daemon-health-trust-binding",
ambiguous_path,
"one",
"daemon-one",
"runtime-one",
)?;
let mut duplicate: IdunnDaemonHealthTrustBindingRecord =
rmp_serde::from_slice(&store_snapshot(&ambiguous)?.remove(0).payload)?;
duplicate.binding_id = "duplicate".into();
SingleFileMessagePackBackingStore::new(&ambiguous).push(&typed_envelope(
&duplicate.binding_id,
&duplicate,
IDUNN_DAEMON_HEALTH_TRUST_BINDING_SCHEMA,
duplicate.bound_at_unix_millis,
)?)?;
let ambiguous_before = store_snapshot(&ambiguous)?;
assert!(
require_test_binding(
ambiguous_path,
"one",
"daemon-one",
"provider.health",
"runtime-one",
TEST_SIGNER_HEX,
)
.is_err()
);
assert_eq!(store_snapshot(&ambiguous)?, ambiguous_before);
Ok(())
}
#[test]
fn require_release_binding_cas_covers_the_whole_validated_store() -> Result<()> {
let temp = TempDir::new()?;
let store_path = temp.path().join("trust.cc");
let path = store_path.to_str().unwrap();
write_test_binding(
"create-daemon-health-trust-binding",
path,
"one",
"daemon-one",
"runtime-one",
)?;
write_test_binding(
"add-daemon-health-trust-binding",
path,
"two",
"daemon-two",
"runtime-two",
)?;
let stale = store_snapshot(&store_path)?;
require_test_binding(
path,
"two",
"daemon-two",
"provider.health",
"runtime-two",
TEST_SIGNER_HEX,
)?;
let store = SingleFileMessagePackBackingStore::new(&store_path);
let error = require_health_binding_release_from_snapshot(
&store,
stale,
"one",
"daemon-one",
"provider.health",
"runtime-one",
&decode_public_key(TEST_SIGNER_HEX)?,
)
.unwrap_err();
assert!(error.to_string().contains("changed during release-binding"));
let records = validated_health_bindings(&store_snapshot(&store_path)?)?;
assert!(
!records
.iter()
.find(|binding| binding.binding_id == "one")
.unwrap()
.release_binding_required
);
assert!(
records
.iter()
.find(|binding| binding.binding_id == "two")
.unwrap()
.release_binding_required
);
Ok(())
}
#[test]
fn concurrent_health_binding_appends_have_one_cas_winner() -> Result<()> {
let temp = TempDir::new()?;
@ -938,6 +1376,106 @@ mod tests {
Ok(())
}
#[test]
fn provider_health_identity_enrollment_is_profile_exact_and_immutable() -> Result<()> {
let temp = TempDir::new()?;
let private = temp.path().join("provider-health-identity.cc");
let options = BTreeMap::from([(
"private-store".to_string(),
private.to_string_lossy().into_owned(),
)]);
let public_key_hex = enroll_provider_health_identity(&options)?;
let signer = open_service_identity_at::<GameCultProviderHealthIdentity>(&private)?;
assert_eq!(
public_key_hex,
encode_public_key(&signer.entry().public_key)?
);
assert_eq!(
decode_public_key(&public_key_hex)?,
signer.entry().public_key
);
let entries =
SingleFileMessagePackBackingStore::new(&private).pull_all_read_only_snapshot()?;
let [entry] = entries.as_slice() else {
panic!("provider health identity store must contain exactly one entry");
};
assert_eq!(entry.r#type, GameCultProviderHealthIdentity::PRIVATE_TYPE);
assert_eq!(entry.key, GameCultProviderHealthIdentity::PRIVATE_KEY);
assert_eq!(
entry.schema_id.as_deref(),
Some(GameCultProviderHealthIdentity::PRIVATE_SCHEMA)
);
assert!(open_service_identity_at::<IdunnServiceIdentity>(&private).is_err());
let before = std::fs::read(&private)?;
assert!(
invoke(&[
"enroll-provider-health-identity",
"--private-store",
private.to_str().unwrap(),
])
.is_err()
);
assert_eq!(std::fs::read(&private)?, before);
let unauthorized = temp.path().join("unauthorized.cc");
assert!(
invoke(&[
"enroll-provider-health-identity",
"--private-store",
unauthorized.to_str().unwrap(),
"--release-binding-required",
"true",
])
.is_err()
);
assert!(!unauthorized.exists());
Ok(())
}
#[test]
fn provider_health_public_key_is_read_only_and_rejects_wrong_profile_or_options() -> Result<()>
{
let temp = TempDir::new()?;
let provider = temp.path().join("provider-health.cc");
let provider_options = BTreeMap::from([(
"private-store".to_string(),
provider.to_string_lossy().into_owned(),
)]);
let expected = enroll_provider_health_identity(&provider_options)?;
let provider_before = std::fs::read(&provider)?;
assert_eq!(provider_health_public_key(&provider_options)?, expected);
assert_eq!(std::fs::read(&provider)?, provider_before);
let wrong_profile = temp.path().join("idunn.cc");
enroll_service_identity_at::<IdunnServiceIdentity>(&wrong_profile)?;
let wrong_before = std::fs::read(&wrong_profile)?;
assert!(
invoke(&[
"provider-health-public-key",
"--private-store",
wrong_profile.to_str().unwrap(),
])
.is_err()
);
assert_eq!(std::fs::read(&wrong_profile)?, wrong_before);
assert!(
invoke(&[
"provider-health-public-key",
"--private-store",
provider.to_str().unwrap(),
"--release-binding-required",
"true",
])
.is_err()
);
assert_eq!(std::fs::read(&provider)?, provider_before);
Ok(())
}
#[test]
fn identity_enrollment_and_export_are_immutable_and_paths_cannot_alias() -> Result<()> {
let temp = TempDir::new()?;
@ -1292,6 +1830,33 @@ mod tests {
"100",
])?;
assert_eq!(read_brake(&store)?.status, "engaged");
invoke(&[
"deployment-brake-status",
"--store",
store.to_str().unwrap(),
"--operator-anchor",
anchor.to_str().unwrap(),
"--runtime-id",
"yggdrasil",
])?;
assert!(
invoke(&[
"deployment-brake-status",
"--store",
store.to_str().unwrap(),
"--operator-anchor",
anchor.to_str().unwrap(),
"--runtime-id",
"yggdrasil",
"--release-id",
"commit-4",
"--deployment-id",
"request-4",
"--now-unix-millis",
"150",
])
.is_err()
);
invoke(&[
"deployment-brake-release",
"--store",

View file

@ -32,7 +32,7 @@ pub const IDUNN_DEPLOYMENT_REQUEST_SCHEMA: &str = "idunn.deployment_request.v2";
pub const IDUNN_CURRENT_DEPLOYMENT_REQUEST_SCHEMA: &str = "idunn.current_deployment_request.v1";
pub const IDUNN_DEPLOYMENT_RESULT_SCHEMA: &str = "idunn.deployment_result.v1";
pub const IDUNN_LIFECYCLE_COMMAND_SCHEMA: &str = "idunn.lifecycle_command.v1";
pub const IDUNN_RELEASE_TARGET_SCHEMA: &str = "idunn.release_target.v2";
pub const IDUNN_RELEASE_TARGET_SCHEMA: &str = "idunn.release_target.v3";
pub const IDUNN_DEPLOYMENT_ARTIFACT_SCHEMA: &str = "idunn.deployment_artifact.v2";
pub const BIFROST_REPOSITORY_RELEASE_AUTHORITY_SCHEMA: &str =
"bifrost.repository_release_authority.v1";
@ -50,6 +50,10 @@ pub const IDUNN_RUDP_HEALTH_INGRESS_SCHEMA: &str = "idunn.rudp_health_ingress.v1
pub const IDUNN_DAEMON_HEALTH_TRUST_BINDING_SCHEMA: &str = "idunn.daemon_health_trust_binding.v1";
pub const IDUNN_AUTHENTICATED_DAEMON_HEALTH_ADMISSION_SCHEMA: &str =
"idunn.authenticated_daemon_health_admission.v1";
pub const IDUNN_RUNTIME_TRAFFIC_ADMISSION_SCHEMA: &str = "idunn.runtime_traffic_admission.v2";
pub const IDUNN_CODEX_CONNECTOR_RUNTIME_TRAFFIC_ADMISSION_RECORD_KEY: &str =
"yggdrasil-codex-connector";
pub const IDUNN_GHOSTLIGHT_RUNTIME_TRAFFIC_ADMISSION_RECORD_KEY: &str = "yggdrasil-ghostlight";
pub const IDUNN_UNSIGNED_DAEMON_HEALTH_DIAGNOSTIC_SCHEMA: &str =
"idunn.unsigned_daemon_health_diagnostic.v1";
pub const MUNINN_TELEMETRY_SURFACE_SCHEMA: &str = "muninn.telemetry_surface.v1";
@ -432,6 +436,8 @@ pub struct IdunnAuthenticatedDaemonHealthAdmissionRecord {
pub deployment_id: Option<String>,
#[cultcache(key = 17)]
pub private_state_exposed: bool,
#[cultcache(key = 18, default)]
pub activation_witness_sha256: Option<String>,
}
impl IdunnAuthenticatedDaemonHealthAdmissionRecord {
@ -462,6 +468,13 @@ impl IdunnAuthenticatedDaemonHealthAdmissionRecord {
&self.source_commit,
)?;
validate_optional_identifier(&self.deployment_id, "deployment id")?;
if self
.activation_witness_sha256
.as_deref()
.is_some_and(|value| !is_sha256(value))
{
bail!("authenticated daemon health activation witness is malformed");
}
if self.private_state_exposed {
bail!("authenticated daemon health admission exposes private state");
}
@ -469,6 +482,71 @@ impl IdunnAuthenticatedDaemonHealthAdmissionRecord {
}
}
/// Idunn-issued traffic authority for a release that has proved its exact
/// deployment, activation, and authenticated provider-health lineage.
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
#[cultcache(
type = "idunn.runtime_traffic_admission",
schema = "idunn.runtime_traffic_admission.v2"
)]
pub struct IdunnRuntimeTrafficAdmissionRecord {
#[cultcache(key = 0)]
pub schema_version: String,
#[cultcache(key = 1)]
pub daemon_id: String,
#[cultcache(key = 2)]
pub release_id: String,
#[cultcache(key = 3)]
pub release_witness_sha256: String,
#[cultcache(key = 4)]
pub source_commit: String,
#[cultcache(key = 5)]
pub deployment_id: String,
#[cultcache(key = 6)]
pub activation_witness_sha256: String,
#[cultcache(key = 7)]
pub signed_health_sha256: String,
#[cultcache(key = 8)]
pub publisher_incarnation_id: String,
#[cultcache(key = 9)]
pub publisher_sequence: u64,
#[cultcache(key = 10)]
pub signer_identity_id: String,
#[cultcache(key = 11)]
pub runtime_process_id: u32,
#[cultcache(key = 12)]
pub runtime_process_starttime_ticks: u64,
}
impl IdunnRuntimeTrafficAdmissionRecord {
pub fn validate(&self) -> Result<()> {
if self.schema_version != IDUNN_RUNTIME_TRAFFIC_ADMISSION_SCHEMA {
bail!("runtime traffic admission schema is unsupported");
}
if self.daemon_id != IDUNN_CODEX_CONNECTOR_RUNTIME_TRAFFIC_ADMISSION_RECORD_KEY
&& self.daemon_id != IDUNN_GHOSTLIGHT_RUNTIME_TRAFFIC_ADMISSION_RECORD_KEY
{
bail!("runtime traffic admission daemon is unsupported");
}
validate_identifier(&self.daemon_id, "daemon id")?;
validate_identifier(&self.release_id, "release id")?;
validate_identifier(&self.deployment_id, "deployment id")?;
validate_identifier(&self.publisher_incarnation_id, "publisher incarnation id")?;
validate_identifier(&self.signer_identity_id, "signer identity id")?;
if !is_sha256(&self.release_witness_sha256)
|| !is_lower_hex(&self.source_commit, 40)
|| !is_sha256(&self.activation_witness_sha256)
|| !is_sha256(&self.signed_health_sha256)
|| self.publisher_sequence == 0
|| self.runtime_process_id == 0
|| self.runtime_process_starttime_ticks == 0
{
bail!("runtime traffic admission lineage is malformed");
}
Ok(())
}
}
/// Quarantined observation of the retired unsigned wire contract. This may
/// explain missing authenticated health but can never satisfy managed health.
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
@ -721,7 +799,7 @@ pub struct IdunnLifecycleCommandRecord {
}
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
#[cultcache(type = "idunn.release_target", schema = "idunn.release_target.v2")]
#[cultcache(type = "idunn.release_target", schema = "idunn.release_target.v3")]
pub struct IdunnReleaseTargetRecord {
#[cultcache(key = 0)]
pub target_id: String,
@ -765,6 +843,8 @@ pub struct IdunnReleaseTargetRecord {
pub requires_bifrost_authority: bool,
#[cultcache(key = 20, default)]
pub observed_upstream_revision: String,
#[cultcache(key = 21)]
pub minimum_source_revision: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
@ -1786,6 +1866,7 @@ cultmesh_rs::cultmesh_documents!(OdinDocuments {
IdunnSignedDaemonHealthRecord => IDUNN_SIGNED_DAEMON_HEALTH_SCHEMA,
IdunnDaemonHealthTrustBindingRecord => IDUNN_DAEMON_HEALTH_TRUST_BINDING_SCHEMA,
IdunnAuthenticatedDaemonHealthAdmissionRecord => IDUNN_AUTHENTICATED_DAEMON_HEALTH_ADMISSION_SCHEMA,
IdunnRuntimeTrafficAdmissionRecord => IDUNN_RUNTIME_TRAFFIC_ADMISSION_SCHEMA,
IdunnUnsignedDaemonHealthDiagnosticRecord => IDUNN_UNSIGNED_DAEMON_HEALTH_DIAGNOSTIC_SCHEMA,
GameCultServiceTrustAnchorRecord => GAMECULT_SERVICE_TRUST_ANCHOR_SCHEMA,
IdunnAuthenticatedProviderHealthProjectionRecord => IDUNN_AUTHENTICATED_PROVIDER_HEALTH_PROJECTION_SCHEMA,
@ -1867,6 +1948,7 @@ mod tests {
signature_algorithm: "ed25519".into(),
signature: vec![9; 64],
private_state_exposed: false,
activation_witness_sha256: Some(format!("sha256-{}", "f".repeat(64))),
}
}
@ -1913,6 +1995,26 @@ mod tests {
source_commit: health.source_commit,
deployment_id: health.deployment_id,
private_state_exposed: false,
activation_witness_sha256: health.activation_witness_sha256,
}
}
fn runtime_traffic_admission_fixture() -> IdunnRuntimeTrafficAdmissionRecord {
let admission = authenticated_admission_fixture();
IdunnRuntimeTrafficAdmissionRecord {
schema_version: IDUNN_RUNTIME_TRAFFIC_ADMISSION_SCHEMA.into(),
daemon_id: IDUNN_CODEX_CONNECTOR_RUNTIME_TRAFFIC_ADMISSION_RECORD_KEY.into(),
release_id: admission.release_id.unwrap(),
release_witness_sha256: admission.release_witness_sha256.unwrap(),
source_commit: admission.source_commit.unwrap(),
deployment_id: admission.deployment_id.unwrap(),
activation_witness_sha256: admission.activation_witness_sha256.unwrap(),
signed_health_sha256: admission.signed_health_sha256,
publisher_incarnation_id: admission.publisher_incarnation_id,
publisher_sequence: admission.publisher_sequence,
signer_identity_id: admission.signer_identity_id,
runtime_process_id: 41,
runtime_process_starttime_ticks: 987_654,
}
}
@ -2114,6 +2216,95 @@ mod tests {
Ok(())
}
#[test]
fn runtime_traffic_admission_is_a_closed_positional_document() -> Result<()> {
let admission = runtime_traffic_admission_fixture();
admission.validate()?;
assert_eq!(
IdunnRuntimeTrafficAdmissionRecord::TYPE,
"idunn.runtime_traffic_admission"
);
assert_eq!(
IdunnRuntimeTrafficAdmissionRecord::SCHEMA_NAME,
IDUNN_RUNTIME_TRAFFIC_ADMISSION_SCHEMA
);
let payload = rmp_serde::to_vec(&admission)?;
assert_eq!(payload.first(), Some(&0x9d));
assert_eq!(
rmp_serde::from_slice::<IdunnRuntimeTrafficAdmissionRecord>(&payload)?,
admission
);
let pre_process_binding = rmp_serde::to_vec(&(
admission.schema_version.clone(),
admission.daemon_id.clone(),
admission.release_id.clone(),
admission.release_witness_sha256.clone(),
admission.source_commit.clone(),
admission.deployment_id.clone(),
admission.activation_witness_sha256.clone(),
admission.signed_health_sha256.clone(),
admission.publisher_incarnation_id.clone(),
admission.publisher_sequence,
admission.signer_identity_id.clone(),
))?;
assert_eq!(pre_process_binding.first(), Some(&0x9b));
assert!(
rmp_serde::from_slice::<IdunnRuntimeTrafficAdmissionRecord>(&pre_process_binding)
.is_err(),
"runtime admission v2 must not decode a pre-process-binding body"
);
let mut ghostlight = admission.clone();
ghostlight.daemon_id = IDUNN_GHOSTLIGHT_RUNTIME_TRAFFIC_ADMISSION_RECORD_KEY.into();
ghostlight.validate()?;
Ok(())
}
#[test]
fn runtime_traffic_admission_refuses_weak_or_partial_lineage() {
let mut admission = runtime_traffic_admission_fixture();
admission.publisher_sequence = 0;
assert!(admission.validate().is_err());
admission = runtime_traffic_admission_fixture();
admission.source_commit = "F".repeat(40);
assert!(admission.validate().is_err());
admission = runtime_traffic_admission_fixture();
admission.activation_witness_sha256 = "missing".into();
assert!(admission.validate().is_err());
admission = runtime_traffic_admission_fixture();
admission.schema_version = "idunn.runtime_traffic_admission.v0".into();
assert!(admission.validate().is_err());
admission = runtime_traffic_admission_fixture();
admission.daemon_id = "caller-selected-daemon".into();
assert!(admission.validate().is_err());
admission = runtime_traffic_admission_fixture();
admission.runtime_process_id = 0;
assert!(admission.validate().is_err());
admission = runtime_traffic_admission_fixture();
admission.runtime_process_starttime_ticks = 0;
assert!(admission.validate().is_err());
}
#[test]
fn activation_binding_is_additive_for_existing_authenticated_admissions() -> Result<()> {
let mut admission = authenticated_admission_fixture();
admission.activation_witness_sha256 = None;
let mut legacy = rmp_serde::to_vec(&admission)?;
assert_eq!(&legacy[..3], &[0xdc, 0, 19]);
assert_eq!(legacy.pop(), Some(0xc0));
legacy[2] = 18;
let decoded: IdunnAuthenticatedDaemonHealthAdmissionRecord =
rmp_serde::from_slice(&legacy)?;
assert_eq!(decoded.activation_witness_sha256, None);
decoded.validate()?;
Ok(())
}
#[test]
fn generic_signed_health_contracts_refuse_weak_or_partial_authority() {
let mut health = signed_health_fixture();
@ -2128,6 +2319,9 @@ mod tests {
health = signed_health_fixture();
health.publisher_sequence = 0;
assert!(health.validate().is_err());
health = signed_health_fixture();
health.activation_witness_sha256 = Some(format!("sha256-{}", "F".repeat(64)));
assert!(health.validate().is_err());
let mut binding = trust_binding_fixture();
binding.binding_authority = "daemon".into();
@ -2145,6 +2339,9 @@ mod tests {
admission = authenticated_admission_fixture();
admission.admitted_at_unix_millis = admission.observed_at_unix_millis - 1;
assert!(admission.validate().is_err());
admission = authenticated_admission_fixture();
admission.activation_witness_sha256 = Some("caller-selected".into());
assert!(admission.validate().is_err());
}
#[test]

View file

@ -457,6 +457,7 @@ mod tests {
release_authority_status: "authorized".to_string(),
requires_bifrost_authority: true,
observed_upstream_revision: "abc123".to_string(),
minimum_source_revision: None,
};
let artifact = IdunnDeploymentArtifactRecord {
artifact_id: "artifact:voidbot:main".to_string(),
@ -501,6 +502,15 @@ mod tests {
status: "planned".to_string(),
planned_at: "2026-06-04T00:00:02Z".to_string(),
};
let release_payload = rmp_serde::to_vec(&release_target)?;
assert_eq!(&release_payload[..3], &[0xdc, 0, 22]);
let mut pre_floor_payload = release_payload.clone();
assert_eq!(pre_floor_payload.pop(), Some(0xc0));
pre_floor_payload[2] = 21;
assert!(
rmp_serde::from_slice::<IdunnReleaseTargetRecord>(&pre_floor_payload).is_err(),
"release-target v3 must not decode a pre-floor positional body"
);
node.put(&release_target.target_id, &release_target)?;
node.put(&artifact.artifact_id, &artifact)?;
node.put(&migration_plan.plan_id, &migration_plan)?;

View file

@ -44,12 +44,16 @@ escalation, and continuity witness state.
- Consequence gate: Yggdrasil keeps `deployment-brake.cc` and its pre-created
sibling `deployment-brake.cc.lock` in `/var/lib/gamecult/idunn-authority`.
The directory is `root:idunn` `0750`, both files are `root:idunn` `0640`, and
Idunn receives only a systemd `ReadOnlyPaths` view. It holds the lock shared
across the final read, validation, and spawn; the root-owned operator writer
takes it exclusive for engage/release. A bounded release authorizes the exact
rollout request and source revision, covering its migration and deploy spawns
until expiry. It is not consumed after the first spawn, and every spawn must
independently revalidate it.
Idunn receives only a systemd `ReadOnlyPaths` view. Idunn validates under a
shared lock before spawning the privileged boundary. The root actuator then
independently reopens and validates the signed brake while remaining the sole
shared-lock holder through one synchronous deploy transaction; the child does
not inherit the lock descriptor. The root-owned operator writer takes the
lock exclusive for engage/release. A bounded release admits the exact target,
rollout request, and source revision only when the transaction starts before
its signed deadline. Admission transfers completion of that transaction to
the actuator; expiry is not a retroactive timer veto. Every later transaction
must independently revalidate the brake.
- Deletion line: any keepalive loop inside Odin, Gjallar, Eve lowerers, or
renderer code must be cut or demoted to a probe that names Idunn as the
restart owner.
@ -95,10 +99,13 @@ Idunn now shares Odin's Rust body:
- `--swarm-profile yggdrasil-local` is the Linux host-local supervisor for
Epiphany, Heimdall, Repixelizer, StreamPixels, and VoidBot. Its only command boundary is the
root-owned `/usr/local/libexec/idunn-yggdrasil` actuator. Restart commands
target the local Compose stack; deployment fails closed unless a root-owned
executable manifest exists for that service under
`/srv/odin/deploy-manifests`. It does not inherit Starfire paths, SSH keys,
ADB authority, or Windows process ownership.
target the local Compose stack. For deployment, the root boundary derives the
repository, ref, daemon id, and release-authority posture from its fixed
target allowlist, then binds the caller's request identifier and source to the
signed root-owned brake. A manifest must be a direct root-owned executable
regular file under `/srv/odin/deploy-manifests`; neither it nor any ancestor
may be group/world-writable, and symlink manifests are refused. It does not
inherit Starfire paths, SSH keys, ADB authority, or Windows process ownership.
- Release authority is explicit per target. Odin, Ghostlight, and Epiphany are
source-observed targets: Idunn derives the newest commit on each admitted ref
that changes build or runtime source, freezes that exact revision into its

View file

@ -1,6 +1,11 @@
#!/bin/sh
set -eu
PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH
LC_ALL=C
export LC_ALL
if [ "$(id -u)" -ne 0 ]; then
echo "idunn-yggdrasil must run through its narrow sudo boundary" >&2
exit 1
@ -8,105 +13,368 @@ fi
action="${1:-}"
target="${2:-}"
source_commit="${3:-}"
repository_full_name="${4:-}"
upstream_ref="${5:-}"
release_authority_id="${6:-}"
release_authority_sha256="${7:-}"
deployment_request_id="${8:-}"
requires_bifrost_authority="${9:-false}"
compose=/srv/compose/yggdrasil-apps.yaml
brake_store=/var/lib/gamecult/idunn-authority/deployment-brake.cc
brake_lock=/var/lib/gamecult/idunn-authority/deployment-brake.cc.lock
brake_anchor=/etc/gamecult/idunn/deployment-brake-operator-anchor.cc
generation_lock=/var/lib/gamecult/idunn-authority/idunn-generation.lock
idunn_provision=/usr/local/bin/idunn-provision
require_release_lineage() {
case "$target" in
bifrost-persona-feedback) target_requires_bifrost_authority=true ;;
epiphany|epiphany-capstone-17|voidbot|heimdall|repixelizer|streampixels|odin|codex-connector|ghostlight|gjallar) target_requires_bifrost_authority=false ;;
*) echo "deployment target has no release-authority policy: $target" >&2; exit 1 ;;
esac
if [ "$requires_bifrost_authority" != "$target_requires_bifrost_authority" ]; then
echo "caller release-authority mode does not match root policy for $target" >&2
require_root_owned_nonwritable_component() {
component="$1"
kind="$2"
if [ -L "$component" ]; then
echo "privileged actuator path component must not be a symlink: $component" >&2
exit 1
fi
requires_bifrost_authority="$target_requires_bifrost_authority"
case "$source_commit" in
*[!0-9a-f]*|'') echo "invalid or missing IDUNN_SOURCE_COMMIT" >&2; exit 1 ;;
case "$kind" in
file) [ -f "$component" ] || { echo "privileged actuator path component is not a regular file: $component" >&2; exit 1; } ;;
directory) [ -d "$component" ] || { echo "privileged actuator path component is not a directory: $component" >&2; exit 1; } ;;
*) echo "internal privileged actuator path-kind error" >&2; exit 1 ;;
esac
[ "${#source_commit}" -eq 40 ] || { echo "IDUNN_SOURCE_COMMIT must be 40 hex characters" >&2; exit 1; }
[ -n "$repository_full_name" ] || { echo "missing repository identity" >&2; exit 1; }
[ -n "$upstream_ref" ] || { echo "missing upstream ref" >&2; exit 1; }
[ -n "$deployment_request_id" ] || { echo "missing Idunn deployment request id" >&2; exit 1; }
owner="$(stat -c '%u' -- "$component")"
mode="$(stat -c '%a' -- "$component")"
[ "$owner" = 0 ] || { echo "privileged actuator path component is not root-owned: $component" >&2; exit 1; }
case "$mode" in
''|*[!0-7]*) echo "privileged actuator path component has an unreadable mode: $component" >&2; exit 1 ;;
esac
group_mode=$(( (mode / 10) % 10 ))
other_mode=$(( mode % 10 ))
if [ $((group_mode & 2)) -ne 0 ] || [ $((other_mode & 2)) -ne 0 ]; then
echo "privileged actuator path component is group/world-writable: $component" >&2
exit 1
fi
}
require_root_owned_regular_path() {
path="$1"
case "$path" in
/*) ;;
*) echo "privileged actuator path must be absolute: $path" >&2; exit 1 ;;
esac
ancestor="$(dirname -- "$path")"
while :; do
require_root_owned_nonwritable_component "$ancestor" directory
[ "$ancestor" = / ] && break
ancestor="$(dirname -- "$ancestor")"
done
require_root_owned_nonwritable_component "$path" file
}
require_root_owned_resolved_executable() {
entrypoint="$1"
ancestor="$(dirname -- "$entrypoint")"
while :; do
require_root_owned_nonwritable_component "$ancestor" directory
[ "$ancestor" = / ] && break
ancestor="$(dirname -- "$ancestor")"
done
[ -e "$entrypoint" ] || { echo "privileged executable entrypoint is missing: $entrypoint" >&2; exit 1; }
[ "$(stat -c '%u' -- "$entrypoint")" = 0 ] || { echo "privileged executable entrypoint is not root-owned: $entrypoint" >&2; exit 1; }
resolved="$(readlink -f -- "$entrypoint")"
[ -n "$resolved" ] || { echo "privileged executable entrypoint cannot be resolved: $entrypoint" >&2; exit 1; }
require_root_owned_regular_path "$resolved"
[ -x "$resolved" ] || { echo "privileged executable is not executable: $resolved" >&2; exit 1; }
}
acquire_idunn_generation_lock() {
# Every target consequence observes one installed Idunn generation. The
# self-bootstrap owns the exclusive side of this lock while replacing and
# accepting that generation; target manifests hold the shared side from
# admission through completion. This lock does not decide brake posture,
# target lifecycle, or release authority.
require_root_owned_regular_path "$generation_lock"
exec 8<"$generation_lock"
/usr/bin/flock --shared 8
}
deployment_target_policy() {
manifest_takes_action=false
minimum_source_revision_required=false
case "$target" in
odin)
daemon_id=yggdrasil-odin
repository_full_name=GameCult/Odin
upstream_ref=refs/heads/codex/ygg-idunn-independent-bootstrap
requires_bifrost_authority=false
manifest_takes_action=true
;;
codex-connector)
daemon_id=yggdrasil-codex-connector
repository_full_name=GameCult/CodexConnector
upstream_ref=refs/heads/codex/ghostlight-release-binding
requires_bifrost_authority=false
minimum_source_revision_required=true
manifest_takes_action=true
;;
ghostlight)
daemon_id=yggdrasil-ghostlight
repository_full_name=GameCult/Ghostlight
upstream_ref=refs/heads/codex/ghostlight-dungeon-mvp
requires_bifrost_authority=false
minimum_source_revision_required=true
manifest_takes_action=true
;;
voidbot)
daemon_id=yggdrasil-voidbot
repository_full_name=GameCult/VoidBot
upstream_ref=refs/heads/main
requires_bifrost_authority=false
manifest_takes_action=true
;;
heimdall)
daemon_id=yggdrasil-heimdall
repository_full_name=GameCult/Heimdall
upstream_ref=refs/heads/main
requires_bifrost_authority=false
;;
epiphany-capstone-17)
daemon_id=yggdrasil-epiphany-capstone-17
repository_full_name=GameCult/Epiphany
upstream_ref=refs/heads/codex/epiphany-shakedown-live
requires_bifrost_authority=false
manifest_takes_action=true
;;
epiphany)
daemon_id=yggdrasil-epiphany
repository_full_name=GameCult/Epiphany
upstream_ref=refs/heads/codex/epiphany-shakedown-live
requires_bifrost_authority=false
manifest_takes_action=true
;;
bifrost-persona-feedback)
daemon_id=yggdrasil-bifrost-persona-feedback
repository_full_name=GameCult/Bifrost
upstream_ref=refs/heads/main
requires_bifrost_authority=true
;;
repixelizer)
daemon_id=yggdrasil-repixelizer
repository_full_name=GameCult/repixelizer
upstream_ref=refs/heads/main
requires_bifrost_authority=false
;;
streampixels)
daemon_id=yggdrasil-streampixels
repository_full_name=GameCult/StreamPixels
upstream_ref=refs/heads/main
requires_bifrost_authority=false
;;
gjallar)
daemon_id=yggdrasil-gjallar
repository_full_name=GameCult/Gjallar
upstream_ref=refs/heads/codex/yggdrasil-aggregate-daemon
requires_bifrost_authority=false
;;
*) echo "deployment target has no root actuator policy: $target" >&2; exit 1 ;;
esac
}
require_signed_deployment_grant() {
source_commit="$3"
deployment_request_id="$4"
release_authority_id="$5"
release_authority_sha256="$6"
deployment_target_policy
case "$source_commit" in
*[!0-9a-f]*|'') echo "invalid or missing source commit" >&2; exit 1 ;;
esac
[ "${#source_commit}" -eq 40 ] || { echo "source commit must be 40 lowercase hex characters" >&2; exit 1; }
case "$deployment_request_id" in
*[!A-Za-z0-9._:/+-]*|'') echo "invalid or missing Idunn deployment request id" >&2; exit 1 ;;
esac
[ "${#deployment_request_id}" -le 256 ] || { echo "Idunn deployment request id is oversized" >&2; exit 1; }
case "$deployment_request_id" in
"deploy:$daemon_id:"?*|"manual:redeploy:$daemon_id:"?*) ;;
*) echo "signed deployment request is not for root target $target" >&2; exit 1 ;;
esac
case "$requires_bifrost_authority" in
true)
[ -n "$release_authority_id" ] || { echo "missing Bifrost release authority id" >&2; exit 1; }
case "$release_authority_sha256" in
*[!0-9a-f]*|'') echo "invalid or missing Bifrost release authority digest" >&2; exit 1 ;;
esac
[ "${#release_authority_sha256}" -eq 64 ] || { echo "Bifrost release authority digest must be 64 hex characters" >&2; exit 1; }
/usr/local/bin/idunn validate-release-authority \
--store /var/lib/gamecult/idunn/yggdrasil.keepalive.cc \
--release-authority-store /srv/bifrost/state/repository-release-authority.cc \
--repository-full-name "$repository_full_name" \
--upstream-ref "$upstream_ref" \
--source-revision "$source_commit" \
--release-authority-id "$release_authority_id" \
--release-authority-sha256 "$release_authority_sha256"
[ "${#release_authority_sha256}" -eq 64 ] || { echo "Bifrost release authority digest must be 64 lowercase hex characters" >&2; exit 1; }
;;
false)
[ -z "$release_authority_id" ] || { echo "source-observed release cannot claim Bifrost authority id" >&2; exit 1; }
[ -z "$release_authority_sha256" ] || { echo "source-observed release cannot claim Bifrost authority digest" >&2; exit 1; }
;;
*) echo "invalid Bifrost authority requirement mode" >&2; exit 1 ;;
esac
require_root_owned_resolved_executable "$idunn_provision"
require_root_owned_regular_path "$brake_store"
require_root_owned_regular_path "$brake_lock"
require_root_owned_regular_path "$brake_anchor"
# This validation is the deployment-admission point. The signed expiry is a
# start-before deadline: it denies a later transaction, but does not become a
# timer-shaped veto over one already admitted. The root actuator remains the
# sole shared-lock holder through the synchronous consequence, so an explicit
# engage/release transition cannot race or rewrite that transaction.
exec 9<"$brake_lock"
/usr/bin/flock --shared 9
now_unix_millis="$(/usr/bin/date +%s%3N)"
case "$now_unix_millis" in
''|*[!0-9]*) echo "root actuator clock did not produce Unix milliseconds" >&2; exit 1 ;;
esac
"$idunn_provision" deployment-brake-status \
--store "$brake_store" \
--operator-anchor "$brake_anchor" \
--runtime-id yggdrasil \
--release-id "$source_commit" \
--deployment-id "$deployment_request_id" \
--now-unix-millis "$now_unix_millis"
if [ "$minimum_source_revision_required" = true ]; then
require_root_owned_resolved_executable /usr/local/bin/idunn
/usr/local/bin/idunn validate-minimum-source-revision \
--daemon "$daemon_id" \
--source-revision "$source_commit"
fi
if [ "$requires_bifrost_authority" = true ]; then
require_root_owned_resolved_executable /usr/local/bin/idunn
/usr/local/bin/idunn validate-release-authority \
--store /var/lib/gamecult/idunn/yggdrasil.keepalive.cc \
--release-authority-store /srv/bifrost/state/repository-release-authority.cc \
--repository-full-name "$repository_full_name" \
--upstream-ref "$upstream_ref" \
--source-revision "$source_commit" \
--release-authority-id "$release_authority_id" \
--release-authority-sha256 "$release_authority_sha256"
fi
}
manifest_group_exists() {
kill -s 0 "-$manifest_pid" 2>/dev/null
}
signal_manifest_group() {
kill -s "$1" "-$manifest_pid" 2>/dev/null || true
}
forward_manifest_signal() {
manifest_wait_interrupted=true
signal_manifest_group "$1"
}
run_manifest_while_holding_authority_locks() {
# Stay alive as the sole lock owner. The child must not inherit descriptors
# 8 or 9: flock locks attach to shared open-file descriptions, so an
# inherited descriptor could retain or unlock the parent's generation or
# deployment transaction. The owned process group also prevents ordinary
# descendants from outliving interruption.
require_root_owned_resolved_executable /usr/bin/setsid
/usr/bin/setsid "$@" 8<&- 9<&- &
manifest_pid=$!
manifest_wait_interrupted=false
trap 'forward_manifest_signal HUP' HUP
trap 'forward_manifest_signal INT' INT
trap 'forward_manifest_signal TERM' TERM
while :; do
manifest_wait_interrupted=false
if wait "$manifest_pid"; then
manifest_status=0
else
manifest_status=$?
fi
if [ "$manifest_wait_interrupted" = true ] && manifest_group_exists; then
continue
fi
break
done
trap - HUP INT TERM
manifest_descendants_leaked=false
if manifest_group_exists; then
manifest_descendants_leaked=true
signal_manifest_group TERM
for _ in 1 2 3 4 5; do
manifest_group_exists || break
sleep 1
done
fi
if manifest_group_exists; then
signal_manifest_group KILL
for _ in 1 2 3 4 5; do
manifest_group_exists || break
sleep 1
done
fi
if manifest_group_exists; then
echo "deployment manifest process group survived SIGKILL" >&2
return 1
fi
if [ "$manifest_descendants_leaked" = true ] && [ "$manifest_status" -eq 0 ]; then
echo "deployment manifest left a descendant process behind" >&2
return 1
fi
return "$manifest_status"
}
case "$action" in
deploy)
[ "$#" -eq 6 ] || { echo "deploy requires exact target, source, request, and release-authority arguments" >&2; exit 2; }
;;
restart)
[ "$#" -eq 2 ] || { echo "restart accepts only one exact target" >&2; exit 2; }
;;
*)
echo "unsupported Idunn Yggdrasil actuator action: $action" >&2
exit 2
;;
esac
acquire_idunn_generation_lock
case "$action:$target" in
restart:heimdall)
require_root_owned_regular_path "$compose"
exec docker compose -f "$compose" restart heimdall
;;
restart:repixelizer)
require_root_owned_regular_path "$compose"
exec docker compose -f "$compose" restart repixelizer
;;
restart:streampixels)
require_root_owned_regular_path "$compose"
docker compose -f "$compose" restart streampixels-service streampixels-web
;;
restart:gjallar)
exec systemctl restart gjallar-yggdrasil.service
;;
deploy:voidbot|restart:voidbot|deploy:epiphany|restart:epiphany|deploy:epiphany-capstone-17|deploy:odin|restart:odin|deploy:codex-connector|restart:codex-connector|deploy:ghostlight|restart:ghostlight)
restart:voidbot|restart:epiphany|restart:odin|restart:codex-connector|restart:ghostlight)
manifest="/srv/odin/deploy-manifests/$target"
if [ ! -x "$manifest" ] || [ ! -O "$manifest" ]; then
echo "root-owned executable deploy manifest is not installed: $manifest" >&2
exit 1
fi
if [ "$action" = deploy ]; then
require_release_lineage
fi
IDUNN_ACTUATOR=1 IDUNN_COMMAND_AUTHORITY=idunn-daemon \
IDUNN_SOURCE_COMMIT="$source_commit" \
IDUNN_REPOSITORY_FULL_NAME="$repository_full_name" \
IDUNN_UPSTREAM_REF="$upstream_ref" \
BIFROST_RELEASE_AUTHORITY_ID="$release_authority_id" \
BIFROST_RELEASE_AUTHORITY_SHA256="$release_authority_sha256" \
IDUNN_DEPLOYMENT_REQUEST_ID="$deployment_request_id" \
IDUNN_REQUIRES_BIFROST_AUTHORITY="$requires_bifrost_authority" \
exec "$manifest" "$action"
require_root_owned_regular_path "$manifest"
[ -x "$manifest" ] || { echo "root actuator manifest is not executable: $manifest" >&2; exit 1; }
export IDUNN_ACTUATOR=1
export IDUNN_COMMAND_AUTHORITY=idunn-daemon
run_manifest_while_holding_authority_locks "$manifest" restart
exit $?
;;
deploy:heimdall|deploy:repixelizer|deploy:streampixels|deploy:bifrost-persona-feedback|deploy:gjallar)
deploy:voidbot|deploy:epiphany|deploy:epiphany-capstone-17|deploy:odin|deploy:codex-connector|deploy:ghostlight|deploy:heimdall|deploy:repixelizer|deploy:streampixels|deploy:bifrost-persona-feedback|deploy:gjallar)
manifest="/srv/odin/deploy-manifests/$target"
if [ ! -x "$manifest" ] || [ ! -O "$manifest" ]; then
echo "root-owned executable deploy manifest is not installed: $manifest" >&2
exit 1
require_root_owned_regular_path "$manifest"
[ -x "$manifest" ] || { echo "root actuator manifest is not executable: $manifest" >&2; exit 1; }
require_signed_deployment_grant "$@"
export IDUNN_ACTUATOR=1
export IDUNN_COMMAND_AUTHORITY=idunn-daemon
export IDUNN_SOURCE_COMMIT="$source_commit"
export IDUNN_REPOSITORY_FULL_NAME="$repository_full_name"
export IDUNN_UPSTREAM_REF="$upstream_ref"
export BIFROST_RELEASE_AUTHORITY_ID="$release_authority_id"
export BIFROST_RELEASE_AUTHORITY_SHA256="$release_authority_sha256"
export IDUNN_DEPLOYMENT_REQUEST_ID="$deployment_request_id"
export IDUNN_REQUIRES_BIFROST_AUTHORITY="$requires_bifrost_authority"
if [ "$manifest_takes_action" = true ]; then
run_manifest_while_holding_authority_locks "$manifest" "$action"
exit $?
fi
require_release_lineage
IDUNN_ACTUATOR=1 IDUNN_COMMAND_AUTHORITY=idunn-daemon \
IDUNN_SOURCE_COMMIT="$source_commit" \
IDUNN_REPOSITORY_FULL_NAME="$repository_full_name" \
IDUNN_UPSTREAM_REF="$upstream_ref" \
BIFROST_RELEASE_AUTHORITY_ID="$release_authority_id" \
BIFROST_RELEASE_AUTHORITY_SHA256="$release_authority_sha256" \
IDUNN_DEPLOYMENT_REQUEST_ID="$deployment_request_id" \
IDUNN_REQUIRES_BIFROST_AUTHORITY="$requires_bifrost_authority" \
exec "$manifest"
run_manifest_while_holding_authority_locks "$manifest"
exit $?
;;
*)
echo "unsupported Idunn Yggdrasil actuator request: $action $target" >&2

View file

@ -19,7 +19,7 @@ UMask=027
PrivateTmp=yes
ProtectHome=yes
ProtectSystem=full
ReadWritePaths=/etc/gamecult/idunn /etc/gamecult/codex-connector /etc/gamecult/ghostlight /etc/systemd/system/codex-connector.service /etc/systemd/system/epiphany-swarm.service /etc/systemd/system/ghostlight-dungeon.service /var/lib/gamecult/idunn /srv/build /srv/voidbot
ReadWritePaths=/etc/gamecult/idunn /etc/gamecult/codex-connector /etc/gamecult/ghostlight-dungeon /etc/systemd/system/codex-connector.service /etc/systemd/system/epiphany-swarm.service /etc/systemd/system/ghostlight-dungeon.service /var/lib/gamecult/idunn /srv/build /srv/voidbot
ReadOnlyPaths=/var/lib/gamecult/idunn-authority
[Install]

View file

@ -1 +1,24 @@
idunn ALL=(root) NOPASSWD: /usr/local/libexec/idunn-yggdrasil *
Cmnd_Alias IDUNN_YGGDRASIL_DEPLOY = \
/usr/local/libexec/idunn-yggdrasil deploy odin *, \
/usr/local/libexec/idunn-yggdrasil deploy codex-connector *, \
/usr/local/libexec/idunn-yggdrasil deploy ghostlight *, \
/usr/local/libexec/idunn-yggdrasil deploy voidbot *, \
/usr/local/libexec/idunn-yggdrasil deploy heimdall *, \
/usr/local/libexec/idunn-yggdrasil deploy epiphany-capstone-17 *, \
/usr/local/libexec/idunn-yggdrasil deploy epiphany *, \
/usr/local/libexec/idunn-yggdrasil deploy bifrost-persona-feedback *, \
/usr/local/libexec/idunn-yggdrasil deploy repixelizer *, \
/usr/local/libexec/idunn-yggdrasil deploy streampixels *, \
/usr/local/libexec/idunn-yggdrasil deploy gjallar *
Cmnd_Alias IDUNN_YGGDRASIL_RESTART = \
/usr/local/libexec/idunn-yggdrasil restart odin, \
/usr/local/libexec/idunn-yggdrasil restart codex-connector, \
/usr/local/libexec/idunn-yggdrasil restart ghostlight, \
/usr/local/libexec/idunn-yggdrasil restart voidbot, \
/usr/local/libexec/idunn-yggdrasil restart heimdall, \
/usr/local/libexec/idunn-yggdrasil restart epiphany, \
/usr/local/libexec/idunn-yggdrasil restart repixelizer, \
/usr/local/libexec/idunn-yggdrasil restart streampixels, \
/usr/local/libexec/idunn-yggdrasil restart gjallar
idunn ALL=(root) NOPASSWD: IDUNN_YGGDRASIL_DEPLOY, IDUNN_YGGDRASIL_RESTART

2
vendor/cultnet-rs vendored

@ -1 +1 @@
Subproject commit fdccc37aa68c3f0e53bfd53a92c15a148978f0c7
Subproject commit 021dca7f3261c9842019f0845b35022455ccf756