Watch
0
0
Fork
You've already forked hyperhive
0

keep the signing policy on a role rewrite through one tested helper; route helper for build_app

This commit is contained in:
atlas 2026-11-16 19:15:11 +01:00 • committed by mara
commit df3fc02279
2 changed files with 126 additions and 106 deletions

View file

@ -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)

View file

@ -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,101 +630,95 @@ 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!(alerts::get_alerts)) .routes(routes!(routes::health))
.routes(routes!(hives::get_hives)) .routes(routes!(alerts::get_alerts))
.routes(routes!(hives::get_hives_status)) .routes(routes!(hives::get_hives))
.routes(routes!(hives::get_links)) .routes(routes!(hives::get_hives_status))
.routes(routes!(hives::get_swarm_info)) .routes(routes!(hives::get_links))
.routes(routes!(jobq_graph::get_jobq_graph)) .routes(routes!(hives::get_swarm_info))
.routes(routes!(jobq_graph::get_jobq_rollup)) .routes(routes!(jobq_graph::get_jobq_graph))
.routes(routes!(config_prs::get_agent_config_pr)) .routes(routes!(jobq_graph::get_jobq_rollup))
.routes(routes!(agents::get_agent_icon)) .routes(routes!(config_prs::get_agent_config_pr))
.routes(routes!(agents_md::get_agents_md, agents_md::put_agents_md)) .routes(routes!(agents::get_agent_icon))
.routes(routes!( .routes(routes!(agents_md::get_agents_md, agents_md::put_agents_md))
inference::get_agent_inference, .routes(routes!(
inference::put_agent_inference, inference::get_agent_inference,
inference::delete_agent_inference inference::put_agent_inference,
)) inference::delete_agent_inference
.routes(routes!( ))
agent_limits::get_agent_limits, .routes(routes!(
agent_limits::put_agent_limits, agent_limits::get_agent_limits,
agent_limits::delete_agent_limits agent_limits::put_agent_limits,
)) agent_limits::delete_agent_limits
.routes(routes!( ))
agent_permissions::get_agent_permissions, .routes(routes!(
agent_permissions::put_agent_permissions, egress_allow::get_allowed_domains,
agent_permissions::delete_agent_permissions egress_allow::add_allowed_domain,
)) egress_allow::remove_allowed_domain
.routes(routes!(agent_permissions::get_permission_catalogue)) ))
.routes(routes!(agent_ssh::get_ssh_ca)) .routes(routes!(
.routes(routes!( egress_deny::get_denied_domains,
egress_allow::get_allowed_domains, egress_deny::add_denied_domain,
egress_allow::add_allowed_domain, egress_deny::remove_denied_domain
egress_allow::remove_allowed_domain ))
)) .routes(routes!(archetypes::get_archetypes))
.routes(routes!( .routes(routes!(config_prs::get_config_prs))
egress_deny::get_denied_domains, .routes(routes!(agents::create_agent))
egress_deny::add_denied_domain, .routes(routes!(forge_admin::mint_agent_forge_token))
egress_deny::remove_denied_domain .routes(routes!(forge_admin::make_forge_admin))
)) .routes(routes!(agents::get_agents))
.routes(routes!(archetypes::get_archetypes)) .routes(routes!(agents::get_agents_status))
.routes(routes!(config_prs::get_config_prs)) .routes(routes!(agents::set_agent_state))
.routes(routes!(agents::create_agent)) .routes(routes!(agents::get_hive_wanted))
.routes(routes!(forge_admin::mint_agent_forge_token)) .routes(routes!(term_stream::stream_agent_term))
.routes(routes!(forge_admin::make_forge_admin)) .routes(routes!(message_stream::stream_messages))
.routes(routes!(agents::get_agents)) .routes(routes!(subagent_term::list_subagents))
.routes(routes!(agents::get_agents_status)) .routes(routes!(bash_task::list_bash_tasks))
.routes(routes!(agents::set_agent_state)) .routes(routes!(agent_commands::list_commands))
.routes(routes!(agents::get_hive_wanted)) .routes(routes!(agent_todos::list_todos))
.routes(routes!(term_stream::stream_agent_term)) .routes(routes!(subagent_term::stream_subagent_term))
.routes(routes!(message_stream::stream_messages)) .routes(routes!(agent_state_stream::stream_agent_state))
.routes(routes!(subagent_term::list_subagents)) .routes(routes!(agent_input::post_agent_input))
.routes(routes!(bash_task::list_bash_tasks)) .routes(routes!(agent_input::post_agents_broadcast))
.routes(routes!(agent_commands::list_commands)) .routes(routes!(agent_control::post_agent_cancel))
.routes(routes!(agent_todos::list_todos)) .routes(routes!(agent_control::post_agent_new_session))
.routes(routes!(subagent_term::stream_subagent_term)) .routes(routes!(agent_custom::post_agent_custom))
.routes(routes!(agent_state_stream::stream_agent_state)) .routes(routes!(schedules::list_schedules, schedules::add_schedule))
.routes(routes!(agent_input::post_agent_input)) .routes(routes!(
.routes(routes!(agent_input::post_agents_broadcast)) schedules::edit_schedule,
.routes(routes!(agent_control::post_agent_cancel)) schedules::remove_schedule
.routes(routes!(agent_control::post_agent_new_session)) ))
.routes(routes!(agent_custom::post_agent_custom)) .routes(routes!(issue_report::get_repos))
.routes(routes!(schedules::list_schedules, schedules::add_schedule)) .routes(routes!(issue_report::get_issue_report_all))
.routes(routes!( .routes(routes!(issue_report::get_issue_report))
schedules::edit_schedule, .routes(routes!(pr_report::get_pr_report_all))
schedules::remove_schedule .routes(routes!(pr_report::get_pr_report))
)) .routes(routes!(pulls::get_pull_repos))
.routes(routes!(issue_report::get_repos)) .routes(routes!(pulls::get_pulls))
.routes(routes!(issue_report::get_issue_report_all)) .routes(routes!(review_classifier::post_try_out))
.routes(routes!(issue_report::get_issue_report)) .routes(routes!(review_classifier::get_try_out))
.routes(routes!(pr_report::get_pr_report_all)) .routes(routes!(review_classifier::get_rules))
.routes(routes!(pr_report::get_pr_report)) .routes(routes!(review_classifier::open_pr::post_open_pr))
.routes(routes!(pulls::get_pull_repos)) .routes(routes!(review_classifier::runs::get_runs))
.routes(routes!(pulls::get_pulls)) .routes(routes!(builder::runs::get_runs))
.routes(routes!(review_classifier::post_try_out)) .routes(routes!(builder::runs::get_run))
.routes(routes!(review_classifier::get_try_out)) .routes(routes!(
.routes(routes!(review_classifier::get_rules)) review_classifier::settings::get_settings,
.routes(routes!(review_classifier::open_pr::post_open_pr)) review_classifier::settings::put_settings
.routes(routes!(review_classifier::runs::get_runs)) ))
.routes(routes!(builder::runs::get_runs)) .routes(routes!(review_classifier::keys::get_keys))
.routes(routes!(builder::runs::get_run)) .routes(routes!(review_classifier::keys::put_key))
.routes(routes!( .routes(routes!(notify_flows::get_flows, notify_flows::put_flows))
review_classifier::settings::get_settings, .routes(routes!(notify_router_api::get_deliveries))
review_classifier::settings::put_settings .routes(routes!(
)) notify_router_api::get_dry_run,
.routes(routes!(review_classifier::keys::get_keys)) notify_router_api::post_dry_run
.routes(routes!(review_classifier::keys::put_key)) ))
.routes(routes!(notify_flows::get_flows, notify_flows::put_flows)) .routes(routes!(webhook::post_webhook_forge))
.routes(routes!(notify_router_api::get_deliveries)) .split_for_parts();
.routes(routes!(
notify_router_api::get_dry_run,
notify_router_api::post_dry_run
))
.routes(routes!(webhook::post_webhook_forge))
.split_for_parts();
// Just the JSON, not the UI — Swagger UI itself is nginx-hosted from // Just the JSON, not the UI — Swagger UI itself is nginx-hosted from
// the nix store (see the module doc comment above). `api` is // the nix store (see the module doc comment above). `api` is
// `Clone`; each request gets its own owned copy for `Json` to // `Clone`; each request gets its own owned copy for `Json` to