Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5ee0d34
fix: cleanup CSR requirements and description
jhateley-godaddy Jul 14, 2026
3da54a9
fix: fix tl eventType enum api-spec
jhateley-godaddy Jul 14, 2026
9d798b4
fix: add missing dnssecVerified field to v2.json
jhateley-godaddy Jul 14, 2026
af67e83
fix: fix enum casing for transports and protocols
jhateley-godaddy Jul 14, 2026
83acc91
fix: fix api spec drift from previous commit
jhateley-godaddy Jul 14, 2026
80b6646
fix: align AgentFunction validation with api-spec
jhateley-godaddy Jul 14, 2026
07c1360
fix: align AgentLifecycleStatusFilter validation with api-spec
jhateley-godaddy Jul 14, 2026
d270d59
fix: fix lint issue from previous commit
jhateley-godaddy Jul 14, 2026
3df37d7
fix: align spec with metadata hash endpoint validation
jhateley-godaddy Jul 14, 2026
4c1d806
fix: enforce required display name and cap on revoke comments
jhateley-godaddy Jul 14, 2026
890265d
fix: align revocation reason code spec, tl, ra
jhateley-godaddy Jul 14, 2026
a7d3353
fix: revert reason code enum to original 7
jhateley-godaddy Jul 15, 2026
d440e69
fix: use const for maxCommentsLength
jhateley-godaddy Jul 15, 2026
1c462fe
Merge branch 'main' into fix/align-specs-with-implementation
jhateley-godaddy Jul 15, 2026
2321e9f
Merge branch 'main' into fix/align-specs-with-implementation
jhateley-godaddy Jul 16, 2026
6282964
Merge branch 'main' into fix/align-specs-with-implementation
jhateley-godaddy Jul 17, 2026
20acee6
fix: revert change to historical json schema
jhateley-godaddy Jul 17, 2026
2753911
fix: optional -> must for server cert in registerAgent description
jhateley-godaddy Jul 17, 2026
938d0d2
fix: add test for valid statuses
jhateley-godaddy Jul 17, 2026
a2af16f
fix: validate revoke comments length in v2 lane
jhateley-godaddy Jul 17, 2026
7573df4
Merge branch 'main' into fix/align-specs-with-implementation
jhateley-godaddy Jul 17, 2026
e34fb89
Merge branch 'main' into fix/align-specs-with-implementation
jhateley-godaddy Jul 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions internal/adapter/docsui/openapi/ra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,12 @@ paths:
description: |
Registers a new agent with the Agent Name Service.

The Registration Authority (RA) validates the agent's identity and
submitted information, then interacts with the CA to issue certificates
or validates provided (BYOC) server certificates.
The request MAY include a Certificate Signing Request (CSR) so that
an Identity certificate can be issued. Identity certificates are
issued by the RA.

The request MUST include an identity CSR. The request can optionally
include a server CSR (for RA-issued server cert) or a BYOC server
certificate with its chain.
The request can optionally include a server CSR (for RA-issued server cert)
or a BYOC server certificate with its chain.
operationId: registerAgent
requestBody:
description: Agent registration request
Expand Down Expand Up @@ -1508,7 +1507,7 @@ components:

Protocol:
type: string
enum: [A2A, MCP, HTTP-API]
enum: [A2A, MCP, HTTP_API]

DiscoveryProfile:
type: string
Expand Down Expand Up @@ -1591,6 +1590,14 @@ components:
endpoints:
type: array
minItems: 1
description: >-
One or more protocol endpoints. Each protocol may appear at
most once across the array — a second endpoint with an
already-used protocol is rejected with 422 DUPLICATE_PROTOCOL,
and an exact protocol+agentUrl repeat with 422
DUPLICATE_ENDPOINT. (By-field uniqueness is not expressible in
OpenAPI/JSON Schema; enforced in
internal/domain/endpoint.go AgentEndpoints.Validate.)
items:
$ref: '#/components/schemas/AgentEndpoint'
serverCsrPEM:
Expand Down Expand Up @@ -1643,6 +1650,9 @@ components:
- agentHost
- endpoints
- version
oneOf:
- required: [serverCsrPEM]
- required: [serverCertificatePEM]

