Repository navigation
feat: approve service types in moderated mode - #244
Conversation
New mode moderated for custom.access_control.service_types: any
authenticated user may add types, but the types of users other than
admins are stored as pending until an admin approves them (PUT
/services/types/approval); admins' types are approved at once. There is
no way back; admins remove types instead.
Services with a pending type are pending too (derived from the type, so
approving the type approves them). Pending types and services are only
visible to admins and their creators (for services: users with a role
on them): GET /services, GET /services/{serviceId} and GET
/services/types hide them from others, and GET /approvals lists those
the user may see. Only admins may update pending services (409); owners
may delete them. GET /me tells whether the user's new types are pending
(service_types_pending).
Closes #238
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Hide verifications of pending services like the services. Store new types as pending before the service, so that it is never served as approved. Let users update pending services to an approved type, e.g., to undo a change of the type. Restore removed types as they were, also if a registration stored them as pending meanwhile. Add tests and docs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Say in the conflict detail, docstrings, API description and docs that pending services can be updated to an approved type, that pending types are stored first, and that admins don't approve types by using them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideIntroduces a moderated service-type mode in which non-admin registrations create pending types and derived pending services, adds authenticated approval workflows, consistently filters pending resources by caller visibility, and updates permissions, documentation, API definitions, CI, and tests. Sequence diagram for moderated service registration and approvalsequenceDiagram
actor User
actor Admin
participant API
participant Types
participant Services
User->>API: POST /services
API->>Types: store_pending_type
Types-->>API: pending type stored
API->>Services: register service
Services-->>API: service stored
API-->>User: 201 Created
User->>API: GET /approvals
API->>Types: getApprovals
Types-->>API: pending types and visible services
API-->>User: 200 Approvals
Admin->>API: PUT /services/types/approval
API->>Types: putServiceTypeApproval
Types-->>API: remove pending marker
API-->>Admin: 200 Approved type
User->>API: GET /services
API->>Types: visible_services
Types-->>API: approved services including newly approved type
API-->>User: 200 Services
Sequence diagram for pending-resource visibility and update protectionsequenceDiagram
actor User
participant API
participant Registry
User->>API: GET /services/{serviceId}
API->>Registry: visible_services
alt user has a role on pending service
Registry-->>API: service visible
API-->>User: 200 Service
else public or unauthorized read
Registry-->>API: service filtered
API-->>User: 404 Not Found
end
User->>API: PUT /services/{serviceId}
API->>Registry: _is_pending
alt pending service and new type is not approved
Registry-->>API: PendingService
API-->>User: 409 Conflict
else approved type
Registry-->>API: update service
API-->>User: 200 Service
end
File-Level Changes
Assessment against 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 #244 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 17 17
Lines 1502 1603 +101
==========================================
+ Hits 1502 1603 +101 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 5 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="275" />
<code_context>
+ approves them.
+ """
+ mode = get_custom_config().access_control.service_types
+ return mode == "moderated" and not is_admin()
</code_context>
<issue_to_address>
**Services bypass moderated approval**
When a moderated rollout still sends registrations to old workers, old workers skip `service_types_pending()` and store types without the pending flag, so services become visible without admin approval and the types are absent from the approvals list.
Stop sending registrations to old workers until they have been upgraded to apply moderated-mode handling.
Also at `cloud_registry/ga4gh/registry/service_types.py:230`.
</issue_to_address>
### Comment 2
<location path="cloud_registry/ga4gh/registry/service_types.py" line_range="295" />
<code_context>
+ """
+ pending = pending_services()
+ if pending is None:
+ return {}
+ own = resource_filter(services_path())
+ if not own:
</code_context>
<issue_to_address>
**Pending services briefly become public**
When a public read checks for pending types just before a moderated registration stores its pending type, then queries services after that registration inserts the service, `visible_services()` returns an unrestricted filter when its initial `pending_services()` query finds no pending type. A concurrent registration can then store the type as pending and insert its service before the caller queries services, so public service and verification reads return that pending service to unauthenticated callers.
Avoid treating an empty pending-type lookup as a durable all-visible decision across a later service query, for example by rechecking pending types or using a consistency strategy that prevents this interleaving from exposing the new service.
</issue_to_address>
### Comment 3
<location path="cloud_registry/ga4gh/registry/server.py" line_range="273" />
<code_context>
+ return problem(exc)
try:
check_service_type(service.data.get("type"))
+ store_pending_type(service.data.get("type"))
service.register_metadata()
except InvalidService as exc:
</code_context>
<issue_to_address>
**Pending services become publicly visible**
When a type-removal request deletes a pending type between registration's pre-insert pending-type write and its post-insert type write, `visible_services()` sees no pending type while registration inserts the service, so public reads expose it; a process stop in that gap also lets startup backfill the type as approved.
Keep the type marked pending throughout registration and removal so it cannot be absent while the service is inserted.
Also at `cloud_registry/ga4gh/registry/server.py:302`.
</issue_to_address>
### Comment 4
<location path="cloud_registry/ga4gh/registry/server.py" line_range="262" />
<code_context>
+ and _is_pending(service_id)
+ # updates to an approved type end the review, e.g., to undo a change
+ # of the type
+ and not is_approved(type_document(service.data.get("type")))
+ ):
+ exc = PendingService()
</code_context>
<issue_to_address>
**Malformed type crashes pending update**
When a non-admin updates a pending service with a type containing an invalid Unicode surrogate, `type_document()` preserves an invalid surrogate in the submitted type, and `is_approved()` queries MongoDB with that value before `check_service_type()` can validate it. PyMongo rejects the query value, so updating a pending service with malformed type strings fails with an internal error instead of the normal `400` response.
Validate the submitted type’s strings before querying whether it is approved, and return the normal invalid-service response for invalid input.
</issue_to_address>
### Comment 5
<location path="cloud_registry/ga4gh/registry/service_types.py" line_range="245" />
<code_context>
+ fields = {CREATED_BY: removed.get(CREATED_BY)}
+ pending = removed.get(PENDING) is True
+ update: dict[str, Any] = (
+ {"$set": {**fields, PENDING: True}}
+ if pending
+ else {"$set": fields, "$unset": {PENDING: ""}}
</code_context>
<issue_to_address>
**Approved types become pending again**
When a pending type is removed, re-added and approved while its delete request is still in progress, and the delete handler then finds a service, `_restore_type()` overwrites the concurrently approved row with the removed snapshot, undoing the approval; the delete returns `409` and services remain hidden until an admin approves the type again.
Restore the removed snapshot only when the current row has not been approved since it was recreated.
Also at `cloud_registry/ga4gh/registry/service_types.py:249-250`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 5 findings to address first, and if the pending-record visibility filter or admin-only approval check is wrong, users could see service metadata and verification details that were meant to stay restricted, or approve types without authorization. Reverting the code would not retract information already exposed or undo approvals that already changed stored state.
Blocking findings: cloud_registry/ga4gh/registry/permissions.py:275, cloud_registry/ga4gh/registry/service_types.py:295, cloud_registry/ga4gh/registry/server.py:273, cloud_registry/ga4gh/registry/server.py:262, cloud_registry/ga4gh/registry/service_types.py:245
Updates of pending services checked whether their type is approved before its strings were validated, so strings that MongoDB can't store (e.g., lone surrogates) failed with 500; they now get 400. Note that deployments switch to moderated only once all instances support it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
This adds a third mode for
custom.access_control.service_types:moderated. It follows the verification pattern.GET /services,GET /services/{serviceId}(404),GET /services/typesand the verification reads hide pending items from everyone except admins and their creators. For services, creators means users with a role on them, also through groups.409s don't name a pending service to users who can't see it.GET /approvals(login required) lists the pendingservice_typesandservicesthe caller may see.PUT /services/types/approval(admins only, no policy for others) approves a type. Approving an approved type is a no-op. There is no unapprove; admins remove types instead.409). The one exception is an update to an approved type, so that a change of type can be undone.GET /me: reportsservice_types_pending.DELETE /services/typesrestores a removed type exactly as it was, also if a registration stored it as pending in the meantime.api.md: new "Pending approvals" section; endpoint table.configuration.md,access-control.md,upgrading.md: list-style policy overlays must addlist-approvals.GET /approvalswithout login returns401.Closes #238
Decisions
GET /approvals, or in the reads when the deployment requires login for reads. No FOCA change is needed.PUT /services/types/approvaltakes the type in the body, likePOST /services/types.GET /approvalsfollowsGET /verifications.open.Verification
pre-commit run --all-files: all passed.pytest(mongomock): 1221 passed, 228 skipped (the Helm chart tests; Helm isn't installed locally). Coverage is 100%.pytestagainst MongoDB 7.0.34: all passed.mkdocs build --strict: passed.400instead of500for lone surrogates in updates of pending services); one documented (switch tomoderatedonly once all instances support it); three narrow races declined, with reasons given in the threads.Declined review findings
POST /services/typesdoesn't, and admins remove it like other unwanted types. This is documented.service_typescollection; theservicestype fields are indexed (feat: register and control service types #241).test_moderated_services; movinggetApprovalsto another module; a separate field to tell the two409s apart (quality, low): the tests read as one scenario, the module docstring covers the endpoints, anddetaildiffers.Open questions
None.
🤖 Generated with Claude Code