Skip to content

feat: add agent API key lifecycle - #6071

Open
danielkov wants to merge 4 commits into
daniel/aim-193-feat-enforce-live-agent-credential-admissionfrom
daniel/aim-194-agent-api-key-lifecycle
Open

feat: add agent API key lifecycle#6071
danielkov wants to merge 4 commits into
daniel/aim-193-feat-enforce-live-agent-credential-admissionfrom
daniel/aim-194-agent-api-key-lifecycle

Conversation

@danielkov

@danielkov danielkov commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds issue, list, rotate, and direct revoke lifecycle support for first-class agent API keys through the existing keys API and api_keys model. Agent keys carry immutable delegated policy and authorizer attribution, required expiry, one-time secrets, transactional audit history, and parent-authoritative runtime admission.

Motivation

AIM-194 requires independently revocable, least-privilege credentials for first-class agents without introducing a parallel credential model or transport.

Impact

Agent credential issuance, listing, and rotation remain behind the M2 organization feature gate; direct revocation remains available when the gate is disabled. Legacy API-key creation, listing, authentication, and revocation remain isolated from principal-backed rows.

Technical details

Atomic replacement

Rotation revokes the old key before creating its replacement in one transaction, which supports same-name replacement while rolling back revocation and audit writes if creation fails.

Stacked dependency

Depends on #6068 for live parent, owner, and delegated-policy admission semantics.


Summary by cubic

Adds agent API-key issue, list, rotate, and revoke lifecycle through the existing keys API, satisfying AIM-194. Agent keys reuse the api_keys model as ordinary rows with immutable delegated policy, required expiry, and parent-authoritative admission.

  • Each agent key records the issuing human as its permanent authorizer and requires expiry (90-day default, one-year cap).
  • Issuance accepts only grants no broader than the agent's live policy via strict selector matching.
  • Rotation (POST /rpc/keys.rotate) revokes the old row and creates a replacement in one atomic operation with freshly approved delegation.
  • Issuance, listing, and rotation require the per-organization M2 feature flag, which fails closed; direct revocation stays available when the flag is off.
  • Legacy keys and the existing agent/agent_user transport scopes keep prior behavior.
  • Agent-key rollout must wait for AIM-199's integrated safety gate to pass.
  • Depends on AIM-193 for live parent, owner, and delegated-policy admission semantics.

Written for commit c3b93e1. Summary will update on new commits.

Review in cubic

@danielkov
danielkov requested a review from a team as a code owner September 4, 2026 10:24
@linear-code

linear-code Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

AIM-194

@changeset-bot

changeset-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c3b93e1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Running ultrareview automatically — This PR introduces a complete agent API-key lifecycle with delegated policy, atomic rotation, expiry enforcement, and audit, spanning authentication, database, and generated API layers — a subtle bug could break authorization or leak credentials, so it warrants a deep multi-pass review.. I'll post findings when complete.

@blacksmith-sh

This comment has been minimized.

@cubic-dev-ai cubic-dev-ai Bot 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.

Ultrareview completed in 13m 9s

All reported issues were addressed across 25 files

Linked issue analysis

Linked issue: AIM-194: feat: add agent API-key lifecycle on existing API keys

Status Acceptance criteria Notes
⚠️ Agent keys use ordinary api_keys rows and existing key generation, hashing, lookup, one-time display, and revocation behavior without a new key format. The PR adds agent-key persistence alongside existing API-key flows and documents reuse of the existing format, but the provided diff does not show all generation and display paths.
Issue, list, rotate, and direct-revoke lifecycle operations are available for first-class agent keys. The PR adds agent-aware payloads, a rotate endpoint, generated client/server support, and an agent-key implementation covering the lifecycle.
⚠️ Agent-key issuance enforces agent identity, tenant and owner eligibility, caller authority, delegated-policy constraints, supported version, and required expiry with a 90-day default and one-year maximum. The agent-key implementation and expanded request types indicate these validations, but the supplied diff does not expose enough validation code or test cases to verify every rejection condition.
⚠️ Owner and exact agent:authorize caller matrices deny unauthorized callers, including agents, ordinary API keys, support sessions, and cross-tenant callers, without existence disclosure. Dedicated agent-key tests and authorization dependencies are present, but the provided excerpts do not show the complete denial matrix or response behavior.
⚠️ Rotation atomically creates a replacement with newly approved delegation and authorizer while directly revoking the old key. The PR explicitly claims transactional replacement and direct revocation, and adds the rotate endpoint, but the transaction and old-row revocation details are not visible in the supplied excerpts.
⚠️ Authentication uses live agent admission and rejects malformed, expired, revoked, cross-tenant, or parent-blocked agent keys while preserving legacy null-principal behavior. The PR describes parent-authoritative runtime admission and isolates legacy queries from principal-backed rows, but the supplied diff does not show the full authentication-path checks.
Agent credential management is gated for issuance, listing, and rotation, while direct revocation remains available with the gate disabled and production rollout waits for the integrated safety gate. The PR explicitly describes the M2 gate behavior and adds the corresponding feature flag.

Tip: instead of fixing issues one by one fix them all with cubic

Re-trigger cubic

Comment thread server/internal/keys/agent_keys.go
Comment thread server/design/keys/design.go Outdated
Comment thread server/internal/keys/agent_keys.go
Comment thread server/internal/keys/agent_keys.go
Comment thread server/internal/keys/impl.go Outdated
Comment thread server/design/keys/design.go
@danielkov
danielkov requested a review from a team as a code owner September 4, 2026 10:47

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 25 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread server/internal/keys/agent_keys_test.go Outdated
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

atlas migrate lint on server/migrations

Status Step Result
3 new migration files detected 20260903215231_aim-183-agent-principals.sql
20260904020443_owner_lookup_indexes.sql
20260904023314_aim-191-delegated-agent-credential-columns.sql
ERD and visual diff generated View Visualization
No issues found View Report
Read the full linting report on Atlas Cloud

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

atlas migrate lint on server/clickhouse/migrations

Status Step Result
No migration files detected  
ERD and visual diff generated View Visualization
No issues found View Report
Read the full linting report on Atlas Cloud

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.

1 participant