Skip to content

refactor(dir): prepare feat/identity-add for the ans scheme (ANS-1) - #2211

Closed
kperry-godaddy wants to merge 7 commits into
agntcy:feat/identity-addfrom
kperry-godaddy:ans1-identity-prep
Closed

kperry-godaddy wants to merge 7 commits into
agntcy:feat/identity-addfrom
kperry-godaddy:ans1-identity-prep

Conversation

@kperry-godaddy

@kperry-godaddy kperry-godaddy commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

ANS-1 of the #2170 series: this is #2171, one commit per item, plus the one-line fix that lets task gen run on this branch. Nothing here is specific to the ans scheme; every commit stands on its own against feat/identity-add.

Commit #2171 item Change
fix(proto): restore the naming/v1 go_package override until #2126 removes the protos — proto/buf.gen.yaml lost the managed go_package entry for agntcy/dir/naming/v1 while the naming protos are still present, so buf generate fails and CI's Verify job (and everything downstream of it) is red on this branch.
fix(cli): accept a key-only identity claim 1 --key and --cert were marked required together, so the command's own first example failed flag validation. --key is required on its own; --cert stays optional.
fix(config): bind the identity task keys from the environment and show the task in the samples 2 identity.enabled and identity.interval were bound in neither the reconciler nor the daemon, so RECONCILER_IDENTITY_* and the daemon's equivalents were inert unless the key appeared in the file. The samples show the task as a live enabled: false block. Item 2 asks for a sample that enables it; that waits for the GetRecords annotation preload raised on #2125, because at this base the task marks every claim failed on its first run. The server binary has no identity key with an environment form at this base (spiffe_trust_domains is a map), so its binding lands with the ans keys in #2174.
refactor(server,reconciler): extract the identity wiring and clear the reconciler lint findings 3 server.New and registerTasks failed the pinned linter (maintainability, cognitive complexity, nesting); the identity wiring moves into newIngestor and newIdentityTask. The duplicated identity/ownership reconcile loops share one helper. No behaviour change.
refactor(api): share the certificate-signer loader and report certificate expiry 4 One loader for every certificate-backed signer: key/certificate match, DER size bound, key type allowlist (CheckSigningKey, with RSA bounded to 2048–8192 bits), validity window. SpiffeSigner gains NotAfter() (exported as CertificateExpiry) and the CLI prints when a certificate-backed claim stops verifying. The SPIFFE verifier bounds the embedded certificate before decoding. Behaviour changes, please confirm: NewSpiffeSigner rejects a mismatched key, an oversized or expired certificate and an unsupported key type; NewKeySigner rejects unsupported key types at load time instead of at signing; and because CheckSigningKey is the same allowlist VerifyJWS derives the algorithm from, RSA keys outside 2048–8192 bits and embedded certificates over 16 KiB no longer verify for any scheme.
chore(deps): tidy the reconciler and tests modules 5 sigstore/sigstore becomes a direct requirement of the reconciler (it is imported directly); three stale indirect requirements leave the tests module. Pre-existing churn, isolated here so the ans PRs' dependency diffs are exactly their own modules.
fix(utils): simplify the safefetch scheme check for the pinned linter — The next module CI lints after reconciler is utils, where a staticcheck finding (QF1001) in the scheme gate of safefetch.Get stopped the run; it came in with the base branch. The condition is rewritten with De Morgan's law, behaviour unchanged, and a table test pins the gate: https and, when allowed, http reach the dialer; every other scheme is rejected first.

Verification

CI on this branch skips Build and Test until Verify and Lint are green. Verify is green from this PR's first commit. Lint runs whole modules in the order reconciler, utils, server, client, tests, api, cli and stops at the first red one; this PR clears reconciler and utils, and the 25 findings left in server and api are #2125's, requested there. Until they land, the results below are from the pinned toolchain locally.

  • task gen: passes with no generated diff (fails on the base). task deps:tidy: no diff in any module.
  • Lint (golangci-lint 2.13.2, whole module, as CI runs it): cli 0 issues, reconciler 0 issues (4 on the base), utils 0 issues (1 on the base). api 2, both pre-existing: the verifyClaim nesting that the registry PR restructures, and a whitespace nit in referrer_test.go, which this PR does not touch. server 23, all pre-existing in files this PR does not touch; server.go's own maintainability finding is cleared. The 25 in server and api are listed on feat(identity): record identity/ownership verifiable claims #2125 (note).
  • Tests: go test -race ./... in api, cli, reconciler, server: 72 packages, all passing.
  • Coverage on new code: every new or changed function at 100% (loadKeyAndCertificate, CheckSigningKey, jwsAlgorithmFor, NewSpiffeSigner, NotAfter, expiryNotice, loadSigner, bindIdentityEnv, registerReconcilerDefaults, newIngestor, reconcileClaim and its two wrappers) except one unreachable error return in newIdentityTask (94.7%) and the two-line expiry print inside runClaim, which needs a live client.

🤖 Generated with Claude Code

kperry-godaddy and others added 6 commits September 28, 2026 16:16
… removes the protos

