Watch
0
0
Fork
You've already forked hyperhive
0

agent ssh connections: declare per agent, render into the agent's ssh config

This commit is contained in:
atlas 2026-11-20 01:38:49 +01:00
commit 934da6f31f

View file

@ -43,7 +43,8 @@ const MAX_ATTEMPTS: usize = 5;
/// The permissions to store for `req`, whose list is already checked. The list
/// replaces the stored one; `unrestricted_internet`, `max_repos` and `ssh` left
/// out keep the ones in `current`. `internet_log` is stored only as `true`, and a request that sets
/// out keep the ones in `current`, and the ssh connections are always kept (they
/// have their own routes). `internet_log` is stored only as `true`, and a request that sets
/// `unrestricted_internet` without it turns it off: an agent that moves to
/// unrestricted and back to restricted does not come back logging.
fn into_stored(req: Permissions, current: &AgentPermissions) -> AgentPermissions {
@ -58,6 +59,7 @@ fn into_stored(req: Permissions, current: &AgentPermissions) -> AgentPermissions
internet_log,
max_repos: req.max_repos.or(current.max_repos),
ssh: req.ssh.or(current.ssh),
ssh_connections: current.ssh_connections.clone(),
}
}
@ -128,7 +130,7 @@ fn view(v: AgentPermissions) -> Permissions {
}
}
fn agent_name(name: &str) -> Result<String, (StatusCode, String)> {
pub(crate) fn agent_name(name: &str) -> Result<String, (StatusCode, String)> {
hive_types::Ident::parse(name)
.map(hive_types::Ident::into_string)
.map_err(|reason| (StatusCode::BAD_REQUEST, reason.to_owned()))
@ -136,7 +138,7 @@ fn agent_name(name: &str) -> Result<String, (StatusCode, String)> {
/// Log a refused `op` on `agent` at `warn` and pass the problem on. The
/// handlers have no caller identity; `detail` is the response's.
fn logged(op: &'static str, agent: &str, problem: ProblemDetails) -> ProblemDetails {
pub(crate) fn logged(op: &'static str, agent: &str, problem: ProblemDetails) -> ProblemDetails {
tracing::warn!(
op,
agent,
@ -198,12 +200,12 @@ fn hive_names(state: &AppState) -> Vec<String> {
state.hives.iter().map(|h| h.name.clone()).collect()
}
fn queue_problem(e: &anyhow::Error) -> ProblemDetails {
pub(crate) fn queue_problem(e: &anyhow::Error) -> ProblemDetails {
tracing::warn!(error = %format!("{e:#}"), "agent permissions: queue failure");
error_problem(wanted_error_status(e), &format!("{e:#}"))
}
async fn open_or_create(
pub(crate) async fn open_or_create(
client: &async_nats::Client,
) -> Result<async_nats::jetstream::kv::Store, ProblemDetails> {
agent_permissions::open_or_create(client)
@ -386,16 +388,17 @@ async fn delete_with(
let (current, revision, _) = read_or_default::<AgentPermissions>(&store, &agent)
.await
.map_err(|e| queue_problem(&e))?;
// Only the flags and the repository limit outlive a clear: dropping
// `unrestricted_internet` would turn an agent created with `false` on,
// dropping `internet_log` would turn a logging agent into an enforced
// one, and a limit is an operator's decision about repositories, not
// part of the permission list.
// Only the flags, the repository limit and the ssh connections outlive a
// clear: dropping `unrestricted_internet` would turn an agent created with
// `false` on, dropping `internet_log` would turn a logging agent into an
// enforced one, and a limit or a connection is an operator's decision
// with its own route, not part of the permission list.
let kept = AgentPermissions {
unrestricted_internet: current.unrestricted_internet,
internet_log: current.internet_log,
max_repos: current.max_repos,
ssh: current.ssh,
ssh_connections: current.ssh_connections.clone(),
..AgentPermissions::default()
};
mirror(leaves, &agent, &held(&current), &held(&kept))
@ -497,6 +500,7 @@ pub(crate) fn at_create(
internet_log: None,
max_repos: None,
ssh: None,
ssh_connections: Vec::new(),
})
}
@ -528,6 +532,7 @@ fn merged_at_create(
},
max_repos: value.max_repos.or(current.max_repos),
ssh: value.ssh.or(current.ssh),
ssh_connections: current.ssh_connections.clone(),
}
}