Repository navigation
fix: identify GitHub release requests and attest durable reservations #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
03c6c37
fix: identify GitHub release requests and attest durable reservations
AyobamiH b845df2
fix: bind recovery causally to committed authority and exact attempt
AyobamiH cfce52d
fix: require gated reservations and complete exact-attempt receipt re…
AyobamiH fdd0276
fix: validate recorded recovery grants on read-only settlement
AyobamiH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import {createPublicKey,verify} from 'node:crypto'; | ||
| import {digest,stableJson} from '../../../dist/hash.js'; | ||
| import {publicKeyFingerprint} from '../../../dist/signer.js'; | ||
| import {exactKeys,releaseTime} from '../../../dist/release-v1-contract.js'; | ||
| import {demand} from './identity.mjs'; | ||
| export function recoveryPolicy(env) { | ||
| if (env.RECOVERY_REQUIRED !== 'true') return null; | ||
| const key=createPublicKey(env.RECOVERY_HANDOFF_PUBLIC_KEY_PEM); | ||
| const pin=publicKeyFingerprint(env.RECOVERY_HANDOFF_PUBLIC_KEY_PEM); | ||
| demand(key.asymmetricKeyType==='ed25519' && pin===env.RECOVERY_HANDOFF_FINGERPRINT && | ||
| pin!==env.SIGNER_FINGERPRINT && pin!==env.RECEIPT_FINGERPRINT && pin!==env.AUTHORITY_FINGERPRINT && | ||
| /^[a-f0-9-]{36}$/.test(env.RECOVERY_RUN_ID), 'recovery_policy_invalid',503); | ||
| return {fingerprint:pin,runId:env.RECOVERY_RUN_ID}; | ||
| } | ||
| export function validateRecoveryGrant(grant,record,claims,env,now=Date.now()) { | ||
| const configured=recoveryPolicy(env); | ||
| demand(configured && stableJson(configured)===stableJson(record.recoveryPolicy), 'recovery_policy_changed'); | ||
| exactKeys(grant,['schema','runId','transactionId','subjectDigest','githubRunId','githubRunAttempt', | ||
| 'workflowCommit','reservationDigest','authorisationAuditDigest','issuedAt','expiresAt', | ||
| 'publicKeyPem','signatureBase64'],'recovery_grant_shape'); | ||
| demand(grant.schema==='donestate.release-recovery-authorisation.v1' && grant.runId===configured.runId && | ||
| grant.transactionId===record.seed.transactionId && grant.subjectDigest===digest(record.seed.subject) && | ||
| grant.githubRunId===claims.run_id && grant.githubRunAttempt===Number(claims.run_attempt) && | ||
| grant.workflowCommit===env.TRUSTED_SOURCE_SHA && grant.reservationDigest===digest(record.reservation) && | ||
| /^[a-f0-9]{64}$/.test(grant.authorisationAuditDigest), 'recovery_grant_binding'); | ||
| const issued=releaseTime(grant.issuedAt),expires=releaseTime(grant.expiresAt); | ||
| demand(issued<=now+30000 && expires>now && expires>issued && expires-issued<=300000 && | ||
| expires<=releaseTime(record.approval.expiresAt), 'recovery_grant_expired'); | ||
| const key=createPublicKey(grant.publicKeyPem); | ||
| demand(key.asymmetricKeyType==='ed25519' && publicKeyFingerprint(grant.publicKeyPem)===configured.fingerprint, | ||
| 'recovery_grant_signer'); | ||
| const {signatureBase64,...unsigned}=grant; | ||
| demand(typeof signatureBase64==='string' && /^[A-Za-z0-9+/]{86}==$/.test(signatureBase64) && | ||
| Buffer.from(signatureBase64,'base64').toString('base64')===signatureBase64 && | ||
| verify(null,Buffer.from('donestate.release-recovery-authorisation.v1\0'+stableJson(unsigned)),key, | ||
| Buffer.from(signatureBase64,'base64')), 'recovery_grant_signature'); | ||
| } | ||
|
|
||
| // A later authenticated attempt may inspect the original effect, never spend | ||
| // the original grant again. Verify that grant at its recorded issuance time. | ||
| export function validateRecordedRecoveryGrant(record, claims, env) { | ||
| const configured = recoveryPolicy(env); | ||
| demand(stableJson(configured) === stableJson(record.recoveryPolicy ?? null), | ||
| 'recovery_policy_changed'); | ||
| if (!configured) return; | ||
| const grant = record.recoveryAuthorisation; | ||
| demand(grant && record.reservation, 'recovery_authorisation_required'); | ||
| const producingAttempt = record.reservation.githubRunAttempt; | ||
| demand(record.reservation.githubRunId === claims.run_id && | ||
| Number.isSafeInteger(producingAttempt) && producingAttempt >= 1 && | ||
| Number(claims.run_attempt) >= producingAttempt, 'recovery_reader_binding'); | ||
| validateRecoveryGrant(grant, record, | ||
| {...claims, run_attempt: String(producingAttempt)}, env, releaseTime(grant.issuedAt)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.