Watch
0
0
Fork
You've already forked hyperhive
0

disable a destroyed agent's identity entity and delete its login role

This commit is contained in:
atlas 2026-11-16 16:50:53 +01:00
commit 299b922039

View file

@ -8,8 +8,8 @@
//! and its grant covers exactly the calls made here (`swarm-bao.nix`'s
//! `controllerPolicyText`: `update` on the agent PKI role's `issue` path, and
//! `create/update` on `secret/data/swarm/agents/*`, on
//! `sys/policies/acl/hive-*`, and on `auth/cert/certs/hive-*`, plus the
//! `identity/` and `sys/auth/cert` stanzas [`crate::agent_entity`] uses).
//! `sys/policies/acl/hive-*`, and on `auth/cert/certs/hive-*` (`delete` too), plus the
//! `identity/` and `sys/auth/cert` stanzas [`crate::agent_entity`] and [`crate::agent_cutoff`] use).
//!
//! **Two credentials, deliberately unrelated.** The certificate reaches the
//! store; the queue secret identifies the agent to the swarm queue. Both sit
@ -80,8 +80,11 @@ fn role_inputs<'a>(agent: &str, credential: &'a mtls::Credential) -> Result<Role
})
}
/// Write the shared policy, name the agent's entity, then write the cert-auth
/// role that attaches the policy.
/// Write the shared policy, name the agent's entity and enable it, then write
/// the cert-auth role that attaches the policy.
///
/// Enabling clears the flag [`crate::agent_cutoff::cut_off`] set when an agent
/// of this name was destroyed, so a new agent of that name can log in.
///
/// The entity comes before the role and is a precondition for it. The role
/// attaches the shared policy alone, so an agent whose entity is not named after
@ -108,6 +111,10 @@ async fn publish_access(
.await
.with_context(|| format!("naming {agent}'s identity entity; the role is not changed"))
.at(MintStep::Entity)?;
crate::agent_cutoff::restore(store, agent)
.await
.with_context(|| format!("enabling {agent}'s identity entity; the role is not changed"))
.at(MintStep::Entity)?;
store
.write_cert_role(
DEFAULT_CERT_MOUNT,
@ -235,7 +242,7 @@ impl<T, E: Into<anyhow::Error>> AtStep<T> for Result<T, E> {
/// presents names *it* rather than its hive;
/// 4. write the shared ACL document [`policy::render_shared_agent`] renders;
/// 5. name the agent's identity entity after the agent ([`crate::agent_entity`]),
/// which the policy reads;
/// which the policy reads, and enable it ([`crate::agent_cutoff::restore`]);
/// 6. write the cert-auth role that ties the three together, attaching that
/// policy and pinning the CA the store named as this leaf's issuer.
///
@ -610,6 +617,45 @@ mod tests {
);
}
/// An agent created under the name of a destroyed one gets its entity
/// enabled and its role back, the enable first.
#[tokio::test]
async fn re_creating_a_cut_off_agent_enables_its_entity_and_writes_its_role() {
let store = FakeAccess::default().with_entity("atlas");
crate::agent_cutoff::cut_off(&store, "atlas")
.await
.expect("accepted");
assert!(store.is_disabled("atlas"), "the control: it was cut off");
assert_eq!(store.role("hive-agent-atlas"), None);
let credential = credential();
let inputs = role_inputs("atlas", &credential).expect("legal");
publish_access(&store, "atlas", &inputs)
.await
.expect("a store that accepts everything");
assert!(!store.is_disabled("atlas"), "{:?}", store.calls());
assert!(store.role("hive-agent-atlas").is_some());
let calls = store.calls();
let at = |call: &str| calls.iter().position(|c| c == call).expect(call);
assert!(
at("set_entity_disabled atlas false")
< at("write_cert_role hive-agent-atlas hive-agent"),
"the entity is enabled before the role is written: {calls:?}"
);
}
#[tokio::test]
async fn a_mint_whose_enable_is_refused_leaves_the_role_alone() {
let store = FakeAccess::default().refusing_disable();
let credential = credential();
let inputs = role_inputs("atlas", &credential).expect("legal");
let err = publish_access(&store, "atlas", &inputs)
.await
.expect_err("the enable is refused");
assert_eq!(failed_step(&err), Some(MintStep::Entity), "{err:#}");
assert!(store.roles_written().is_empty(), "{:?}", store.calls());
}
#[tokio::test]
async fn a_renewal_whose_entity_step_fails_leaves_the_role_alone() {
let store = FakeAccess::without_accessor();