hive-c0re: block direct agent repo creation, add c0re-mediated create (#1787)

Agents must no longer create repos with their own forge token (a
write-scoped token otherwise creates + owns repos and can self-merge,
bypassing operator-only-merge). Instead:

- Set max_repo_creation=0 on every agent forge user (marker-guarded
  PATCH in sync_agent; covers agents provisioned before this). Blocks
  new direct creation; push/PR/clone and existing repos are untouched.
- Provision a c0re-owned 'agents' org (the namespace agent repos land
  in) plus an empty 'operators' team inside it. The org owns the repos
  so perms stay c0re-managed; the operator joins the team out-of-band.
- create_agent_repo() is the sanctioned path: creates the repo in the
  agents org, adds the requesting agent as a *write* collaborator (not
  owner), and applies branch protection that whitelists merge + required
  approval to the operators team — so the author can't merge its own PR.
- is_hive_managed_namespace() guards 'internal'/'agent-configs'/'core'
  against a future create surface passing an explicit owner.

No existing repos are modified. The agent/hivectl surface that invokes
create_agent_repo is a follow-up commit.
This commit is contained in:
atlas 2026-06-19 12:45:43 +02:00 committed by mara
commit 867be7bb98
2 changed files with 192 additions and 1 deletions

View file

@ -60,6 +60,16 @@ pub fn forge_email_aligned_marker(name: &str) -> PathBuf {
forge_dir().join(format!("email-aligned-{name}"))
}
/// `forge/repo-creation-disabled-<name>` — marker: `<name>`'s forge user
/// has had `max_repo_creation = 0` applied (blocks direct agent-initiated
/// repo creation — see #1787). One-shot guard so the PATCH runs once per
/// agent (including agents provisioned before the change); delete to
/// re-apply.
#[must_use]
pub fn forge_repo_creation_disabled_marker(name: &str) -> PathBuf {
forge_dir().join(format!("repo-creation-disabled-{name}"))
}
/// `matrix/` — host-side matrix provisioning state (admin token, hive
/// Space room id, per-agent password creds). The shared registration
/// token is bind-mounted into the tuwunel container via nix and stays