Skip to content

feat(client): add the ans identity key resolver - #2300

Merged
ramizpolic merged 8 commits into
agntcy:mainfrom
kperry-godaddy:ans-resolver
Oct 8, 2026
Merged

ramizpolic merged 8 commits into
agntcy:mainfrom
kperry-godaddy:ans-resolver

Conversation

@kperry-godaddy

@kperry-godaddy kperry-godaddy commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds the ans:// key resolver in client/utils/identity/resolvers/ans, implementing resolvers.Resolver as #2173 describes. An ans:// subject publishes no key: the key is the public key of the identity certificate the claim carries, trusted once the agent's transparency log attests the certificate's fingerprint for the agent the subject names.

Resolve(ctx, subject, certificate):

  1. requires the canonical spelling ans://v<major>.<minor>.<patch>.<lowercase host>, so one identity verifies under one subject only;
  2. parses the certificate and requires a URI SAN byte-equal to the subject (the rule identity.Sign already applies), the current time within its validity, and a key claims are verified with;
  3. looks up the _ans-badge.<host> TXT record, takes the one record for the subject's version (an exact match, else a versionless one; two candidates are an error), and accepts its URL only if it is https, names a host in trusted_log_hosts, and is exactly /v1/agents/{uuid} with a lowercase UUID;
  4. fetches the agent's status token from that log through utils/safefetch (no redirects, 64 KiB cap) and verifies it with the configured keys;
  5. requires the token to name the same agent and name, a status of ACTIVE, WARNING or DEPRECATED, and the certificate's SHA-256 fingerprint among its valid identity certificates;
  6. returns the certificate's public key.

Once #2174 registers the resolver, a verified result for an ans:// claim means: the claim was signed by the key of the certificate it carries; that certificate names the subject, is within its validity, and its fingerprint is listed as a valid identity certificate in a status token signed by a trusted transparency log for an agent whose name is the subject and whose status allows use. The certificate's issuer chain is not checked, the DNS pointer is not trusted, and the receipt and tree head are not checked. In unpinned mode the log's signing keys are fetched over TLS from the trusted host, so the proof reduces to TLS plus the log's own statement.

Failure semantics

The reconciler keeps a stored result for a while when a lookup fails for reasons that say nothing about the claim (isTransient), and stores a verdict otherwise. The resolver declares which is which:

  • The contract lives in the resolvers package: resolvers.Final(err) marks a failure as a verdict about the claim whatever its cause, and errors.Is(err, resolvers.ErrFinal) tells a caller so before it looks at the cause. Causes stay readable through errors.As. [Task]: Wire ANS resolver for verification #2174 adds that check as the first case of the reconciler's isTransient.
  • Verdicts: the subject's spelling; the certificate (missing, malformed, not naming the subject, outside its validity); what the badge record says (none for the version, more than one, a URL outside the gate); and what the log states or refuses to state: a terminal status, a token for another agent or name, a missing fingerprint, an expired or malformed token, a malformed /root-keys body in unpinned mode, a token signed by a key not in root_keys in pinned mode (fail closed; the error names the key id), and a 404, 410, 401, 403 or any other answer that is not a 5xx, 408, 429 or a redirect.
  • Left for the caller to classify by the cause: a DNS lookup that fails (SERVFAIL, a timeout, the local resolver being down), a trusted log that cannot be reached (a connection failure, a 5xx, 408 or 429, a redirect the client refuses to follow, the log budget's deadline), and the caller's own deadline. The reconciler treats them as for every other scheme: "no such host" is final, the rest is transient, and a redirect becomes transient when [Task]: Wire ANS resolver for verification #2174 updates isTransient. [Task]: Wire ANS resolver for verification #2174 also gives ans:// claims their own grace (identity.ans.stale_grace, default 24h) in place of the task's seven days, so a publisher who breaks their own DNS can delay a revocation by at most that grace, and makes the task skip storing a result when the task itself was interrupted.
  • The DNS stage and the log stage each get their own budget (timeout, default 10s) derived from the caller's context, so a slow zone cannot shorten the log's window. A hung trusted log therefore costs at most two timeouts per distinct subject per run; the circuit breaker stays a follow-up.
  • The attestation (badge target plus the log's statement) is memoized per subject for status_cache_ttl (default 30s, at least 5s, capped by the token's expiry), and claims that arrive while a subject's lookup is running wait for it, each under its own context. N claims for one subject, whoever attached them, in turn or at once, cost one DNS lookup and one log fetch between them. That TTL is the most a revocation can be delayed on top of the verification interval.

Every error starts with ans name:, ans certificate:, ans badge: or ans log:, so stored results stay comparable; a claim whose caller gives up while another claim's lookup of the same subject is running gets ans: waiting for the lookup of <subject>: <cause>.

Dependency (the open decision on #2170)

github.com/agentnameservice/ans-sdk-go is pinned at v0.1.19 in client/go.mod. Only its models and verify/scitt packages are imported; they link the standard library and github.com/fxamacker/cbor/v2, which was already in the module graph (bumped 2.9.2 to 2.9.4 and promoted to a direct requirement for the test fixtures). The SDK's verify package, which would link miekg/dns, is not imported: the ANS name and the badge record are parsed locally. A renovate rule groups github.com/agentnameservice/** bumps into their own PR, to be reviewed as trust-path changes. Dependent modules only see the cbor bump.

New takes WithLookupTXT, WithLogClient, WithFetcher and WithClock options, which the reconciler's tests use to drive the resolver with a fake DNS, a fake log and a moving clock.

Configuration

ansresolver.Config is what #2174 wires under reconciler.identity.ans:

Key Default Meaning
trusted_log_hosts required Transparency-log hosts (host or host:port) a badge record may point at; a log on a private address is refused by the SSRF-safe client
root_keys required unless unpinned The logs' signing keys, as the lines their /root-keys endpoint serves
allow_unpinned_root_keys false Fetch each log's keys from /root-keys instead; cannot be combined with root_keys
root_keys_ttl 10m How long fetched keys are used before they are fetched again
status_cache_ttl 30s How long a subject's attestation is reused across claims; at least 5s
timeout 10s Budget for each network stage of one lookup
clock_skew 30s Tolerance on the status token's expiry (at most 10m)

Not in this PR

Fixtures

testdata/ is a snapshot taken on 2026-09-11 from a local build of the Agent Name Service reference implementation (github.com/agentnameservice/ans) running its demo stack; the capture commands are in golden_test.go. The snapshot stands on its own: the golden tests pin the clock to the capture time and drive the real log client through a fake fetcher, pinned and unpinned, and mint_test.go mints equivalent material for every other test.

Commits

  1. feat(safefetch): add an option that refuses redirects
  2. chore(deps): group ans-sdk-go updates in renovate
  3. feat(client): add the ans identity key resolver (package, tests, fixtures, go.mod changes)

After the first review round:

  1. fix(ans): leave lookup failures to the task and mark terminal log answers final
  2. fix(ans): validate the status cache lifetime instead of flooring it
  3. perf(ans): share in-flight lookups and sweep the memo once per lifetime
  4. docs(ans): describe the fixture snapshot and the refusal of private logs

Verification

  • task lint over the client and utils modules with the pinned golangci-lint 2.13.2: 0 issues.
  • go test -race ./... in client and utils: pass. The new package and the resolvers package have 100% statement coverage.
  • go mod tidy -go=1.27.1 leaves every module unchanged.

Part of #2170. Closes #2173.

🤖 Generated with Claude Code

kperry-godaddy and others added 3 commits October 6, 2026 16:03
A resolver that fetches from an operator-trusted host must not let a 3xx
send the request anywhere else. WithoutRedirects makes the client hand the
3xx back to the caller as a StatusError instead of following it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: kperry <[email protected]>
The Agent Name Service SDK verifies ans:// identity claims, so its bumps
are reviewed as trust-path changes rather than folded into the Go patch
group. The rule is last so its group name wins over the patch grouping.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: kperry <[email protected]>
An ans:// subject publishes no key. The key is the public key of the
identity certificate the claim carries, trusted once the agent's
transparency log attests the certificate's fingerprint for the agent the
subject names. The resolver parses the canonical name, checks the
certificate's URI SAN and validity, follows the _ans-badge TXT record to a
log on the configured allow-list, fetches the agent's status token through
the SSRF-guarded client without following redirects, verifies it with the
pinned root keys (or the keys the log publishes, when unpinned mode is
configured), and returns the certificate's key.

Failures the publisher controls (the subject, the certificate, the DNS
record) are plain errors the reconciler treats as final; only a failure of
a trusted log while the caller is still waiting keeps its cause, so a
publisher cannot keep an earlier result alive by breaking their own DNS.
The DNS and log stages each get their own budget, and the attestation is
memoized per subject, so a stack of claims attached by anyone costs one
DNS lookup and one log fetch between them.

The SDK dependency is limited to its models and verify/scitt packages,
which link only fxamacker/cbor. The golden fixtures were captured from the
Agent Name Service reference implementation's demo stack.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: kperry <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Terminal-error classification and cache scalability and lifetime behavior do not yet satisfy the documented resolver contract.

Review effort: Balanced
Findings: 5 Medium severity · 1 Low severity

Open (6)
What changed in this PR

Adds ANS identity-key resolution using certificate validation, DNS badge discovery, and trusted transparency-log attestations.

Changes:

  • Implements the configurable ans:// resolver, caching, and final-error semantics.
  • Adds redirect refusal to SSRF-safe fetching.
  • Adds comprehensive fixtures/tests and pins ANS-related dependencies.
File Description
utils/​safefetch/​fetch.go Adds redirect refusal.
utils/​safefetch/​fetch_test.go Tests redirect behavior.
tests/​go.mod Updates CBOR dependency.
tests/​go.sum Updates dependency checksums.
renovate.json Groups ANS SDK updates.
reconciler/​go.mod Updates CBOR dependency.
reconciler/​go.sum Updates dependency checksums.
client/​utils/​identity/​resolvers/​resolvers.go Adds final-error contract.
client/​utils/​identity/​resolvers/​resolvers_test.go Tests final-error wrapping.
client/​utils/​identity/​resolvers/​ans/​testdata/​status-token.cbor Adds captured status token.
client/​utils/​identity/​resolvers/​ans/​testdata/​root-keys.txt Adds captured root key.
client/​utils/​identity/​resolvers/​ans/​testdata/​identity-cert.pem Adds captured certificate.
client/​utils/​identity/​resolvers/​ans/​testdata/​fixture.json Describes captured fixture.
client/​utils/​identity/​resolvers/​ans/​name.go Parses canonical ANS names.
client/​utils/​identity/​resolvers/​ans/​name_test.go Tests ANS names.
client/​utils/​identity/​resolvers/​ans/​mint_test.go Generates synthetic fixtures.
client/​utils/​identity/​resolvers/​ans/​log.go Fetches and verifies log tokens.
client/​utils/​identity/​resolvers/​ans/​log_test.go Tests log verification and caching.
client/​utils/​identity/​resolvers/​ans/​golden_test.go Tests captured ANS fixtures.
client/​utils/​identity/​resolvers/​ans/​fixtures_test.go Provides test doubles.
client/​utils/​identity/​resolvers/​ans/​config.go Defines resolver configuration.
client/​utils/​identity/​resolvers/​ans/​config_test.go Tests configuration validation.
client/​utils/​identity/​resolvers/​ans/​certificate.go Validates identity certificates.
client/​utils/​identity/​resolvers/​ans/​certificate_test.go Tests certificate validation.
client/​utils/​identity/​resolvers/​ans/​badge.go Resolves and validates DNS badges.
client/​utils/​identity/​resolvers/​ans/​badge_test.go Tests badge handling.
client/​utils/​identity/​resolvers/​ans/​ans.go Implements the ANS resolver.
client/​utils/​identity/​resolvers/​ans/​ans_test.go Tests resolver behavior.
client/​go.mod Adds ANS SDK and CBOR dependencies.
client/​go.sum Adds dependency checksums.
cli/​go.mod Updates CBOR dependency.
cli/​go.sum Updates dependency checksums.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@muscariello muscariello left a comment

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.

Clean resolver, and the URL gate and token checks hold up. I ran the tests with -race locally and read VerifyStatusTokenAt in the SDK. I agree with Copilot on the 5 s TTL floor and the missing fixture commit. The rest is inline: one decision (the SDK), two behaviours to settle before #2174, and small fixes.

Comment thread client/go.mod

require (
buf.build/gen/go/agntcy/oasf/protocolbuffers/go v1.36.12-20260928171943-6220fce8636b.2
github.com/agentnameservice/ans-sdk-go v0.1.19

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.

This settles the open decision on #2170 (depend on ans-sdk-go or write it ourselves). I read VerifyStatusTokenAt and found nothing wrong; the question is whether we want a v0.1.x vendor SDK in the trust path. @ramizpolic, can you call this on #2170 before we merge?

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.

Okay from my end here, as long as we are covered by renovate and tests to cover the functionality, both of which are already present in the PR.

if err != nil {
// Once the caller has given up, the failure is the caller's, not the log's.
if ctx.Err() != nil {
err = final(err)

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.

"Failed after the caller gave up" is stored as a verdict. reconcileRecord runs each record under a 1-minute deadline and stores any non-transient failure, so a shutdown or deadline mid-lookup turns a verified claim into failed until the next run (1 h by default). I'd have the task skip storing when its context is done. The slow-DNS case this rule guards against can be handled on its own.

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.

Agreed. b75b45b drops the rule: a lookup that ends because the caller's context did is left unmarked, like any other failure to reach the network, so the task classifies it by its cause. For #2174 the task will skip storing when its own context is done (a shutdown), while a record deadline stays on the transient path under the grace from the next thread, so the slow-DNS case is bounded by the grace rather than turned into a verdict.


txts, err := r.lookupTXT(ctx, recordName)
if err != nil {
return TrustedLog{}, final(fmt.Errorf("ans badge: lookup %s: %w", recordName, err))

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.

Every DNS error is final, including our own resolver being down. For other schemes a DNS failure other than not-found is transient. A kube-dns restart would flip every verified ans:// claim to failed for one interval. Suggest a short, configurable grace for ans in #2174 instead of final vs. the task's hard-coded 7 days.

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.

Agreed. b75b45b leaves DNS lookup errors unmarked, so the task classifies them as it does for dns: subjects ("no such host" is final, the rest transient); what the record says (none for the version, two of them, a URL outside the gate) stays a verdict. #2174 adds identity.ans.stale_grace, default 24h, in place of the task's seven days for ans:// claims: a publisher who breaks their own DNS can delay a revocation by at most that, and a kube-dns restart costs nothing.

func (c *scittLogClient) Status(ctx context.Context, log TrustedLog) (*Status, error) {
body, err := c.fetch.Get(ctx, log.Origin+"/v1/agents/"+log.AgentID+"/status-token")
if err != nil {
return nil, fmt.Errorf("ans log: fetch status token: %w", err)

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.

The description says 404, 410, 401 and 403 are final at the log, and that 3xx is not. Here none are marked. They end up final only because the reconciler's isTransient treats just 5xx/408/429 as transient, so a 3xx is also a failed verdict today. Please mark the terminal statuses Final here, add a 3xx test, and fix the description.

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.

Done in b75b45b: a 404, 410, 401, 403 or any answer that is not a 5xx, 408, 429 or a redirect is marked Final, for the status token and for /root-keys; redirects and transport failures are left for the task. Tests cover 301, 404, 403 and 429 on the token, 404 and 500 on the keys, and fetchError has its own table. The description now says a redirect becomes transient once #2174 updates isTransient.

AgentID: payload.AgentID,
Name: payload.AnsName,
State: State(payload.Status),
ExpiresAt: time.Unix(payload.Exp, 0),

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.

time.Unix(payload.Exp, 0) is never IsZero(), and the SDK rejects exp=0 as expired. So "zero means no expiry" and the IsZero check in recall are dead code. Remove them or fix the comment.

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.

Taken as you suggested in 339da05, with a test that a statement without an expiry is never reused.

trusted: trusted,
pinned: pinned,
lookupTXT: net.DefaultResolver.LookupTXT,
fetch: safefetch.New(safefetch.WithTimeout(cfg.GetTimeout()), safefetch.WithMaxBytes(maxResponseBytes), safefetch.WithoutRedirects()),

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.

safefetch refuses non-public addresses and has no override, so a log in a private network can't be used. Intended? If so, please say so in the config docs.

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.

Intended: the same SSRF guard as the other schemes, with no override. Stated on TrustedLogHosts in 13f26ee and in #2174's docs.

return attestation{}, false
}

if att.status != nil && !att.status.ExpiresAt.IsZero() && now.After(att.status.ExpiresAt.Add(r.cfg.GetClockSkew())) {

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.

Suggested change for the dead-code point above.

A correction to that comment: it is dead only for the shipped client. Status belongs to the public TrustedLogClient interface, so another client could return a zero ExpiresAt. With this change a zero value counts as already expired, which is harmless: the attestation is just never cached.

Suggested change
if att.status != nil && !att.status.ExpiresAt.IsZero() && now.After(att.status.ExpiresAt.Add(r.cfg.GetClockSkew())) {
if att.status != nil && now.After(att.status.ExpiresAt.Add(r.cfg.GetClockSkew())) {

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.

Applied in 339da05.

Comment on lines +52 to +53
// ExpiresAt is when the statement stops being valid; zero means it does
// not expire.

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.

Matching doc change, so the comment says what the code does.

Suggested change
// ExpiresAt is when the statement stops being valid; zero means it does
// not expire.
// ExpiresAt is when the statement stops being valid. The log's tokens
// always carry one, so a zero value counts as already expired.

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.

Applied in 339da05.

kperry-godaddy and others added 4 commits October 7, 2026 08:37
…wers final

A DNS lookup that fails and a trusted log that cannot be reached say
nothing about the claim, yet the resolver marked both as verdicts, so a
restart of the local resolver or a shutdown mid-run flipped every
verified ans:// claim to failed until the next run. Both are now left for
the task to classify by their cause, as for every other scheme. What the
zone says and what the log states remain verdicts.

A 404, 410, 401 or 403 from the log, or any other answer that is not a
server-side failure, a timeout, rate limiting or a redirect, was left
unmarked and ended up final only through the task's own list. It is now
marked where the contract is declared.

Addresses review on agntcy#2300.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
A status_cache_ttl under five seconds was silently raised to five at run
time, so an operator who read the field as the most a revocation can be
delayed got more than they set. The minimum is now part of validation,
as MinStatusCacheTTL, and the configured value is used as it is.

The expiry check on a kept statement also tested for a zero time that
the log client never produces. A zero expiry now counts as already
expired, so such a statement is never reused.

Addresses review on agntcy#2300.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claims of one subject that arrived while its lookup was running each
started their own, so a burst still cost a DNS lookup and a log fetch
per claim; the memo only served the claims that came after. They now
wait for the lookup in flight, each under its own context: a waiter
whose caller gives up returns at once, and when the leading caller
gives up, a waiter still waiting runs the lookup itself.

Every insertion into the memo also scanned every entry, which is
quadratic in the subjects verified within one lifetime. An expired entry
is now dropped when a claim asks for it, and the rest are swept once per
lifetime.

Addresses review on agntcy#2300.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
The golden test said fixture.json records the reference commit the
capture ran at. It never did once that field went, so the comment now
says what the snapshot is and why it stands on its own. The config
states that the SSRF-safe client refuses a log on a private address,
which the resolver inherits by design.

Addresses review on agntcy#2300.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kperry-godaddy

Copy link
Copy Markdown
Contributor Author

Thanks @muscariello. Four commits address the inline threads, with a reply on each, and the description's failure-semantics section is rewritten to match. The two behaviours you asked to settle before #2174 are settled as you proposed: lookup failures are left to the task, which gets a short configurable grace for ans:// and skips storing when it was interrupted. The SDK call stays with @ramizpolic on #2170.

@ramizpolic

Copy link
Copy Markdown
Member

The SDK call is okay from my end, we already cover it via tests and renovate for tracking.

@ramizpolic ramizpolic left a comment

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.

LGTM

Comment on lines +66 to +68
func final(err error) error {
return resolvers.Final(err) //nolint:wrapcheck // the mark is the wrapping
}

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.

nit: is the reason here simply to pass lint checks for this method or we can use resolvers.Final instead of final here

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.

Lint only: resolvers.Final(err) returns an error from another package, so wrapcheck wanted a wrap around it, and the helper held the one exception. #2304 calls resolvers.Final directly and tells wrapcheck in .golangci.yml that Final is the wrapping.

Comment on lines +300 to +303
dnsCtx, cancelDNS := context.WithTimeout(ctx, r.cfg.GetTimeout())
target, err := r.lookupBadge(dnsCtx, name)

cancelDNS()

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.

nit: handle context cancellation explicitly

Suggested change
dnsCtx, cancelDNS := context.WithTimeout(ctx, r.cfg.GetTimeout())
target, err := r.lookupBadge(dnsCtx, name)
cancelDNS()
dnsCtx, cancelDNS := context.WithTimeout(ctx, r.cfg.GetTimeout())
defer cancelDNS()
target, err := r.lookupBadge(dnsCtx, name)

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.

there are similar approaches on other places, its not an issue, but it is easier to handle if the contexts are not reused

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.

Taken in #2304: both stage budgets are released with defer.

@ramizpolic
ramizpolic added this pull request to the merge queue Oct 8, 2026
Merged via the queue into agntcy:main with commit 3f8dc02 Oct 8, 2026
34 checks passed
vivekkrishna pushed a commit to vivekkrishna/dir that referenced this pull request Oct 13, 2026
* docs(resolvers): state the one rule for a final error

The ErrFinal doc still told a resolver to mark a failure observed after
the caller gave up as a verdict, the rule the ans resolver dropped in
b75b45b. A resolver following it would store a failed result on every
shutdown mid-lookup. The doc now states the one rule: a verdict is about
what the resolver can judge; a failure to reach the network, the
caller's own deadline included, is left unmarked.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* refactor(safefetch): let a StatusError say whether a retry may help

The ans resolver and the reconciler's identity task each kept their own
list of the HTTP statuses that say nothing about the resource (5xx, 408,
429, a redirect), so a change to one would have drifted from the other
without a test failing. The rule now lives with the type that carries the
code, as StatusError.Transient, and the resolver uses it; the task follows
in the wiring change.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(ans): judge an answer that the badge name does not exist

An authoritative answer that _ans-badge.<host> does not exist is what the
zone says, not a failure to reach it, yet it was left for the task to
classify, so the package's contract held only through the task's own
rule for a not-found DNS error. It is now a verdict here, like a name
that answers without a badge record. The badge-URL host echoed in an
error is now bounded like every other text taken from DNS.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(ans): give a waiter that gave up its own cause

A claim waiting on another claim's lookup of the same subject got the
leader's error when both callers had given up, so its stored cause could
name the leader's cancellation rather than its own deadline. A waiter now
reports its own context's error whenever its context is done, and runs
the lookup itself only while it is live.

The in-flight tests move into a testing/synctest bubble: the waiter is
parked before the leader gives up, so the take-over path is the one
exercised, fake time replaces the wall-clock deadlines, and a revoked
verdict is shown reaching every waiter from one log fetch.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* refactor(ans): take the review nits on agntcy#2300

The resolver called resolvers.Final through a local helper that existed
only to hold one wrapcheck exception; the linter is now told that Final
wraps, and the package calls it directly. The budgets of the two network
stages are released with defer, as elsewhere, instead of by hand after
each stage.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* feat(identity): require a certificate on ans:// claims

An ans:// subject, like a spiffe:// one, is proven by the certificate the
claim carries rather than by a published key. identity.NeedsCertificate
names both schemes and identity.Check applies the rule: those claims need a
certificate, every other claim must not carry one, since the certificate
sits outside the signed payload and could be grafted on from elsewhere.

Client.claim now runs identity.Check after signing instead of repeating the
rule, so a claim the reconciler would refuse is never pushed. The dirctl
help, the proto comments and the tests cover ans:// alongside spiffe://.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: kperry <[email protected]>

* feat(reconciler): verify ans:// claims through the ans resolver

The identity task gains an ans resolver, built when the new
reconciler.identity.ans block is enabled and routed to by forSubject; while
the block is off an ans:// claim fails as an unsupported scheme. The block
carries the resolver's own settings (trusted logs, pinned or fetched root
keys, lifetimes, timeout, clock skew) and is checked at startup: a record
may carry an ans:// identity claim and an ans:// ownership claim, each
taking two of the resolver's timeouts, and all of that must fit the record
budget; and the resolver's memo of a subject must expire between runs.

isTransient learns two things: a failure the resolver marked with
resolvers.Final is never transient, whatever cause it carries; and an HTTP
answer that says nothing about the resource is, judged by safefetch's
StatusError.Transient so that the task and the resolver share one list. An
ans:// result outlives lookups that get no answer (the publisher's DNS,
the trusted log) for identity.ans.stale_grace, 24 hours by default,
rather than the task's seven days, since the publisher's own DNS is among
those lookups: a publisher who breaks their own DNS delays a revocation by
at most that. The grace sits in the resolver set beside the scheme
dispatch. A run stopped mid-lookup stores no failure for the claim it was
on, for every scheme, and reports the interruption.

The run summary logs its duration and how many results were kept through
transient failures, the startup line names the trusted logs, the pinned
keys and the grace, and unpinned mode is called out. The keys take a
comma-separated value from the environment, in the reconciler and under
dirctl daemon; the samples and Helm values carry the block, off by default.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: kperry <[email protected]>

* docs(dir): describe the ans identity scheme

The identity page gains the ans:// subject: what the claim carries, the
shape of the badge record, how the transparency log attests the
certificate, what a verified result proves and does not prove, which
failures are final and which are transient, how the log's keys are pinned
or fetched, the time budget, the configuration keys and the log lines to
watch. The CLI reference, the trust-model and Go SDK pages, the publishing
skill, the reconciler README and the changelog follow. The word "ans"
joins the codespell ignore list.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: kperry <[email protected]>

* test(reconciler): cover a record whose annotations cannot be read

The path that leaves stored results alone when the record itself cannot
be pulled had no test, and the one line this change touched in it was
the patch's only uncovered line.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* refactor(identity): name the subject schemes in one place

Which scheme a subject is spelled in, whether its claims carry a
certificate, which resolver finds its keys and how long a stored result
survives lookups that get no answer were each decided by their own list
of prefixes, in the client package and in the reconciler, with a test to
catch them drifting apart. The client package now owns the schemes:
Scheme, SchemeOf and Scheme.NeedsCertificate, with the certificate rule's
error text built from the same table. The reconciler keeps one entry per
scheme (resolver and grace) keyed by it, so adding a scheme is one line
in each place that has something to say about it.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(ans): forget the memo between runs

The resolver's memo of a subject's attestation outlived a run: an entry
made late in one run was still fresh when the next began, so a revocation
could wait a run longer than the documented status_cache_ttl, and the
startup rule tying the lifetime to the interval only narrowed the gap.
The resolver can now be told to Forget, the task tells every resolver
that keeps answers when a run starts, and the lifetime is what it says:
how long an answer is reused within a run. The interval rule goes.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(reconciler): let a zero stale_grace keep nothing

An operator who wanted no grace for ans:// results could not ask for it:
zero meant the 24-hour default, in the config loaders and again in the
task, so the documented workaround was a value of one second. Zero now
keeps nothing, and the default lives only where defaults belong, in the
reconciler's and the daemon's viper defaults.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* feat(ans): name a signing key that is not pinned, once per run

A transparency log that rotates its key fails every ans:// claim it
attests until the operator pins the new key, and that is the right
outcome of pinning, but the only sign of it was a failed result per
claim. The resolver now names the cause (ErrUnpinnedRootKey) under the
verdict mark, and the identity task warns once per run until the key is
pinned. root_keys already takes several keys; the docs now say to pin the
next key beside the current one so a rotation has no gap, and a test
shows a token signed by either pinned key verifies.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* docs(dir): say what a stored result is about and what turning ans off does

Two questions from review: a kept result outlives the claim that produced
it, and turning the ans block off fails every ans:// result. Both are
intended, and the page now says so: a result is about the record's
declared subject, not one claim, and a scheme the task cannot verify does
not keep its results.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(reconciler): keep the unpinned-key warning on one line

The warning about a signing key root_keys does not hold logged the
resolver's error as it came, and that text carries the key id the log's
token named. CodeQL (go/log-injection) flagged it: a remote party's text
with a line break in it could forge a log entry. The text is now kept on
one line before it is logged.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Signed-off-by: kperry <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: Add ANS resolver

4 participants