From ff120b634a3e97f5126d4f6cfd34963fb7ff2e9c Mon Sep 17 00:00:00 2001 From: AppSolves Date: Sat, 14 Nov 2026 15:09:46 +0100 Subject: [PATCH 1/3] fix: forward Environment credentials without shared-secret fallback --- CHANGELOG.md | 2 ++ docs/authentication.md | 2 +- docs/deployment.md | 2 +- docs/installation.md | 23 ++++++++++++++++++++--- docs/review-rollout.md | 10 ++++++++-- docs/validation.md | 17 +++++++++++++++++ src/setup.ts | 18 +++++++++++++++--- tests/setup.test.ts | 4 ++-- tests/workflows.test.ts | 23 +++++++++++++++++++++-- 9 files changed, 87 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2885ca3..a707bff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased — security remediation pass +- Correct Environment secret forwarding: generate named references after a required environment-free caller guard rejects repository/organization credentials. Empty literals did not enable Environment lookup; named references alone would allow fallback. Existing callers must update through a PR; reusable/Worker pins and credentials remain unchanged. See docs/review-rollout.md. + - Explicitly forward only named Environment credential grants; add a credential-only availability diagnostic, safe runner/broker/OIDC failure codes and failed-job publication safeguards. - Add migration 0003 with recoverable, App-owned progress comments, verified run status, failure metadata and bounded operator reconciliation. Existing sessions remain valid. - Add opt-in source-scoped Buildx caching and a credential-free cache benchmark; execute review images by content ID. Keep cache off until measurements justify its cost. diff --git a/docs/authentication.md b/docs/authentication.md index 42c2703..1ff93f0 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -1,6 +1,6 @@ # Authentication and credential ownership -Reusable callers must explicitly grant the two optional secret names with empty values; the called installation/actor Environment supplies the actual credential. No repository-key fallback or blanket inheritance is supported. [Credential diagnostics and rollout](review-rollout.md) include a no-inference availability check. Migration 0003 does not change encryption/session formats or require reconnecting. +Reusable callers must use explicit named secret references after the environment-free `credential-scope` guard rejects nonempty repository/organization credentials under either name. The called installation/actor Environment supplies the actual credential. Literal empty grants do not enable Environment secret resolution. Named references alone would permit a global-secret fallback if an Environment secret were missing; keep the guard and its required dependency. [Credential diagnostics and rollout](review-rollout.md) explain the GitHub contract and no-inference check. No reusable-workflow/Worker pin or session format changes are needed for this caller-only correction. ## Official ChatGPT OAuth diff --git a/docs/deployment.md b/docs/deployment.md index f8fcee5..172cc81 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -1,6 +1,6 @@ # Deployment checklist -For existing deployments, follow [the coordinated immutable-pin upgrade](review-rollout.md) before deploying this revision. Apply additive migration 0003, update the caller's named Environment secret grants, and set its workflow pin and Worker TRUSTED_WORKFLOW to the same actual merged commit. Keep merge disabled. Report validation before the production change; a temporary mismatch fails closed. +For Worker/reusable-workflow upgrades, follow [the coordinated immutable-pin upgrade](review-rollout.md), apply required migrations and set the caller pin and Worker TRUSTED_WORKFLOW to the same actual merged commit. The caller-only Environment-secret correction uses named references plus a scope guard; it keeps the existing `4ed668864cac0682e09ec49a2515a6e1893a2780` pin and needs no Worker deployment or migration. Keep merge disabled. Report validation before any production change; a temporary pin mismatch fails closed. This document is operator instructions, not evidence of an existing hosted deployment. Do not register, deploy, publish a release or use paid inference without your own authorization. diff --git a/docs/installation.md b/docs/installation.md index 3a06101..7e69eea 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -36,14 +36,31 @@ concurrency: group: codexbot-credentials cancel-in-progress: false jobs: + credential-scope: + runs-on: ubuntu-24.04 + timeout-minutes: 1 + permissions: {} + steps: + - name: Reject credentials outside protected Environments + shell: bash + env: + CODEXBOT_SHARED_CREDENTIAL_PRESENT: ${{ secrets.CODEXBOT_VAULT_KEY != '' || secrets.CODEXBOT_API_KEY != '' }} + run: | + node --input-type=module <<'JS' + if (process.env.CODEXBOT_SHARED_CREDENTIAL_PRESENT !== 'false') { + console.error(JSON.stringify({event: 'review_failed', stage: 'environment', code: 'non_environment_credentials_forbidden'})); + process.exitCode = 1; + } + JS review: + needs: [credential-scope] permissions: contents: read id-token: write uses: YOUR-ORG/codexbot/.github/workflows/review.yml@FULL_COMMIT_SHA secrets: - CODEXBOT_VAULT_KEY: '' - CODEXBOT_API_KEY: '' + CODEXBOT_VAULT_KEY: ${{ secrets.CODEXBOT_VAULT_KEY }} + CODEXBOT_API_KEY: ${{ secrets.CODEXBOT_API_KEY }} with: request_id: ${{ inputs.request_id }} credential_owner: ${{ inputs.credential_owner }} @@ -54,7 +71,7 @@ jobs: Use the exact filename .github/workflows/codexbot.yml and the backend's trusted immutable source pin. Do not add secrets: inherit, fork-head checkout, repository hooks or PR-controlled commands. The reusable workflow resolves its own source from GitHub's TLS-delivered workload identity; the backend independently verifies the signed claims/run before releasing anything. -The two explicit empty secret grants are required: the called job resolves its own installation/actor Environment. They do not copy a repository/organization secret into the job. Do not replace them with a shared key or blanket inheritance. The reusable workflow declares the two optional secret names; exactly one owning Environment credential must be present. The credential-only diagnostic checks availability and a read-only administrator workload, without building an image, acquiring a session or running Codex. See [coordinated upgrades](review-rollout.md). +Use the two named secret references, not literal empty grants. The `credential-scope` job must have no Environment and must succeed before the reusable workflow starts. It passes only a boolean to its process and rejects nonempty repository/organization credentials under either name, preventing fallback to shared keys. Do not remove this guard, add `always()` to its dependent job or use blanket inheritance. Exactly one credential must exist in the owning protected Environment. The credential-only diagnostic checks availability and a read-only administrator workload, without building an image, acquiring a session or running Codex. See [credential semantics and existing-caller migration](review-rollout.md#credential-diagnosis). ## Credentials diff --git a/docs/review-rollout.md b/docs/review-rollout.md index 584cc6c..54616dd 100644 --- a/docs/review-rollout.md +++ b/docs/review-rollout.md @@ -2,7 +2,13 @@ ## Credential diagnosis -An Environment secret existing in GitHub is not proof that a called workflow receives it. [GitHub's reusable-workflow contract](https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows#using-inputs-and-secrets-in-a-reusable-workflow) requires a named grant in the caller as well as the Environment on the called job. Both workflows must be updated together. CodexBot uses two optional named declarations and explicit empty caller grants. The Environment supplies the value; repository/organization keys are not forwarded. Never add `secrets: inherit` or move a user's key into repository secrets. +An Environment secret existing in GitHub is not proof that a called workflow receives it. [GitHub's reusable-workflow contract](https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows#using-inputs-and-secrets-in-a-reusable-workflow) requires named secret references in the caller, such as `CODEXBOT_VAULT_KEY: ${{ secrets.CODEXBOT_VAULT_KEY }}`, as well as the Environment on the called job. Literal `""` grants pass empty values and do not enable this Environment lookup. The earlier empty-grant guidance and static regression assertions were incorrect; they did not exercise GitHub's secret resolver. + +Named references alone are insufficient for isolation: GitHub can supply a repository/organization secret if the owning Environment key is absent. The caller therefore first runs `credential-scope` **without an Environment**, checking only whether either global credential name is nonempty. A fixed diagnostic rejects these configurations before the reusable workflow can start. Only boolean presence reaches that process, never the credential values. The dependent review job has a required `needs` relationship and normal success gating. Do not add blanket inheritance, `always()` or `continue-on-error`, or attach an Environment to the guard. + +[GitHub reads repository/organization secrets when a run is queued, and Environment secrets when the job starts](https://docs.github.com/en/actions/reference/security/secrets#when-github-actions-reads-secrets). Thus the guard and caller references use the same global-secret snapshot. Removing a global secret after a rejected run requires a **new dispatch**, not assuming an old rerun re-reads it. Keep credentials only in the installation/actor Environment. A missing Environment key then remains empty and fails the existing XOR availability check. The optional secret declarations, strict OIDC and protected Environment remain unchanged. + +For an existing empty-grant caller, copy the corrected guard, `needs` and two references from [manual installation](installation.md#manual-workflow) into a reviewed caller PR. Keep `4ed668864cac0682e09ec49a2515a6e1893a2780` and the matching Worker pin: this correction changes neither the reusable workflow nor Worker code, requires no deployment/migration/reconnection and does not require a new source pin. After normal protected-branch approval/merge, dispatch a fresh `credential_check_only: true` run on the protected default branch. Do not weaken the Environment's branch policy just to test a PR branch. The review job checks for exactly one credential before checkout/install/build. A missing or ambiguous credential fails with a fixed JSON diagnostic. With `credential_check_only: true`, it then compiles the trusted client and verifies a read-only OIDC diagnostic; no image build, session lease, credential decryption, inference or publishing is performed. A passing check proves availability and the checked workload claims, not OAuth entitlement or privileged broker admission. Use a new UUID for the diagnostic request/attempt and the actual installation/actor IDs. Its caller must remain on the protected default branch allowed by the Environment. @@ -48,7 +54,7 @@ OpenAI's connector is independent. Its [documented manual command](https://learn 1. Validate and merge the feature branch. Obtain the **actual merged commit SHA** from GitHub and verify that it contains the reviewed reusable workflow. Never substitute an example, branch name, guessed SHA or an unrelated last commit. 2. Drain active old reviews. Apply migration 0003 using pinned Wrangler's remote migrations command. It is additive; do not reapply ALTER statements individually. Keep `MERGE_DEPLOYMENT_AUTHORIZED=false` and repository merge disabled. -3. Prepare a caller PR using that exact SHA plus the two empty named secret grants and optional credential-only input. Preserve its run-name, permissions, concurrency and default-branch protection. Update the textual trigger separately if desired; do not change authorization or merge policy. +3. Prepare a caller PR using that exact SHA plus the environment-free credential-scope guard, required dependency, named secret references and optional credential-only input. Preserve its run-name, permissions, concurrency and default-branch protection. Update the textual trigger separately if desired; do not change authorization or merge policy. 4. Report local/CI validation before deployment. Deploy the reviewed Worker with `TRUSTED_WORKFLOW=OWNER/codexbot/.github/workflows/review.yml@THAT_SAME_SHA`, preserving existing bindings, OAuth gate, secrets and domain settings. Merge the caller PR using normal protection checks. There is no atomic transaction across Cloudflare and GitHub: during the short mismatch window requests fail closed. Do not relax either SHA check to hide it. 5. Read back both actual pins and compare them byte-for-byte. Run the credential-only workflow check under the owning actor/installation Environment. Then request a new advisory/no-merge review for end-to-end broker/provider acceptance. Old Actions review attempts are not rerun to borrow a new credential/pin; use a new authorized comment. 6. Inspect the same progress comment, workflow link, sanitized failures and native review. Provider inference remains a distinct live test with the owner's authorization/allowance, never an API-key fallback. Roll back both pins together on failure; keep additive DB columns. A backend/caller protected-branch or deployment-permission block is a release blocker, not permission to bypass safeguards. diff --git a/docs/validation.md b/docs/validation.md index b132034..5bdc513 100644 --- a/docs/validation.md +++ b/docs/validation.md @@ -1,5 +1,22 @@ # Validation record and release gates +## Environment secret forwarding correction — 2026-11-14 + +A real [GitHub Actions contract probe](https://github.com/AppSolves/codexbot/actions/runs/43602684286) used synthetic, non-credential canaries in two separate test Environments and a uniquely named repository canary. No OpenAI credentials, production Environment changes, OIDC bypass, inference or deployment were involved. All six assertions passed: + +| GitHub configuration | Observed result | +|---|---| +| Literal empty caller grant; Environment contains the named canary | Empty value | +| No caller grant; Environment contains the named canary | Empty value | +| Named secret reference; canary exists only in Environment | Environment value | +| Named reference; same name in repository and Environment | Environment value | +| Named reference; key absent from Environment, present in repository | Repository fallback, demonstrating why references alone are unsafe | +| Caller job without Environment | Sees global canary presence but cannot see the Environment-only canary | + +The [probe commit](https://github.com/AppSolves/codexbot/commit/9e602025fdb2ff5c2176584d0d40f1af58222118) preserves the exact assertions and workflow definitions; its diagnostic branch is retained as evidence. The temporary canary secret and both test Environments were removed after successful completion. The production generator now combines named references with a required environment-free guard that rejects either global credential name. Regression tests execute its fail-closed script, enforce its dependency/permissions/boolean-only inputs and compare the manual example against the generator. Static tests do not implement or mock GitHub's secret resolver. `npm run check` (124 tests, typecheck, lint, build), `npm run test:clean`, actionlint for repository/generated/caller workflows and `git diff --check` passed. The production reusable workflow and Worker pin remain `4ed668864cac0682e09ec49a2515a6e1893a2780`. + +The real owning-repository credential/OIDC diagnostic must be freshly dispatched on its protected default branch after the caller PR receives normal approval and is merged. The canary probe does not establish that repository's OAuth session, broker admission or inference success. See [the caller-only migration](review-rollout.md#credential-diagnosis). + The latest [review reliability rollout](review-rollout.md) adds focused tests for credential forwarding/availability, broker error redaction, no-release-before-admission, workload-bound stage/failure updates, permanent non-approval after failed jobs, comment ownership/leases/idempotency/ambiguous responses and bounded recovery. The credential-only workflow checks availability and read-only OIDC identity only. A separate manually dispatched cache benchmark measures real GHA import/export; cache remains opt-in until that evidence justifies it. These checks do not assert live provider inference. Run the exact commands in [development](development.md). Local checks cover HMAC, policy/parser/aliases, safe regex, quotas, immutable commit/tree/blob context, output schema/DLP/limits/confidence, OAuth/OIDC contracts, native review and guarded-merge state machines, installation-scoped session leases/CAS, atomic setup, and D1/HTTP fault transitions. diff --git a/src/setup.ts b/src/setup.ts index b9b9cd3..6eafd3d 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -31,9 +31,21 @@ export function callerWorkflow(source: string, ref: string, backend: string): st dispatch_attempt: { description: 'Durable backend dispatch identity', required: true, type: 'string' }, credential_check_only: { description: 'Check Environment availability without broker admission or inference', required: false, type: 'boolean', default: false } } } }, permissions: {}, concurrency: { group: 'codexbot-credentials', 'cancel-in-progress': false }, jobs: { - review: { permissions: { contents: 'read', 'id-token': 'write' }, uses: `${source}/.github/workflows/review.yml@${ref}`, - // Named empty grants enable Environment resolution without repository-secret fallback. - secrets: { CODEXBOT_VAULT_KEY: '', CODEXBOT_API_KEY: '' }, + 'credential-scope': { 'runs-on': 'ubuntu-24.04', 'timeout-minutes': 1, permissions: {}, steps: [{ + name: 'Reject credentials outside protected Environments', shell: 'bash', + // No Environment here: this checks the same queued repository/org snapshot + // used by the named references below, without passing credential values. + env: { CODEXBOT_SHARED_CREDENTIAL_PRESENT: "${{ secrets.CODEXBOT_VAULT_KEY != '' || secrets.CODEXBOT_API_KEY != '' }}" }, + run: `node --input-type=module <<'JS' +if (process.env.CODEXBOT_SHARED_CREDENTIAL_PRESENT !== 'false') { + console.error(JSON.stringify({event: 'review_failed', stage: 'environment', code: 'non_environment_credentials_forbidden'})); + process.exitCode = 1; +} +JS +` + }] }, + review: { needs: ['credential-scope'], permissions: { contents: 'read', 'id-token': 'write' }, uses: `${source}/.github/workflows/review.yml@${ref}`, + secrets: { CODEXBOT_VAULT_KEY: '${{ secrets.CODEXBOT_VAULT_KEY }}', CODEXBOT_API_KEY: '${{ secrets.CODEXBOT_API_KEY }}' }, with: { request_id: '${{ inputs.request_id }}', credential_owner: '${{ inputs.credential_owner }}', installation_id: '${{ inputs.installation_id }}', credential_check_only: '${{ inputs.credential_check_only }}', backend } } } }); } diff --git a/tests/setup.test.ts b/tests/setup.test.ts index 74a0331..25a3758 100644 --- a/tests/setup.test.ts +++ b/tests/setup.test.ts @@ -4,11 +4,11 @@ import { Octokit } from '@octokit/rest'; import { parse } from 'yaml'; import { callerWorkflow, setupPullRequest, ensureProtectedEnvironment } from '../src/setup.js'; import { RELEASE } from './fixtures.js'; -await test('generated workflow pins reusable code, has minimal permissions and never shares secrets', () => { +await test('generated caller pins reusable code and guards named Environment credentials', () => { const yaml = callerWorkflow('operator/codexbot', RELEASE, 'https://self.invalid'); const workflow = parse(yaml) as { permissions: unknown; jobs: { review: { uses: string; secrets?: unknown; permissions: unknown; with: { backend: string } } } }; assert.equal(workflow.jobs.review.uses, `operator/codexbot/.github/workflows/review.yml@${RELEASE}`); - assert.deepEqual(workflow.jobs.review.secrets, { CODEXBOT_VAULT_KEY: '', CODEXBOT_API_KEY: '' }); + assert.deepEqual(workflow.jobs.review.secrets, { CODEXBOT_VAULT_KEY: '${{ secrets.CODEXBOT_VAULT_KEY }}', CODEXBOT_API_KEY: '${{ secrets.CODEXBOT_API_KEY }}' }); assert.deepEqual(workflow.permissions, {}); assert.equal(workflow.jobs.review.with.backend, 'https://self.invalid'); assert.match(yaml, /dispatch_attempt/); assert.throws(() => callerWorkflow('operator/codexbot', 'main', 'https://self.invalid')); }); diff --git a/tests/workflows.test.ts b/tests/workflows.test.ts index c2803da..259d311 100644 --- a/tests/workflows.test.ts +++ b/tests/workflows.test.ts @@ -24,12 +24,31 @@ await test('reusable workflow has no GitHub write permissions, shared secrets or assert.ok(!text.includes('pull_request.head')); assert.ok(!text.includes('secrets: inherit')); assert.ok(!text.includes('upload-artifact')); assert.equal(record(record(jobs.publish).permissions).contents, 'read'); }); -await test('Environment secret grants are explicit and empty, with no repository-secret fallback or blanket inheritance', async () => { +await test('named Environment references require a successful caller scope guard, without credential values or blanket inheritance', async () => { const workflow = record(parse(await readFile('.github/workflows/review.yml', 'utf8'))); const contract = record(record(workflow.on).workflow_call); assert.deepEqual(Object.keys(record(contract.secrets)).sort(), ['CODEXBOT_API_KEY','CODEXBOT_VAULT_KEY']); const caller = record(parse(callerWorkflow('operator/codexbot', RELEASE, 'https://self.invalid'))); - assert.deepEqual(record(record(caller.jobs).review).secrets, { CODEXBOT_VAULT_KEY: '', CODEXBOT_API_KEY: '' }); + const jobs = record(caller.jobs), review = record(jobs.review), guard = record(jobs['credential-scope']); + assert.deepEqual(review.secrets, { CODEXBOT_VAULT_KEY: '${{ secrets.CODEXBOT_VAULT_KEY }}', CODEXBOT_API_KEY: '${{ secrets.CODEXBOT_API_KEY }}' }); + assert.deepEqual(review.needs, ['credential-scope']); assert.equal(review.if, undefined); + assert.equal(guard.environment, undefined); assert.deepEqual(guard.permissions, {}); assert.equal(guard['timeout-minutes'], 1); + const guardSteps = guard.steps as Record[]; assert.equal(guardSteps.length, 1); + assert.deepEqual(guardSteps[0]!.env, { CODEXBOT_SHARED_CREDENTIAL_PRESENT: "${{ secrets.CODEXBOT_VAULT_KEY != '' || secrets.CODEXBOT_API_KEY != '' }}" }); + const guardScript = String(guardSteps[0]!.run).split("<<'JS'\n")[1]!.replace(/\nJS\s*$/, ''); + for (const value of ['false', 'true', '', 'opaque-secret']) { + const env = Object.assign(Object.create(null) as NodeJS.ProcessEnv, { CODEXBOT_SHARED_CREDENTIAL_PRESENT: value }); + const result = spawnSync(process.execPath, ['--input-type=module', '-e', guardScript], { env, encoding: 'utf8' }); + assert.equal(result.status, value === 'false' ? 0 : 1); + assert.ok(!result.stdout.includes('opaque-secret')); assert.ok(!result.stderr.includes('opaque-secret')); + if (value !== 'false') assert.equal(JSON.parse(result.stderr).code, 'non_environment_credentials_forbidden'); + } + assert.ok(!JSON.stringify(caller).includes('secrets: inherit')); + assert.equal(guard['continue-on-error'], undefined); assert.equal(guardSteps[0]!['continue-on-error'], undefined); + const manual = record(parse((await readFile('docs/installation.md', 'utf8')).split('```yaml\n')[1]!.split('```')[0]!)); + assert.deepEqual(record(manual.jobs)['credential-scope'], guard); + assert.deepEqual(record(record(manual.jobs).review).needs, review.needs); + assert.deepEqual(record(record(manual.jobs).review).secrets, review.secrets); const steps = record(record(workflow.jobs).review).steps as Record[]; const check = String(steps[0]!.run).split("<<'JS'\n")[1]!.replace(/\nJS\s*$/, ''); for (const [vault, api, status] of [['','',1],['opaque-vault','',0],['','opaque-api',0],['opaque-vault','opaque-api',1]] as const) { From 5e9ae4873638942fb854a3a9b5cdd6472bb5449a Mon Sep 17 00:00:00 2001 From: AppSolves Date: Sat, 14 Nov 2026 15:13:04 +0100 Subject: [PATCH 2/3] docs: distinguish caller repair from hosted generator deployment --- docs/deployment.md | 2 ++ docs/review-rollout.md | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/deployment.md b/docs/deployment.md index 172cc81..dd51ba8 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -2,6 +2,8 @@ For Worker/reusable-workflow upgrades, follow [the coordinated immutable-pin upgrade](review-rollout.md), apply required migrations and set the caller pin and Worker TRUSTED_WORKFLOW to the same actual merged commit. The caller-only Environment-secret correction uses named references plus a scope guard; it keeps the existing `4ed668864cac0682e09ec49a2515a6e1893a2780` pin and needs no Worker deployment or migration. Keep merge disabled. Report validation before any production change; a temporary pin mismatch fails closed. +The shared setup generator is bundled into `/v1/setup`. Publishing its corrected templates for future hosted installations requires a separately authorized Worker bundle deployment, with the existing trusted review pin preserved. The existing caller can be repaired independently; no backend deployment is performed by the fix PR. + This document is operator instructions, not evidence of an existing hosted deployment. Do not register, deploy, publish a release or use paid inference without your own authorization. ## GitHub App diff --git a/docs/review-rollout.md b/docs/review-rollout.md index 54616dd..3f48384 100644 --- a/docs/review-rollout.md +++ b/docs/review-rollout.md @@ -8,7 +8,9 @@ Named references alone are insufficient for isolation: GitHub can supply a repos [GitHub reads repository/organization secrets when a run is queued, and Environment secrets when the job starts](https://docs.github.com/en/actions/reference/security/secrets#when-github-actions-reads-secrets). Thus the guard and caller references use the same global-secret snapshot. Removing a global secret after a rejected run requires a **new dispatch**, not assuming an old rerun re-reads it. Keep credentials only in the installation/actor Environment. A missing Environment key then remains empty and fails the existing XOR availability check. The optional secret declarations, strict OIDC and protected Environment remain unchanged. -For an existing empty-grant caller, copy the corrected guard, `needs` and two references from [manual installation](installation.md#manual-workflow) into a reviewed caller PR. Keep `4ed668864cac0682e09ec49a2515a6e1893a2780` and the matching Worker pin: this correction changes neither the reusable workflow nor Worker code, requires no deployment/migration/reconnection and does not require a new source pin. After normal protected-branch approval/merge, dispatch a fresh `credential_check_only: true` run on the protected default branch. Do not weaken the Environment's branch policy just to test a PR branch. +For an existing empty-grant caller, copy the corrected guard, `needs` and two references from [manual installation](installation.md#manual-workflow) into a reviewed caller PR. Keep `4ed668864cac0682e09ec49a2515a6e1893a2780` and the matching Worker pin: repairing this caller requires no deployment/migration/reconnection or new source pin. After normal protected-branch approval/merge, dispatch a fresh `credential_check_only: true` run on the protected default branch. Do not weaken the Environment's branch policy just to test a PR branch. + +`src/setup.ts` is shared by CLI-assisted setup and the hosted Worker's `/v1/setup` endpoint. Updated CLI source generates the corrected caller immediately; an existing hosted backend keeps its bundled old generator until an operator separately authorizes deploying the updated bundle. That future generator deployment must preserve the current `TRUSTED_WORKFLOW` value and requires no reusable-workflow pin rollout. Updating the existing caller does not need to wait for it. The review job checks for exactly one credential before checkout/install/build. A missing or ambiguous credential fails with a fixed JSON diagnostic. With `credential_check_only: true`, it then compiles the trusted client and verifies a read-only OIDC diagnostic; no image build, session lease, credential decryption, inference or publishing is performed. A passing check proves availability and the checked workload claims, not OAuth entitlement or privileged broker admission. Use a new UUID for the diagnostic request/attempt and the actual installation/actor IDs. Its caller must remain on the protected default branch allowed by the Environment. From 6b6b91839ef52de994b5e2b4f54cc89e3b649943 Mon Sep 17 00:00:00 2001 From: AppSolves Date: Sat, 14 Nov 2026 15:34:06 +0100 Subject: [PATCH 3/3] test: follow admitted requests and actual concurrent claim owners --- tests/security-regressions.test.ts | 3 ++- tests/store.test.ts | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/security-regressions.test.ts b/tests/security-regressions.test.ts index 1a0b121..051d0b5 100644 --- a/tests/security-regressions.test.ts +++ b/tests/security-regressions.test.ts @@ -72,7 +72,8 @@ await test('atomic quotas, same-head idempotency, bounded rerun and tenant isola const { db, sqlite } = database(), store = new Store(db), request = snapshot(); request.config.quotas.cooldown_seconds = 0; try { const attempts = await Promise.allSettled([store.create(request), store.create({ ...request, id: crypto.randomUUID() })]); assert.equal(attempts.filter(x => x.status === 'fulfilled').length, 1); - await store.transition(request.id, 'created', 'failed'); + const admitted = attempts.find(x => x.status === 'fulfilled'); assert.ok(admitted); + assert.equal(await store.transition(admitted.value.id, 'created', 'failed'), true); await assert.rejects(store.create({ ...request, id: crypto.randomUUID() }), /duplicate_review_or_quota_exceeded/); const rerun = { ...request, id: crypto.randomUUID(), command: { ...request.command, rerun: true } }; await store.create(rerun); await store.transition(rerun.id, 'created', 'failed'); diff --git a/tests/store.test.ts b/tests/store.test.ts index e60f6ef..7ccc639 100644 --- a/tests/store.test.ts +++ b/tests/store.test.ts @@ -15,12 +15,13 @@ await test('request transitions bind exactly one run and preserve publication st await store.create(request); assert.equal(await store.transition(request.id, 'created', 'dispatched'), true); const starts = await Promise.all([store.transition(request.id, 'dispatched', 'running', '1'), store.transition(request.id, 'dispatched', 'running', '2')]); assert.equal(starts.filter(Boolean).length, 1); - await assert.rejects(store.result(request.id, clean(), true, '2')); - await store.result(request.id, clean(), true, '1'); await store.result(request.id, clean(), true, '1'); - await assert.rejects(store.result(request.id, { ...clean(), summary: 'A different result must not replace the first one.' }, true, '1')); - assert.equal(await store.transition(request.id, 'reviewed', 'publishing', '2'), false); - await assert.rejects(store.claimPublication(request.id, '2')); - const lease = await store.claimPublication(request.id, '1'); assert.equal((await store.get(request.id)).row.state, 'publishing'); + const admittedRun = starts[0] ? '1' : '2', rejectedRun = starts[0] ? '2' : '1'; + await assert.rejects(store.result(request.id, clean(), true, rejectedRun)); + await store.result(request.id, clean(), true, admittedRun); await store.result(request.id, clean(), true, admittedRun); + await assert.rejects(store.result(request.id, { ...clean(), summary: 'A different result must not replace the first one.' }, true, admittedRun)); + assert.equal(await store.transition(request.id, 'reviewed', 'publishing', rejectedRun), false); + await assert.rejects(store.claimPublication(request.id, rejectedRun)); + const lease = await store.claimPublication(request.id, admittedRun); assert.equal((await store.get(request.id)).row.state, 'publishing'); await assert.rejects(store.published(request.id, 99, 'wrong-owner')); await store.published(request.id, 99, lease); assert.equal((await store.get(request.id)).row.review_id, 99); } finally { sqlite.close(); } @@ -33,13 +34,14 @@ await test('cross-run refresh lock plus version CAS protects rotating tokens', a const other = { ...request, id: 'another-request' }; const acquired = await Promise.allSettled([store.acquire(request), store.acquire(other)]); assert.equal(acquired.filter(x => x.status === 'fulfilled').length, 1); - await assert.rejects(store.rotate(other, 1, initial)); - await store.rotate(request, 1, initial); assert.equal((await store.session(request.repositoryId, request.actorId, request.installationId))?.version, 2); - await assert.rejects(store.rotate(request, 1, initial)); + const owner = acquired[0]!.status === 'fulfilled' ? request : other, rejected = owner === request ? other : request; + await assert.rejects(store.rotate(rejected, 1, initial)); + await store.rotate(owner, 1, initial); assert.equal((await store.session(request.repositoryId, request.actorId, request.installationId))?.version, 2); + await assert.rejects(store.rotate(owner, 1, initial)); await assert.rejects(store.saveSession(request.repositoryId, request.actorId, initial, request.installationId)); await assert.rejects(store.acquire({ ...request, repositoryId: 99 })); assert.equal(await store.session(request.repositoryId, 99, request.installationId), null); - await store.release(request); await store.acquire(other); await store.release(other); + await store.release(owner); await store.acquire(rejected); await store.release(rejected); await store.removeInstallation(request.installationId); assert.equal(await store.session(request.repositoryId, request.actorId, request.installationId), null); } finally { sqlite.close(); } });