AgentRevocationRequest:
type: object
Expand Down Expand Up @@ -1910,6 +1920,10 @@ components:
metaDataHash:
type: string
pattern: '^SHA256:[a-f0-9]{64}$'
description: >-
Optional integrity pin over the metadata descriptor.
Meaningless on its own: it MUST be accompanied by metaDataUrl.
A metaDataHash without a metaDataUrl is rejected with 422 INVALID_ENDPOINT.
documentationUrl:
type: string
format: uri
Expand All @@ -1923,10 +1937,14 @@ components:
type: array
items:
type: string
enum: [STREAMABLE-HTTP, SSE, JSON-RPC, GRPC, REST, HTTP]
enum: [STREAMABLE_HTTP, SSE, JSON_RPC, GRPC, REST, HTTP]
required:
- protocol
- agentUrl
anyOf:
- not:
required: [metaDataHash]
- required: [metaDataUrl]

AgentFunction:
type: object
Expand Down
2 changes: 1 addition & 1 deletion internal/adapter/docsui/openapi/tl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ components:
ansName: { type: string, example: "ans://v1.0.0.agent.example.com" }
eventType:
type: string
enum: [AGENT_REGISTRATION, DOMAIN_VALIDATION, AGENT_ACTIVE, AGENT_REVOCATION]
enum: [AGENT_REGISTERED, AGENT_RENEWED, AGENT_DEPRECATED, AGENT_REVOKED]
raId: { type: string, example: "ans-ra-local" }
issuedAt: { type: string, format: date-time }
timestamp: { type: string, format: date-time }
Expand Down
3 changes: 3 additions & 0 deletions internal/domain/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ func NewRegistration(
if ownerID == "" {
return nil, NewValidationError("MISSING_OWNER_ID", "ownerId is required")
}
if displayName == "" {
return nil, NewValidationError("MISSING_DISPLAY_NAME", "displayName is required")
}
if ansName.IsZero() {
return nil, NewValidationError("MISSING_ANS_NAME", "ansName is required")
}
Expand Down
13 changes: 7 additions & 6 deletions internal/domain/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ func TestNewRegistration_Validations(t *testing.T) {
csr *AgentCSR
code string
}{
{"missing agent id", "", "o", validName, "", "", validEndpoints, nil, &validCSR, "MISSING_AGENT_ID"},
{"missing owner", "a", "", validName, "", "", validEndpoints, nil, &validCSR, "MISSING_OWNER_ID"},
{"missing ans name", "a", "o", AnsName{}, "", "", validEndpoints, nil, &validCSR, "MISSING_ANS_NAME"},
{"missing agent id", "", "o", validName, "displayName", "", validEndpoints, nil, &validCSR, "MISSING_AGENT_ID"},
{"missing owner", "a", "", validName, "displayName", "", validEndpoints, nil, &validCSR, "MISSING_OWNER_ID"},
{"missing ans name", "a", "o", AnsName{}, "displayName", "", validEndpoints, nil, &validCSR, "MISSING_ANS_NAME"},
{"missing display name", "a", "o", validName, "", "", validEndpoints, nil, &validCSR, "MISSING_DISPLAY_NAME"},
{"display name too long", "a", "o", validName, strings.Repeat("x", 65), "", validEndpoints, nil, &validCSR, "DISPLAY_NAME_TOO_LONG"},
{"description too long", "a", "o", validName, "", strings.Repeat("x", 151), validEndpoints, nil, &validCSR, "DESCRIPTION_TOO_LONG"},
{"no endpoints", "a", "o", validName, "", "", nil, nil, &validCSR, "MISSING_ENDPOINTS"},
{"description too long", "a", "o", validName, "displayName", strings.Repeat("x", 151), validEndpoints, nil, &validCSR, "DESCRIPTION_TOO_LONG"},
{"no endpoints", "a", "o", validName, "displayName", "", nil, nil, &validCSR, "MISSING_ENDPOINTS"},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand All @@ -109,7 +110,7 @@ func TestNewRegistration_CertFQDNMismatch(t *testing.T) {
ep := []AgentEndpoint{{Protocol: ProtocolMCP, AgentURL: "https://agent.example.com/mcp"}}
cert := &ByocServerCertificate{SubjectCommonName: "other.example.com"}

_, err := NewRegistration("a", "o", ansName, "", "", ep, cert, &csr, time.Now())
_, err := NewRegistration("a", "o", ansName, "displayName", "", ep, cert, &csr, time.Now())
assert.ErrorIs(t, err, ErrCertificate)
}

Expand Down
20 changes: 18 additions & 2 deletions internal/domain/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
)

const (
maxFunctionTags = 20
maxTagLength = 20
maxFunctionTags = 5
maxTagLength = 20
maxFunctionIDLength = 64
maxFunctionNameLength = 64
// maxMetadataURLLength bounds the operator-supplied metadataUrl. It
// is emitted verbatim as the DNSAID `cap` SvcParam and embedded in the
// signed TL attestation, so an unbounded value would bloat the
Expand All @@ -29,12 +31,26 @@ type AgentFunction struct {

// Validate checks that the function has valid fields.
func (f AgentFunction) Validate() error {
if len(f.ID) > maxFunctionIDLength {
return NewValidationError(
"INVALID_FUNCTION",
fmt.Sprintf("function id length %d exceeds %d characters", len(f.ID), maxFunctionIDLength),
)
}
if strings.TrimSpace(f.ID) == "" {
return NewValidationError("INVALID_FUNCTION", "function id cannot be blank")
}

if len(f.Name) > maxFunctionNameLength {
return NewValidationError(
"INVALID_FUNCTION",
fmt.Sprintf("function name length %d exceeds %d characters", len(f.Name), maxFunctionNameLength),
)
}
if strings.TrimSpace(f.Name) == "" {
return NewValidationError("INVALID_FUNCTION", "function name cannot be blank")
}

for _, tag := range f.Tags {
if len(tag) > maxTagLength {
return NewValidationError(
Expand Down
12 changes: 11 additions & 1 deletion internal/domain/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ func TestAgentFunction_Validate(t *testing.T) {
assert.NoError(t, f.Validate())
})

t.Run("reject long id", func(t *testing.T) {
err := AgentFunction{ID: strings.Repeat("x", 65), Name: "n"}.Validate()
assert.ErrorIs(t, err, ErrValidation)
})

t.Run("reject blank id", func(t *testing.T) {
err := AgentFunction{ID: " ", Name: "ok"}.Validate()
assert.ErrorIs(t, err, ErrValidation)
})

t.Run("reject long name", func(t *testing.T) {
err := AgentFunction{ID: "id", Name: strings.Repeat("x", 65)}.Validate()
assert.ErrorIs(t, err, ErrValidation)
})

t.Run("reject blank name", func(t *testing.T) {
err := AgentFunction{ID: "id", Name: ""}.Validate()
assert.ErrorIs(t, err, ErrValidation)
Expand All @@ -30,7 +40,7 @@ func TestAgentFunction_Validate(t *testing.T) {
})

t.Run("reject too many tags", func(t *testing.T) {
tags := make([]string, 21)
tags := make([]string, 6)
for i := range tags {
tags[i] = "t"
}
Expand Down
1 change: 1 addition & 0 deletions internal/domain/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestParseTransport(t *testing.T) {
{"STREAMABLE-HTTP", TransportStreamableHTTP, false},
{"sse", TransportSSE, false},
{"json-rpc", TransportJSONRPC, false},
{"json_rpc", TransportJSONRPC, false},
{"JSONRPC", TransportJSONRPC, false},
{"GRPC", TransportGRPC, false},
{"REST", TransportREST, false},
Expand Down
9 changes: 8 additions & 1 deletion internal/ra/handler/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ func (h *LifecycleHandler) List(w http.ResponseWriter, r *http.Request) {
filter.Statuses = nil
break
}
filter.Statuses = append(filter.Statuses, domain.RegistrationStatus(s))
switch domain.RegistrationStatus(s) {
case domain.StatusPendingDNS, domain.StatusActive, domain.StatusDeprecated, domain.StatusRevoked:
filter.Statuses = append(filter.Statuses, domain.RegistrationStatus(s))
default:
WriteError(w, domain.NewValidationError("INVALID_STATUS",
"status must be one of PENDING_DNS, ACTIVE, DEPRECATED, REVOKED, ALL"))
return
}
}
} else {
filter.Statuses = []domain.RegistrationStatus{domain.StatusActive}
Expand Down
20 changes: 20 additions & 0 deletions internal/ra/handler/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ func TestList_BadLimitReturns422(t *testing.T) {
}
}

func TestList_BadStatusReturns422(t *testing.T) {
t.Parallel()
fx := newHandlerFixture(t)
rec := fx.request(t, http.MethodGet, "/v2/ans/agents?status=BOGUS", nil, fx.asOwner("alice"))
if rec.Code != http.StatusUnprocessableEntity {
t.Fatalf("want 422, got %d body=%s", rec.Code, rec.Body)
}
}

func TestList_UnfilterableStatusReturns422(t *testing.T) {
t.Parallel()
fx := newHandlerFixture(t)
// PENDING_VALIDATION/FAILED/EXPIRED are valid AgentLifecycleStatus
// values but are not in AgentLifecycleStatusFilter — not filterable.
rec := fx.request(t, http.MethodGet, "/v2/ans/agents?status=PENDING_VALIDATION", nil, fx.asOwner("alice"))
if rec.Code != http.StatusUnprocessableEntity {
t.Fatalf("want 422, got %d body=%s", rec.Code, rec.Body)
}
}

func TestDetail_OwnedReturns200(t *testing.T) {
t.Parallel()
fx := newHandlerFixture(t)
Expand Down
11 changes: 11 additions & 0 deletions internal/ra/handler/v1lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handler

import (
"encoding/json"
"fmt"
"net/http"

"github.com/go-chi/chi/v5"
Expand All @@ -10,6 +11,10 @@ import (
"github.com/godaddy/ans/internal/ra/service"
)

const (
maxCommentsLength = 200
)

// V1LifecycleHandler groups the V1 post-registration transitions:
// verify-acme, verify-dns, revoke. Shares the `RegistrationService`
// with V2; diverges only in DTO shape and TL-lane emission.
Expand Down Expand Up @@ -149,6 +154,12 @@ func (h *V1LifecycleHandler) Revoke(w http.ResponseWriter, r *http.Request) {
return
}

if len(req.Comments) > maxCommentsLength {
WriteError(w, domain.NewValidationError("COMMENTS_TOO_LONG",
fmt.Sprintf("comments exceeds %d characters", maxCommentsLength)))
return
}
Comment on lines +159 to +163

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@jhateley-godaddy jhateley-godaddy Jul 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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


agentID := chi.URLParam(r, "agentId")
res, err := h.svc.Revoke(r.Context(), agentID, service.RevokeInput{
Reason: domain.RevocationReason(req.Reason),
Expand Down
18 changes: 18 additions & 0 deletions internal/ra/handler/v1lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,24 @@ func TestV1Revoke_MissingReason_422(t *testing.T) {
}
}

func TestV1Revoke_CommentsTooLong_422(t *testing.T) {
t.Parallel()
fx := newHandlerFixture(t)
agentID, _ := fx.v1RegisterAgent(t, "alice", "agent.example.com", "1.0.0")
revBody, _ := json.Marshal(map[string]any{
"reason": "KEY_COMPROMISE",
"comments": strings.Repeat("a", 201),
})
rec := fx.request(t, http.MethodPost, "/v1/agents/"+agentID+"/revoke",
bytes.NewReader(revBody), fx.asOwner("alice"))
if rec.Code != http.StatusUnprocessableEntity {
t.Fatalf("want 422, got %d body=%s", rec.Code, rec.Body)
}
if !strings.Contains(rec.Body.String(), "COMMENTS_TOO_LONG") {
t.Errorf("expected COMMENTS_TOO_LONG code, got %s", rec.Body)
}
}

// TestV1Revoke_NotOwned_403 confirms WriteOwnership 403 on
// not-owned revoke attempts (as opposed to read routes which 404).
func TestV1Revoke_NotOwned_403(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions internal/tl/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"time"

anscrypto "github.com/godaddy/ans/internal/crypto"
"github.com/godaddy/ans/internal/domain"
)

// SchemaVersion pins the envelope version. "V2" because our V2 RA
Expand Down Expand Up @@ -279,6 +280,9 @@ func (ev *Event) Validate() error {
if _, err := time.Parse(time.RFC3339, ev.Timestamp); err != nil {
return fmt.Errorf("event: timestamp must be RFC3339: %w", err)
}
if ev.RevocationReasonCode != "" && !domain.RevocationReason(ev.RevocationReasonCode).IsValid() {
return fmt.Errorf("event: invalid revocationReasonCode %q", ev.RevocationReasonCode)
}
return nil
}

Expand Down
12 changes: 12 additions & 0 deletions internal/tl/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ func TestEnvelope_Validate_Success(t *testing.T) {
}
}

func TestEnvelope_Validate_RevocationReasonCode_Valid(t *testing.T) {
t.Parallel()
env := fixedEnvelope()
env.Payload.Producer.Event.RevocationReasonCode = "AA_COMPROMISE"
if err := env.Validate(); err != nil {
t.Fatalf("Validate: %v", err)
}
}

func TestEnvelope_Validate_MissingFields(t *testing.T) {
t.Parallel()
cases := map[string]func(e *event.Envelope){
Expand All @@ -137,6 +146,9 @@ func TestEnvelope_Validate_MissingFields(t *testing.T) {
"no ansName": func(e *event.Envelope) { e.Payload.Producer.Event.AnsName = "" },
"no timestamp": func(e *event.Envelope) { e.Payload.Producer.Event.Timestamp = "" },
"non-RFC3339 time": func(e *event.Envelope) { e.Payload.Producer.Event.Timestamp = "yesterday" },
"bad revocationReasonCode": func(e *event.Envelope) {
e.Payload.Producer.Event.RevocationReasonCode = "BOGUS"
},
}
for name, mutate := range cases {
t.Run(name, func(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions internal/tl/event/v1/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"errors"
"fmt"
"time"

"github.com/godaddy/ans/internal/domain"
)

// SchemaVersion pins the envelope label for V1 events. Producer +
Expand Down Expand Up @@ -186,6 +188,9 @@ func (e *Event) Validate() error {
if _, err := time.Parse(time.RFC3339, e.Timestamp); err != nil {
return fmt.Errorf("event/v1: event.timestamp not RFC3339: %w", err)
}
if e.RevocationReasonCode != "" && !domain.RevocationReason(e.RevocationReasonCode).IsValid() {
return fmt.Errorf("event/v1: invalid revocationReasonCode %q", e.RevocationReasonCode)
}
return nil
}

Expand Down
12 changes: 12 additions & 0 deletions internal/tl/event/v1/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ func TestEnvelope_Validate_Success(t *testing.T) {
}
}

func TestEnvelope_Validate_RevocationReasonCode_Valid(t *testing.T) {
t.Parallel()
env := fixedEnvelope()
env.Payload.Producer.Event.RevocationReasonCode = "SUPERSEDED"
if err := env.Validate(); err != nil {
t.Fatalf("Validate: %v", err)
}
}

func TestEnvelope_Validate_Failures(t *testing.T) {
t.Parallel()
cases := map[string]func(e *v1.Envelope){
Expand All @@ -155,6 +164,9 @@ func TestEnvelope_Validate_Failures(t *testing.T) {
"no ansName": func(e *v1.Envelope) { e.Payload.Producer.Event.AnsName = "" },
"no timestamp": func(e *v1.Envelope) { e.Payload.Producer.Event.Timestamp = "" },
"non-RFC3339 time": func(e *v1.Envelope) { e.Payload.Producer.Event.Timestamp = "yesterday" },
"bad revocationReasonCode": func(e *v1.Envelope) {
e.Payload.Producer.Event.RevocationReasonCode = "BOGUS"
},
}
for name, mutate := range cases {
t.Run(name, func(t *testing.T) {
Expand Down
Loading