One Semaphore user per repository, so a token reaches one project (CP-43) #27

Merged
pit merged 1 commit from hermes/cp43-per-repo-ci-users into main 2026-11-07 18:10:01 +00:00
Owner

Follow-up to !26, on CP-43. The Operator chose one user per repository over one shared ci.

Summary

 semaphore/projects/projects.tf
- ephemeral "random_password" "ci"            # one password
+ ephemeral "random_password" "ci"            # one per repository
- resource "semaphoreui_user" "ci" {          # username = "ci"
+ resource "semaphoreui_user" "ci" {          # for_each: ci-tracker, ci-forge,
+                                              #   ci-secrets, ci-silo
- resource "semaphoreui_project_user" "ci" {  # user_id = ci.id
+ resource "semaphoreui_project_user" "ci" {  # user_id = ci[each.key].id

A Semaphore API token carries the whole reach of the user it was minted for. With one ci user, Manager on all four projects, each repository's token could start any repository's deploy. That made the ticket's "each token starts and reads a task in its own project only" false, measured: every token's GET /api/projects listed all four, and a POST to a foreign project answered 201.

Now ci-tracker, ci-forge, ci-secrets and ci-silo exist, each Manager on its own project and a member of no other. The names are the short ones the store paths already use (secret/ci/tracker/semaphore-api).

Hand resolution taken before this

The destroy the judge refuses (workshop ADR-0011) was done by hand, as the ADR prescribes:

  • the single ci user (id 2) deleted in Semaphore: DELETE /api/users/2 → 204. Its four tokens went with it, by the api_token.user_id ... on delete cascade in the schema.
  • its stale state entries removed with tofu state rm semaphoreui_user.ci and tofu state rm semaphoreui_project_user.ci. The provider errors on the 404 instead of dropping a vanished resource, so the plan could not be made until they were gone.

Evidence

  • Plan against PROD's state after the hand resolution, with the judge: 8 to add, 0 to change, 0 to destroy, plan-check: the plan destroys and replaces nothing.
  • mise exec -- make check: rc 0, 167 ok, 0 FAIL.
  • The four users do not exist yet: the deploy creates them.

Merge Danger

Door: two-way

The Stack is already applied and green; this changes only who the four API tokens belong to. Reverting returns to a single ci user, which needs the same hand deletion in reverse (the judge will refuse that destroy again).

Blast Radius: the deploy's Semaphore identity

  • The store paths secret/ci/{tracker,forge,secrets,silo}/semaphore-api still hold the retired ci tokens, now invalid. They are overwritten with the new users' tokens straight after this merges; until then no repository's deploy workflow exists, so nothing reads them.
  • The 16 stopped probe tasks from the reach test stay until the deploy restarts the server, which empties the pool so they can be deleted (DELETE /api/project/{id}/tasks/{id} answers 400 while the pool holds a row).
Follow-up to `!26`, on CP-43. The Operator chose one user per repository over one shared `ci`. ## Summary ```diff semaphore/projects/projects.tf - ephemeral "random_password" "ci" # one password + ephemeral "random_password" "ci" # one per repository - resource "semaphoreui_user" "ci" { # username = "ci" + resource "semaphoreui_user" "ci" { # for_each: ci-tracker, ci-forge, + # ci-secrets, ci-silo - resource "semaphoreui_project_user" "ci" { # user_id = ci.id + resource "semaphoreui_project_user" "ci" { # user_id = ci[each.key].id ``` A Semaphore API token carries the whole reach of the user it was minted for. With one `ci` user, Manager on all four projects, each repository's token could start any repository's deploy. That made the ticket's "each token starts and reads a task in its own project only" false, measured: every token's `GET /api/projects` listed all four, and a POST to a foreign project answered 201. Now `ci-tracker`, `ci-forge`, `ci-secrets` and `ci-silo` exist, each Manager on its own project and a member of no other. The names are the short ones the store paths already use (`secret/ci/tracker/semaphore-api`). ## Hand resolution taken before this The destroy the judge refuses (workshop ADR-0011) was done by hand, as the ADR prescribes: - the single `ci` user (id 2) deleted in Semaphore: `DELETE /api/users/2` → 204. Its four tokens went with it, by the `api_token.user_id ... on delete cascade` in the schema. - its stale state entries removed with `tofu state rm semaphoreui_user.ci` and `tofu state rm semaphoreui_project_user.ci`. The provider errors on the 404 instead of dropping a vanished resource, so the plan could not be made until they were gone. ## Evidence - Plan against PROD's state after the hand resolution, with the judge: **8 to add, 0 to change, 0 to destroy**, `plan-check: the plan destroys and replaces nothing.` - `mise exec -- make check`: rc 0, **167 ok, 0 FAIL**. - The four users do not exist yet: the deploy creates them. ## Merge Danger **Door:** two-way The Stack is already applied and green; this changes only who the four API tokens belong to. Reverting returns to a single `ci` user, which needs the same hand deletion in reverse (the judge will refuse that destroy again). **Blast Radius:** the deploy's Semaphore identity - The store paths `secret/ci/{tracker,forge,secrets,silo}/semaphore-api` still hold the **retired** `ci` tokens, now invalid. They are overwritten with the new users' tokens straight after this merges; until then no repository's deploy workflow exists, so nothing reads them. - The 16 stopped probe tasks from the reach test stay until the deploy restarts the server, which empties the pool so they can be deleted (`DELETE /api/project/{id}/tasks/{id}` answers 400 while the pool holds a row).
One Semaphore user per repository, so a token reaches one project (CP-43)
All checks were successful
plan / guest-plan-check (pull_request_target) Successful in 24s
plan / runner-guest-plan-check (pull_request_target) Successful in 17s
plan / projects-plan-check (pull_request_target) Successful in 21s
pr-checks / check (pull_request) Successful in 40s
d97b85b3ed
A Semaphore API token carries the whole reach of the user it was minted
for. The single `ci` user, Manager on all four projects, therefore gave
every repository's workflow the power to start any repository's deploy,
which the ticket's "its own project only" forbids.

So `ci-<repo>`: one user per repository, Manager on its own project and a
member of no other. Same ephemeral write-only password and the same
`password_wo_version` rule as before, one set per user.

The hand resolution this needed, done before the change: the single `ci`
user and its four membership rows were deleted in Semaphore (a destroy the
judge refuses), and their stale entries removed from the state with
`tofu state rm`. The plan is 8 to add, 0 to change, 0 to destroy.
Member

Review started (round 1/5) on d97b85b3ed — reading the diff now.

**Review started** (round 1/5) on d97b85b3ed66211acf74c9341e253ddb0e1b5403 — reading the diff now.
bot-minos approved these changes 2026-11-07 18:01:54 +00:00
bot-minos left a comment

review-meta: repo=olympus/infra-cockpit pr=27 head=d97b85b3ed66211acf74c9341e253ddb0e1b5403 round=1/5 verdict=merge

Recommendation: merge

Reviewer: bot-minos. Round 1, so no prior blocking findings to re-check.


Spec

Spec source. CP-43 (Vikunja task 271, project 11), read with its thread. The body still says "The ci user: Manager on the four projects"; its own comment of 2026-11-07 17:58 records the Operator's amendment to one user per repository ("least privilege", after the reach test measured every token seeing and starting tasks in all four projects), and the PR implements that amendment. Judged against the amended text, which the Operator wrote, not against the superseded line.

Findings: 0.

CP-43 criterion (as amended) Result Evidence
One user per repository, Manager on its own project, a member of no other met projects.tf:127-151; plan (below) shows semaphoreui_user.ci["<repo>"] ×4 and semaphoreui_project_user.ci["<repo>"], role = "manager", ×4
No user shared between projects met for_each = var.repositories on both resources, user_id = semaphoreui_user.ci[each.key].id (projects.tf:149) — no unkeyed path back to a shared user
Password never in state or store met, unchanged in kind ephemeral + password_wo, password_wo_version = 1 per user (projects.tf:120-140); write-only attributes are null in state, as CP-43's own post-apply audit found on !26
Tokens land at secret/ci/<repo>/semaphore-api met, by naming projects.tf:130-135 derives ci-tracker/ci-forge/ci-secrets/ci-silo from the four keys, which is the short name the store path carries; docs/deploy.md:152-164 states the rule and the reason
The reach claim itself ("each token starts and reads a task in its own project only") unproven, and unprovable before the merge the four users are created by this deploy; no token exists yet. The PR says the same and defers it to post-merge live acceptance. Not a defect in the diff — see Could not verify.

The one requirement change is recorded where this repo says decisions live (the ticket comment), and docs/deploy.md:161-164 gained the reason, not only the fact. That is the spec axis done properly.


Standards

Standards sources. AGENTS.md (§Secrets, §Toolchain, §Docs, §Agent skills → PR body names CP-<index>), docs/agents/issue-tracker.md, and the Fowler smell baseline. No violation of a documented rule. Two advisories.

ADVISORY 1 — the rename stopped at the paragraph it wrote, not at every line that names the thing

docs/deploy.md and projects.tf now describe two different systems:

  • semaphore/projects/projects.tf:3 — "and the ci user that each repository's deploy workflow starts its template as" — singular, at the head of the file this PR rewrote, contradicting projects.tf:109-113 forty lines below.
  • docs/deploy.md:138 — table row | ci's membership | Manager, because polling a task needs CanManageProjectResources |.
  • docs/deploy.md:193 — "the deploy adds its project, its template and ci's membership."

Same drift, outside the diff, so not asked for this round: semaphore/projects/variables.tf:3, versions.tf:13, providers.tf:9, docs/environment.md:70.

Fix: ci-<repo> at those lines. Nothing in the code depends on the wording; this is AGENTS.md §Docs ("the documentation is docs/deploy.md") applied to a rename that half-landed.

ADVISORY 2 — the short name is derived inline three times, by a rule that is not one-to-one

semaphore/projects/projects.tf:133-135:

username = "ci-${replace(each.key, "infra-", "")}"
name     = "ci-${replace(each.key, "infra-", "")}"
email    = "noreply+semaphore-${replace(each.key, "infra-", "")}@thepit.space"

Two things, one fix:

  1. Duplicated Code — the same derivation written three times; move the rule and three lines move together.

  2. The rule is not injective, and replace replaces globally. Measured on this config's own expressions (tofu console):

    replace("infra-forge", "infra-", "")       => "forge"
    replace("forge",       "infra-", "")       => "forge"      # same username, different repository
    replace("acme-infra-tools", "infra-", "")  => "acme-tools" # mid-string, mangled
    

    variables.tf:3 promises "Adding a repository is one line here and nothing else." A line adding a repository whose short form collides would give two Semaphore users the same username — either the apply fails on the duplicate, or (if the server allows duplicates) the hand-mint step at docs/deploy.md:155 ("logs in as it") has two rows it cannot tell apart, and a token minted for one repository lands in another's store path. That is the failure this PR exists to close, reachable by an edit the file invites.

    Not reachable with today's four defaults, so not a defect — an unguarded door in a file that promises it keeps none.

Fix, smallest: one locals map — short = { for k in var.repositories : k => trimprefix(k, "infra-") } — used at all three sites, plus a validation on var.repositories that the derived names are distinct. trimprefix also ends the mid-string mangle.

Checked and cleared

  • No plaintext secret in the diff (AGENTS.md §Secrets); the write-only password path is unchanged in kind.
  • mise exec -- throughout; commit message is the repo's prose-with-reasoning form; PR body names CP-43.
  • The 8-adds/0-destroys shape follows ADR-0011: the destroy was taken by hand and documented, not smuggled into an apply.

Verified

Ran on a worktree at d97b85b, OpenTofu 1.12.6 from mise.

What Result
mise exec -- make check rc 0, 176 ok lines, 0 FAIL — env pin/map, env tests, plan-check tests, tofu fmt -recursive -check. Your body says 167 ok; my count of ^ ok lines is 176. Counting, not a failure — both rc 0, 0 FAIL.
tofu validate in semaphore/projects (providers installed, -backend=false) Success! The configuration is valid. — for_each on the ephemeral resource and all three replace() interpolations are legal under 1.12.6
tofu plan of the real projects.tf (backend.tf dropped, empty local state, bogus endpoint) Plan: 32 to add, 0 to change, 0 to destroy; users appear as ci-forge, ci-secrets, ci-silo, ci-tracker, with four semaphoreui_project_user.ci["<repo>"] each role = "manager". The mapping, the per-key ephemeral password and the membership are what the PR claims.
CI on d97b85b (get_commit_statuses) plan / projects-plan-check success (21s); plan / guest-plan-check success; plan / runner-guest-plan-check success. pr-checks / check was still pending when I read them — my local make check is its equivalent and green.
Read both changed files in full, plus variables.tf, outputs.tf, versions.tf, providers.tf, the Makefile projects targets, .forgejo/workflows/plan.yml, scripts/tests/plan-check.sh (the projects sandbox), docs/deploy.md, docs/environment.md, AGENTS.md

Both changed files earn their place: projects.tf is the change, deploy.md is the procedure it invalidates. No file the change should have touched is missing from the diff, apart from the four stale lines in ADVISORY 1.

Could not verify

  • The reach property — that each token starts and reads a task in its own project only. The users do not exist yet and I hold no Semaphore admin token. This is the one claim I cannot lay a hand on, and the one the PR itself defers to post-merge live acceptance. If it fails there it fails loudly: each token's GET /api/projects listing more than one project.
  • 8 to add, 0 to change, 0 to destroy against PROD's state after the hand state rm — needs the deploy's state key. Indirect support only: CI's projects-plan-check is green on this head against the plan-only record.
  • The hand resolution itself (DELETE /api/users/2 → 204, the two tofu state rm invocations). No access to the server or PROD's state; taken on the PR body's word, consistent with the plan shape above and with CP-43's thread.

Summary

Axis Findings Worst
Spec 0 (0 blockers) none — the amended CP-43 text is what the diff implements
Standards 2 advisories (0 blockers) ADVISORY 2 — the non-injective replace() name derivation, in a file that promises "one line and nothing else"

No blocker: this is the least-privilege fix the ticket's own comment calls for, it plans clean, and the repo's floor is green on it. The two advisories are advice and travel with the merge; neither moves the verdict.

State: APPROVE.

review-meta: repo=olympus/infra-cockpit pr=27 head=d97b85b3ed66211acf74c9341e253ddb0e1b5403 round=1/5 verdict=merge Recommendation: merge Reviewer: bot-minos. Round 1, so no prior blocking findings to re-check. --- ## Spec **Spec source.** `CP-43` (Vikunja task 271, project 11), read with its thread. The body still says *"The `ci` user: Manager on the four projects"*; its own comment of 2026-11-07 17:58 records the Operator's amendment to one user per repository ("least privilege", after the reach test measured every token seeing and starting tasks in all four projects), and the PR implements that amendment. Judged against the amended text, which the Operator wrote, not against the superseded line. **Findings: 0.** | CP-43 criterion (as amended) | Result | Evidence | | --- | --- | --- | | One user per repository, Manager on its own project, a member of no other | met | `projects.tf:127-151`; plan (below) shows `semaphoreui_user.ci["<repo>"]` ×4 and `semaphoreui_project_user.ci["<repo>"]`, `role = "manager"`, ×4 | | No user shared between projects | met | `for_each = var.repositories` on both resources, `user_id = semaphoreui_user.ci[each.key].id` (`projects.tf:149`) — no unkeyed path back to a shared user | | Password never in state or store | met, unchanged in kind | `ephemeral` + `password_wo`, `password_wo_version = 1` per user (`projects.tf:120-140`); write-only attributes are null in state, as CP-43's own post-apply audit found on `!26` | | Tokens land at `secret/ci/<repo>/semaphore-api` | met, by naming | `projects.tf:130-135` derives `ci-tracker`/`ci-forge`/`ci-secrets`/`ci-silo` from the four keys, which is the short name the store path carries; `docs/deploy.md:152-164` states the rule and the reason | | The reach claim itself ("each token starts and reads a task in its own project only") | **unproven, and unprovable before the merge** | the four users are created by this deploy; no token exists yet. The PR says the same and defers it to post-merge live acceptance. Not a defect in the diff — see *Could not verify*. | The one requirement change is recorded where this repo says decisions live (the ticket comment), and `docs/deploy.md:161-164` gained the reason, not only the fact. That is the spec axis done properly. --- ## Standards **Standards sources.** `AGENTS.md` (§Secrets, §Toolchain, §Docs, §Agent skills → PR body names `CP-<index>`), `docs/agents/issue-tracker.md`, and the Fowler smell baseline. No violation of a documented rule. Two advisories. ### ADVISORY 1 — the rename stopped at the paragraph it wrote, not at every line that names the thing `docs/deploy.md` and `projects.tf` now describe two different systems: - `semaphore/projects/projects.tf:3` — *"and the `ci` user that each repository's deploy workflow starts its template as"* — singular, at the head of the file this PR rewrote, contradicting `projects.tf:109-113` forty lines below. - `docs/deploy.md:138` — table row `| `ci`'s membership | Manager, because polling a task needs `CanManageProjectResources` |`. - `docs/deploy.md:193` — *"the deploy adds its project, its template and `ci`'s membership."* Same drift, outside the diff, so not asked for this round: `semaphore/projects/variables.tf:3`, `versions.tf:13`, `providers.tf:9`, `docs/environment.md:70`. Fix: `ci-<repo>` at those lines. Nothing in the code depends on the wording; this is `AGENTS.md` §Docs ("the documentation is `docs/deploy.md`") applied to a rename that half-landed. ### ADVISORY 2 — the short name is derived inline three times, by a rule that is not one-to-one `semaphore/projects/projects.tf:133-135`: ```hcl username = "ci-${replace(each.key, "infra-", "")}" name = "ci-${replace(each.key, "infra-", "")}" email = "noreply+semaphore-${replace(each.key, "infra-", "")}@thepit.space" ``` Two things, one fix: 1. **Duplicated Code** — the same derivation written three times; move the rule and three lines move together. 2. **The rule is not injective, and `replace` replaces globally.** Measured on this config's own expressions (`tofu console`): ``` replace("infra-forge", "infra-", "") => "forge" replace("forge", "infra-", "") => "forge" # same username, different repository replace("acme-infra-tools", "infra-", "") => "acme-tools" # mid-string, mangled ``` `variables.tf:3` promises *"Adding a repository is one line here and nothing else."* A line adding a repository whose short form collides would give two Semaphore users the same username — either the apply fails on the duplicate, or (if the server allows duplicates) the hand-mint step at `docs/deploy.md:155` ("logs in as it") has two rows it cannot tell apart, and a token minted for one repository lands in another's store path. That is the failure this PR exists to close, reachable by an edit the file invites. Not reachable with today's four defaults, so not a defect — an unguarded door in a file that promises it keeps none. Fix, smallest: one `locals` map — `short = { for k in var.repositories : k => trimprefix(k, "infra-") }` — used at all three sites, plus a `validation` on `var.repositories` that the derived names are distinct. `trimprefix` also ends the mid-string mangle. ### Checked and cleared - No plaintext secret in the diff (`AGENTS.md` §Secrets); the write-only password path is unchanged in kind. - `mise exec --` throughout; commit message is the repo's prose-with-reasoning form; PR body names `CP-43`. - The 8-adds/0-destroys shape follows ADR-0011: the destroy was taken by hand and documented, not smuggled into an apply. --- ## Verified Ran on a worktree at `d97b85b`, OpenTofu `1.12.6` from `mise`. | What | Result | | --- | --- | | `mise exec -- make check` | **rc 0**, 176 `ok` lines, 0 FAIL — env pin/map, env tests, plan-check tests, `tofu fmt -recursive -check`. Your body says 167 `ok`; my count of `^ ok` lines is 176. Counting, not a failure — both rc 0, 0 FAIL. | | `tofu validate` in `semaphore/projects` (providers installed, `-backend=false`) | `Success! The configuration is valid.` — `for_each` on the `ephemeral` resource and all three `replace()` interpolations are legal under 1.12.6 | | `tofu plan` of the real `projects.tf` (`backend.tf` dropped, empty local state, bogus endpoint) | `Plan: 32 to add, 0 to change, 0 to destroy`; users appear as `ci-forge`, `ci-secrets`, `ci-silo`, `ci-tracker`, with four `semaphoreui_project_user.ci["<repo>"]` each `role = "manager"`. The mapping, the per-key ephemeral password and the membership are what the PR claims. | | CI on `d97b85b` (`get_commit_statuses`) | `plan / projects-plan-check` **success** (21s); `plan / guest-plan-check` success; `plan / runner-guest-plan-check` success. `pr-checks / check` was still `pending` when I read them — my local `make check` is its equivalent and green. | | Read | both changed files in full, plus `variables.tf`, `outputs.tf`, `versions.tf`, `providers.tf`, the `Makefile` projects targets, `.forgejo/workflows/plan.yml`, `scripts/tests/plan-check.sh` (the projects sandbox), `docs/deploy.md`, `docs/environment.md`, `AGENTS.md` | Both changed files earn their place: `projects.tf` is the change, `deploy.md` is the procedure it invalidates. No file the change should have touched is missing from the diff, apart from the four stale lines in ADVISORY 1. ## Could not verify - **The reach property** — that each token starts and reads a task in its own project only. The users do not exist yet and I hold no Semaphore admin token. This is the one claim I cannot lay a hand on, and the one the PR itself defers to post-merge live acceptance. If it fails there it fails loudly: each token's `GET /api/projects` listing more than one project. - **`8 to add, 0 to change, 0 to destroy` against PROD's state** after the hand `state rm` — needs the deploy's state key. Indirect support only: CI's `projects-plan-check` is green on this head against the plan-only record. - **The hand resolution itself** (`DELETE /api/users/2` → 204, the two `tofu state rm` invocations). No access to the server or PROD's state; taken on the PR body's word, consistent with the plan shape above and with CP-43's thread. --- ## Summary | Axis | Findings | Worst | | --- | --- | --- | | Spec | 0 (0 blockers) | none — the amended CP-43 text is what the diff implements | | Standards | 2 advisories (0 blockers) | ADVISORY 2 — the non-injective `replace()` name derivation, in a file that promises "one line and nothing else" | No blocker: this is the least-privilege fix the ticket's own comment calls for, it plans clean, and the repo's floor is green on it. The two advisories are advice and travel with the merge; neither moves the verdict. State: APPROVE.
pit merged commit f5136bd6da into main 2026-11-07 18:10:01 +00:00
pit deleted branch hermes/cp43-per-repo-ci-users 2026-11-07 18:10:01 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
olympus/infra-cockpit!27
No description provided.