Repository navigation
Fix/align specs with implementation - #68
Conversation
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
There was a problem hiding this comment.
Pull request overview
Aligns the published OpenAPI/JSON schemas (RA + TL) with the system’s actual runtime behavior, and tightens validation so ingest and handler logic consistently enforces the contract described in the specs.
Changes:
- Updated RA/TL OpenAPI specs and served TL schema to match canonical enum tokens and event model, and to document/enforce key request constraints.
- Added/expanded runtime validations (e.g., required
displayName, revocation comment length, revocation reason code validation at TL ingest) with corresponding tests. - Hardened domain validation for endpoint function constraints (tag count, ID/name length) and broadened protocol/transport parsing test coverage.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| spec/api-spec-v2.yaml | Updates RA v2 OpenAPI to reflect canonical enums and request constraints (e.g., protocol tokens, oneOf, metadata hash/url relationship). |
| spec/api-spec-tl-v2.yaml | Updates TL v2 OpenAPI eventType enum to the shipped lifecycle events. |
| internal/tl/service/schemas/V2.json | Adds dnssecVerified to DNSRecord schema to match emitted event payloads. |
| internal/tl/event/v1/event.go | Enforces revocationReasonCode validation for V1 TL events. |
| internal/tl/event/v1/event_test.go | Adds tests for valid/invalid revocationReasonCode handling (V1). |
| internal/tl/event/event.go | Enforces revocationReasonCode validation for V2 TL events. |
| internal/tl/event/event_test.go | Adds tests for valid/invalid revocationReasonCode handling (V2). |
| internal/ra/handler/v1lifecycle.go | Adds max-length validation for revocation comments in the V1 revoke handler. |
| internal/ra/handler/v1lifecycle_test.go | Adds test coverage for “comments too long” revocation requests (V1). |
| internal/ra/handler/lifecycle.go | Restricts status filtering to spec-supported filter enum values; rejects invalid/unfilterable statuses. |
| internal/ra/handler/lifecycle_test.go | Adds tests asserting 422 on invalid/unfilterable status filters. |
| internal/domain/status.go | Expands RevocationReason enum set and updates validity checks. |
| internal/domain/status_test.go | Updates tests to include new RevocationReason values. |
| internal/domain/protocol_test.go | Extends transport parsing tests to cover underscore form (json_rpc). |
| internal/domain/endpoint.go | Tightens AgentFunction validation (max tags, max ID/name lengths). |
| internal/domain/endpoint_test.go | Adds/updates tests for new AgentFunction validation constraints. |
| internal/domain/agent.go | Requires displayName in NewRegistration validation. |
| internal/domain/agent_test.go | Updates registration validation tests to cover missing/too-long displayName. |
| internal/adapter/docsui/openapi/tl.yaml | Mirrors TL OpenAPI eventType enum updates for docs UI. |
| internal/adapter/docsui/openapi/ra.yaml | Mirrors RA OpenAPI updates for docs UI (enums/constraints/documentation). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jcrisp-godaddy
left a comment
There was a problem hiding this comment.
Curious about the inclusion of EXPIRED_CERT in the revocation reason enum — it doesn't appear in RFC 5280's CRLReason enumeration (Section 5.3.1), which the V2.json schema cites as its source. Is there a use case, or did it perhaps come along with the original V2.json set?
jcrisp-godaddy
left a comment
There was a problem hiding this comment.
REMOVE_FROM_CRL is in RFC 5280, but it's an un-revocation signal (reinstating a cert from CERTIFICATE_HOLD) rather than a reason to revoke. Even if ANS eventually verifies external CRLs, that would be a read operation — the ANS revocation reason would still reflect the underlying cause (e.g. KEY_COMPROMISE), not a CRL operational directive. Is there a "reinstate from hold" lifecycle in mind that would give this code meaning, or is it safe to drop?
jcrisp-godaddy
left a comment
There was a problem hiding this comment.
The original 7-token set appeared to deliberately exclude UNSPECIFIED, which has the effect of requiring callers to state a reason when revoking. Including it weakens the audit trail — a revocation without a meaningful reason is harder to act on or investigate later. Was the exclusion intentional, and is there a case where a caller genuinely can't determine a reason?
|
@jcrisp-godaddy I agree with your findings.
In short - I will revert the change to align with the original 7 and remove the RFC 5280 reference.
|
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
csnitker-godaddy
left a comment
There was a problem hiding this comment.
PR Review — intent-focused pass on #68
Scope: fix/align-specs-with-implementation → main, 14 commits (13 change commits + 1 no-op merge of main), +194/−46 across 20 files. Two directions of spec↔code alignment closing issue #59's nine drift items: spec edits (spec/api-spec-v2.yaml, spec/api-spec-tl-v2.yaml, docsui mirrors, served TL schemas V0/V1/V2.json) and new runtime validation (domain, RA handlers, TL ingest codecs on both lanes). No new dependencies. CI green on head 1c462fe.
Process. Three passes: (1) three reviewers each answering a slice of ten intent-derived questions produced 9 findings; (2) verification against the checked-out head (call-graph walks for Validate() reach, .Comments readers, schema serving, spec property definitions) dropped 3, leaving 6; (3) an adversarial cross-examiner (killed 2) and an independent from-scratch reviewer (raised exactly 1, matching the survivors' top item) reconciled to 1 final finding. Everything else is in the drop list below with the criterion that removed it — several are one-line fixes worth cherry-picking anyway (marked ⚙).
Recommendation
Merge after fixing the one finding below — roughly 6 lines of production code plus one test, completing the PR's own stated deliverable. Also worth updating the PR description before merge: it still advertises the RevocationReason enum expansion that a7d3353 reverted (the final diff removes those 4 tokens from the served schemas), so the merge commit reference would be misleading as-is.
This is careful work: 8½ of issue #59's nine items are genuinely closed, both docsui mirrors are byte-identical to the spec files (verified by blob hash), the TL ingest guard is symmetric across the V1/V2 lanes with the enum delegated to the single domain source of truth, and the tightened limits provably cannot retro-break agents persisted under the old limits (validation is entry-gated at NewRegistration; no rehydration/renewal/verify path re-validates stored data). The one miss: the comments length cap landed on the lane whose spec doesn't declare it, and not on the lane whose spec does.
Finding
1. V2 revoke lane never enforces the spec-declared comments maxLength 200 — Major
See the inline comment on internal/ra/handler/v1lifecycle.go:157-161 for full detail and the suggested fix. Short version: spec/api-spec-v2.yaml AgentRevocationRequest declares comments: maxLength: 200 (the exact line issue #59 item 9 cites), but POST /v2/ans/agents/{agentId}/revoke accepts any comments value up to the 64 KiB body cap with 200 OK — no layer below the handler checks it either. The new COMMENTS_TOO_LONG guard exists only on the V1 lane.
What we looked at and dropped
Documented so these don't get re-raised later. ⚙ = cheap fix, author's discretion.
- ⚙ Served historical schemas narrowed while the spec still claims they're verbatim production fetches. V0.json/V1.json
revocationReasonCodewent 11→7 tokens, butspec/api-spec-tl-v2.yaml:666-669still says the V0/V1 bodies "are the production schemas fetched from transparency.ans.godaddy.com… for historical-verifier backwards compatibility" — now false, and V0 has no ingest lane in this TL (the file exists purely as a fidelity mirror; its retired eventType tokens were deliberately kept in the same edit). Cheap fix: reword the route description (and consider restoring V0's historical enum). - ⚙ Register description prose still says server-cert input is "optional". The same PR added
oneOfmaking exactly-one-ofserverCsrPEM/serverCertificatePEMmandatory (code 422s neither-present withINVALID_SERVER_CERT_INPUT,registration.go:423-430), but the edited prose (api-spec-v2.yaml:181-182) still reads "can optionally include". One-sentence fix in both mirror files. - ⚙ New length checks count bytes; OpenAPI
maxLengthcounts code points. A 200-character CJK revocation comment is 600 bytes → rejected at a third of the documented budget (v1lifecycle.go:157;endpoint.go:34,44). If bytes is deliberate policy, state the unit in the spec; elseutf8.RuneCountInString. - Replay of a pre-PR-sealed event with a now-dropped reason token now 422s instead of returning the duplicate answer (ingest validates before dedup,
internal/tl/service/log.go). Dropped as implausible-precondition: requires an external producer × a dropped-token leaf × a lost-ack replay; this repo's RA is provably immune (domain pre-validates the 7-token set before the event builders run). - Present-but-empty strings satisfy the new
required-based oneOf/anyOf but code treats""as absent. Dropped: only degenerate explicitly-empty discriminators slip through; the realistic no-omitemptyaccident sends both keys and is caught by the oneOf itself;minLengthappears nowhere in the house spec style. ?status=ALL&status=BOGUSreturns 200 while the reverse order 422s (pre-existingALLbreak precedes the new switch). Dropped: only schema-invalid requests are affected, and the 200 they get (unfiltered) is what their ownALLrequested. Trivial restructure if wanted: validate every value, apply ALL after the loop.- Status-filter accept arm has zero test coverage (no test sends a valid non-ALL status through the new switch) and no boundary-accept tests at 64/64/5/200. Dropped as future-regression-only — the arm and limits were verified correct today; both are cheap test-hygiene additions.
?status=(empty) and lowercaseactivenow 422. Verified as fixes, not breaks: pre-PR both produced a silently-empty 200 (WHERE status IN ('')), never the documented default-ACTIVE.- Tightened AgentFunction/displayName limits vs already-persisted agents. Verified non-issue:
AgentFunction.Validate → AgentEndpoints.Validate → NewRegistrationhas exactly one non-test caller (RegisterAgent, new registrations only); store rehydration is raw struct/JSON assembly; TL events carry no functions/tags. - New TL reason-code check reaching read/verify paths. Verified non-issue: every
Validate()caller is on the ingest/append path;statustoken.go,identitybadge.go,envelope_wrapper.go, andcmd/ans-verifyunmarshal without validating — historical leaves keep serving and verifying. dnssecVerifiedschema addition breaking old-leaf validation. Verified non-issue: field isomitempty(absent when false); V2.json's DNSRecord has norequiredlist and noadditionalProperties: false; V1's map-typed attestations structurally can't carry it, so V1.json correctly wasn't touched.- Pre-existing V1 envelope
Validateweaker than V2 (no keyId/signature check at envelope level). Pre-existing asymmetry untouched by this PR; out of scope.
Strengths worth preserving
- Docsui mirrors byte-identical to the spec files (blob 297f598 / d4ffa5b) — issue #59 called for this explicitly.
- Symmetric TL ingest guards with a single enum source of truth (
tl/event/event.go:283,tl/event/v1/event.go:191, both delegating todomain.RevocationReason.IsValid()). - Empty-reason passthrough scoped exactly to the issue's ask (
!= ""short-circuit +omitempty) — non-revocation events unaffected. - Output canonicalized, input leniency retained (
ParseProtocol/ParseTransportstill accept hyphenated forms, newjson_rpctest) — no break for existing senders. - Status-filter guard matches the spec enum exactly and preserves ALL/default semantics, with tests documenting the invalid-vs-unfilterable distinction.
- The enum-decision thread executed cleanly: 11-token expansion reverted across all three served schemas in one commit, and the now-inaccurate "RFC 5280" citation dropped.
- Precise new spec prose: the endpoints-uniqueness description names both error codes in the actual check order (
DUPLICATE_ENDPOINTbeforeDUPLICATE_PROTOCOL, matchingendpoint.go:199-211) and honestly notes JSON-Schema can't express it. displayNamerequired check placed in the domain (agent.go:121-123) so both lanes inherit it — the finding above is what happens when the alternative placement is chosen.
Final count: 1 finding (0 Critical, 1 Major, 0 Minor). 9 initial → 6 verified → 1 after cross-examination and independent fresh review. A disciplined alignment PR that closes 8½ of 9 drift items — finish the ninth on the lane that declares it, refresh the description, and it's ready.
🤖 Generated with Claude Code
| if len(req.Comments) > maxCommentsLength { | ||
| WriteError(w, domain.NewValidationError("COMMENTS_TOO_LONG", | ||
| fmt.Sprintf("comments exceeds %d characters", maxCommentsLength))) | ||
| return | ||
| } |
There was a problem hiding this comment.
Major — this guard needs a twin on the V2 lane (or a home in the shared service).
The declaring spec for this constraint is spec/api-spec-v2.yaml (AgentRevocationRequest → comments: maxLength: 200) — the exact line issue #59 item 9 cites — but POST /v2/ans/agents/{agentId}/revoke (internal/ra/handler/lifecycle.go:375-392) decodes comments with no length check at any layer: the V2 handler validates only reason, service.Revoke never reads RevokeInput.Comments, and domain.Revoke(reason, now) takes no comments parameter. Any value up to the route's 64 KiB body cap returns 200 OK, so the same logical request is 422 on V1 but 200 on V2, and item 9's second half stays open on the only lane whose published spec declares the constraint.
Suggested fix: mirror this check in LifecycleHandler.Revoke after the MISSING_REASON guard (the constant is already in this package), plus a V2 twin of TestV1Revoke_CommentsTooLong_422. Alternative worth considering: enforce once in service.Revoke, since RevokeInput already carries the field for both lanes — that placement makes this class of single-lane miss impossible, the same reasoning that put the displayName check in domain.NewRegistration.
There was a problem hiding this comment.
Served historical schemas narrowed while the spec still claims they're verbatim production fetches
-fixed in 20acee6
Register description prose still says server-cert input is "optional"
-fixed in 2753911
Status-filter accept arm has zero test coverage (no test sends a valid non-ALL status through the new switch)
-fixed in 938d0d2
guard needs a twin on the V2 lane (or a home in the shared service)
-fixed in a2af16f
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
Signed-off-by: James Hateley <jhateley@godaddy.com>
csnitker-godaddy
left a comment
There was a problem hiding this comment.
Re-review of head e34fb89 — all findings resolved. Approving. ✅
Every item from the previous review was addressed, including three that were only flagged as discretionary:
a2af16f— the Major finding, fixed.LifecycleHandler.Revokenow enforcescomments ≤ 200after theMISSING_REASONguard with the sameCOMMENTS_TOO_LONGcode as V1 and the shared package constant, plusTestRevoke_CommentsTooLong_422on the V2 route. Both lanes now enforce the spec'smaxLength: 200; issue #59 item 9 is fully closed.20acee6— historical schemas restored the clean way. V0.json/V1.json carry the original 11-token enum again; the net change vs main is one description line each (dropping the "RFC 5280" citation — correct, sinceEXPIRED_CERTwas never in that RFC). The "production schemas fetched from…" prose is accurate again up to that annotation line, and the historical validation surface is untouched.2753911— register prose fixed ("optionally" → "must"), applied to both mirror files.938d0d2— beyond the ask: all four filterable statuses tested individually plus a multi-value combination test.
Merged-main interaction checks (the riskier half of this re-review) — all clean:
- docsui mirrors remain byte-identical to the spec files (
spec/api-spec-v2.yaml≡docsui/ra.yaml, blob5c6cdbc) even though main's #47 added ~444 lines to the same file and the merge had to reconcile both sides. domain.NewRegistrationstill has exactly one non-test caller, so the round-1 verdict that the tightened limits can't retro-break persisted agents survives #47's registration-path changes.- TL
Validate()call sites are the identical ingest-only set — #46's event feed and the newtlclientadapter added no read-path validation; historical leaves keep serving and verifying. - No new
RegistrationStatusconstants on main; the status-filter switch remains exactly co-extensive with the spec enum. - CI green on
e34fb89(Build & Test, Lint).
One non-blocking ask: please refresh the PR description before merging — it still says the RevocationReason enum was expanded (UNSPECIFIED, CA_COMPROMISE, REMOVE_FROM_CRL, EXPIRED_CERT), but after a7d3353 + 20acee6 the net schema change is a one-line description edit, so that bullet would mislead anyone reading the merge commit.
Previously-documented discretionary items left as-is (fine to defer): byte-vs-rune length units (now at least consistent across lanes), boundary-accept tests at 64/64/5/200, the ALL-order validation skip, and the inherent V1.json-advertises-11 / V1-ingest-enforces-7 tension for new external producers — a one-sentence note in that schema's description would square it whenever the file is next touched.
🤖 Generated with Claude Code
Fixes schema/implementation drift issues reported in #59.
Validation and Error Handling Improvements:
displayNameinNewRegistrationand corresponding test coverage for missing and overly long values. [1] [2]commentsin revocation requests, returning a 422 error if exceeded, with tests for this case. [1] [2]RevocationReasonCodein event payloads and associated tests. [1] [2]AgentFunctiontags to a maximum of 5, and added max length checks (64 chars) for bothIDandName, with updated validation and tests. [1] [2] [3] [4]Enum and OpenAPI Schema Updates:
Protocoland transport types (e.g.,HTTP-API→HTTP_API,STREAMABLE-HTTP→STREAMABLE_HTTP) in OpenAPI specs and parsing logic. [1] [2] [3]OpenAPI/Schema Clarifications:
metaDataHashand its relationship withmetaDataUrl, and enforced their co-presence. [1] [2]API Filtering and Error Reporting:
Other Minor Improvements: