Skip to content

feat(server): add claims storage, identity status API and claim search filters - #2257

Merged
ramizpolic merged 6 commits into
mainfrom
feat/identity-04-claims-api
Oct 2, 2026
Merged

ramizpolic merged 6 commits into
mainfrom
feat/identity-04-claims-api

Conversation

@ramizpolic

@ramizpolic ramizpolic commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Fourth PR in the identity/ownership claims epic (#2212), after #2221 (claim types), #2223 (signing and verification) and #2242 (key resolvers), all merged. Adds the read side of claim verification: where the last result of each claim is stored, how to read it, and how to search on it.

Nothing writes the table yet. This PR creates the schema and the readers only; the reconciler task that verifies claims and writes results is a separate PR. No resolver or SPIFFE wiring, and server/ingest is untouched.

Storage

identity_claims holds the last verification result of a record's claim, one row per (record_cid, role) (composite primary key), with subject, status (verified or failed), error and verified_at. subject and status are indexed for the search filters. The table is created by the existing AutoMigrate and cascades with the record, like scan_reports and name_verifications, so removing a record removes its claim results.

UpsertIdentityClaim (the writer the reconciler will call) rejects an unknown role or status, and fills verified_at if it is unset. GetIdentityClaimByCID returns ErrIdentityClaimNotFound when there is no row.

IdentityService

A new read-only agntcy.dir.identity.v1.IdentityService, registered in server.go only:

  • GetIdentityStatus(cid | name [, version]) returns the identity and owner results. A claim with no result yet is left unset: that is not an error. A name resolves to its latest version unless a version is given.
  • Resolve(name [, version]) returns all versions of a name newest first, or the specific version.

The service is independent of NamingService: it has its own name lookup (a name without an http:// or https:// prefix also matches its prefixed forms, as NamingService.Resolve does), and naming.go is not touched, so NamingService can be removed without affecting it.

Search filters

Four new RecordQueryTypes on search/v1, handled by the server query builder and exposed in dirctl search:

Query type dirctl search Matches
IDENTITY --identity the subject of the record's identity claim; wildcards
OWNER --owner the subject of the record's ownership claim; wildcards
IDENTITY_VERIFIED --identity-verified the identity claim has a verified result
OWNER_VERIFIED --owner-verified the ownership claim has a verified result

Each filter is role-scoped: an owner subject never matches --identity. They compile to correlated EXISTS subqueries on identity_claims, so a record is never duplicated.

These filters only look for what is there. The claim subject filters have no --exclude- twin, and the two verified filters have no =false form: records without a verified claim are not something to search for. --identity-verified=false is ignored by the CLI, and the server rejects a negated subject query or a verified query with any value but true rather than reading it as something else.

Notes

  • DatabaseAPI gains a sub-interface (IdentityClaimDatabaseAPI), which takes it to 11 embedded methods; I added //nolint:interfacebloat with the reason. Fakes that implement the whole interface (one in reconciler/tasks/signature) gain the two new methods.
  • The generated code (api/identity/v1/identity_service*.pb.go, api/search/v1/record_query.pb.go) is from buf generate with the pinned buf 1.66.1; no other generated file changed.
  • I did not add the new service to the example authz policies in the OpenShift chart/docs: they list individual methods per deployment and don't list NamingService either.

Contains

  • proto/agntcy/dir/identity/v1/identity_service.proto, proto/agntcy/dir/search/v1/record_query.proto (+ generated api/)
  • server/database/gorm/identity_claims.go, server/types/identity.go, server/types/database.go, server/types/search.go
  • server/database/gorm/record.go, migration.go, server/database/utils/utils.go (filters)
  • server/controller/identity.go, server/server.go
  • cli/cmd/search/filters.go, search.go, and docs/content/dir/dir-cli-reference.md

Verification

go build, go vet, go test and golangci-lint (0 issues) pass for server, cli and reconciler, and go build/go vet for api, client, utils and tests.

  • Storage: upsert replaces the row for the same (record, role) and keeps the other role; not found; invalid role and status rejected; verified_at defaulted; the rows go with the record.
  • Search: each of --identity, --owner, --identity-verified and --owner-verified has a test against a seeded claims table (a record with verified claims, a record with a failed identity claim, and one with none): exact and wildcard subjects, an owner subject not matching --identity and the reverse, combinations, and a count that does not double records with several matching claims.
  • API: GetIdentityStatus with no claims (no error), one claim, both claims, by CID, by name (latest and a given version), the CID taking precedence over a name, and the error codes. Resolve returns all versions newest first and the specific version.
  • Query conversion and CLI: the new query types, the rejected negated and false forms, and flag registration: no --exclude-identity / --exclude-owner, and =false on the claim verified flags adds no query.
  • I mutation-tested the SQL: swapping the role mapping and checking failed instead of verified each make a test fail.

Closes #2215

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow Buf CI / verify-proto (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped⏩ skipped✅ passedOct 2, 2026, 11:35 AM

@github-actions github-actions Bot added the size/L Denotes a PR that changes 1000-1999 lines label Oct 1, 2026
@ramizpolic
ramizpolic marked this pull request as ready for review October 1, 2026 14:22
@ramizpolic
ramizpolic requested a review from a team as a code owner October 1, 2026 14:22
@ramizpolic
ramizpolic requested review from csirmazbendeguz, lgecse and tkircsi and a balanced review from Copilot October 1, 2026 14:36

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

Claim responses can violate their error-field contract, and subject filtering cannot use its declared index.

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

Open (3)
What changed in this PR

Adds persisted identity/ownership verification results, a read-only identity API, and claim-aware search support.

Changes:

  • Adds claim-result storage and role-scoped search filters.
  • Introduces and registers IdentityService.
  • Exposes identity/owner filters through dirctl and documentation.
File Description
server/​types/​search.go Adds claim search filters.
server/​types/​identity.go Defines claim storage types and constants.
server/​types/​database.go Adds claim persistence API.
server/​server.go Registers IdentityService.
server/​database/​utils/​utils.go Converts claim queries into filters.
server/​database/​utils/​utils_test.go Tests query conversion.
server/​database/​identity_claims_test.go Tests storage and filtering.
server/​database/​gorm/​record.go Integrates claims and filters.
server/​database/​gorm/​migration.go Migrates the claims table.
server/​database/​gorm/​identity_claims.go Implements claim persistence and SQL filters.
server/​controller/​identity.go Implements identity RPCs.
server/​controller/​identity_test.go Tests identity RPC behavior.
reconciler/​tasks/​signature/​task_test.go Updates the database fake.
proto/​agntcy/​dir/​search/​v1/​record_query.proto Defines claim query types.
proto/​agntcy/​dir/​identity/​v1/​identity_service.proto Defines IdentityService.
docs/​content/​dir/​dir-cli-reference.md Documents new flags.
cli/​cmd/​search/​search.go Adds CLI examples.
cli/​cmd/​search/​filters.go Registers and builds claim filters.
cli/​cmd/​search/​filters_test.go Tests new CLI filters.
api/​search/​v1/​record_query.pb.go Regenerates search API types.
api/​identity/​v1/​identity_service.pb.go Generates identity messages.
api/​identity/​v1/​identity_service_grpc.pb.go Generates identity gRPC bindings.
Files not reviewed (3)
  • api/identity/v1/identity_service.pb.go: Generated file
  • api/identity/v1/identity_service_grpc.pb.go: Generated file
  • api/search/v1/record_query.pb.go: Generated file

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

Comment thread server/controller/identity.go Resolved
Comment thread server/database/gorm/identity_claims.go Resolved
Comment thread docs/content/dir/dir-cli-reference.md Resolved
@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.79661% with 57 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/database/gorm/identity_claims.go 19.6% 45 Missing ⚠️
server/types/search.go 0.0% 8 Missing ⚠️
server/controller/identity.go 94.2% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread server/types/search.go Resolved
Comment thread server/controller/identity.go Resolved
Comment thread server/controller/identity.go Resolved
@ramizpolic
ramizpolic added this pull request to stack #2268 October 2, 2026 08:30
@ramizpolic
ramizpolic requested a review from tkircsi October 2, 2026 09:01
tkircsi
tkircsi previously approved these changes Oct 2, 2026

@tkircsi tkircsi 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.

LGTM! Thanks!

…h filters

Add the identity_claims table keyed by (record_cid, role) with the last
verification result of a record's identity and ownership claims, a read-only
IdentityService (GetIdentityStatus, Resolve) over it, and the search filters
that read the same data (identity, owner, identity-verified, owner-verified)
on the search/v1 query types, the server query builder and dirctl search.

Nothing writes the table yet; the reconciler task will. The name lookup of
NamingService.Resolve moves into a helper shared with IdentityService.

Signed-off-by: Ramiz Polic <[email protected]>
Restore naming.go and give the identity controller its own name lookup, so
NamingService can be removed without touching IdentityService.

Signed-off-by: Ramiz Polic <[email protected]>
--exclude-identity and --exclude-owner, and --identity-verified=false and
--owner-verified=false, filtered on what is absent or unverified, which
nobody searches for. The claim subject filters keep their include form
only, and the claim verified filters keep only the true form. The server
rejects the negated and false queries instead of silently reading them.

Signed-off-by: Ramiz Polic <[email protected]>
GetIdentityStatus answers NotFound for a CID that is not a record instead
of an empty result, and only returns a reason for a failed claim. The
subject filters match on LOWER(subject), so index that instead of the
plain column. Drop a leftover Excluded.Owners field.

Signed-off-by: Ramiz Polic <[email protected]>
Measured on 200k records and 2k claims, the subject filter takes ~45ms
with no subject index, with the plain one, and with a functional
LOWER(subject) one: the planner drives the correlated EXISTS from records
and never uses any of them. The index only pays off if the query shape
changes, so it is left as it was.

Signed-off-by: Ramiz Polic <[email protected]>
@ramizpolic
ramizpolic force-pushed the feat/identity-04-claims-api branch from 3d05f18 to b74e23d Compare October 2, 2026 11:04
Build the dial options in a fresh slice instead of appending to the
caller-provided authOpts, which gocritic's appendAssign reports and wsl
wants separated from the connection setup.

Signed-off-by: Ramiz Polic <[email protected]>
@ramizpolic
ramizpolic added this pull request to the merge queue Oct 2, 2026
Merged via the queue into main with commit 56ced2a Oct 2, 2026
37 checks passed
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.

Feature: Add claims storage and identity status API

3 participants