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
2 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
|
/// Write the shared policy, name the agent's entity and enable it, then write
|
||||||
/// the cert-auth role that attaches the policy.
|
/// 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;
|
let queue_credential = wanted;
|
||||||
|
|
||||||
// The role is where the agent's SSH switch lives, so a rewrite keeps what it
|
let inputs = inputs_keeping_ssh(&store, agent, &credential).await?;
|
||||||
// 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)?;
|
|
||||||
publish_access(&store, agent, &inputs).await?;
|
publish_access(&store, agent, &inputs).await?;
|
||||||
tracing::info!(agent, %path, role = %name, "agent store identity published");
|
tracing::info!(agent, %path, role = %name, "agent store identity published");
|
||||||
|
|
||||||
|
|
@ -470,7 +480,7 @@ async fn read_back_as_agent(
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
use super::{
|
||||||
ENV_AGENT_PKI_MOUNT, ENV_AGENT_PKI_ROLE, MintStep, QUEUE_SECRET_BYTES, agent_pki,
|
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 crate::store::fake::FakeAccess;
|
||||||
use swarm_secret_client::{mtls, policy};
|
use swarm_secret_client::{mtls, policy};
|
||||||
|
|
@ -656,14 +666,16 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
// The rewrite reads the role it replaces, and keeps the grant.
|
// 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
|
.await
|
||||||
.expect("reads");
|
.expect("reads");
|
||||||
assert!(ssh);
|
|
||||||
let again = role_inputs("atlas", &credential, ssh).expect("legal");
|
|
||||||
assert_eq!(again.attached, ["hive-agent", "hive-agent-ssh"]);
|
assert_eq!(again.attached, ["hive-agent", "hive-agent-ssh"]);
|
||||||
|
|
||||||
// The control: a role that never had it does not gain it.
|
// 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 off = FakeAccess::default();
|
||||||
let inputs = role_inputs("atlas", &credential, false).expect("legal");
|
let inputs = role_inputs("atlas", &credential, false).expect("legal");
|
||||||
publish_access(&off, "atlas", &inputs)
|
publish_access(&off, "atlas", &inputs)
|
||||||
|
|
|
||||||
|
|
@ -574,6 +574,20 @@ pub(crate) async fn start_forge(
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The routes of an agent's permissions, the permission catalogue and the SSH
|
||||||
|
/// CA key the permissions card shows, kept apart so `build_app` stays under the
|
||||||
|
/// line limit.
|
||||||
|
fn permission_routes(router: OpenApiRouter<AppState>) -> OpenApiRouter<AppState> {
|
||||||
|
router
|
||||||
|
.routes(routes!(
|
||||||
|
agent_permissions::get_agent_permissions,
|
||||||
|
agent_permissions::put_agent_permissions,
|
||||||
|
agent_permissions::delete_agent_permissions
|
||||||
|
))
|
||||||
|
.routes(routes!(agent_permissions::get_permission_catalogue))
|
||||||
|
.routes(routes!(agent_ssh::get_ssh_ca))
|
||||||
|
}
|
||||||
|
|
||||||
/// The routes that write, delete and list an agent's linked accounts and
|
/// The routes that write, delete and list an agent's linked accounts and
|
||||||
/// backend environment, and those of its claude login, kept apart so
|
/// backend environment, and those of its claude login, kept apart so
|
||||||
/// `build_app` stays under the line limit.
|
/// `build_app` stays under the line limit.
|
||||||
|
|
@ -616,8 +630,9 @@ fn linked_account_routes(router: OpenApiRouter<AppState>) -> OpenApiRouter<AppSt
|
||||||
/// tripped a lint about the startup sequence, which is not where the change
|
/// tripped a lint about the startup sequence, which is not where the change
|
||||||
/// was. A new route now costs one line here and none there.
|
/// was. A new route now costs one line here and none there.
|
||||||
pub(crate) fn build_app(state: AppState) -> axum::Router {
|
pub(crate) fn build_app(state: AppState) -> axum::Router {
|
||||||
let (router, api) =
|
let (router, api) = permission_routes(linked_account_routes(
|
||||||
linked_account_routes(OpenApiRouter::<AppState>::with_openapi(ApiDoc::openapi()))
|
OpenApiRouter::<AppState>::with_openapi(ApiDoc::openapi()),
|
||||||
|
))
|
||||||
.routes(routes!(routes::health))
|
.routes(routes!(routes::health))
|
||||||
.routes(routes!(alerts::get_alerts))
|
.routes(routes!(alerts::get_alerts))
|
||||||
.routes(routes!(hives::get_hives))
|
.routes(routes!(hives::get_hives))
|
||||||
|
|
@ -639,13 +654,6 @@ pub(crate) fn build_app(state: AppState) -> axum::Router {
|
||||||
agent_limits::put_agent_limits,
|
agent_limits::put_agent_limits,
|
||||||
agent_limits::delete_agent_limits
|
agent_limits::delete_agent_limits
|
||||||
))
|
))
|
||||||
.routes(routes!(
|
|
||||||
agent_permissions::get_agent_permissions,
|
|
||||||
agent_permissions::put_agent_permissions,
|
|
||||||
agent_permissions::delete_agent_permissions
|
|
||||||
))
|
|
||||||
.routes(routes!(agent_permissions::get_permission_catalogue))
|
|
||||||
.routes(routes!(agent_ssh::get_ssh_ca))
|
|
||||||
.routes(routes!(
|
.routes(routes!(
|
||||||
egress_allow::get_allowed_domains,
|
egress_allow::get_allowed_domains,
|
||||||
egress_allow::add_allowed_domain,
|
egress_allow::add_allowed_domain,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue