Repository navigation
fix: address rc1 pre-release review findings - #292
Conversation
Deployments that stopped owners from granting roles by removing or restricting owners-change-permissions inherit the new invitation rules, with which owners grant roles again. Warn on startup if owners may create invitations while no rule lets them grant roles to users. Part of #290. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The migration to namespaced subjects left the creators and acceptors of invitations bare, so open invitations of owners were deleted on acceptance. Rewrite created_by, created_as.user and accepted.user_id, only where bare and unchanged since read. Part of #290. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Users may be able to set unverified email addresses to any value, e.g. that of the invited user. Store the email address of an acceptance only if the claim email_verified is true; the user identifier is the only reliable identification. Part of #290. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Very large expiry_days overflowed the expiry times, so that every invitation creation failed with 500. Allow at most 3650 days. Part of #290. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Recipe and upgrade note for the rules of invitations, invitations in the namespace migration, admin-registered services and the limit, leaving members of owner groups, verified emails, the expiry maximum, reference entries of the newer modules and the audit log lines. Part of #290. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Count only invitations that the migration rewrote (those changed meanwhile are left for another run), read the email claim only if verified, comment the order of the startup warnings, and rewrap docs. Part of #290. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Part of #290. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideAddresses the v1.0.0rc1 review findings by closing an invitation-based owner privilege-escalation path, safely migrating invitation subjects, restricting invitation expiry, protecting unverified email data, and updating the related upgrade, operational, API, and reference documentation with comprehensive tests. Sequence diagram for invitation-based role grant warningsequenceDiagram
participant App
participant Permissions as Permissions
participant Config as ConfiguredPolicies
participant Logger
App->>Permissions: warn_owner_rules()
Permissions->>Config: _owner_rules(policies, invitations, POST)
Permissions->>Config: _owner_rules(policies, user_permissions, PUT)
alt owners can create invitations and cannot grant user roles
Permissions->>Logger: warning(...)
end
Sequence diagram for safe invitation subject migrationsequenceDiagram
participant Migration as namespace_subjects
participant Invitations as MongoDBInvitations
Migration->>Invitations: find(bare invitation subjects)
loop each invitation with bare user fields
Migration->>Invitations: update_one(_id and unchanged fields)
alt values still match
Invitations-->>Migration: matched_count = 1
else invitation changed meanwhile
Invitations-->>Migration: matched_count = 0
end
end
Migration-->>Migration: return invitations count
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #292 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 2321 2356 +35
=========================================
+ Hits 2321 2356 +35 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cloud_registry/namespace_subjects.py" line_range="378" />
<code_context>
"service_types": _namespace_service_types(namespace, dry_run),
"services": _namespace_services(namespace, dry_run),
"user_names": _namespace_user_names(namespace, dry_run),
+ "invitations": _namespace_invitations(namespace, dry_run),
}
if configured:
</code_context>
<issue_to_address>
**Open invitations are deleted during migration**
When the migration runs while an invitation is being accepted after its creator’s role has been namespaced but before its invitation metadata is rewritten, `namespace_subjects()` rewrites stored role rules before it reaches invitations. An acceptance during that gap compares the invitation’s still-bare `created_as.user` with the now-namespaced owner roles, fails `_creator_may_grant()`, and deletes the invitation; the invited user gets a not-found response and the invitation cannot be used again.
Quiesce invitation acceptance for the migration window, or coordinate the migration and acceptance flow so the creator metadata and role rules cannot be observed in mismatched namespaces.
</issue_to_address>
### Comment 2
<location path="cloud_registry/namespace_subjects.py" line_range="328-336" />
<code_context>
+ # only while the values are as read, so that an acceptance released
+ # meanwhile isn't recreated without its time; such invitations are
+ # not counted, and rewritten by another run
+ result = collection.update_one(
+ {"_id": invitation["_id"], **bare},
+ {
+ "$set": {
+ field: _namespaced(namespace, value)
+ for field, value in bare.items()
+ }
+ },
+ )
+ count += result.matched_count
+ return count
</code_context>
<issue_to_address>
**Failed acceptance remains claimed**
When the migration runs while an acceptance is in flight, and that acceptance fails after the migration rewrites its claimed user ID, `_namespace_invitations` can rewrite `accepted.user_id` after an acceptance request claims an invitation but before that request fails. The request's cleanup in `acceptInvitation` then filters on the old user ID and cannot unset `accepted`, leaving an invitation marked accepted although its role was not granted.
Coordinate the migration with in-flight acceptances, or make acceptance cleanup robust to the subject being namespaced during the request.
</issue_to_address>
### Comment 3
<location path="cloud_registry/ga4gh/registry/invitations.py" line_range="454-455" />
<code_context>
acceptance: dict[str, Any] = {"user_id": user_id, "accepted_at": now()}
- for claim in ("name", "email"):
+ claim_names = ["name"]
+ if claims.get("email_verified") is True:
+ claim_names.append("email")
+ for claim in claim_names:
value = claims.get(claim)
</code_context>
<issue_to_address>
**Old unverified emails remain visible**
When accepted invitations created before this change contain an email captured without a verified-email check, `_acceptance()` prevents new unverified emails from being written, but `_serve()` still returns `accepted.email` from existing invitation documents without verification metadata. Owners therefore continue to see potentially spoofed addresses for those acceptances.
Remove historical acceptance emails that cannot be proven verified, or store verification provenance and filter served emails accordingly.
</issue_to_address>
### Comment 4
<location path="cloud_registry/ga4gh/registry/permissions.py" line_range="766-767" />
<code_context>
+ {str(rule) for rule in _owner_rules(policies, f"{service}/invitations", "POST")}
+ )
+ if not inviting or any(
+ _owner_rules(policies, f"{service}/permissions/{user}", "PUT")
+ for user in EXAMPLE_USERS
+ ):
+ return
</code_context>
<issue_to_address>
**Specific role rule suppresses warning**
When configured rules allow POST to invitations and PUT only for one of the example user identifiers, `any(...)` returns true when a PUT rule matches just one example user, so `_warn_invitation_rules` skips the warning even though owners can still grant roles to arbitrary invitees through POST. Deployments relying on the startup warning to identify that broader grant path get no warning.
Warn unless the configured PUT rules cover the general user-role path, rather than merely matching one example identifier.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 4 findings to address first, and the migration rewrites invitation creator and accepter identifiers that are later used to check who may accept an invitation and who received its role. If it maps an identifier incorrectly, invitation acceptance or role attribution can be wrong; reverting the code does not restore the stored identifiers, though the affected records can be repaired.
Blocking findings: cloud_registry/namespace_subjects.py:378, cloud_registry/namespace_subjects.py:336, cloud_registry/ga4gh/registry/invitations.py:455, cloud_registry/ga4gh/registry/permissions.py:767
Accepting invitations while the namespace migration runs can delete them or leave them claimed; extend the maintenance window to cover acceptances. Part of #290. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Addresses the pre-release review findings for v1.0.0rc1 (one medium, five lows; the release prep itself follows in a separate PR).
warn_owner_rules()now also warns when configured rules let owners (or*) create invitations (POST .../invitations) while no rule lets them grant roles to users (PUT .../permissions/<user>for any of the example users). It is a semantic check on the effective rules, so it covers named and list overlays alike. A restriction ofowners-change-group-permissionsalone doesn't trigger it, since invitations grant only users' roles, and neither does the 0.5.0-style:userrule (owners may still grant users' roles there). The recipe in access-control.md now nullsowners-manage-invitationsandowners-revoke-invitationsas well, and upgrading.md "From 0.6.0" has a note. A test runs the recipe end to end: both grant paths return 403._namespace_invitations()rewrites barecreated_by,created_as.userandaccepted.user_id, but nevercreated_as.group. The update is guarded on the values as read, so an acceptance released in the meantime isn't recreated without its time. Only rewritten invitations are counted; the new count isinvitations. Docstring, tests and upgrading.md "Several token issuers" are updated._createdBy: null, then restart). I checked thatadd_service_creators()keeps null ($exists) andreconcile_service_counts()ignores it ($type: string).created_by).accepted.emailis stored only ifemail_verifiedistrue(a JSON boolean, as in OIDC Core). The spec and docs now say thatuser_idis the only reliable identifier. The UI (ai-post-deploy, 6707e0b) doesn't use invitations at all (a grep ofsrcfinds no use ofacceptedor invitations), so it is unaffected.expiry_days(low 6): now 1..3650 (MAX_EXPIRY_DAYS). It is documented and tested.service_types,rename,locks,invitationsandservice_limits; operations.md "Audit logs" now covers the invitation and limit log lines, and how roles granted by invitation appear in FOCA's log.Not in this PR:
Closes #290
Verification
Locally (Python 3.13,
uv sync --frozen --extra dev --extra docs):coverage run --source cloud_registry,scripts -m pytest: 1538 passed, 262 skipped, coverage 100%.pytestagainst MongoDB 7.0, in my own container on port 27091, removed afterwards: 1544 passed, 255 skipped. This ran before the last review-fix commit; the namespace tests pass on the final commit, and the full suite passed with mongomock.pre-commit run --all-files: passed (ruff, mypy, semgrep, ast-grep, gitleaks, actionlint).mkdocs build --strict: passed.Declined review findings
_createdBy: nullupgrade block is unrelated to fix: address rc1 pre-release review findings #290". It is low finding 2 of the review, listed in fix: address rc1 pre-release review findings #290. The behaviour it relies on was verified, as described above.created_bybut bare inaccepted.user_id, one with noaccepted, an admin one and a group one, and a new test covers an invitation changed meanwhile."true"foremail_verified. OIDC Core defines it as a boolean. Being strict fails safe: no email is shown, nothing unverified is shown. The docs sayemail_verified: true.:userrule.Open questions
None.
🤖 Generated with Claude Code