feat/identity-add dropped the managed go_package entry for
agntcy/dir/naming/v1 while the naming protos and their generated Go
code are still present, so buf generate cannot determine a Go import
path for them and task gen fails on every branch built on it. The
entry comes back until the protos are removed together with naming.v1.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: kperry <[email protected]>
A claim signed with a plain key, the command's own first example, failed flag validation because --key and --cert were declared required together. --key is required on its own; --cert is optional, applies to spiffe:// subjects only and needs the key it certifies.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…w the task in the samples

Neither the reconciler loader nor the daemon loader bound identity.enabled
or identity.interval, and no shipped configuration file mentions the task,
so viper's AutomaticEnv never resolved RECONCILER_IDENTITY_* or
DIRECTORY_DAEMON_RECONCILER_IDENTITY_*: the keys took effect only when a
configuration file happened to contain them, and the task could not be
enabled from the environment at all. Both loaders bind the two keys, with
the task off by default and the reconciler defaulting the interval to the
task's own default.

The compose environment, the daemon configuration and the Helm values show
the block commented out. It stays off because the task does not yet read
record annotations and marks every claim failed at this base.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…e reconciler lint findings

server.New and Service.registerTasks each built the identity claim
verification dependencies inline: the SPIFFE trust bundles and the
resolver registry for dns, https and did subjects. That block now lives in
one helper per composition root, newIngestor in the server and
newIdentityTask in the reconciler, each with its own table-driven test.
The extraction is behaviour-preserving: the same constructors run in the
same order with the same error text, and the unchanged callers only gain
an early return on the helper's error.

The identity reconciler task's two claim walkers were duplicates of each
other apart from the referrer type, the proto type and the role. A generic
reconcileClaim now carries the shared walk, decode, verify and upsert flow
for both, with the two exported verify functions passed as values; the
per-kind log and error text is preserved verbatim, and a table-driven test
covers both roles, undecodable referrers and walk and upsert failures.

This clears every finding of the pinned golangci-lint in the reconciler
module: gocognit (32) and nestif (6) on registerTasks and the dupl pair in
tasks/identity/task.go. In the server module it clears the maintidx
finding on New; the remaining findings there are pre-existing in files this
change does not touch. No functional change.

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

NewSpiffeSigner loads its key and certificate through loadKeyAndCertificate, which holds the checks every certificate-backed signer needs: the key must match the certificate's public key, the certificate must fit in 16 KiB of DER, the key type must be one claims can be signed with, and the certificate's validity window must contain the current time. Each of these is a behaviour change for SPIFFE signers: a mismatched key, an oversized certificate, an unsupported key type such as P-521, or an expired or not-yet-valid certificate is refused at load instead of producing a claim that never verifies. A verifier applies the same 16 KiB bound to the certificate embedded in a SPIFFE claim before decoding and parsing it.

CheckSigningKey exposes the key allowlist signers and verifiers share; NewKeySigner applies it at load, so an unsupported key is refused before any claim is signed instead of failing at the first Sign call. jwsAlgorithmFor accepts RSA keys of 2048 to 8192 bits only: smaller moduli are too weak to sign claims and larger ones make verification a denial-of-service vector. Because VerifyJWS derives the algorithm through the same function, RSA keys outside that range and embedded certificates over 16 KiB no longer verify for any scheme.

SpiffeSigner implements the exported CertificateExpiry interface, and after a certificate-backed claim is pushed the claim command prints when the claim stops verifying and that it must be pushed again once the certificate is renewed, with the remaining lifetime rounded to minutes so short-lived SVIDs read correctly. A plain key signer prints nothing.

No existing test relied on inputs the loader now refuses; the SPIFFE test helper only loses its named returns. Lint debt in the edited files is cleared: named returns and an unwrapped signer error in sign, and the string-pointer helper that new(expr) replaces.

Signed-off-by: kperry <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
sigstore/sigstore is imported directly by the reconciler's name task
but was listed as indirect; three requirements the tests module no
longer uses remain listed. Both are pre-existing tidy drift on
feat/identity-add, isolated here so the ans scheme's dependency diffs
carry only their own modules.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: kperry <[email protected]>
@kperry-godaddy
kperry-godaddy requested a review from a team as a code owner September 29, 2026 03:10
@github-actions github-actions Bot added the size/L Denotes a PR that changes 1000-1999 lines label Sep 29, 2026
CI lints whole modules and stops at the first red one. With ./reconciler
clean, it now stops at ./utils on a staticcheck finding in the scheme gate
of safefetch.Get (QF1001, De Morgan's law). The condition is rewritten
without the negated conjunction; behaviour is unchanged, and a table test
pins the gate: https and, when allowed, http pass through to the dialer,
every other scheme is rejected before any network activity.

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

Copy link
Copy Markdown
Contributor Author

Closing: superseded by the identity rework on main. The two defects this PR fixed (the key-only claim, the RECONCILER_IDENTITY_* bindings) are fixed there, and the rest belonged to the removed server/identity design. The ans:// work continues against the new resolver contract in #2300 (#2173), with the wiring to follow for #2174; see #2170.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 1000-1999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant