keep the signing policy on a role rewrite through one tested helper; route helper for build_app
This commit is contained in:
parent
e621397252
commit
df3fc02279
1 changed files with 126 additions and 106 deletions
|
|
@ -84,6 +84,22 @@ fn role_inputs<'a>(
|
|||
})
|
||||
}
|
||||
|
||||
/// The inputs for `agent`'s role, with the signing policy attached when the role
|
||||
/// it replaces has it. The role is where the agent's SSH switch lives, so a
|
||||
/// rewrite for a new certificate keeps what it has (`crate::agent_ssh`).
|
||||
async fn inputs_keeping_ssh<'a>(
|
||||
store: &impl AccessStore,
|
||||
agent: &str,
|
||||
credential: &'a mtls::Credential,
|
||||
) -> Result<RoleInputs<'a>> {
|
||||
let name = policy::agent_object_name(agent).at(MintStep::Role)?;
|
||||
let ssh = crate::agent_ssh::role_has_ssh(store, &name)
|
||||
.await
|
||||
.with_context(|| format!("reading the policies of the cert-auth role {name}"))
|
||||
.at(MintStep::Role)?;
|
||||
role_inputs(agent, credential, ssh).at(MintStep::Role)
|
||||
}
|
||||
|
||||
/// Write the shared policy, name the agent's entity and enable it, then write
|
||||
/// the cert-auth role that attaches the policy.
|
||||
///
|
||||
|
|
@ -331,13 +347,7 @@ pub async fn mint_and_verify(agent: &str) -> Result<()> {
|
|||
}
|
||||
let queue_credential = wanted;
|
||||
|
||||
// The role is where the agent's SSH switch lives, so a rewrite keeps what it
|
||||
// has (`crate::agent_ssh`).
|
||||
let ssh = crate::agent_ssh::role_has_ssh(&store, &name)
|
||||
.await
|
||||
.with_context(|| format!("reading the policies of the cert-auth role {name}"))
|
||||
.at(MintStep::Role)?;
|
||||
let inputs = role_inputs(agent, &credential, ssh).at(MintStep::Role)?;
|
||||
let inputs = inputs_keeping_ssh(&store, agent, &credential).await?;
|
||||
publish_access(&store, agent, &inputs).await?;
|
||||
tracing::info!(agent, %path, role = %name, "agent store identity published");
|
||||
|
||||
|
|
@ -470,7 +480,7 @@ async fn read_back_as_agent(
|
|||
mod tests {
|
||||
use super::{
|
||||
ENV_AGENT_PKI_MOUNT, ENV_AGENT_PKI_ROLE, MintStep, QUEUE_SECRET_BYTES, agent_pki,
|
||||
failed_step, generate_queue_secret, publish_access, role_inputs,
|
||||
failed_step, generate_queue_secret, inputs_keeping_ssh, publish_access, role_inputs,
|
||||
};
|
||||
use crate::store::fake::FakeAccess;
|
||||
use swarm_secret_client::{mtls, policy};
|
||||
|
|
@ -656,14 +666,16 @@ mod tests {
|
|||
);
|
||||
|
||||
// The rewrite reads the role it replaces, and keeps the grant.
|
||||
let ssh = crate::agent_ssh::role_has_ssh(&on, "hive-agent-atlas")
|
||||
let again = inputs_keeping_ssh(&on, "atlas", &credential)
|
||||
.await
|
||||
.expect("reads");
|
||||
assert!(ssh);
|
||||
let again = role_inputs("atlas", &credential, ssh).expect("legal");
|
||||
assert_eq!(again.attached, ["hive-agent", "hive-agent-ssh"]);
|
||||
|
||||
// The control: a role that never had it does not gain it.
|
||||
let fresh = inputs_keeping_ssh(&FakeAccess::default(), "atlas", &credential)
|
||||
.await
|
||||
.expect("reads");
|
||||
assert_eq!(fresh.attached, ["hive-agent"]);
|
||||
let off = FakeAccess::default();
|
||||
let inputs = role_inputs("atlas", &credential, false).expect("legal");
|
||||
publish_access(&off, "atlas", &inputs)
|
||||
|
|
|
|||
Loading…
Reference in a new issue