Repository navigation
feat: let admins verify services - #111
Conversation
Add admin-only PUT and DELETE /services/{serviceId}/verification and
public GET /services/{serviceId}/verification and GET /verifications.
The GA4GH endpoints are unchanged. The verification time is kept in a
hidden service field, which is reset in the same write when the
service's URL or API type changes (compare-and-swap with retries).
Closes #64
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Verifications now name what was verified, and are bound to it:
- PUT /services/{serviceId}/verification accepts an optional body with
the URL and API type the admin checked. The service is only verified
if it has exactly that URL (as written) and the same API type key,
checked in the update filter; otherwise 409, nothing changes.
- Replacing a service keeps its verification only if the stored URL is
unchanged as written and the key is unchanged, so other spellings
(e.g., an added query or fragment, which keys ignore) reset it. The
compare-and-swap filter includes the URL as read.
- Verification responses include the URL and API type of the service,
read from the same document, so that clients can match them against
GET /services.
The problem details helper of the server module is public now, to
build the 409 response.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
PUT /services/{serviceId}/verification verified services
unconditionally if the body wasn't parsed (e.g., form data, text, or
malformed JSON), as Connexion then passes no body. Such requests return
400 now; only an empty body or JSON null verify the service as
registered. Invalid URLs in the body return 400 with the reason, not
409.
Also:
- Move `problem()` to `cloud_registry.exceptions`, for both
controllers.
- Build the verification query step by step, returning errors early;
name filter variables `query`.
- Describe both meanings of `retries` of `register_metadata()`.
- Set `x-body-name` on the request body, as Connexion advises.
- List the reset rules of verifications in the README.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideIntroduces admin-managed service verification through dedicated endpoints, storing verification timestamps privately and exposing matched verification data publicly. Verification is protected with strict input validation and atomic URL/type checks, is safely reset during concurrent service identity changes, and is covered by OpenAPI updates, documentation, and extensive lifecycle, authorization, and concurrency tests. Sequence diagram for atomic admin service verificationsequenceDiagram
actor Admin
participant API
participant ServicesDB
Admin->>API: PUT /services/{serviceId}/verification
API->>ServicesDB: find_one_and_update(id, url, service_key)
alt Service matches checked URL and API type
ServicesDB-->>API: service with _verifiedAt
API-->>Admin: 200 Verification
else Service exists but identity differs
ServicesDB-->>API: no match
API-->>Admin: 409 Conflict
else Service is unknown
ServicesDB-->>API: no service
API-->>Admin: 404 Not Found
end
Sequence diagram for verified service discoverysequenceDiagram
participant Client
participant Registry
Client->>Registry: GET /services
Registry-->>Client: Registered services
Client->>Registry: GET /verifications
Registry-->>Client: Verified services sorted by service_id
Client->>Client: Keep matching service_id, url and type
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 #111 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 9 +1
Lines 492 573 +81
=========================================
+ Hits 492 573 +81 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 6 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cloud_registry/ga4gh/registry/service.py" line_range="22-25" />
<code_context>
# Internal field identifying a service by its normalized URL and API type
# (not version), with a unique index (cf. `config.yaml`); not served
KEY = "_serviceKey"
+# Internal field with the time an admin verified a service (cf.
+# `verification.py`); removed when its URL (as written) or key changes; not
+# served
+VERIFIED = "_verifiedAt"
# Projection excluding internal fields
-PROJECTION = {"_id": False, KEY: False}
</code_context>
<issue_to_address>
**Verification metadata leaks or disappears**
When an old application replica handles a read or replacement after a new version has stored a verification, the old projection exposes `_verifiedAt` in service responses, and the old whole-document replacement removes it, so callers see internal metadata or the service loses its verification.
Make verification metadata rollout-safe so old replicas neither expose it in service responses nor erase it during replacement, or prevent old replicas from handling these records.
Also at `cloud_registry/ga4gh/registry/service.py:27`, `cloud_registry/ga4gh/registry/service.py:329-340`.
</issue_to_address>
### Comment 2
<location path="cloud_registry/ga4gh/registry/verification.py" line_range="250" />
<code_context>
+ )
+ return [
+ {"service_id": service["id"], **_verification(service)} for service in services
+ ]
</code_context>
<issue_to_address>
**Recreated services inherit stale trust**
When a client fetches `/verifications`, then a service is deleted and recreated with the same identifier, URL, and type before the client fetches `/services`, `getVerifications` provides no service-incarnation value, so the documented identifier/URL/type match accepts the new, unverified record using the stale verification. Include an incarnation value in both reads and require it to match, or expose verification atomically with the service.
Include an incarnation value in both reads and require it to match, or expose verification atomically with the service.
Also at `README.md:243`.
</issue_to_address>
### Comment 3
<location path="cloud_registry/ga4gh/registry/verification.py" line_range="118-120" />
<code_context>
+ passes to controllers as no body.
+ """
+ # form data is consumed when it is parsed, so it isn't in the raw body
+ if request.form or request.files:
+ return True
+ data = request.get_data().strip()
+ return bool(data) and not (request.is_json and data == b"null")
+
</code_context>
<issue_to_address>
**Empty form bodies bypass rejection**
When a nonempty form body parses to empty `request.form` and `request.files`, `request.form` parsing consumes form data even when it produces no fields (for example, a body of `&`). `_has_unparsed_body()` then reads an empty stream and returns false, so `putServiceVerification()` verifies the service unconditionally instead of rejecting the non-JSON body; an admin's intended checked-URL precondition is skipped.
Determine whether the body is empty or JSON `null` before accessing the form parser, or otherwise preserve the original body-presence information.
</issue_to_address>
### Comment 4
<location path="cloud_registry/ga4gh/registry/service.py" line_range="346-349" />
<code_context>
OAuthProblem,
Unauthorized,
)
+from flask import Response
from werkzeug.exceptions import (
</code_context>
<issue_to_address>
**Concurrent service updates fail**
When another request inserts the same identifier first, or changes an existing service after `_replace()` reads it but before the conditional replacement, the upsert raises `DuplicateKeyError`; the handler calls `_check_duplicate()`, which excludes the same identifier, and then re-raises instead of retrying. The caller's registration or update fails with a 500.
Retry the replacement after re-reading the service when a duplicate-key error is caused by a concurrent write to the same identifier.
</issue_to_address>
### Comment 5
<location path="cloud_registry/ga4gh/registry/verification.py" line_range="196" />
<code_context>
+ )
+ service = get_collection("services").find_one_and_update(
+ query,
+ {"$set": {VERIFIED: _now()}},
+ projection=VERIFICATION_PROJECTION,
+ return_document=ReturnDocument.AFTER,
</code_context>
<issue_to_address>
**Renewal time moves backward**
When two admin PUTs overlap and the earlier request samples its time before a later request but reaches Mongo after it, `_now()` is sampled before the database write and stored unconditionally, so an earlier request that reaches Mongo after a later renewal overwrites its newer timestamp. Callers then see `verified_at` move backward and the newer check appear stale.
Set the timestamp at the atomic database write, or atomically retain the maximum timestamp.
</issue_to_address>
### Comment 6
<location path="tests/test_verification.py" line_range="244" />
<code_context>
+ first = verify(client).json["verified_at"]
+ second = verify(client)
+ assert second.status_code == 200
+ assert second.json["verified_at"] >= first
+ assert verified(client) == [service]
+
</code_context>
<issue_to_address>
**Renewal can go untested**
When the second PUT leaves the stored verification time unchanged, `test_verify_again` accepts an unchanged timestamp because `>=` is true when `second.json["verified_at"]` equals `first`; a PUT that never renews the verification therefore passes.
Control the clock so the second verification has a later millisecond, then assert that timestamp is returned and stored.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 6 findings to address first, and if an admin verifies the wrong URL or API type, clients may treat that public verification as a trust signal and send credentials or work to an endpoint that was not checked. Revoking the verification or reverting the change cannot undo anything already sent.
Blocking findings: cloud_registry/ga4gh/registry/service.py:25, cloud_registry/ga4gh/registry/verification.py:250, cloud_registry/ga4gh/registry/verification.py:120, cloud_registry/ga4gh/registry/service.py:349, cloud_registry/ga4gh/registry/verification.py:196, and 1 more
- Reject form bodies without fields (e.g., `&`) when verifying: they are consumed when parsed, so a body counts as sent if the request has a content length although its raw data is gone. - Read a service again and retry if replacing it fails with a duplicate key error not caused by another service with the same key (e.g., a concurrent upsert with the identifier), instead of failing with 500; real duplicates still return 409. - Never move the time of a verification back on renewals (`$max`), and serve the time stored. - Control the clock in the renewal tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Admins can mark registered services as verified (#64). The GA4GH Service Registry endpoints are unchanged; verification is served by additional endpoints only:
PUT /services/{serviceId}/verification(admin only): verifies the service, or renews the verification time. An optional body{"url": ..., "type": {...}}names what the admin checked: if the service no longer has exactly that URL and API type, nothing changes and the response is409 Conflict(checked atomically). Bodies that aren't empty,nullor a JSON object (e.g. form data, malformed JSON) and invalid URLs get400 Bad Request, so the check can't be skipped by accident. Returns{"url": ..., "type": {...}, "verified_at": ...}.DELETE /services/{serviceId}/verification(admin only): removes the verification.GET /services/{serviceId}/verification(public):{"url": ..., "type": {...}, "verified_at": ...}, or 404 if the service is unknown or not verified.GET /verifications(public): all verified services as[{"service_id": ..., "url": ..., "type": {...}, "verified_at": ...}], sorted by identifier. Clients such as proTES combine it withGET /services, keeping services whose identifier, URL and type match.The time is stored in a hidden service field (
_verifiedAt), never served by the GA4GH endpoints. A verification is reset in the same write when the service's URL changes in any way (exact string comparison, so also queries, fragments, case or trailing slashes) or its API type changes, using compare-and-swap with retries, so a concurrent verify or unverify is never lost and a verification never survives such a change. Name, version and other changes keep it. Verifications and unverifications are logged with the admin'ssub.Admin-only access needs no new policy: no policy matches
/services/:id/verification, so only theadminrole grants it; owners and maintainers get 403 (tested).Field names are snake_case, like the other additions resources (
/me, permissions).README: new section "Verified services".
Closes #64
Verification
Locally (Python 3.12, Helm 3.18.6):
ruff check .,ruff format --check .: passedmypy cloud_registry tests: no issues in 28 filesast-grep scan,ast-grep test --skip-snapshot-tests: passedpytestunder coverage (chart tests included): 332 passed, none skipped; coverage 100% (571 statements)CI: all checks passed (static code analysis; tests on Python 3.10 and 3.12; Helm chart; Docker Compose; Read the Docs).
Notes
server._problemmoved tocloud_registry.exceptions.problem, for the 409 from the verification controller.🤖 Generated with Claude Code
Summary by Sourcery
Enable administrators to verify registered services while keeping existing GA4GH service endpoints unchanged.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: