Repository navigation
Receipts: sign enforcement_mode and gateway_build (migration 052) #236
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
32 commits
Select commit
Hold shift + click to select a range
232b833
QA: agent-middleware gateway/migrations/
PetrefiedThunder b22fd2a
Merge main into metacode/qa5-am-gateway-migrations
PetrefiedThunder 7a8b331
Fix legacy SQLite boolean defaults
PetrefiedThunder 206364d
Test legacy SQLite boolean row repair
PetrefiedThunder d3726fc
Merge remote-tracking branch 'origin/main' into metacode/qa5-am-gatew…
PetrefiedThunder f992032
Chain SQLite boolean repair after API key usage migration
PetrefiedThunder 5919ba1
Merge remote-tracking branch 'origin/main' into metacode/qa5-am-gatew…
PetrefiedThunder 036356b
Merge remote-tracking branch 'origin/main' into metacode/qa5-am-gatew…
PetrefiedThunder 89a5956
Chain SQLite boolean repair after approval gate migration
PetrefiedThunder 89428ce
Merge remote-tracking branch 'origin/main' into metacode/qa5-am-gatew…
PetrefiedThunder 874515d
Rechain SQLite boolean migration after API key usage events
PetrefiedThunder 6b4c2f2
Merge remote-tracking branch 'origin/main' into hermes-tmp-61
PetrefiedThunder 9020bf6
Merge remote-tracking branch 'origin/main' into hermes-tmp-61
PetrefiedThunder c96958b
feat(migrations): port agent-middleware-api 047-050 with the same rev…
PetrefiedThunder 22fdca0
Merge port of api migrations 047-050; renumber SQLite boolean default…
PetrefiedThunder 02ad942
Sign enforcement mode and gateway build into receipts (migration 052)
PetrefiedThunder f563483
fix(migrations): rls_bypass in env.py, boot check for reconcile columns
PetrefiedThunder e3bf41b
Merge #234 head f5634837 (review fixes)
PetrefiedThunder e705953
Merge #61 head e3bf41bc6ddbb245b8205b1329be6497a0462074
PetrefiedThunder 29d6363
test: cover receipt 052 columns in migration proof
PetrefiedThunder 830cf4d
docs: regenerate receipt provenance OpenAPI schema
PetrefiedThunder e6d5f99
fix(migrations): port TENANT_RLS_MODE setting; RLS for resolution tables
PetrefiedThunder 40615d3
Merge #234 head e6d5f997 (TENANT_RLS_MODE, resolution-table RLS)
PetrefiedThunder 8bc350a
Merge #61 (carries #234 e6d5f997)
PetrefiedThunder 6d977e2
feat(migrations): add opt-in TENANT_RLS_MODE=enable and PG RLS proof
PetrefiedThunder 6ea1f92
Merge remote-tracking branch 'origin/main' into fix/234-v2
PetrefiedThunder e62d99e
Revert "feat(migrations): add opt-in TENANT_RLS_MODE=enable and PG RL…
PetrefiedThunder ae9a810
Merge e62d99e2a into metacode/qa5-am-gateway-migrations
PetrefiedThunder 2b820df
Merge ae9a81050 into hermes/receipt-mode-build
PetrefiedThunder c6124e4
Merge origin/main into hermes/receipt-mode-build
PetrefiedThunder 63be05b
test(receipts): pin populated enforcement_mode and gateway_build vectors
PetrefiedThunder bf5c634
docs(spec): document enforcement_mode and gateway_build receipt members
PetrefiedThunder 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
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,21 @@ | ||
| # Schema 052: receipt enforcement mode and gateway build | ||
|
|
||
| Migration `052_receipt_mode_build` revises `051_sqlite_boolean_defaults`. It | ||
| adds nullable `receipts.enforcement_mode` (`enforce` or `permissive`) and | ||
| `receipts.gateway_build` (the image commit SHA from | ||
| `app.core.build_metadata.get_build_commit_sha`, NULL when unknown). Receipts | ||
| issued after 052 sign both fields when set; existing receipts stay NULL and | ||
| keep verifying with their original signatures. No row is updated. | ||
|
|
||
| ## Compatibility release | ||
|
|
||
| Production boot requires the database revision to match the packaged head, so | ||
| a 051-packaged image cannot restart after 052 is applied. Qualify a | ||
| 052-capable image against a disposable PostgreSQL upgrade from 051 first. | ||
| These release checks have not been run against staging or production. | ||
|
|
||
| ## Rollback boundary | ||
|
|
||
| Downgrade to 051 refuses while any receipt carries either field, because | ||
| dropping signed fields would make those receipts fail verification. Recover | ||
| with a 052-capable image and the database left at 052. |
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,52 @@ | ||
| """Record the enforcement mode and gateway build on receipts. | ||
|
|
||
| Revision ID: 052_receipt_mode_build | ||
| Revises: 051_sqlite_boolean_defaults | ||
|
|
||
| Adds nullable ``receipts.enforcement_mode`` and ``receipts.gateway_build``. | ||
| Existing receipts stay NULL, and their signatures do not cover these fields, | ||
| so they keep verifying. Columns are added only when missing. | ||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| revision: str = "052_receipt_mode_build" | ||
| down_revision: str = "051_sqlite_boolean_defaults" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
| COLUMNS = (("enforcement_mode", 16), ("gateway_build", 64)) | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| existing = {c["name"] for c in sa.inspect(op.get_bind()).get_columns("receipts")} | ||
| missing = [(name, size) for name, size in COLUMNS if name not in existing] | ||
| if not missing: | ||
| return | ||
| with op.batch_alter_table("receipts") as batch_op: | ||
| for name, size in missing: | ||
| batch_op.add_column(sa.Column(name, sa.String(length=size), nullable=True)) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| # A receipt signed with these fields cannot verify once they are dropped, | ||
| # so refuse rather than silently invalidate signed evidence. | ||
| signed = ( | ||
| op.get_bind() | ||
| .execute( | ||
| sa.text( | ||
| "SELECT COUNT(*) FROM receipts " | ||
| "WHERE enforcement_mode IS NOT NULL OR gateway_build IS NOT NULL" | ||
| ) | ||
| ) | ||
| .scalar_one() | ||
| ) | ||
| if signed: | ||
| raise RuntimeError( | ||
| f"052 downgrade refused: {signed} receipt(s) carry signed " | ||
| "enforcement_mode/gateway_build values that 051 cannot store" | ||
| ) | ||
| with op.batch_alter_table("receipts") as batch_op: | ||
| batch_op.drop_column("gateway_build") | ||
| batch_op.drop_column("enforcement_mode") |
5 changes: 5 additions & 0 deletions
5
gateway/tests/fixtures/receipt_signing_golden/success_enforcement_build.json
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,5 @@ | ||
| { | ||
| "signature_b64_over_test_seed": "ij5D5zN7SmVmsdfpNdnRfcqKxefmpBkMaNl3uaQ9kzDVXsHYm8bpCTv4+uILG2nJaLk377ziq/Vgd/+elmY5Bw==", | ||
| "signing_input": "{\"alg\":\"Ed25519\",\"audit_event_id\":\"aud_golden_0001\",\"created_at\":\"2026-09-14T17:00:00+00:00\",\"credits_authorized\":\"2.5\",\"credits_charged\":\"2.5\",\"dispatch_attempt_id\":\"disp_golden_0001\",\"enforcement_mode\":\"enforce\",\"gateway_build\":\"0123456789abcdef0123456789abcdef01234567\",\"idempotency_record_id\":\"idem_golden_0001\",\"key_id\":\"key_golden_0001\",\"kid\":\"sk_golden_0001\",\"ledger_entry_id\":\"led_golden_0001\",\"outcome\":\"success\",\"payload_hash\":\"e3d1cb8f6369020b87a3ba8b48c3108e335312f145b952ca69481e893f7be090\",\"permit_id\":\"pmt_golden_0001\",\"receipt_id\":\"rcpt_golden_0005\",\"request_hash\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"response_hash\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"tool\":\"golden-path-echo\",\"wallet_id\":\"agt-golden-0001\"}", | ||
| "signing_input_sha256": "12bbc80225eede4e0e9912adf5cf9e9639823c3cb7681723ffa3be2ded27567e" | ||
| } |
5 changes: 5 additions & 0 deletions
5
gateway/tests/fixtures/receipt_signing_golden/success_permissive.json
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,5 @@ | ||
| { | ||
| "signature_b64_over_test_seed": "0yzqc74K4pSRk4GTbh84j9oT0p2x1PF5nql2o3nj4uogrUBEukMfd8WDMlBrNsSrsXFbugLlSKWcex5ONB8xCg==", | ||
| "signing_input": "{\"alg\":\"Ed25519\",\"audit_event_id\":\"aud_golden_0001\",\"created_at\":\"2026-09-14T17:00:00+00:00\",\"credits_authorized\":\"2.5\",\"credits_charged\":\"2.5\",\"dispatch_attempt_id\":\"disp_golden_0001\",\"enforcement_mode\":\"permissive\",\"idempotency_record_id\":\"idem_golden_0001\",\"key_id\":\"key_golden_0001\",\"kid\":\"sk_golden_0001\",\"ledger_entry_id\":\"led_golden_0001\",\"outcome\":\"success\",\"payload_hash\":\"cf576b4daa8eb839999dc82d2c11bd21b37d522caefcbcc916d0dfee35947eff\",\"permit_id\":\"pmt_golden_0001\",\"receipt_id\":\"rcpt_golden_0006\",\"request_hash\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"response_hash\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"tool\":\"golden-path-echo\",\"wallet_id\":\"agt-golden-0001\"}", | ||
| "signing_input_sha256": "b6974c6a391007871b52f9b076aac25b8053ada1dadb2c2c8ca81a82b025fd9b" | ||
| } |
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
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.