diff --git a/CHANGELOG.md b/CHANGELOG.md index ca41694..d5c4014 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Security and behavior changes +- Accept GitHub's documented immutable default OIDC subjects for new/renamed repositories, exactly binding owner ID, repository ID and Environment while retaining the legacy subject and all signed identity/workflow checks. + - Add primary Fully Autonomous merging (0 humans), optional Human-in-the-Loop (1–6), owner-opted-in merge-on-approval and a repository/installation-scoped live acceptance gate. Preserve GitHub protections, native approval and exact-head checks. - Add explicit CLI consent and protected repository assignment for unattended reviews of authorized contributors without provider accounts. Migration 0006 scopes grants by installation/repository/owner and fences each consent generation through leases, refresh and privileged publication. Manual commands never borrow an assigned connection. - Make CLI provisioning the current public onboarding path; browser OAuth remains deferred and disabled until its separate client is provisioned. diff --git a/docs/installation.md b/docs/installation.md index 124fe5d..9822bfc 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -96,3 +96,5 @@ Disconnect retrieves/revokes the latest ChatGPT session, deletes the encrypted r Run [advisory acceptance](acceptance.md), then independently enable approval if appropriate. Merge needs a separate whitelist, protected branch, either explicit --merge or owner-opted-in automatic merge-on-approval, and the operator's deployment acceptance gate. Choose Fully Autonomous (0 humans) or Human-in-the-Loop (1–6); stricter GitHub human requirements remain enforced. Pending CI also requires the App-bound required guard and optional merge permissions. Ready PRs use a native exact-head merge. Unknown/conflicting/queue states are manual-only; the bot never bypasses protections. For unattended reviews from authorized contributors without provider accounts, connect the administrator's own repository credential with `--allow-automatic-reviews`, then opt into `credentials.automatic_reviewer: YOUR_LOGIN` and `review.auto_review: true` through protected configuration. The event actor still passes the repository review policy. Never copy another repository's vault, refresh token or Environment secrets. See [explicit credential consent](configuration.md#unattended-credential-consent). + +The broker supports both GitHub default OIDC subject formats: legacy repository names and the immutable `OWNER@OWNER_ID/REPO@REPOSITORY_ID` format used for new repositories. Both require the exact protected Environment, signed numeric tenant claims and immutable reusable workflow. Custom subject templates are unsupported. See [GitHub OIDC reference](https://docs.github.com/en/actions/reference/security/oidc#immutable-subject-claims). diff --git a/src/worker/oidc.ts b/src/worker/oidc.ts index a59719b..f4eb273 100644 --- a/src/worker/oidc.ts +++ b/src/worker/oidc.ts @@ -33,7 +33,11 @@ export function checkClaims(claims: JWTPayload, expected: WorkflowIdentity): Wor requireCondition(claims.workflow_ref === workflowRef && claims.workflow_sha === expected.workflowSha, 'oidc_caller_workflow_mismatch', 403); requireCondition(/@[a-f0-9]{40}$/.test(expected.trustedWorkflow) && claims.job_workflow_ref === expected.trustedWorkflow && claims.job_workflow_sha === expected.trustedWorkflow.split('@')[1], 'oidc_reusable_workflow_mismatch', 403); requireCondition(claims.runner_environment === 'github-hosted' && claims.environment === expected.environment, 'oidc_environment_mismatch', 403); - requireCondition(claims.sub === `repo:${expected.repository}:environment:${expected.environment.replace(/:/g, '%3A')}`, 'oidc_subject_mismatch', 403); + const [owner, repository] = expected.repository.split('/'); + const suffix = `:environment:${expected.environment.replace(/:/g, '%3A')}`; + // GitHub's default for new/renamed repositories includes immutable owner and repository IDs. + const immutable = `repo:${owner}@${expected.ownerId}/${repository}@${expected.repositoryId}${suffix}`; + requireCondition(claims.sub === `repo:${expected.repository}${suffix}` || claims.sub === immutable, 'oidc_subject_mismatch', 403); requireCondition(typeof claims.run_id === 'string' && /^\d+$/.test(claims.run_id) && typeof claims.run_attempt === 'string' && /^\d+$/.test(claims.run_attempt) && typeof claims.jti === 'string', 'oidc_run_missing', 403); requireCondition(Number.isSafeInteger(Number(claims.run_id)) && Number(claims.run_id) > 0 && Number.isSafeInteger(Number(claims.run_attempt)) && Number(claims.run_attempt) > 0 && claims.jti.length > 0 && claims.jti.length <= 200, 'oidc_invalid_run_identity', 403); return { runId: claims.run_id, attempt: claims.run_attempt, jti: claims.jti }; diff --git a/tests/oidc.test.ts b/tests/oidc.test.ts index fe146ff..1e0df98 100644 --- a/tests/oidc.test.ts +++ b/tests/oidc.test.ts @@ -21,3 +21,16 @@ await test('OIDC cryptographically rejects forged signatures, expiry, issuer and const wrongIssuer = await new SignJWT(claims).setProtectedHeader({ alg: 'RS256' }).setIssuer('https://attacker.invalid').setAudience('https://broker.invalid').setIssuedAt().setNotBefore('0s').setExpirationTime('5m').sign(keys.privateKey); await assert.rejects(verifyWorkload(wrongIssuer, 'https://broker.invalid', expected, () => keys.publicKey)); }); + +await test('immutable default subjects bind both numeric identities and the exact review/publishing Environment',async()=>{ + const keys=await generateKeyPair('RS256'); + for(const environment of ['codexbot-1-5','codexbot-publish-1','production:restricted']){ + const subject=`repo:owner@3/repo@2:environment:${environment.replace(/:/g,'%3A')}`; + const input={...claims,environment,sub:subject},identity={...expected,environment}; + const jwt=await new SignJWT(input).setProtectedHeader({alg:'RS256'}).setIssuer('https://token.actions.githubusercontent.com').setAudience('https://broker.invalid').setIssuedAt().setNotBefore('0s').setExpirationTime('5m').sign(keys.privateKey); + assert.equal((await verifyWorkload(jwt,'https://broker.invalid',identity,()=>keys.publicKey)).runId,'123'); + for(const invalid of [subject.replace('owner@3','owner@99'),subject.replace('repo@2','repo@22'),subject.replace('owner@3','other@3'),subject.replace('repo@2','other@2'),subject+':extra',subject.replace(':environment:',':ref:'),subject.replace('@3','@03')])assert.throws(()=>checkClaims({...input,sub:invalid},identity),{code:'oidc_subject_mismatch'}); + assert.throws(()=>checkClaims(input,{...identity,environment:'other'}),{code:'oidc_environment_mismatch'}); + assert.throws(()=>checkClaims({...input,job_workflow_sha:WORKFLOW},identity),{code:'oidc_reusable_workflow_mismatch'}); + } +});