Repository navigation
[audit-high] SQLite stored false booleans as the word false, which reads as true #61
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
24 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 f563483
fix(migrations): rls_bypass in env.py, boot check for reconcile columns
PetrefiedThunder e3bf41b
Merge #234 head f5634837 (review fixes)
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 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 da49517
Merge origin/main into metacode/qa5-am-gateway-migrations
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Schema 051: SQLite boolean defaults and rollback boundary | ||
|
|
||
| Migration `051_sqlite_boolean_defaults` revises | ||
| `050_demo_key_first_used` (the api-chain port, PR #234). PR #61 must merge | ||
| after PR #234. | ||
| On SQLite it repairs legacy text booleans in refresh tokens, human approvals, | ||
| and permits, then replaces their text defaults with integer false defaults. | ||
| PostgreSQL schema and data are unchanged. | ||
|
|
||
| ## Compatibility release before migration | ||
|
|
||
| Before an authorized rollout, confirm the database revision, back up the | ||
| database, and qualify a 051-capable recovery image. Rehearse the migration on | ||
| a copy of any SQLite database created before the corrected 022 and 023 | ||
| migrations, including existing rows and inserts that omit these columns. | ||
| The application requires its packaged Alembic head, so an older image cannot | ||
| restart after the database reaches 051. | ||
|
|
||
| ## Rollback after activation | ||
|
|
||
| SQLite downgrade raises `sqlite_boolean_defaults_downgrade_unsupported` | ||
| instead of marking a database downgraded while retaining corrected values | ||
| and defaults. Recover with a 051-capable image and the database at 051. | ||
| Returning to an older packaged head requires a separately reviewed migration | ||
| and compatibility plan. |
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
50 changes: 50 additions & 0 deletions
50
gateway/migrations/versions/051_sqlite_boolean_defaults.py
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,50 @@ | ||
| """Repair legacy SQLite text booleans and replace their text defaults. | ||
|
|
||
| Revision ID: 051_sqlite_boolean_defaults | ||
| Revises: 050_demo_key_first_used | ||
| """ | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
| revision: str = "051_sqlite_boolean_defaults" | ||
| down_revision: str = "050_demo_key_first_used" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| if op.get_bind().dialect.name != "sqlite": | ||
| return | ||
|
|
||
| for table, column in ( | ||
| ("refresh_tokens", "revoked"), | ||
| ("human_approvals", "simulated"), | ||
| ("permits", "requires_human_approval"), | ||
| ): | ||
| op.execute( | ||
| sa.text( | ||
| f"UPDATE {table} SET {column} = 0 " | ||
| f"WHERE typeof({column}) = 'text' " | ||
| f"AND lower({column}) IN ('false', 'f', '0', 'no')" | ||
| ) | ||
| ) | ||
| op.execute( | ||
| sa.text( | ||
| f"UPDATE {table} SET {column} = 1 " | ||
| f"WHERE typeof({column}) = 'text' " | ||
| f"AND lower({column}) IN ('true', 't', '1', 'yes')" | ||
| ) | ||
| ) | ||
| with op.batch_alter_table(table) as batch_op: | ||
| batch_op.alter_column( | ||
| column, | ||
| existing_type=sa.Boolean(), | ||
| existing_nullable=False, | ||
| server_default=sa.false(), | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| if op.get_bind().dialect.name == "sqlite": | ||
| raise RuntimeError("sqlite_boolean_defaults_downgrade_unsupported") |
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.