Repository navigation
feat: invite users to services by link - #274
Conversation
Owners (and admins) create an invitation to a service for a role
(POST /services/{serviceId}/invitations), which returns a one-time
token; the invited user accepts it (POST /invitations/accept), which
grants the role to their own identifier, as PUT .../permissions/{userId}
would. Owners list the invitations with who accepted them, and revoke
open ones (GET, DELETE).
- Collection `invitations` with the SHA-256 hash of the token only,
expiry (default 7 days, `custom.access_control.invitations
.expiry_days`), TTL index, and acceptance (user, name, email if
released, time).
- Accepting claims the invitation atomically (single use), and
releases it if the role can't be granted (e.g., last owner).
- At most 20 open invitations per service by default
(`max_open_per_service`, `null` for no limit; 409
`invitations-limit`); accepted ones: 409 `invitation-accepted`.
- Invitations are deleted with the roles of a service and move with
them on renames.
- Policies for the new paths; maintainers and other users get 403.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the "Invitations" section to the access control docs: links with the token in the fragment, single use, expiry, listing and revoking, the limit per service, storage, the risk of forwarded links, and the options; link it from "Roles on services". Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review findings on the invitations: - Invitations store how their creator was allowed to create them (admin, owner, or member of an owner group) and are deleted instead of accepted once that owner role is gone, so that removed owners can't regain the role with their own invitations. - The limit counts all invitations until they expire, also accepted ones, so that owners can't grow the collection by accepting their own invitations (`max_open_per_service` -> `max_per_service`). - Users whose roles the permissions API couldn't revoke (`groups/...`, leading slash, dot segments) can't accept invitations (400). - Names and email addresses in accepted invitations are removed with the user's roles on the service. - Docs: configuration and upgrade notes, accept description; smaller cleanups (shared filters, return type, role read once). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Second review round: - Check the creator of an invitation while the service is locked (`put_role(check=...)`), so that a rename, which moves the roles before the invitations, can't make a valid invitation look orphaned and get it deleted; the acceptance fails and releases it instead. - Creators who were owners through a group and left it can't accept their own invitations (their token shows their groups); others can, while the group is owner. - Docs: how to find the invitations of a removed admin. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideIntroduces secure, link-based service invitations with one-time atomic acceptance, configurable expiry and limits, creator-authority safeguards, lifecycle-aware storage, new policies and API documentation, and extensive concurrency and integration tests. Sequence diagram for link-based service invitation acceptancesequenceDiagram
actor Owner
actor User
participant API
participant Invitations
participant Permissions
Owner->>API: postServiceInvitation
API->>Invitations: insert_one token_hash
Invitations-->>API: invitation and token
API-->>Owner: 201 InvitationCreated with token
Owner->>User: Send invitation link
User->>API: acceptInvitation with token
API->>Invitations: find_one_and_update open unexpired invitation
Invitations-->>API: atomically claimed invitation
API->>Permissions: put_role(service_id, user_id, user, role, check)
Permissions-->>API: role granted
API->>Permissions: remember_current_user
API-->>User: 200 ServiceRole
State diagram for invitation lifecyclestateDiagram-v2
[*] --> Open: postServiceInvitation
Open --> Accepted: acceptInvitation
Open --> Revoked: deleteServiceInvitation
Open --> Expired: expires_at reached
Accepted --> Expired: expires_at reached
Open --> Deleted: service deleted or creator loses authority
Accepted --> Deleted: service deleted
Revoked --> [*]
Expired --> [*]
Deleted --> [*]
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 #274 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 20 21 +1
Lines 2008 2179 +171
==========================================
+ Hits 2008 2179 +171 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cloud_registry/ga4gh/registry/permissions.py" line_range="601-604" />
<code_context>
_forget_names(serviceId, subject)
+ # the user's name and email address in the invitations they
+ # accepted, as names are deleted with the role
+ get_collection(INVITATIONS).update_many(
+ {"service_id": serviceId, "accepted.user_id": subject},
+ {"$unset": {"accepted.name": "", "accepted.email": ""}},
+ )
</code_context>
<issue_to_address>
**Revoked users’ details remain visible**
When the worker crashes or the invitation update fails after role revocation, `_delete_roles`/`revoke_roles` removes the role before the invitation update clears accepted names and email addresses. The details remain visible, and a retry can return not found without retrying the cleanup.
Make the accepted-detail cleanup reliably retryable after role revocation.
</issue_to_address>
### Comment 2
<location path="cloud_registry/ga4gh/registry/invitations.py" line_range="335" />
<code_context>
+ "expires_at": created_at + timedelta(days=expiry_days),
+ }
+ collection = get_collection(INVITATIONS)
+ collection.insert_one(document)
+ # the service may have been deleted (with its invitations) meanwhile
+ if not service_exists(serviceId):
</code_context>
<issue_to_address>
**Revoked owners create unusable invitations**
When the creator loses their owner role after `_created_as` returns but before the invitation is inserted, `postServiceInvitation` inserts the invitation after `_created_as` checks the creator's owner role, without holding the service lock. If that role is revoked before insertion, creation still returns a token, but acceptance finds the creator is no longer an owner, deletes the invitation, and returns `404`.
Perform the owner check and insertion while holding the service lock, or recheck under that lock before returning the created invitation.
</issue_to_address>
### Comment 3
<location path="cloud_registry/ga4gh/registry/invitations.py" line_range="300" />
<code_context>
+ Returns:
+ The invitation (cf. `_serve()`), with its token (`token`), only
+ returned here; with status `201`. Or an error response: `409` if the
+ service has as many open invitations as allowed.
+
+ Raises:
</code_context>
<issue_to_address>
**Limit description excludes accepted invitations**
When the service has accepted but unexpired invitations, `postServiceInvitation`'s docstring describes the limit as counting open invitations, but `_check_limit` counts every unexpired invitation, including accepted ones. Maintainers relying on this controller contract will misread why creation returns `409`.
Describe the limit in the docstring as applying to all unexpired invitations, open or accepted.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and anyone who obtains an invitation token can accept it and gain the selected service role, including owner access; a leaked or misdirected link can therefore expose service data or control. Reverting removes the invitation flow but does not undo granted roles or access that already occurred, so affected roles must be revoked explicitly.
Blocking findings: cloud_registry/ga4gh/registry/permissions.py:604, cloud_registry/ga4gh/registry/invitations.py:335
Recheck the creator after storing an invitation and delete it if the role was revoked meanwhile. Serve the name and email address of users who accepted an invitation only while they have a role on the service. Describe the invitation limit precisely. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # cloud_registry/ga4gh/registry/permissions.py
Summary
Owners can invite users to their services by link without knowing their
sub. An owner creates an invitation for a role and sends the link through any channel. The colleague logs in and accepts it, which grants the role to their own identifier. No email addresses are involved. This follows the design in the issue, as decided in the 2026-10-20 review: point 7 B for invitations and point 9 for display names.Closes #101
Merge only after the v0.6.0 tag. This is part of v1.0.0-rc1, and the upgrade notes go into a new "From 0.6.0" section.
What changes
Endpoints (additions spec, tag
cloud-registry). Owners and admins can use these:POST /services/{serviceId}/invitationswith{"role": "owner" | "maintainer"}. It returns201with the invitation and its one-timetoken. This is the only response that contains the token.GET /services/{serviceId}/invitationslists the open and accepted invitations that haven't expired, without tokens. Accepted ones includeaccepted:user_id, plusnameandemailif the identity provider releases them, andaccepted_at.DELETE /services/{serviceId}/invitations/{invitationId}revokes an open invitation. Accepted ones return409with codeinvitation-accepted; revoke the role instead.Any authenticated user can call
POST /invitations/acceptwith{"token": ...}. The token is in the body so that it stays out of access logs. Accepting grants the role likePUT .../permissions/{userId}and replaces any other role the user has on the service. It also stores the user's display name for the service.Storage. A new collection,
invitations, holds only the SHA-256 hash of each token (secrets.token_urlsafe(32)), never the token itself. Each invitation has an expiry, by default 7 days (custom.access_control.invitations.expiry_days), and a TTL index onexpires_at; reads skip expired invitations until MongoDB deletes them.Single use. Accepting claims the invitation atomically with
find_one_and_updateon an open, unexpired invitation. If the role can't be granted (e.g.last-owner, the service being renamed, or the service deleted), the claim is released.Service lifecycle. Invitations are deleted with the roles on their service, i.e. when the service is deleted or stale roles are cleared, and they move with the roles when the service is renamed, including resumed renames.
Policies in
config.yaml:owners-manage-invitations(GET, POST),owners-revoke-invitations(DELETE) andaccept-invitations(*). Maintainers and other users get403.Docs:
access-control.mdhas a new "Invitations" section: links with the token in the URL fragment, single use, expiry, creators, identifiers, listing and revoking, the limit, storage, the forwarding risk, and the options.api.mdlists the endpoints and the conflict codes.configuration.mddescribes the options.upgrading.mdhas a new "From 0.6.0" section: a new collection and indexes, and three new policy rules that overlays which list the policies must add.Beyond the issue (from the reviews)
404. Without this, removed owners could regain the role with invitations they had created earlier.custom.access_control.invitations.max_per_serviceinvitations that haven't expired, open or accepted. The default is 20;nullmeans no limit. Above the limit, creating returns409with codeinvitations-limit. Accepted invitations count so that owners can't grow the collection by accepting their own invitations.400). These are identifiers that aregroups, start withgroups/or a slash, or contain./..segments.put_role()inpermissions.pynow takes the role as an argument, plus an optionalcheckthat runs inside the lock. The helpersrequire_subject()andget_current_claims()are now public.Verification
200, seven409). Coverage: 100%.pre-commit run --all-files(ruff, mypy, semgrep, ast-grep, gitleaks, actionlint): passed.mkdocs build --strict: passed.CI passedand Sourcery.Declined review findings
PUT .../permissions. Each invitation gives exactly one try, and owners see who accepted and can revoke the role.Args/Attributesin the new config model's docstring: this is the repo's convention.Notes
maintainerinvitation is downgraded, unless they are the last owner (409).to-post.mdas D-10, to be posted once feat: invite users to services by link #101 is in the backend.🤖 Generated with Claude Code
Summary by Sourcery
Enable secure, configurable link-based invitations for granting service roles to authenticated users.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: