Repository navigation
fix: make namespace dry runs read-only - #343
Merged
Merged
Conversation
--dry-run called create_app(), which creates the configured indexes, replaces the configured rules and changes the TTL index of invitations. With a newer image, that left pods of the older version unable to restart. A dry run now only reads the config and registers the collections, without indexes; the docs say what it doesn't predict. Closes #339 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Reviewer's GuideThis PR makes namespace-subject dry runs genuinely read-only by separating FOCA config loading from startup, registering collections without index creation or rule replacement, documenting the resulting count and validation limitations, and testing preservation of legacy indexes and documents. Sequence diagram for the read-only namespace-subject dry runsequenceDiagram
participant CLI as namespace_subjects CLI
participant RO as _read_only_app
participant FOCA as create_foca
participant Mongo as register_mongodb
participant DB as MongoDB
participant Migration as namespace_subjects
CLI->>RO: _read_only_app()
RO->>FOCA: create_foca()
FOCA-->>RO: validated config
RO->>Mongo: register_mongodb(mongo_config)
Mongo->>DB: register collections without indexes
Mongo-->>RO: Flask app
CLI->>Migration: namespace_subjects(namespace, dry_run=True)
Migration->>DB: read stored subjects and rules
DB-->>Migration: counts
Migration-->>CLI: exit 0
Sequence diagram for the namespace-subject migration startup pathsequenceDiagram
participant CLI as namespace_subjects CLI
participant App as create_app
participant FOCA as create_foca
participant DB as MongoDB
participant Migration as namespace_subjects
CLI->>App: create_app()
App->>FOCA: create_foca()
FOCA-->>App: validated config
App->>DB: create configured indexes and replace rules
App-->>CLI: started app
CLI->>Migration: namespace_subjects(namespace, dry_run=False)
Migration->>DB: read and update namespace subjects
DB-->>Migration: migration result
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Linked issues
#339 fix: make namespace dry runs read-only · 3 of 3 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | With --dry-run, read the config and stored data without FOCA's app setup or the app's startup tasks. | ✅ Met | Dry runs use _read_only_app(), which loads the config and registers collections without indexes instead of calling create_app(). |
| 2 | Add a regression test showing that a dry run on 1.0.0rc1 data preserves indexes and rules and still counts subjects. | ✅ Met | The test sets up older-style indexes and a configured rule, asserts the dry-run count, and compares database indexes and documents before and after. |
| 3 | Say in the command documentation that dry runs are read-only. | ✅ Met | The module documentation and --dry-run help say it makes no database changes; the upgrade guide explains its limitations. |
Sourcery assessment
Approved.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #343 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 2406 2426 +20
=========================================
+ Hits 2406 2426 +20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #339
Summary
Finding L3 of the 1.0.0rc2 pre-release review:
python -m cloud_registry.namespace_subjects <namespace> --dry-runcalledcreate_app(), which creates the configured indexes, replaces the configured rules and changes the TTL index of invitations. Run with a newer image against a database that an older version still uses, the dry run left pods of that version unable to restart, and owners on them could get403 Forbidden.A dry run now reads the config (
create_foca(), split fromcreate_app()) and registers the collections with FOCA'sregister_mongodb(), without their indexes, and with the collection of the stored rules. It needs no write access at all.The docs say what a dry run no longer predicts.
Verification
test_main_dry_run_read_onlyfailed first. It sets up the indexes and rules of 1.0.0rc1, and compares all indexes and documents before and after the dry run.tests/test_namespace_subjects.pyandtests/test_issuers.pyon both (32 passed each),namespace_subjects.pyat 100%; CI runs the full suite.pre-commit run --all-filesandmkdocs build --strict: pass.--auth, as a user with only thereadrole: exit 0 with correct counts. The same user fails on index creation without--dry-run.Declined review findings
--helpand the upgrade guide instead of computing them fromsecurity.access_control.policies, as the migration leaves configured rules alone and only warns about them.create_foca()(low, quality): covered by every test that creates the app.🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Summary by Sourcery
Make namespace migration dry runs safely inspect stored data without performing application startup changes.
Bug Fixes:
Enhancements:
Documentation:
Tests: