add one shared templated agent policy and name each agent's bao entity after it
This commit is contained in:
parent
d893097ffe
commit
4cdf807afc
1 changed files with 777 additions and 13 deletions
|
|
@ -8,7 +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-*`).
|
||||
//! `sys/policies/acl/hive-*`, and on `auth/cert/certs/hive-*`, plus the
|
||||
//! `identity/` and `sys/auth/cert` stanzas [`crate::agent_entity`] uses).
|
||||
//!
|
||||
//! **Two credentials, deliberately unrelated.** The certificate reaches the
|
||||
//! store; the queue secret identifies the agent to the swarm queue. Both sit
|
||||
|
|
@ -67,13 +68,18 @@ struct RoleInputs<'a> {
|
|||
ca: &'a str,
|
||||
/// The policy document the role attaches.
|
||||
policy: String,
|
||||
/// The policies the role attaches by name: the agent's own, and the one every
|
||||
/// agent shares.
|
||||
attached: [String; 2],
|
||||
}
|
||||
|
||||
fn role_inputs<'a>(agent: &str, credential: &'a mtls::Credential) -> Result<RoleInputs<'a>> {
|
||||
let name = policy::agent_object_name(agent)?;
|
||||
Ok(RoleInputs {
|
||||
name: policy::agent_object_name(agent)?,
|
||||
name: name.clone(),
|
||||
ca: &credential.ca,
|
||||
policy: policy::render_agent(agent)?,
|
||||
attached: [name, policy::SHARED_AGENT_POLICY.to_owned()],
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -119,9 +125,9 @@ pub(crate) fn generate_queue_secret() -> Result<String> {
|
|||
/// identity at the swarm queue, minted here so that the credential an agent
|
||||
/// presents names *it* rather than its hive;
|
||||
/// 4. write the ACL document [`policy::render_agent`] renders — read and list on
|
||||
/// this one agent's paths and nothing else;
|
||||
/// 5. write the cert-auth role that ties the three together, pinning the CA
|
||||
/// the store named as this leaf's issuer.
|
||||
/// this one agent's paths — and the shared [`policy::render_shared_agent`];
|
||||
/// 5. write the cert-auth role that ties the three together, attaching both
|
||||
/// policies and pinning the CA the store named as this leaf's issuer.
|
||||
///
|
||||
/// Policy before role, for the reason `read_policy::provision` gives: the role
|
||||
/// names the policy, so the other order leaves a window in which it points at
|
||||
|
|
@ -199,17 +205,29 @@ pub async fn mint_and_verify(agent: &str) -> Result<()> {
|
|||
.write_policy(&inputs.name, &inputs.policy)
|
||||
.await
|
||||
.with_context(|| format!("writing the read policy {}", inputs.name))?;
|
||||
store
|
||||
.write_policy(policy::SHARED_AGENT_POLICY, &policy::render_shared_agent())
|
||||
.await
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"writing the shared agent policy {}",
|
||||
policy::SHARED_AGENT_POLICY
|
||||
)
|
||||
})?;
|
||||
store
|
||||
.write_cert_role(
|
||||
DEFAULT_CERT_MOUNT,
|
||||
&inputs.name,
|
||||
inputs.ca,
|
||||
&inputs.name,
|
||||
&inputs.name,
|
||||
&inputs.attached.each_ref().map(String::as_str),
|
||||
)
|
||||
.await
|
||||
.with_context(|| format!("writing the cert-auth role {}", inputs.name))?;
|
||||
tracing::info!(agent, %path, role = %name, "agent store identity published");
|
||||
// Before the read-back below, whose login would otherwise create the
|
||||
// entity under a generated name.
|
||||
crate::agent_entity::ensure_agent(&store, agent).await;
|
||||
|
||||
read_back_as_agent(&credential, &name, &path, &queue_path, &queue_credential).await?;
|
||||
tracing::info!(
|
||||
|
|
@ -450,6 +468,11 @@ mod tests {
|
|||
"the CN the leaf is issued for"
|
||||
);
|
||||
assert_eq!(inputs.ca, "AGENT-CA");
|
||||
assert_eq!(
|
||||
inputs.attached,
|
||||
["hive-agent-atlas", policy::SHARED_AGENT_POLICY],
|
||||
"the role attaches the agent's own policy and the shared one"
|
||||
);
|
||||
assert_eq!(inputs.policy, policy::render_agent("atlas").expect("legal"));
|
||||
assert!(!inputs.policy.contains("swarm/hives/"), "{}", inputs.policy);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue