Skip to content

feat: add AI Gateway coderd key CRUD endpoints - #25565

Merged
pawbana merged 10 commits into
mainfrom
pb/gateway-multi-replica-key-auth-endpoints
Jun 3, 2026
Merged

pawbana merged 10 commits into
mainfrom
pb/gateway-multi-replica-key-auth-endpoints

Conversation

@pawbana

@pawbana pawbana commented May 21, 2026 •

Copy link
Copy Markdown
Collaborator

Adds create, list and delete endpoints for AI Gateway keys used to authenticate into Coderd.
All endpoints require Owner permission.

@github-actions

Copy link
Copy Markdown
Contributor

Docs preview

📖 View docs preview for docs/reference/api/enterprise.md

pawbana commented May 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-db-queries branch from 07965bc to 4809647 Compare May 21, 2026 13:14
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch 2 times, most recently from 0815067 to a5a848b Compare May 21, 2026 13:30
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-db-queries branch from 4809647 to 68caa22 Compare May 21, 2026 13:30
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch from a5a848b to 67fff61 Compare May 21, 2026 14:35
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-db-queries branch from 68caa22 to 09af228 Compare May 21, 2026 14:35
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch from 67fff61 to 7d951c2 Compare May 21, 2026 15:57
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-db-queries branch from 09af228 to 9851434 Compare May 21, 2026 15:57
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch 2 times, most recently from e6e5378 to 3649959 Compare May 21, 2026 16:47
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-db-queries branch 2 times, most recently from 2702dec to ae89f52 Compare May 21, 2026 17:04
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch from 3649959 to 6bb4bb7 Compare May 21, 2026 17:04
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-db-queries branch from ae89f52 to 56911cf Compare May 21, 2026 17:42
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch from 6bb4bb7 to 03d293f Compare May 21, 2026 17:42
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-db-queries branch from 56911cf to 4a8ae2b Compare May 21, 2026 17:54
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch 3 times, most recently from cbb96c5 to 575f979 Compare May 22, 2026 09:34
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-db-queries branch from 4c654bf to f397e3c Compare May 22, 2026 09:34
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch from 575f979 to eae6f67 Compare May 22, 2026 13:48
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-db-queries branch from f397e3c to b932b20 Compare May 22, 2026 13:48
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch from eae6f67 to cf66448 Compare May 22, 2026 15:09
@pawbana

pawbana commented May 22, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-06-02 13:42 UTC by @pawbana
Spend: $83.49 / $112.56

Review history
  • R1 (2026-05-22), 1 Nit, 1 P1, 1 P2, COMMENT. Review
  • R2 (2026-05-22), 2 Nit, 1 P1, 2 P2, COMMENT. Review
  • R3 (2026-05-22): 20 reviewers, 4 Nit, 1 P1, 4 P2, 3 P3, COMMENT. Review
  • R4 (2026-05-22): 6 reviewers, 5 Nit, 1 P1, 4 P2, 4 P3, COMMENT. Review
  • R5 (2026-06-02), 5 Nit, 1 P1, 4 P2, 4 P3, COMMENT. Review
  • R6 (2026-06-02): 4 reviewers, 6 Nit, 1 P1, 4 P2, 4 P3, APPROVE. Review

deep-review v0.6.1 | Round 6 | 32aee9e..03eddf0

Last posted: Round 6, 15 findings (1 P1, 4 P2, 4 P3, 6 Nit), APPROVE. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P1 Author fixed (225e14577f) aigatewaycoderdkey.go:31 GenerateSecret(KeyLength) produces 43 random chars; prepending "cgw_" yields 47, not 43. Hash mismatch on future validation. R1 Netero Yes
CRF-2 P2 Author fixed (225e14577f) aigatewaycoderdkeys.go:34 Swagger @router annotations missing /api/v2 prefix; generated docs show wrong URLs R1 Netero Yes
CRF-3 Nit Author fixed (225e14577f) aigatewaycoderdkeys.go:24 Double space in nameFormatDetail user-facing string R1 Netero Yes
CRF-4 P2 Author fixed (e2e898d184d2) aigatewaycoderdkeys.go:35 Create and delete handlers do not emit audit events despite audit table registration R2 Netero Yes
CRF-5 Nit Author fixed (e2e898d184d2) aigatewaycoderdkeys.go:14 "an standalone" should be "a standalone" in doc comment R2 Netero Yes
CRF-6 P2 Author fixed (a3c0764) aigatewaycoderdkey.go:31 Hash covers unprefixed random string; no unit test or Validate function documents this contract R3 Bisky P2, Hisoka P3, Chopper P3, Kurapika P3, Ryosuke P3, Knov P3, Meruem P3, Razor P2 Yes
CRF-7 P2 Author fixed (a3c0764) aigatewaycoderdkeys_test.go:42 Audit events from CRF-4 fix are untested; sibling features have audit test files R3 Mafu-san P2, Chopper P2, Bisky P3 Yes
CRF-8 P3 Author fixed (a3c0764) aigatewaycoderdkeys_test.go:176 FeatureGate test asserts require.Error without verifying 403 status code R3 Bisky P3, Chopper P3, Kite P4 Yes
CRF-9 P3 Author fixed (a3c0764) aigatewaycoderdkeys.go:204 Delete handler uses httpapi.Write for 204; sends JSON body violating RFC 7231 R3 Meruem Yes
CRF-10 P3 Author fixed (a3c0764) aigatewaycoderdkeys_test.go:25 aibridgeEnabledOpts duplicates aibridgeOpts from aibridge_test.go in same package R3 Robin P3, Zoro Nit Yes
CRF-11 Nit Author fixed (a3c0764) aigatewaycoderdkeys.go:175 "Invalid key ID" missing trailing period; inconsistent with sibling messages R3 Leorio Yes
CRF-12 Nit Author fixed (a3c0764) aigatewaycoderdkeys.go:24 Missing doc comment on CreateAIGatewayCoderdKeyRequest; breaks pattern from sibling types R3 Leorio Yes
CRF-13 P3 Author fixed (03eddf07cf22) aigatewaycoderdkeys_test.go:88 ListResponseDoesNotLeakSecrets checks "secret" and "hashed_secret" but not "key" (the actual plaintext field name) R4 Bisky Yes
CRF-14 Nit Author fixed (03eddf07cf22) querier_test.go:14693 preExsiting typo (should be preExisting) R4 Mafuuu, Gon Yes
CRF-15 Nit Open aigatewaykeys.go:125 Swagger @id list-ai-gatewaykeys inconsistent with hyphenated sibling IDs R6 Netero Yes

Contested and acknowledged

(none)

Round log

Round 1

Netero-only. 1 P1, 1 P2, 1 Nit. Reviewed against 535c9cda87bd..13719f7701b9.

Round 2

Netero-only. CRF-1, CRF-2, CRF-3 addressed. 1 P2, 1 Nit new. Reviewed against 535c9cda87bd..225e14577f3d.

Round 3

Panel (20 reviewers). CRF-4, CRF-5 addressed. 2 P2, 3 P3, 2 Nit new. Reviewed against f412d7fc42c8..e2e898d184d2.

Round 4

Panel (6 reviewers). CRF-6 through CRF-12 addressed. 1 P3, 1 Nit new. No open P0-P2. Reviewed against 9275dcf..a3c0764.

Round 5

BLOCKED. CRF-13 (P3) and CRF-14 (Nit) silent. No review.

Round 6

Panel (4 reviewers). CRF-13 and CRF-14 addressed. 1 Nit new (Netero). No open P0-P3. Reviewed against 32aee9e..03eddf07cf22.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Kurapika security
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-db-queries branch from 0fa846e to 889b7a6 Compare June 2, 2026 09:39
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch 2 times, most recently from 27909af to e08ef69 Compare June 2, 2026 10:52
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-db-queries branch from 889b7a6 to 324ac9d Compare June 2, 2026 10:52
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch from e08ef69 to bc98d05 Compare June 2, 2026 11:03
Base automatically changed from pb/gateway-multi-replica-key-auth-db-queries to main June 2, 2026 11:25
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch from bc98d05 to c6ab060 Compare June 2, 2026 11:26
@pawbana

pawbana commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review 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.

Round 5 blocked. Two findings from R4 have no author response or code fix.

CRF-13 (P3): ListResponseDoesNotLeakSecrets checks for "secret" and "hashed_secret" but not "key" (the actual JSON field for the plaintext key). The rename commit (c6ab0602) updated types but did not modify the leak test assertions.

CRF-14 (Nit): preExsiting typo in querier_test.go. The rename commit changed the type name but left the misspelled variable name across five references.

Further review is blocked until the author responds to or addresses these findings. A reply acknowledging, contesting, or fixing each is sufficient to unblock.

🤖 This review was automatically generated with Coder Agents.

@pawbana

pawbana commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review 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.

Round 6 panel review (4 reviewers). All 14 prior findings verified fixed. CRF-13 and CRF-14 (which blocked R5) confirmed resolved in 03eddf07.

The PR has been through 6 rounds of review across 4 panel sessions (20, 6, 6, and 4 reviewers). 14 findings raised and addressed, including a P1 key-length/hash mismatch (CRF-1), missing audit events (CRF-4/CRF-7), an implicit hash contract that 8 reviewers converged on (CRF-6), and an RFC 7231 violation (CRF-9). The author adopted Razor's structural alternative for the hash contract, eliminating the prefix-stripping ambiguity entirely. Test coverage is thorough: unit test for key generation with positive and negative hash validation, audit test with real Postgres backend and diff-level assertions, RBAC/feature-gate/validation/leak-detection integration tests.

1 Nit remaining (CRF-15, swagger operation ID inconsistency). Non-blocking.

"This is a genuine test suite. Every test proves behavior. Nothing is costume jewelry." Bisky, admiring the stones.

🤖 This review was automatically generated with Coder Agents.

Comment thread enterprise/coderd/aigatewaykeys.go Resolved
pawbana added 7 commits June 2, 2026 14:35
Adds POST / GET / DELETE handlers for /api/v2/aibridge/coderd-keys
under the existing AI Bridge feature gate. Create returns the plaintext
secret exactly once (cgw_<random>... format); list returns metadata plus
a short non-secret token_prefix so admins can correlate keys with the
daemons presenting them. Delete identifies keys by UUID in the path and
is idempotent.
@pawbana
pawbana force-pushed the pb/gateway-multi-replica-key-auth-endpoints branch from d365992 to 2f6ac7f Compare June 2, 2026 14:36
@pawbana
pawbana marked this pull request as ready for review June 2, 2026 16:05
Comment thread coderd/aigatewaykey/aigatewaykey.go Resolved
Comment thread coderd/aigatewaykey/aigatewaykey.go Resolved
Comment thread coderd/aibridge/keys/keys.go Resolved
Comment thread enterprise/coderd/aigatewaykeys.go Resolved
Comment thread enterprise/coderd/aigatewaykeys_test.go Resolved
Comment thread enterprise/coderd/aigatewaykeys_test.go Resolved
Comment thread enterprise/coderd/aigatewaykeys_test.go Resolved
require.Equal(t, http.StatusBadRequest, resp.StatusCode)

// Delete existing key -> 204 (SDK returns nil error on 204).
created, err := ownerClient.CreateAIGatewayKey(ctx, codersdk.CreateAIGatewayKeyRequest{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also missing the status code assertions here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You could also add a 204 check here to match the comment.

Comment thread enterprise/coderd/aigatewaykeys_test.go Resolved

@dannykopping dannykopping left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

require.Equal(t, http.StatusBadRequest, resp.StatusCode)

// Delete existing key -> 204 (SDK returns nil error on 204).
created, err := ownerClient.CreateAIGatewayKey(ctx, codersdk.CreateAIGatewayKeyRequest{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You could also add a 204 check here to match the comment.

@pawbana
pawbana merged commit 96e3a64 into main Jun 3, 2026
31 checks passed
@pawbana
pawbana deleted the pb/gateway-multi-replica-key-auth-endpoints branch June 3, 2026 11:50
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants