Land the Idunn projection, UDP route actuation, and the Odin daemon
This had been sitting uncommitted in the worktree. It is real work rather than stray edits: RouteBinding gains stable_socket and an NginxStreamUdp driver so a route can be actuated over UDP, control_plane and drivers grow the Idunn-owned projection and bounded RUDP transport, and crates/odin-daemon arrives as a new member of the workspace. The deployment recipe comes with it, including the required_gitlinks fix the core-stack repoint made necessary: it named vendor/cultnet-rs, which no longer exists now that CultNet comes from CultLib, so Idunn would have refused to admit the target. The list is empty because Odin has no submodules left; the core stack is pinned by revision in Cargo.lock inside the frozen source tree. Everything except odin-daemon builds here. odin-daemon reads systemd listen file descriptors through std::os::fd and cannot compile on Windows by design, so Linux CI is its first real witness. muninn and sleipnir pass 162 tests; the one failure expects an Unreliable media channel that no CultNet lineage has ever declared, and predates this. Committed rather than left in flight. rustfmt reports 94 files across the repo, which predates this work, so formatting is left for its own pass instead of being buried in a 4,000-line diff. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
bc2fdedcb0
commit
eedce4f3de
10 changed files with 7342 additions and 807 deletions
|
|
@ -6,6 +6,7 @@ members = [
|
|||
"crates/muninn-move-tracker",
|
||||
"crates/muninn-psmoveapi-tracker",
|
||||
"crates/odin-core",
|
||||
"crates/odin-daemon",
|
||||
]
|
||||
resolver = "3"
|
||||
exclude = [
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,7 +1,8 @@
|
|||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::net::IpAddr;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
|
||||
use anyhow::{bail, ensure, Context, Result};
|
||||
use anyhow::{Context, Result, bail, ensure};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const TARGET_DECLARATION_SCHEMA: &str = "gamecult.idunn.target_declaration.v1";
|
||||
|
|
@ -425,11 +426,45 @@ pub struct RouteBinding {
|
|||
pub reload_unit: String,
|
||||
}
|
||||
|
||||
impl RouteBinding {
|
||||
pub(crate) fn stable_socket(&self) -> Result<(IpAddr, u16)> {
|
||||
let authority = match self.driver {
|
||||
RouteDriver::NginxStreamTcp => self
|
||||
.stable_endpoint
|
||||
.strip_prefix("http://")
|
||||
.or_else(|| self.stable_endpoint.strip_prefix("tcp://")),
|
||||
RouteDriver::NginxStreamUdp => self.stable_endpoint.strip_prefix("rudp://"),
|
||||
}
|
||||
.context("stable endpoint transport does not match its route driver")?;
|
||||
ensure!(
|
||||
!authority
|
||||
.chars()
|
||||
.any(|character| matches!(character, '/' | '?' | '#' | '@' | '[' | ']')),
|
||||
"stable endpoint is not a plain IP address and port"
|
||||
);
|
||||
let (host, port) = authority
|
||||
.rsplit_once(':')
|
||||
.context("stable endpoint has no port")?;
|
||||
let host = host
|
||||
.parse::<IpAddr>()
|
||||
.context("stable endpoint host is not an IP address")?;
|
||||
ensure!(
|
||||
matches!(host, IpAddr::V4(_)),
|
||||
"route binding v2 stable endpoints use explicit IPv4 addresses"
|
||||
);
|
||||
let port = port
|
||||
.parse::<u16>()
|
||||
.context("stable endpoint port is not a u16")?;
|
||||
ensure!(port > 0, "stable endpoint port is zero");
|
||||
Ok((host, port))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum RouteDriver {
|
||||
NginxHttp,
|
||||
NginxStreamTcp,
|
||||
NginxStreamUdp,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
|
@ -1027,6 +1062,14 @@ impl OperatorBinding {
|
|||
require_id(&route.route_id, "route id")?;
|
||||
require_value(&route.stable_endpoint, "stable endpoint")?;
|
||||
require_host(&route.private_host)?;
|
||||
let private_host: IpAddr = route
|
||||
.private_host
|
||||
.parse()
|
||||
.context("route private host is not an IP address")?;
|
||||
ensure!(
|
||||
private_host.is_loopback(),
|
||||
"systemd-transient candidate routes must use a loopback private host"
|
||||
);
|
||||
ensure!(
|
||||
route.private_port_start > 0,
|
||||
"private port range starts at zero"
|
||||
|
|
@ -1035,6 +1078,7 @@ impl OperatorBinding {
|
|||
route.private_port_start < route.private_port_end,
|
||||
"candidate rollout requires at least two private ports"
|
||||
);
|
||||
route.stable_socket()?;
|
||||
require_absolute_path(&route.config_path, "route config")?;
|
||||
require_unit(&route.reload_unit, "route reload unit")?;
|
||||
}
|
||||
|
|
@ -1301,11 +1345,10 @@ impl OperatorBinding {
|
|||
self.route.as_ref(),
|
||||
) {
|
||||
(true, ServiceTransport::Http, Some(route))
|
||||
if route.driver == RouteDriver::NginxHttp =>
|
||||
if route.driver == RouteDriver::NginxStreamTcp =>
|
||||
{
|
||||
ensure!(
|
||||
route.stable_endpoint.starts_with("http://")
|
||||
|| route.stable_endpoint.starts_with("https://"),
|
||||
route.stable_endpoint.starts_with("http://"),
|
||||
"HTTP stable endpoint is not an HTTP URI"
|
||||
);
|
||||
}
|
||||
|
|
@ -1317,6 +1360,14 @@ impl OperatorBinding {
|
|||
"TCP stable endpoint is not a TCP URI"
|
||||
);
|
||||
}
|
||||
(true, ServiceTransport::Rudp, Some(route))
|
||||
if route.driver == RouteDriver::NginxStreamUdp =>
|
||||
{
|
||||
ensure!(
|
||||
route.stable_endpoint.starts_with("rudp://"),
|
||||
"RUDP stable endpoint is not an RUDP URI"
|
||||
);
|
||||
}
|
||||
(false, _, None) => {}
|
||||
_ => bail!("route binding does not match the launch contract"),
|
||||
}
|
||||
|
|
@ -1681,13 +1732,13 @@ expected_signer_identity_id = "test-service-runtime-signer"
|
|||
trust_anchor_store = "/etc/gamecult/trust/test-service.cc"
|
||||
|
||||
[route]
|
||||
driver = "nginx-http"
|
||||
driver = "nginx-stream-tcp"
|
||||
route_id = "test-service-public"
|
||||
stable_endpoint = "https://yggdrasil.gamecult.org/test-service/"
|
||||
stable_endpoint = "http://127.0.0.1:18830"
|
||||
private_host = "127.0.0.1"
|
||||
private_port_start = 18831
|
||||
private_port_end = 18839
|
||||
config_path = "/etc/nginx/idunn-routes/test-service.conf"
|
||||
config_path = "/etc/nginx/idunn-stream-routes/test-service.conf"
|
||||
reload_unit = "nginx.service"
|
||||
|
||||
[process_write_lease]
|
||||
|
|
@ -1765,16 +1816,33 @@ nodes = ["yggdrasil"]
|
|||
#[test]
|
||||
fn route_transport_mismatch_is_rejected() {
|
||||
let recipe = TargetDeclaration::parse(RECIPE).unwrap();
|
||||
let binding =
|
||||
OperatorBinding::parse(&BINDING.replace("nginx-http", "nginx-stream-tcp")).unwrap();
|
||||
assert!(binding.admit(&recipe).is_err());
|
||||
assert!(
|
||||
OperatorBinding::parse(&BINDING.replace("nginx-stream-tcp", "nginx-stream-udp"))
|
||||
.is_err()
|
||||
);
|
||||
|
||||
let binding = OperatorBinding::parse(&BINDING.replace(
|
||||
"https://yggdrasil.gamecult.org/test-service/",
|
||||
"tcp://yggdrasil.gamecult.org:443",
|
||||
))
|
||||
assert!(
|
||||
OperatorBinding::parse(
|
||||
&BINDING.replace("http://127.0.0.1:18830", "tcp://yggdrasil.gamecult.org:443",),
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
assert!(recipe.service.route_required);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rudp_route_uses_the_udp_stream_driver() {
|
||||
let recipe = TargetDeclaration::parse(
|
||||
&RECIPE.replace("transport = \"http\"", "transport = \"rudp\""),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(binding.admit(&recipe).is_err());
|
||||
let binding = OperatorBinding::parse(
|
||||
&BINDING
|
||||
.replace("nginx-stream-tcp", "nginx-stream-udp")
|
||||
.replace("http://127.0.0.1:18830", "rudp://127.0.0.1:17872"),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(binding.admit(&recipe).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1892,24 +1960,30 @@ nodes = ["yggdrasil"]
|
|||
|
||||
#[test]
|
||||
fn v2_binding_is_explicitly_singleton() {
|
||||
assert!(OperatorBinding::parse(
|
||||
&BINDING.replace("desired_replicas = 1", "desired_replicas = 2")
|
||||
)
|
||||
.is_err());
|
||||
assert!(OperatorBinding::parse(&BINDING.replace(
|
||||
"nodes = [\"yggdrasil\"]",
|
||||
"nodes = [\"yggdrasil\", \"raven\"]"
|
||||
))
|
||||
.is_err());
|
||||
assert!(
|
||||
OperatorBinding::parse(
|
||||
&BINDING.replace("desired_replicas = 1", "desired_replicas = 2")
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
assert!(
|
||||
OperatorBinding::parse(&BINDING.replace(
|
||||
"nodes = [\"yggdrasil\"]",
|
||||
"nodes = [\"yggdrasil\", \"raven\"]"
|
||||
))
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_static_workload_identity_has_no_authority_in_v2() {
|
||||
assert!(OperatorBinding::parse(&BINDING.replace(
|
||||
"schema = \"gamecult.idunn.operator_binding.v2\"",
|
||||
"schema = \"gamecult.idunn.operator_binding.v1\"",
|
||||
),)
|
||||
.is_err());
|
||||
assert!(
|
||||
OperatorBinding::parse(&BINDING.replace(
|
||||
"schema = \"gamecult.idunn.operator_binding.v2\"",
|
||||
"schema = \"gamecult.idunn.operator_binding.v1\"",
|
||||
),)
|
||||
.is_err()
|
||||
);
|
||||
let with_static_identity = BINDING.replace(
|
||||
"driver = \"systemd-transient\"",
|
||||
"driver = \"systemd-transient\"\nuser = \"test-service\"\ngroup = \"test-service\"",
|
||||
|
|
@ -1923,10 +1997,12 @@ nodes = ["yggdrasil"]
|
|||
OperatorBinding::parse(&BINDING.replace("state_group = \"test-service\"\n", ""),)
|
||||
.is_err()
|
||||
);
|
||||
assert!(OperatorBinding::parse(
|
||||
&BINDING.replace("state_group = \"test-service\"", "state_group = \"root\""),
|
||||
)
|
||||
.is_err());
|
||||
assert!(
|
||||
OperatorBinding::parse(
|
||||
&BINDING.replace("state_group = \"test-service\"", "state_group = \"root\""),
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{bail, ensure, Context, Result};
|
||||
use anyhow::{Context, Result, bail, ensure};
|
||||
pub use cultnet_rs::IdunnExpectedIncarnationRecord as ExpectedIncarnation;
|
||||
use cultnet_rs::{
|
||||
IdunnExpectedCapability, IdunnExpectedDependency, IdunnExpectedRoute,
|
||||
IDUNN_EXPECTED_INCARNATION_SCHEMA,
|
||||
IDUNN_EXPECTED_INCARNATION_SCHEMA, IdunnExpectedCapability, IdunnExpectedDependency,
|
||||
IdunnExpectedRoute,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::control_plane::SequenceAdmittedReady;
|
||||
use crate::deployment::{
|
||||
capability_compatible, CapabilityDependency, DependencyKind, ExternalCapabilityBinding,
|
||||
OperatorBinding, ServiceTransport, SourceSelectionPolicy, StartupOrder, StateDeclaration,
|
||||
TargetDeclaration,
|
||||
CapabilityDependency, DependencyKind, ExternalCapabilityBinding, OperatorBinding,
|
||||
ServiceTransport, SourceSelectionPolicy, StartupOrder, StateDeclaration, TargetDeclaration,
|
||||
capability_compatible,
|
||||
};
|
||||
|
||||
pub const SOURCE_SELECTION_FACTS_SCHEMA: &str = "idunn.source_selection_facts.v1";
|
||||
|
|
@ -286,11 +286,11 @@ fn managed_ready_provider_refs(
|
|||
let endpoint = expected
|
||||
.route
|
||||
.as_ref()
|
||||
.map(|route| route.candidate_endpoint.clone());
|
||||
.map(|route| route.stable_endpoint.clone());
|
||||
let mut providers = Vec::new();
|
||||
for capability in &observed.observed_capabilities {
|
||||
providers.push(DependencyProviderRef {
|
||||
provider_id: observed.runtime_id.clone(),
|
||||
provider_id: expected.target.clone(),
|
||||
authority: DependencyProviderAuthority::ManagedReady {
|
||||
target: expected.target.clone(),
|
||||
incarnation_id: expected.incarnation_id.clone(),
|
||||
|
|
@ -995,11 +995,12 @@ fn sha256_id(bytes: &[u8]) -> String {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use cultnet_rs::{
|
||||
GameCultProviderHealthIdentity, GameCultRuntimeCapability, IdunnRuntimeActivationLaunch,
|
||||
IdunnServiceIdentity, ODIN_RUNTIME_TOPOLOGY_CORRELATION_SCHEMA,
|
||||
OdinRuntimeTopologyCorrelationPurpose, OdinRuntimeTopologyCorrelationRecord,
|
||||
OdinTopologyAuthenticationContext, OdinTopologyIdentity,
|
||||
authenticate_odin_runtime_topology_correlation, enroll_service_identity_at,
|
||||
verify_runtime_authority, GameCultProviderHealthIdentity, GameCultRuntimeCapability,
|
||||
IdunnRuntimeActivationLaunch, IdunnServiceIdentity, OdinRuntimeTopologyCorrelationPurpose,
|
||||
OdinRuntimeTopologyCorrelationRecord, OdinTopologyAuthenticationContext,
|
||||
OdinTopologyIdentity, ODIN_RUNTIME_TOPOLOGY_CORRELATION_SCHEMA,
|
||||
verify_runtime_authority,
|
||||
};
|
||||
|
||||
const RECIPE: &str = r#"
|
||||
|
|
@ -1113,13 +1114,13 @@ expected_signer_identity_id = "service-runtime-signer"
|
|||
trust_anchor_store = "/etc/gamecult/trust/service.cc"
|
||||
|
||||
[route]
|
||||
driver = "nginx-http"
|
||||
driver = "nginx-stream-tcp"
|
||||
route_id = "service"
|
||||
stable_endpoint = "https://example.invalid/service/"
|
||||
stable_endpoint = "http://127.0.0.1:17999"
|
||||
private_host = "127.0.0.1"
|
||||
private_port_start = 18000
|
||||
private_port_end = 18009
|
||||
config_path = "/etc/nginx/idunn-routes/service.conf"
|
||||
config_path = "/etc/nginx/idunn-stream-routes/service.conf"
|
||||
reload_unit = "nginx.service"
|
||||
|
||||
[brakes]
|
||||
|
|
@ -1189,7 +1190,7 @@ nodes = ["yggdrasil"]
|
|||
}
|
||||
}
|
||||
|
||||
fn ready_odin_provider(runtime_id: &str, capacity: u32) -> SequenceAdmittedReady {
|
||||
fn ready_odin_provider(target: &str, runtime_id: &str, capacity: u32) -> SequenceAdmittedReady {
|
||||
(|| -> Result<SequenceAdmittedReady> {
|
||||
let root = tempfile::tempdir()?;
|
||||
let provider = enroll_service_identity_at::<GameCultProviderHealthIdentity>(
|
||||
|
|
@ -1200,6 +1201,7 @@ nodes = ["yggdrasil"]
|
|||
let odin_signer =
|
||||
enroll_service_identity_at::<OdinTopologyIdentity>(&root.path().join("odin.cc"))?;
|
||||
let mut expected = odin();
|
||||
expected.target = target.into();
|
||||
expected.runtime_id = runtime_id.into();
|
||||
expected.expected_signer_identity_id = provider.entry().identity_id.clone();
|
||||
let launch = IdunnRuntimeActivationLaunch::issue(&expected, digest(b'8'), 100, &idunn)?;
|
||||
|
|
@ -1262,7 +1264,7 @@ nodes = ["yggdrasil"]
|
|||
}
|
||||
|
||||
fn plan() -> CompiledDeploymentPlan {
|
||||
let providers = [ready_odin_provider("odin-yggdrasil", 1)];
|
||||
let providers = [ready_odin_provider("odin", "odin-yggdrasil", 1)];
|
||||
plan_with(&providers)
|
||||
}
|
||||
|
||||
|
|
@ -1302,7 +1304,7 @@ nodes = ["yggdrasil"]
|
|||
|
||||
#[test]
|
||||
fn compiler_parses_the_exact_bytes_it_receipts() {
|
||||
let providers = [ready_odin_provider("odin-yggdrasil", 1)];
|
||||
let providers = [ready_odin_provider("odin", "odin-yggdrasil", 1)];
|
||||
let first = plan_with(&providers);
|
||||
let second = plan_with(&providers);
|
||||
assert_eq!(first, second);
|
||||
|
|
@ -1316,17 +1318,19 @@ nodes = ["yggdrasil"]
|
|||
"contract = \"service.health\"",
|
||||
"contract = \"service.health.v2\"",
|
||||
);
|
||||
let providers = [ready_odin_provider("odin-yggdrasil", 1)];
|
||||
assert!(compile_deployment_plan(
|
||||
changed.as_bytes(),
|
||||
BINDING.as_bytes(),
|
||||
source(RECIPE),
|
||||
"service-incarnation-2",
|
||||
Some(18002),
|
||||
111,
|
||||
&providers,
|
||||
)
|
||||
.is_err());
|
||||
let providers = [ready_odin_provider("odin", "odin-yggdrasil", 1)];
|
||||
assert!(
|
||||
compile_deployment_plan(
|
||||
changed.as_bytes(),
|
||||
BINDING.as_bytes(),
|
||||
source(RECIPE),
|
||||
"service-incarnation-2",
|
||||
Some(18002),
|
||||
111,
|
||||
&providers,
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
let mut corrupted = first;
|
||||
corrupted
|
||||
.binding_blob
|
||||
|
|
@ -1382,8 +1386,8 @@ nodes = ["yggdrasil"]
|
|||
fn dependency_selection_uses_observed_ready_capacity_and_stable_identity_order() {
|
||||
let declaration = TargetDeclaration::parse(RECIPE).unwrap();
|
||||
let admitted = [
|
||||
ready_odin_provider("odin-z", 4),
|
||||
ready_odin_provider("odin-yggdrasil", 2),
|
||||
ready_odin_provider("odin-z", "odin-runtime-z", 4),
|
||||
ready_odin_provider("odin-yggdrasil", "odin-runtime-yggdrasil", 2),
|
||||
];
|
||||
let providers = admitted
|
||||
.iter()
|
||||
|
|
@ -1395,6 +1399,10 @@ nodes = ["yggdrasil"]
|
|||
"odin-yggdrasil"
|
||||
);
|
||||
assert_eq!(selected[0].provider.as_ref().unwrap().capacity, 2);
|
||||
assert_eq!(
|
||||
selected[0].provider.as_ref().unwrap().endpoint.as_deref(),
|
||||
Some("tcp://10.77.0.1:17871")
|
||||
);
|
||||
assert!(matches!(
|
||||
&selected[0].provider.as_ref().unwrap().authority,
|
||||
DependencyProviderAuthority::ManagedReady {
|
||||
|
|
@ -1459,7 +1467,7 @@ nodes = ["yggdrasil"]
|
|||
assert!(!expected.write_lease_required);
|
||||
assert_eq!(
|
||||
expected.dependencies[0].provider_id.as_deref(),
|
||||
Some("odin-yggdrasil")
|
||||
Some("odin")
|
||||
);
|
||||
assert_eq!(
|
||||
expected.dependencies[0].provider_authority.as_deref(),
|
||||
|
|
@ -1494,7 +1502,7 @@ nodes = ["yggdrasil"]
|
|||
"service-incarnation-sorted",
|
||||
Some(18002),
|
||||
111,
|
||||
&[ready_odin_provider("odin-yggdrasil", 1)],
|
||||
&[ready_odin_provider("odin", "odin-yggdrasil", 1)],
|
||||
)
|
||||
.unwrap();
|
||||
let release = SealedRelease::new(
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -5,10 +5,12 @@ use cultcache_rs::{
|
|||
use cultnet_rs::{
|
||||
GameCultProviderHealthIdentity, IDUNN_DEPLOYMENT_BRAKE_AUTHORITY, IDUNN_DEPLOYMENT_BRAKE_ID,
|
||||
IDUNN_DEPLOYMENT_BRAKE_SCHEMA, IDUNN_DEPLOYMENT_BRAKE_SCOPE, IDUNN_DEPLOYMENT_RELEASE_PURPOSE,
|
||||
IDUNN_LIFECYCLE_BRAKE_AUTHORITY, IDUNN_LIFECYCLE_BRAKE_SCHEMA, IDUNN_LIFECYCLE_BRAKE_SCOPE,
|
||||
IdunnDeploymentBrakeObservation, IdunnDeploymentBrakeOperatorIdentity,
|
||||
IdunnDeploymentBrakeRecord, IdunnDeploymentBrakeReleasePurpose, IdunnServiceIdentity,
|
||||
ServiceIdentityProfile, ServiceIdentityTrustAnchor, derive_service_identity_id,
|
||||
enroll_service_identity_at, evaluate_idunn_deployment_brake,
|
||||
IdunnDeploymentBrakeRecord, IdunnDeploymentBrakeReleasePurpose, IdunnLifecycleBrakeObservation,
|
||||
IdunnLifecycleBrakeRecord, IdunnServiceIdentity, OdinTopologyIdentity, ServiceIdentityProfile,
|
||||
ServiceIdentityTrustAnchor, derive_service_identity_id, enroll_service_identity_at,
|
||||
evaluate_idunn_continuity_restart, evaluate_idunn_deployment_brake,
|
||||
export_service_identity_trust_anchor, open_service_identity_at,
|
||||
};
|
||||
use odin_core::{
|
||||
|
|
@ -49,39 +51,34 @@ pub fn run(args: impl IntoIterator<Item = String>) -> Result<()> {
|
|||
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")?)?;
|
||||
}
|
||||
"export-provider-health-public-anchor" => export_identity_anchor::<
|
||||
GameCultProviderHealthIdentity,
|
||||
>(
|
||||
&options, "provider health public anchor"
|
||||
)?,
|
||||
"enroll-idunn-identity" => enroll_identity::<IdunnServiceIdentity>(&options)?,
|
||||
"export-idunn-public-anchor" => {
|
||||
require_only(&options, &["private-store", "public-anchor"])?;
|
||||
let private = path(&options, "private-store")?;
|
||||
let public = path(&options, "public-anchor")?;
|
||||
reject_alias(&private, &public)?;
|
||||
refuse_existing(&public, "public anchor")?;
|
||||
let signer = open_service_identity_at::<IdunnServiceIdentity>(&private)?;
|
||||
export_service_identity_trust_anchor(&signer, &public)?;
|
||||
export_identity_anchor::<IdunnServiceIdentity>(&options, "Idunn public anchor")?
|
||||
}
|
||||
"enroll-odin-topology-identity" => enroll_identity::<OdinTopologyIdentity>(&options)?,
|
||||
"export-odin-topology-public-anchor" => {
|
||||
export_identity_anchor::<OdinTopologyIdentity>(&options, "Odin topology public anchor")?
|
||||
}
|
||||
"enroll-deployment-brake-operator" => {
|
||||
require_only(&options, &["private-store"])?;
|
||||
enroll_service_identity_at::<IdunnDeploymentBrakeOperatorIdentity>(&path(
|
||||
&options,
|
||||
"private-store",
|
||||
)?)?;
|
||||
enroll_identity::<IdunnDeploymentBrakeOperatorIdentity>(&options)?
|
||||
}
|
||||
"export-deployment-brake-operator-anchor" => {
|
||||
require_only(&options, &["private-store", "public-anchor"])?;
|
||||
let private = path(&options, "private-store")?;
|
||||
let public = path(&options, "public-anchor")?;
|
||||
reject_alias(&private, &public)?;
|
||||
refuse_existing(&public, "deployment brake operator anchor")?;
|
||||
let signer =
|
||||
open_service_identity_at::<IdunnDeploymentBrakeOperatorIdentity>(&private)?;
|
||||
export_service_identity_trust_anchor(&signer, &public)?;
|
||||
export_identity_anchor::<IdunnDeploymentBrakeOperatorIdentity>(
|
||||
&options,
|
||||
"deployment brake operator anchor",
|
||||
)?
|
||||
}
|
||||
"deployment-brake-engage" => deployment_brake_engage(&options)?,
|
||||
"deployment-brake-release" => deployment_brake_release(&options)?,
|
||||
"deployment-brake-status" => deployment_brake_status(&options)?,
|
||||
"lifecycle-brake-engage" => lifecycle_brake_engage(&options)?,
|
||||
"lifecycle-brake-release" => lifecycle_brake_release(&options)?,
|
||||
"lifecycle-brake-status" => lifecycle_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)?,
|
||||
|
|
@ -97,6 +94,26 @@ pub fn run(args: impl IntoIterator<Item = String>) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn enroll_identity<P: ServiceIdentityProfile>(options: &BTreeMap<String, String>) -> Result<()> {
|
||||
require_only(options, &["private-store"])?;
|
||||
enroll_service_identity_at::<P>(&path(options, "private-store")?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn export_identity_anchor<P: ServiceIdentityProfile>(
|
||||
options: &BTreeMap<String, String>,
|
||||
label: &str,
|
||||
) -> Result<()> {
|
||||
require_only(options, &["private-store", "public-anchor"])?;
|
||||
let private = path(options, "private-store")?;
|
||||
let public = path(options, "public-anchor")?;
|
||||
reject_alias(&private, &public)?;
|
||||
refuse_existing(&public, label)?;
|
||||
let signer = open_service_identity_at::<P>(&private)?;
|
||||
export_service_identity_trust_anchor(&signer, &public)?;
|
||||
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(
|
||||
|
|
@ -262,6 +279,184 @@ fn deployment_brake_status(options: &BTreeMap<String, String>) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn lifecycle_brake_engage(options: &BTreeMap<String, String>) -> Result<()> {
|
||||
require_only(
|
||||
options,
|
||||
&[
|
||||
"store",
|
||||
"runtime-id",
|
||||
"target",
|
||||
"reason",
|
||||
"updated-at-unix-millis",
|
||||
],
|
||||
)?;
|
||||
let updated = parse_u64(options, "updated-at-unix-millis")?;
|
||||
let record = IdunnLifecycleBrakeRecord {
|
||||
schema_version: IDUNN_LIFECYCLE_BRAKE_SCHEMA.into(),
|
||||
authority: IDUNN_LIFECYCLE_BRAKE_AUTHORITY.into(),
|
||||
runtime_id: required(options, "runtime-id")?.into(),
|
||||
target: required(options, "target")?.into(),
|
||||
scope: IDUNN_LIFECYCLE_BRAKE_SCOPE.into(),
|
||||
status: "engaged".into(),
|
||||
reason: required(options, "reason")?.into(),
|
||||
updated_at_unix_millis: updated,
|
||||
released_until_unix_millis: None,
|
||||
};
|
||||
replace_lifecycle_brake(&path(options, "store")?, record)
|
||||
}
|
||||
|
||||
fn lifecycle_brake_release(options: &BTreeMap<String, String>) -> Result<()> {
|
||||
allow_only(
|
||||
options,
|
||||
&[
|
||||
"store",
|
||||
"runtime-id",
|
||||
"target",
|
||||
"reason",
|
||||
"updated-at-unix-millis",
|
||||
"released-until-unix-millis",
|
||||
],
|
||||
)?;
|
||||
let updated = parse_u64(options, "updated-at-unix-millis")?;
|
||||
let record = IdunnLifecycleBrakeRecord {
|
||||
schema_version: IDUNN_LIFECYCLE_BRAKE_SCHEMA.into(),
|
||||
authority: IDUNN_LIFECYCLE_BRAKE_AUTHORITY.into(),
|
||||
runtime_id: required(options, "runtime-id")?.into(),
|
||||
target: required(options, "target")?.into(),
|
||||
scope: IDUNN_LIFECYCLE_BRAKE_SCOPE.into(),
|
||||
status: "released".into(),
|
||||
reason: required(options, "reason")?.into(),
|
||||
updated_at_unix_millis: updated,
|
||||
released_until_unix_millis: options
|
||||
.get("released-until-unix-millis")
|
||||
.map(|value| {
|
||||
value
|
||||
.parse()
|
||||
.context("--released-until-unix-millis must be u64")
|
||||
})
|
||||
.transpose()?,
|
||||
};
|
||||
replace_lifecycle_brake(&path(options, "store")?, record)
|
||||
}
|
||||
|
||||
fn lifecycle_brake_status(options: &BTreeMap<String, String>) -> Result<()> {
|
||||
require_only(
|
||||
options,
|
||||
&["store", "runtime-id", "target", "now-unix-millis"],
|
||||
)?;
|
||||
let runtime_id = lifecycle_identifier(options, "runtime-id")?;
|
||||
let target = lifecycle_identifier(options, "target")?;
|
||||
let now = parse_u64(options, "now-unix-millis")?;
|
||||
match read_lifecycle_brake(&path(options, "store")?)? {
|
||||
None => {
|
||||
evaluate_idunn_continuity_restart(
|
||||
IdunnLifecycleBrakeObservation::Missing,
|
||||
runtime_id,
|
||||
target,
|
||||
now,
|
||||
)
|
||||
.map_err(|denial| anyhow!("lifecycle brake denied continuity restart: {denial:?}"))?;
|
||||
println!("allowed runtime={runtime_id} target={target} brake=absent");
|
||||
}
|
||||
Some(record) => {
|
||||
evaluate_idunn_continuity_restart(
|
||||
IdunnLifecycleBrakeObservation::Present(&record),
|
||||
runtime_id,
|
||||
target,
|
||||
now,
|
||||
)
|
||||
.map_err(|denial| anyhow!("lifecycle brake denied continuity restart: {denial:?}"))?;
|
||||
if let Some(expires) = record.released_until_unix_millis {
|
||||
println!(
|
||||
"allowed runtime={} target={} brake=released expires={expires}",
|
||||
record.runtime_id, record.target
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"allowed runtime={} target={} brake=released expires=never",
|
||||
record.runtime_id, record.target
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn replace_lifecycle_brake(path: &Path, record: IdunnLifecycleBrakeRecord) -> Result<()> {
|
||||
record.validate()?;
|
||||
let store = SingleFileMessagePackBackingStore::new(path);
|
||||
let entries = store.pull_all_read_only_snapshot()?;
|
||||
let current = match entries.as_slice() {
|
||||
[] => None,
|
||||
[entry]
|
||||
if entry.r#type == IdunnLifecycleBrakeRecord::TYPE
|
||||
&& entry.schema_id.as_deref() == Some(IDUNN_LIFECYCLE_BRAKE_SCHEMA) =>
|
||||
{
|
||||
let current_record = IdunnLifecycleBrakeRecord::decode_canonical(&entry.payload)?;
|
||||
if entry.key != current_record.target {
|
||||
bail!("lifecycle brake envelope key does not match its target");
|
||||
}
|
||||
if current_record.runtime_id != record.runtime_id
|
||||
|| current_record.target != record.target
|
||||
{
|
||||
bail!("lifecycle brake store is bound to another runtime or target");
|
||||
}
|
||||
if record.updated_at_unix_millis <= current_record.updated_at_unix_millis {
|
||||
bail!("lifecycle brake update time must advance");
|
||||
}
|
||||
Some(entry.clone())
|
||||
}
|
||||
_ => bail!("lifecycle brake store is corrupt or ambiguous"),
|
||||
};
|
||||
let next = typed_envelope(
|
||||
&record.target,
|
||||
&record,
|
||||
IDUNN_LIFECYCLE_BRAKE_SCHEMA,
|
||||
record.updated_at_unix_millis,
|
||||
)?;
|
||||
if !store.compare_exchange(
|
||||
&[CultCacheExpectedEnvelope {
|
||||
r#type: IdunnLifecycleBrakeRecord::TYPE.into(),
|
||||
key: record.target.clone(),
|
||||
current,
|
||||
}],
|
||||
&[next],
|
||||
)? {
|
||||
bail!("lifecycle brake changed during transition");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn read_lifecycle_brake(path: &Path) -> Result<Option<IdunnLifecycleBrakeRecord>> {
|
||||
if !path.exists() {
|
||||
return Ok(None);
|
||||
}
|
||||
let entries = SingleFileMessagePackBackingStore::new(path).pull_all_read_only_snapshot()?;
|
||||
let entry = match entries.as_slice() {
|
||||
[] => return Ok(None),
|
||||
[entry] => entry,
|
||||
_ => bail!("lifecycle brake store is ambiguous"),
|
||||
};
|
||||
if entry.r#type != IdunnLifecycleBrakeRecord::TYPE
|
||||
|| entry.schema_id.as_deref() != Some(IDUNN_LIFECYCLE_BRAKE_SCHEMA)
|
||||
{
|
||||
bail!("lifecycle brake store contains a foreign record");
|
||||
}
|
||||
let record = IdunnLifecycleBrakeRecord::decode_canonical(&entry.payload)?;
|
||||
if entry.key != record.target {
|
||||
bail!("lifecycle brake envelope key does not match its target");
|
||||
}
|
||||
Ok(Some(record))
|
||||
}
|
||||
|
||||
fn lifecycle_identifier<'a>(options: &'a BTreeMap<String, String>, name: &str) -> Result<&'a str> {
|
||||
let value = required(options, name)?;
|
||||
if value.trim().is_empty() || value.len() > 256 || value.chars().any(char::is_control) {
|
||||
bail!("--{name} is empty, oversized, or contains control characters");
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn replace_brake(path: &Path, record: IdunnDeploymentBrakeRecord, millis: u64) -> Result<()> {
|
||||
let store = SingleFileMessagePackBackingStore::new(path);
|
||||
let entries = store.pull_all_read_only_snapshot()?;
|
||||
|
|
@ -907,7 +1102,7 @@ fn normalized(path: &Path) -> Result<PathBuf> {
|
|||
}
|
||||
|
||||
fn usage() -> &'static str {
|
||||
"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>"
|
||||
"Usage: idunn-provision enroll-provider-health-identity --private-store <path>\n idunn-provision provider-health-public-key --private-store <path>\n idunn-provision export-provider-health-public-anchor --private-store <path> --public-anchor <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-odin-topology-identity --private-store <path>\n idunn-provision export-odin-topology-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 lifecycle-brake-engage --store <path> --runtime-id <id> --target <id> --reason <text> --updated-at-unix-millis <u64>\n idunn-provision lifecycle-brake-release --store <path> --runtime-id <id> --target <id> --reason <text> --updated-at-unix-millis <u64> [--released-until-unix-millis <u64>]\n idunn-provision lifecycle-brake-status --store <path> --runtime-id <id> --target <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)]
|
||||
|
|
@ -1476,6 +1671,144 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn provider_and_odin_anchor_exports_are_profile_exact_immutable_and_non_aliasing() -> Result<()>
|
||||
{
|
||||
let temp = TempDir::new()?;
|
||||
let provider_private = temp.path().join("provider-private.cc");
|
||||
let provider_anchor = temp.path().join("provider-anchor.cc");
|
||||
invoke(&[
|
||||
"enroll-provider-health-identity",
|
||||
"--private-store",
|
||||
provider_private.to_str().unwrap(),
|
||||
])?;
|
||||
assert!(
|
||||
invoke(&[
|
||||
"export-provider-health-public-anchor",
|
||||
"--private-store",
|
||||
provider_private.to_str().unwrap(),
|
||||
"--public-anchor",
|
||||
provider_private.to_str().unwrap(),
|
||||
])
|
||||
.is_err()
|
||||
);
|
||||
invoke(&[
|
||||
"export-provider-health-public-anchor",
|
||||
"--private-store",
|
||||
provider_private.to_str().unwrap(),
|
||||
"--public-anchor",
|
||||
provider_anchor.to_str().unwrap(),
|
||||
])?;
|
||||
let provider_entries = store_snapshot(&provider_anchor)?;
|
||||
let [provider_envelope] = provider_entries.as_slice() else {
|
||||
panic!("provider anchor store must contain exactly one envelope");
|
||||
};
|
||||
assert_eq!(
|
||||
provider_envelope.r#type,
|
||||
GameCultProviderHealthIdentity::TRUST_ANCHOR_TYPE
|
||||
);
|
||||
assert_eq!(
|
||||
provider_envelope.key,
|
||||
GameCultProviderHealthIdentity::TRUST_ANCHOR_KEY
|
||||
);
|
||||
assert_eq!(
|
||||
provider_envelope.schema_id.as_deref(),
|
||||
Some(GameCultProviderHealthIdentity::TRUST_ANCHOR_SCHEMA)
|
||||
);
|
||||
let provider: ServiceIdentityTrustAnchor =
|
||||
rmp_serde::from_slice(&provider_envelope.payload)?;
|
||||
assert_eq!(rmp_serde::to_vec(&provider)?, provider_envelope.payload);
|
||||
assert_eq!(
|
||||
provider.identity_id,
|
||||
derive_service_identity_id::<GameCultProviderHealthIdentity>(&provider.public_key)?
|
||||
);
|
||||
assert!(open_service_identity_at::<OdinTopologyIdentity>(&provider_private).is_err());
|
||||
let provider_before = std::fs::read(&provider_anchor)?;
|
||||
assert!(
|
||||
invoke(&[
|
||||
"export-provider-health-public-anchor",
|
||||
"--private-store",
|
||||
provider_private.to_str().unwrap(),
|
||||
"--public-anchor",
|
||||
provider_anchor.to_str().unwrap(),
|
||||
])
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(std::fs::read(&provider_anchor)?, provider_before);
|
||||
|
||||
let odin_private = temp.path().join("odin-private.cc");
|
||||
let odin_anchor = temp.path().join("odin-anchor.cc");
|
||||
invoke(&[
|
||||
"enroll-odin-topology-identity",
|
||||
"--private-store",
|
||||
odin_private.to_str().unwrap(),
|
||||
])?;
|
||||
assert!(open_service_identity_at::<GameCultProviderHealthIdentity>(&odin_private).is_err());
|
||||
assert!(
|
||||
invoke(&[
|
||||
"export-odin-topology-public-anchor",
|
||||
"--private-store",
|
||||
odin_private.to_str().unwrap(),
|
||||
"--public-anchor",
|
||||
odin_private.to_str().unwrap(),
|
||||
])
|
||||
.is_err()
|
||||
);
|
||||
invoke(&[
|
||||
"export-odin-topology-public-anchor",
|
||||
"--private-store",
|
||||
odin_private.to_str().unwrap(),
|
||||
"--public-anchor",
|
||||
odin_anchor.to_str().unwrap(),
|
||||
])?;
|
||||
let odin_entries = store_snapshot(&odin_anchor)?;
|
||||
let [odin_envelope] = odin_entries.as_slice() else {
|
||||
panic!("Odin anchor store must contain exactly one envelope");
|
||||
};
|
||||
assert_eq!(
|
||||
odin_envelope.r#type,
|
||||
OdinTopologyIdentity::TRUST_ANCHOR_TYPE
|
||||
);
|
||||
assert_eq!(odin_envelope.key, OdinTopologyIdentity::TRUST_ANCHOR_KEY);
|
||||
assert_eq!(
|
||||
odin_envelope.schema_id.as_deref(),
|
||||
Some(OdinTopologyIdentity::TRUST_ANCHOR_SCHEMA)
|
||||
);
|
||||
let odin: ServiceIdentityTrustAnchor = rmp_serde::from_slice(&odin_envelope.payload)?;
|
||||
assert_eq!(rmp_serde::to_vec(&odin)?, odin_envelope.payload);
|
||||
assert_eq!(
|
||||
odin.identity_id,
|
||||
derive_service_identity_id::<OdinTopologyIdentity>(&odin.public_key)?
|
||||
);
|
||||
assert_ne!(provider.identity_id, odin.identity_id);
|
||||
let odin_before = std::fs::read(&odin_anchor)?;
|
||||
assert!(
|
||||
invoke(&[
|
||||
"export-odin-topology-public-anchor",
|
||||
"--private-store",
|
||||
odin_private.to_str().unwrap(),
|
||||
"--public-anchor",
|
||||
odin_anchor.to_str().unwrap(),
|
||||
])
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(std::fs::read(&odin_anchor)?, odin_before);
|
||||
|
||||
let wrong_profile_output = temp.path().join("wrong-profile.cc");
|
||||
assert!(
|
||||
invoke(&[
|
||||
"export-provider-health-public-anchor",
|
||||
"--private-store",
|
||||
odin_private.to_str().unwrap(),
|
||||
"--public-anchor",
|
||||
wrong_profile_output.to_str().unwrap(),
|
||||
])
|
||||
.is_err()
|
||||
);
|
||||
assert!(!wrong_profile_output.exists());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn identity_enrollment_and_export_are_immutable_and_paths_cannot_alias() -> Result<()> {
|
||||
let temp = TempDir::new()?;
|
||||
|
|
@ -1916,6 +2249,159 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lifecycle_brake_is_absence_allow_and_exact_to_runtime_target_and_expiry() -> Result<()> {
|
||||
let temp = TempDir::new()?;
|
||||
let missing = temp.path().join("missing-lifecycle.cc");
|
||||
invoke(&[
|
||||
"lifecycle-brake-status",
|
||||
"--store",
|
||||
missing.to_str().unwrap(),
|
||||
"--runtime-id",
|
||||
"idunn-yggdrasil",
|
||||
"--target",
|
||||
"ghostlight",
|
||||
"--now-unix-millis",
|
||||
"100",
|
||||
])?;
|
||||
assert!(!missing.exists());
|
||||
|
||||
let store = temp.path().join("ghostlight-lifecycle.cc");
|
||||
invoke(&[
|
||||
"lifecycle-brake-engage",
|
||||
"--store",
|
||||
store.to_str().unwrap(),
|
||||
"--runtime-id",
|
||||
"idunn-yggdrasil",
|
||||
"--target",
|
||||
"ghostlight",
|
||||
"--reason",
|
||||
"operator maintenance",
|
||||
"--updated-at-unix-millis",
|
||||
"200",
|
||||
])?;
|
||||
let engaged = read_lifecycle_brake(&store)?.context("lifecycle brake must exist")?;
|
||||
assert_eq!(engaged.status, "engaged");
|
||||
assert_eq!(engaged.runtime_id, "idunn-yggdrasil");
|
||||
assert_eq!(engaged.target, "ghostlight");
|
||||
assert!(read_brake(&store).is_err());
|
||||
assert!(
|
||||
invoke(&[
|
||||
"lifecycle-brake-status",
|
||||
"--store",
|
||||
store.to_str().unwrap(),
|
||||
"--runtime-id",
|
||||
"idunn-yggdrasil",
|
||||
"--target",
|
||||
"ghostlight",
|
||||
"--now-unix-millis",
|
||||
"201",
|
||||
])
|
||||
.is_err()
|
||||
);
|
||||
|
||||
let engaged_bytes = std::fs::read(&store)?;
|
||||
assert!(
|
||||
invoke(&[
|
||||
"lifecycle-brake-release",
|
||||
"--store",
|
||||
store.to_str().unwrap(),
|
||||
"--runtime-id",
|
||||
"idunn-nightwing",
|
||||
"--target",
|
||||
"ghostlight",
|
||||
"--reason",
|
||||
"wrong runtime",
|
||||
"--updated-at-unix-millis",
|
||||
"300",
|
||||
])
|
||||
.is_err()
|
||||
);
|
||||
assert!(
|
||||
invoke(&[
|
||||
"lifecycle-brake-release",
|
||||
"--store",
|
||||
store.to_str().unwrap(),
|
||||
"--runtime-id",
|
||||
"idunn-yggdrasil",
|
||||
"--target",
|
||||
"odin",
|
||||
"--reason",
|
||||
"wrong target",
|
||||
"--updated-at-unix-millis",
|
||||
"300",
|
||||
])
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(std::fs::read(&store)?, engaged_bytes);
|
||||
|
||||
invoke(&[
|
||||
"lifecycle-brake-release",
|
||||
"--store",
|
||||
store.to_str().unwrap(),
|
||||
"--runtime-id",
|
||||
"idunn-yggdrasil",
|
||||
"--target",
|
||||
"ghostlight",
|
||||
"--reason",
|
||||
"bounded continuity window",
|
||||
"--updated-at-unix-millis",
|
||||
"300",
|
||||
"--released-until-unix-millis",
|
||||
"500",
|
||||
])?;
|
||||
invoke(&[
|
||||
"lifecycle-brake-status",
|
||||
"--store",
|
||||
store.to_str().unwrap(),
|
||||
"--runtime-id",
|
||||
"idunn-yggdrasil",
|
||||
"--target",
|
||||
"ghostlight",
|
||||
"--now-unix-millis",
|
||||
"499",
|
||||
])?;
|
||||
for (runtime, target, now) in [
|
||||
("idunn-nightwing", "ghostlight", "499"),
|
||||
("idunn-yggdrasil", "odin", "499"),
|
||||
("idunn-yggdrasil", "ghostlight", "500"),
|
||||
] {
|
||||
assert!(
|
||||
invoke(&[
|
||||
"lifecycle-brake-status",
|
||||
"--store",
|
||||
store.to_str().unwrap(),
|
||||
"--runtime-id",
|
||||
runtime,
|
||||
"--target",
|
||||
target,
|
||||
"--now-unix-millis",
|
||||
now,
|
||||
])
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
let released_bytes = std::fs::read(&store)?;
|
||||
assert!(
|
||||
invoke(&[
|
||||
"lifecycle-brake-engage",
|
||||
"--store",
|
||||
store.to_str().unwrap(),
|
||||
"--runtime-id",
|
||||
"idunn-yggdrasil",
|
||||
"--target",
|
||||
"ghostlight",
|
||||
"--reason",
|
||||
"stale replay",
|
||||
"--updated-at-unix-millis",
|
||||
"300",
|
||||
])
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(std::fs::read(&store)?, released_bytes);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn brake_compare_exchange_rejects_stale_transition_snapshot() -> Result<()> {
|
||||
let temp = TempDir::new()?;
|
||||
|
|
|
|||
23
crates/odin-daemon/Cargo.toml
Normal file
23
crates/odin-daemon/Cargo.toml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
[package]
|
||||
name = "odin-daemon"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[lib]
|
||||
name = "odin_daemon"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
chrono = "0.4"
|
||||
cultcache-rs = { git = "https://github.com/GameCult/CultLib.git", rev = "cbde940df2f5ee0ccac50e8dbfe9f36ffbebb585", package = "cultcache-rs" }
|
||||
cultmesh-rs = { path = "../../vendor/cultmesh-rs" }
|
||||
cultnet-rs = { git = "https://github.com/GameCult/CultLib.git", rev = "cbde940df2f5ee0ccac50e8dbfe9f36ffbebb585", package = "cultnet-rs" }
|
||||
fs2 = "0.4"
|
||||
rmp-serde = "1.3"
|
||||
serde = "1"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3"
|
||||
1832
crates/odin-daemon/src/lib.rs
Normal file
1832
crates/odin-daemon/src/lib.rs
Normal file
File diff suppressed because it is too large
Load diff
1248
crates/odin-daemon/src/main.rs
Normal file
1248
crates/odin-daemon/src/main.rs
Normal file
File diff suppressed because it is too large
Load diff
72
deployment/idunn/recipe.toml
Normal file
72
deployment/idunn/recipe.toml
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
schema = "gamecult.idunn.target_declaration.v1"
|
||||
target = "odin"
|
||||
source_stamp_environment = "ODIN_BUILD_COMMIT"
|
||||
required_gitlinks = []
|
||||
|
||||
[[steps]]
|
||||
id = "test-odin-daemon"
|
||||
phase = "test"
|
||||
runner = "rust-build"
|
||||
argv = ["cargo", "test", "--locked", "-p", "odin-daemon"]
|
||||
|
||||
[[steps]]
|
||||
id = "build-odin-daemon"
|
||||
phase = "build"
|
||||
runner = "rust-build"
|
||||
argv = [
|
||||
"cargo",
|
||||
"build",
|
||||
"--locked",
|
||||
"--release",
|
||||
"-p",
|
||||
"odin-daemon",
|
||||
"--bin",
|
||||
"odin-daemon",
|
||||
]
|
||||
|
||||
[[artifacts]]
|
||||
id = "odin-daemon"
|
||||
source_kind = "runner-output"
|
||||
runner = "rust-build"
|
||||
source = "target/release/odin-daemon"
|
||||
destination = "odin-daemon"
|
||||
executable = true
|
||||
|
||||
[service]
|
||||
executable_artifact = "odin-daemon"
|
||||
arguments = [
|
||||
{ kind = "literal", value = "--store" },
|
||||
{ kind = "binding", name = "store_path" },
|
||||
{ kind = "literal", value = "--idunn-projection" },
|
||||
{ kind = "binding", name = "idunn_projection_path" },
|
||||
{ kind = "literal", value = "--idunn-anchor" },
|
||||
{ kind = "binding", name = "idunn_anchor_path" },
|
||||
]
|
||||
transport = "rudp"
|
||||
route_required = true
|
||||
required_environment = [
|
||||
"GAMECULT_IDUNN_CANDIDATE_BIND",
|
||||
"GAMECULT_IDUNN_PROCESS_WRITE_LEASE",
|
||||
"GAMECULT_IDUNN_RUNTIME_BUNDLE",
|
||||
"ODIN_TOPOLOGY_IDENTITY",
|
||||
]
|
||||
|
||||
[service.health]
|
||||
contract = "odin.runtime-health.v1"
|
||||
|
||||
[state]
|
||||
schema_generation = "odin-v2"
|
||||
|
||||
[[state.slots]]
|
||||
id = "topology"
|
||||
relative_path = "topology.cc"
|
||||
kind = "cultcache-file"
|
||||
schema = "odin.runtime_topology_correlation.v2"
|
||||
writer = "process-bound-single-writer"
|
||||
recovery = "preserve"
|
||||
startup = "create-or-open-after-write-lease"
|
||||
|
||||
[[provides]]
|
||||
capability = "odin.verse-rendezvous"
|
||||
schema = "odin.verse-topology.v1"
|
||||
compatibility = "v1"
|
||||
Loading…
Reference in a new issue