fix: [nomad-step-3] S3.3 — wp-oauth-register.sh (Forgejo OAuth app + Vault KV) (#936) #940
No reviewers
Labels
No labels
action
backlog
blocked
bug-report
cannot-reproduce
in-progress
in-triage
needs-triage
prediction/actioned
prediction/dismissed
prediction/unreviewed
priority
rejected
reproduced
tech-debt
underspecified
vision
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: disinto-admin/disinto#940
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/issue-936"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #936
Changes
bb305f34ebto11566c2757AI Review
Summary
S3.3 adds
wp-oauth-register.shand wires it intovault-seed-woodpecker.sh. Three blockers prevent it from functioning.Blockers
critical
lib/init/nomad/wp-oauth-register.sh:91: Straytoken_rawline executes as a bare command. Underset -euo pipefailthis aborts with "command not found" wheneverFORGE_TOKENis not in the environment (the normal case — it reads from Vault). Every invocation that needs to fetch the token from Vault will crash before doing so. Fix: delete the baretoken_rawline; the assignment on the next line is sufficient.critical
tools/vault-seed-woodpecker.sh:141:--dry-runis hardcoded in the call towp-oauth-register.sh. This line is inside theelsebranch ofif [ "$DRY_RUN" -eq 1 ], so it runs only whenDRY_RUN=0(normal production mode) — yet still passes--dry-run. The OAuth registration never actually executes. Fix: remove the--dry-runflag and pass$DRY_RUNvia the already-exported env var, or pass the flag conditionally.critical
lib/init/nomad/wp-oauth-register.sh:194:forgejo_secretis unbound in the dry-run + app-not-exists path. WhenDRY_RUN=1and the app does not exist, the innerif [ "$DRY_RUN" -eq 1 ]branch (line 137–138) logs and continues without assigningforgejo_secret. Step 3/3 then references$forgejo_secretbare in the comparison (line 194), triggering "unbound variable" underset -u. Fix: initializeforgejo_secret=""before the Step 2/3 block, alongsideexisting_client_id.Advisory (non-blocking)
lib/init/nomad/wp-oauth-register.sh:165–171: When the app already exists andforgejo_secretis empty (the normal re-run case), the script generatesopenssl rand -hex 32and stores it as the OAuth secret. This is not the actual Forgejo client secret — it was only returned at creation time. On every subsequent run a new random value is generated, so the idempotency check at line 193 will always fail and wrong credentials are continually overwritten. The script cannot be truly idempotent for the app-exists path. The correct behavior is: if app exists and Vault already hasforgejo_client+forgejo_secret, trust Vault and skip (i.e., check Vault first before generating anything). The current code does the opposite — reads Vault only after already having generated a new random value.Verdict
REQUEST_CHANGES — Three blockers: stray token_raw command crashes the script, hardcoded --dry-run means OAuth never runs in production, and forgejo_secret is unbound under set -u in the dry-run+app-not-exists path.
Reviewed at
11566c2| AGENTS.mdAI Review: REQUEST_CHANGES — Three blockers: stray token_raw command crashes the script, hardcoded --dry-run means OAuth never runs in production, and forgejo_secret is unbound under set -u in the dry-run+app-not-exists path.
AI Re-review (round 2)
Previous Findings
token_rawbare command → FIXED: removed in incremental diff--dry-runon child call → PARTIAL: flag removed, but propagation mechanism is broken (see below)forgejo_secretunbound underset -u→ FIXED: initialized to""at line 120Remaining Blocker
lib/init/nomad/wp-oauth-register.sh:63:DRY_RUN=0unconditionally overrides the inherited env var.vault-seed-woodpecker.sh:136exportsDRY_RUN=1, then callswp-oauth-register.shwith no flags. The child resetsDRY_RUN=0at its flag-parsing preamble before any$@loop can set it back. Result: whenever the parent runs with--dry-run, Step 3/3 calls out towp-oauth-register.shwhich runs in live mode — making real Forgejo API calls and writing to Vault. The|| [ "$DRY_RUN" -eq 1 ]on theifline only masks the exit code; it does not affect execution mode inside the child. Fix: change line 63 toDRY_RUN="${DRY_RUN:-0}"so the child honors an exported value, or pass--dry-runconditionally at the call site.Advisory (non-blocking)
tools/vault-seed-woodpecker.sh:137–143: OAuth failures are silently swallowed — ifwp-oauth-register.shexits non-zero andFORGE_URLis set (it always defaults), the parent logs a warning and exits 0. This means Vault write errors or auth failures in the child are invisible to the caller. Consider whether silent toleration is intentional or if at least a non-zero exit should propagate when Forgejo is reachable but the call fails.Verdict
REQUEST_CHANGES — DRY_RUN propagation still broken: wp-oauth-register.sh unconditionally resets DRY_RUN=0, so the child always runs live even when the parent exports DRY_RUN=1
Reviewed at
442d24b| Previous:11566c2| AGENTS.mdAI Re-review (round 2): REQUEST_CHANGES — DRY_RUN propagation still broken: wp-oauth-register.sh unconditionally resets DRY_RUN=0, so the child always runs live even when the parent exports DRY_RUN=1
AI Re-review (round 3)
Previous Findings\n\n- DRY_RUN unconditional reset
wp-oauth-register.sh:63:DRY_RUN=0overrode exported parent value → FIXED: changed toDRY_RUN="${DRY_RUN:-0}"; parentexport DRY_RUNat line 136 of vault-seed-woodpecker.sh now propagates correctly into the child.\n\n### Advisory (carried forward, non-blocking)\n\n- lowtools/vault-seed-woodpecker.sh:137–143: OAuth failure is still silently swallowed — ifwp-oauth-register.shexits non-zero, theelif [ -n "${FORGE_URL:-}" ]branch (always true given the default) logs a warning and exits 0. Vault write errors inside the child are invisible to the caller. No change from prior round; acceptable if intentional.Verdict
APPROVE — DRY_RUN propagation blocker fixed: child now uses ${DRY_RUN:-0} and honors parent export
Reviewed at
13088f4| Previous:442d24b| AGENTS.mdAI Re-review (round 3): APPROVE — DRY_RUN propagation blocker fixed: child now uses ${DRY_RUN:-0} and honors parent export