Skip to content

fix(ra): seal the gate-verified ACME method into domainValidation - #75

Merged
csnitker-godaddy merged 1 commit into
mainfrom
claude/issue-61-fix-b854b6
Jul 16, 2026
Merged

csnitker-godaddy merged 1 commit into
mainfrom
claude/issue-61-fix-b854b6

Conversation

@csnitker-godaddy

Copy link
Copy Markdown
Member

Summary

Fixes #61.

The domain-control challenge gate (verify-acme) is any-of — either the DNS-01 TXT record or the HTTP-01 resource satisfies it — but both AGENT_REGISTERED event builders hardcoded domainValidation: "ACME-DNS-01", so an agent whose domain control was proven via HTTP-01 was sealed into the append-only log with a wrong method token.

As the issue notes, the defect is structural, not a wrong literal: the gate computes the satisfied challenge type, but the event is built in a later HTTP call (verify-dns) where that result is out of scope, and CertificateOrder had no field to carry it across the boundary.

Pre-implementation shape diff

Wire shape touched: attestations.domainValidation on the AGENT_REGISTERED inner event. Canonical schemas (internal/tl/service/schemas/V1.json, V2.json, both mirrored from the reference TL contract):

"domainValidation": {
  "description": "ACME challenge type used for domain validation",
  "enum": ["ACME-DNS-01", "ACME-HTTP-01", "ACME-TLS-ALPN-01"],
  "type": "string"
}

with Attestations.required: [] in both lanes. Differences introduced by this change, called out explicitly:

  • The emitted value is now ACME-DNS-01 or ACME-HTTP-01, chosen by which artifact actually satisfied the gate. Both tokens are already in the enum on both lanes; no schema change.
  • ACME-TLS-ALPN-01 remains never-emitted (the RA offers no TLS-ALPN challenge).
  • For registrations that predate recording (pre-migration-012 rows mid-flow during a deploy), the field is now omitted instead of stamped ACME-DNS-01. Omission is valid in both lanes (required: [], omitempty on both Go structs) and is the honest encoding of "method unknown" — the log is append-only, so a fabricated token could never be corrected.
  • V1 lane deviation from the reference implementation: the reference emits a constant ACME-DNS-01; we now emit the faithful token. The reference schema enumerates all three methods, so the value is shape-compatible. This should sync with the ANS-1 spec wording flagged in specs(ans-1): rewrite Registration & Lifecycle against the reference implementation (v0.2.0) ans-spec#32.

Changes

  • Domain: CertificateOrder.VerifiedChallenge + RecordVerifiedChallenge(); ChallengeType.ACMEMethodToken() mapping (DNS_01→ACME-DNS-01, HTTP_01→ACME-HTTP-01, unknown→empty); IsZero() covers the new field.
  • Gate (gateOrderChallenges): a passing gate records the satisfied type on the order and logs it at INFO (agentId, fqdn, challengeType). Every downstream path already persists the order, including the async-provider ISSUING park.
  • Persistence: migration 012_cert_order_verified_challenge.sql adds agent_registrations.cert_order_verified_challenge (NULL = not recorded); wired through the SQLite agent store codec and INSERT/UPDATE.
  • Event builders (V2 buildAgentRegisteredEvent, V1 buildAgentRegisteredV1Event): derive domainValidation from the recorded type instead of the constant.

Testing

  • New end-to-end regression tests drive register → verify-acme → verify-dns with a DNS verifier blind to DOMAIN_VALIDATION probes, forcing the gate down the HTTP-01 path: the sealed event must carry ACME-HTTP-01 on both V1 and V2 lanes, and the satisfied type must be persisted at verify-acme time. Both tests were confirmed to fail against the previous hardcoded builders.
  • Complementary tests pin DNS-01 flows sealing ACME-DNS-01, unrecorded rows omitting the field from the canonical bytes, the SQLite round-trip (NULL→empty, recorded value survives the UPDATE path), and the new domain methods.
  • make check passes: fmt, vet, golangci-lint, coverage 90.4% (≥90% gate), internal/domain at 100%. make test-race clean on the touched packages.

🤖 Generated with Claude Code

The domain-control challenge gate is any-of — either the DNS-01 TXT
record or the HTTP-01 resource satisfies it — but both AGENT_REGISTERED
event builders hardcoded domainValidation to "ACME-DNS-01", so an
agent whose domain control was proven via HTTP-01 was sealed into the
append-only log with the wrong method token.

The gate result could not simply be read at emit time: the event is
built in a later HTTP call (verify-dns) where the verified type is out
of scope, and CertificateOrder had no field to carry it. Persist the
satisfied challenge type on the order when the gate passes
(migration 012, cert_order_verified_challenge), and derive the sealed
token from it in both the V1 and V2 builders. Rows that predate
recording omit the field — the schemas mark it optional in both lanes,
and an append-only log must never carry a fabricated method token.

Fixes #61

Signed-off-by: Connor Snitker <csnitker@godaddy.com>
Copilot AI review requested due to automatic review settings July 15, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a structural RA attestation defect by persisting which ACME challenge type actually satisfied the domain-control gate (DNS-01 vs HTTP-01) and using that recorded value when sealing the terminal AGENT_REGISTERED event’s attestations.domainValidation on both V1 and V2 TL lanes.

Changes:

  • Add CertificateOrder.VerifiedChallenge + helpers to record the satisfied challenge at gate-pass time and map it to the TL method token (ACME-DNS-01 / ACME-HTTP-01).
  • Persist the verified challenge through SQLite (migration + store codec) so it survives the verify-acme → verify-dns call boundary.
  • Update both V1 and V2 event builders to derive domainValidation from the persisted value (and omit it when unrecorded), with regression coverage for HTTP-01, DNS-01, and pre-recording rows.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/ra/service/v1event.go V1 builder now sources domainValidation from the recorded verified challenge (instead of a constant).
internal/ra/service/order_flow_test.go Adds end-to-end regression tests ensuring HTTP-01 vs DNS-01 flows seal the correct domainValidation, and unrecorded rows omit it.
internal/ra/service/lifecycle.go Records the satisfied challenge type on the aggregate at gate pass time and uses it in the V2 builder.
internal/domain/order.go Introduces VerifiedChallenge, RecordVerifiedChallenge(), and ACMEMethodToken() mapping for TL emission.
internal/domain/order_test.go Adds unit tests for the new order/challenge-type helpers and updated IsZero() behavior.
internal/adapter/store/sqlite/order_persistence_test.go Extends SQLite round-trip coverage to include the new verified-challenge field through UPDATE paths.
internal/adapter/store/sqlite/migrations/012_cert_order_verified_challenge.sql Adds the cert_order_verified_challenge column (NULL = not recorded).
internal/adapter/store/sqlite/agent.go Wires the new column through row decode/encode and INSERT/UPDATE statements.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@csnitker-godaddy
csnitker-godaddy added this pull request to the merge queue Jul 16, 2026
Merged via the queue into main with commit 99152ec Jul 16, 2026
3 checks passed
@csnitker-godaddy
csnitker-godaddy deleted the claude/issue-61-fix-b854b6 branch July 16, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ra: sealed domainValidation is always ACME-DNS-01, even when HTTP-01 satisfied the challenge gate

3 participants