Watch
0
0
Fork
You've already forked hyperhive
0

lock the service forge accounts out of creating organizations

This commit is contained in:
atlas 2026-11-16 21:40:02 +01:00
commit 87dc4c5533
6 changed files with 55 additions and 12 deletions

View file

@ -330,9 +330,9 @@ authors every classifier review, and it pushes the branches the try-out section
creates.
`swarm-controller` creates it as `review-classifier`, with the email
`review-classifier@services.hyperhive.local` and no repo creation, and mints
its one token, `swarm-review-classifier` with scope `write:repository`, into
the store at `swarm/services/review-classifier/forge/token`. A pass at start
`review-classifier@services.hyperhive.local`, no repo creation and no
organizations, and mints its one token, `swarm-review-classifier` with scope
`write:repository`, into the store at `swarm/services/review-classifier/forge/token`. A pass at start
and every five minutes re-mints when the token is missing or no longer
matches the forge. The controller refuses an existing account by that name
with any other email. The controller posts the reviews and pushes the try-out

View file

@ -2183,16 +2183,17 @@ fn legacy_agent_email(agent: &str) -> String {
format!("{agent}@hive.local")
}
/// The `admin_edit_user` body that sets `max_repo_creation = 0` on `agent`
/// and nothing else. `login_name` + `source_id = 0` (local auth,
/// which is what [`Client::create_agent_user`] creates) ride along because
/// Forgejo resets `use_custom_avatar` on an admin edit that omits
/// `login_name`; every other field is left unset so nothing else is touched.
/// The `admin_edit_user` body that sets `max_repo_creation = 0` and
/// `allow_create_organization = false` on `agent` and nothing else.
/// `login_name` + `source_id = 0` (local auth, which is what
/// [`Client::create_agent_user`] creates) ride along because Forgejo resets
/// `use_custom_avatar` on an admin edit that omits `login_name`; every other
/// field is left unset so nothing else is touched.
fn repo_creation_lockdown(agent: &str) -> EditUserOption {
EditUserOption {
active: None,
admin: None,
allow_create_organization: None,
allow_create_organization: Some(false),
allow_git_hook: None,
allow_import_local: None,
description: None,
@ -2214,11 +2215,9 @@ fn repo_creation_lockdown(agent: &str) -> EditUserOption {
}
/// [`repo_creation_lockdown`] for an agent's account: `max_repos` repositories
/// instead of none, and no organizations. The service accounts that share the
/// lockdown stay at none and are not touched on organizations.
/// instead of none.
fn agent_account_lockdown(agent: &str, max_repos: u32) -> EditUserOption {
EditUserOption {
allow_create_organization: Some(false),
max_repo_creation: Some(i64::from(max_repos)),
..repo_creation_lockdown(agent)
}

View file

@ -288,4 +288,25 @@ mod tests {
assert!(format!("{err:#}").contains("not the swarm builder's"));
assert!(lockdown_patch(&seen, LOGIN).is_none());
}
/// An existing account is locked out of repo creation and of
/// organizations on every pass.
#[tokio::test]
async fn the_job_locks_the_builder_out_of_repos_and_organizations() {
use super::super::tests::{lockdown_patch, stub_forge};
let (client, seen) = stub_forge(
(409, r#"{"message":"user already exists"}"#),
(200, r#"{"email":"builder@services.hyperhive.local"}"#),
(200, "{}"),
)
.await;
client
.ensure_builder_user()
.await
.expect("the builder's own account");
let body = lockdown_patch(&seen, LOGIN).expect("no lockdown PATCH sent");
assert_eq!(body["max_repo_creation"], 0);
assert_eq!(body["allow_create_organization"], false);
}
}

View file

@ -473,4 +473,25 @@ mod tests {
assert!(format!("{err:#}").contains("not the CI metrics poller's"));
assert!(lockdown_patch(&seen, LOGIN).is_none());
}
/// An existing account is locked out of repo creation and of
/// organizations on every pass.
#[tokio::test]
async fn the_job_locks_the_poller_out_of_repos_and_organizations() {
use super::super::tests::{lockdown_patch, stub_forge};
let (client, seen) = stub_forge(
(409, r#"{"message":"user already exists"}"#),
(200, r#"{"email":"ci-metrics@services.hyperhive.local"}"#),
(200, "{}"),
)
.await;
client
.ensure_ci_metrics_user()
.await
.expect("the poller's own account");
let body = lockdown_patch(&seen, LOGIN).expect("no lockdown PATCH sent");
assert_eq!(body["max_repo_creation"], 0);
assert_eq!(body["allow_create_organization"], false);
}
}

View file

@ -582,5 +582,6 @@ mod tests {
.expect("the classifier's own account");
let body = lockdown_patch(&seen, LOGIN).expect("no lockdown PATCH sent");
assert_eq!(body["max_repo_creation"], 0);
assert_eq!(body["allow_create_organization"], false);
}
}

View file

@ -660,6 +660,7 @@ mod tests {
.expect("the hive's own account");
let body = lockdown_patch(&seen, "hive-alpha").expect("no lockdown PATCH sent");
assert_eq!(body["max_repo_creation"], 0);
assert_eq!(body["allow_create_organization"], false);
}
fn team(permission: TeamPermission, units: &[&str]) -> Team {