Skip to content

fix: address rc1 pre-release review findings - #292

Merged
uniqueg merged 8 commits into
devfrom
fix/290-rc1-review
Oct 29, 2026
Merged

uniqueg merged 8 commits into
devfrom
fix/290-rc1-review

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Addresses the pre-release review findings for v1.0.0rc1 (one medium, five lows; the release prep itself follows in a separate PR).

  • Invitations re-open owner role-granting (medium): 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 of owners-change-group-permissions alone doesn't trigger it, since invitations grant only users' roles, and neither does the 0.5.0-style :user rule (owners may still grant users' roles there). The recipe in access-control.md now nulls owners-manage-invitations and owners-revoke-invitations as 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 migration skipped invitations (low 1): new idempotent _namespace_invitations() rewrites bare created_by, created_as.user and accepted.user_id, but never created_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 is invitations. Docstring, tests and upgrading.md "Several token issuers" are updated.
  • Backfill counts admin-registered services against the admin (low 2), documented rather than changed: whether a user is an admin can't be determined reliably at startup. In admin mode (the default), only groups are admins, through the group claims of their tokens, which aren't stored, so the backfill can't tell an admin owner from any other owner. upgrading.md now explains this and gives the reset query (_createdBy: null, then restart). I checked that add_service_creators() keeps null ($exists) and reconcile_service_counts() ignores it ($type: string).
  • Leaving members of owner groups (low 4): access-control.md now says to revoke the open invitations a leaving member created (listed by created_by).
  • Unverified email (low 5): accepted.email is stored only if email_verified is true (a JSON boolean, as in OIDC Core). The spec and docs now say that user_id is the only reliable identifier. The UI (ai-post-deploy, 6707e0b) doesn't use invitations at all (a grep of src finds no use of accepted or invitations), so it is unaffected.
  • Unbounded expiry_days (low 6): now 1..3650 (MAX_EXPIRY_DAYS). It is documented and tested.
  • Docs (low 7): reference.md entries for service_types, rename, locks, invitations and service_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%.
  • pytest against 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.
  • Not run locally: Helm chart tests (no Helm) and the Docker smoke test; CI runs them.
  • CI on the pushed head: all checks passed (Lint, Test with mongomock and MongoDB 7.0, Chart, Docs, Smoke test, Scan image, Release readiness, CodeQL, CI passed).

Declined review findings

  • Quality (medium): "the _createdBy: null upgrade 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.
  • Quality (low): more shapes in the migration tests. The fixture already has one invitation namespaced in created_by but bare in accepted.user_id, one with no accepted, an admin one and a group one, and a new test covers an invitation changed meanwhile.
  • Adversarial (low): accept the string "true" for email_verified. OIDC Core defines it as a boolean. Being strict fails safe: no email is shown, nothing unverified is shown. The docs say email_verified: true.
  • Sourcery (medium): old unverified emails remain visible. There are none: invitations are unreleased, and acceptances from dev images expire within the expiry time.
  • Sourcery (medium): a PUT rule that covers only one example user suppresses the warning. This is deliberate: owners who may grant users' roles directly gain nothing material by invitation, and requiring all example users would warn on the documented :user rule.
  • Sourcery (2x medium): migration concurrent with acceptances. Addressed in the docs instead: the maintenance window of the migration now covers accepting invitations (23d2c59).

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 7 commits October 29, 2026 06:16
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]>
@sourcery-ai

sourcery-ai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Addresses 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 warning

sequenceDiagram
    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
Loading

Sequence diagram for safe invitation subject migration

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Prevent invitation-based privilege escalation when owner role-granting is disabled.
  • Added startup detection for owner or wildcard rules that allow invitation creation without direct user-role grants.
  • Refined the rule evaluation to cover named and list overlays and distinguish user-role grants from group-permission grants.
  • Updated the documented policy-removal recipe and added end-to-end warning and authorization tests.
cloud_registry/app.py
cloud_registry/ga4gh/registry/permissions.py
docs/access-control.md
docs/upgrading.md
tests/test_access_control.py
Make invitation identity data safer and clarify its reliability.
  • Store accepted email addresses only when the identity provider supplies the boolean claim email_verified: true.
  • Document that user_id is the only reliable accepted-user identifier, while names and emails are display data.
  • Expanded API, access-control, and invitation tests for verified and unverified claims.
cloud_registry/api/additions.openapi.yaml
cloud_registry/ga4gh/registry/invitations.py
docs/access-control.md
tests/test_invitations.py
Extend namespace migration to invitation subjects without losing concurrent updates.
  • Added an idempotent migration for bare invitation creators, creator users, and accepted users, while preserving group subjects.
  • Used value-guarded updates so invitations changed or removed during migration are not incorrectly counted or recreated.
  • Included invitation counts, dry-run behavior, documentation, and concurrency-focused tests.
cloud_registry/namespace_subjects.py
docs/upgrading.md
tests/test_namespace_subjects.py
Bound invitation expiry configuration to prevent timestamp overflow.
  • Introduced MAX_EXPIRY_DAYS of 3650 and enforced the upper bound in the configuration model.
  • Documented the limit and tested boundary and invalid values.
cloud_registry/service_models/custom_config.py
docs/configuration.md
tests/service_models/test_custom_config.py
Document service behavior, operational logging, and migration implications identified during pre-release review.
  • Documented admin-registered service backfill limitations and the reset query for _createdBy.
  • Added guidance for revoking invitations created by departing owner-group members.
  • Added reference entries and described invitation, service-limit, and counter-correction log events.
docs/access-control.md
docs/operations.md
docs/reference.md
docs/upgrading.md

Assessment against linked issues

Issue Objective Addressed Explanation
#290 Prevent upgrades from re-enabling owners’ ability to grant user roles through invitations, including updating the access-control recipe, upgrade guidance, and startup warning. ✅
#290 Correct invitation and service-creator data handling: namespace bare invitation subjects during migration, avoid attributing admin-mode backfill services to admins through documented reset guidance, revoke/document invitations created by departing owner-group members, and store accepted email only when verified. ✅
#290 Bound invitation expiry to 1–3650 days and complete the related documentation, including missing reference entries and invitation/limit audit-log guidance. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (06b2cdc) to head (23d2c59).
⚠️ Report is 1 commits behind head on dev.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 29, 2026 05:45

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread cloud_registry/namespace_subjects.py Resolved
Comment thread cloud_registry/namespace_subjects.py Resolved
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]>
@uniqueg
uniqueg merged commit 58b4951 into dev Oct 29, 2026
17 checks passed
@uniqueg
uniqueg deleted the fix/290-rc1-review branch October 29, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: address rc1 pre-release review findings

1 participant