Skip to content

fix(coderd): list endpoints return 500 for API keys with ID-scoped allow lists - #32145

Merged
ksrinija merged 5 commits into
mainfrom
sk/core-780
Nov 18, 2026
Merged

ksrinija merged 5 commits into
mainfrom
sk/core-780

Conversation

@ksrinija

@ksrinija ksrinija commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Note

This PR was generated by Coder Agents on behalf of @ksrinija.

Ticket Link

Fixes CORE-780

Description

List endpoints returned 500 with pq: column reference "id" is ambiguous for API keys whose scope has an ID-scoped allow list (for example --allow template:<uuid>). The SQL authorization filters for workspaces, templates, audit logs and connection logs used the shared resourceIDMatcher(), which emits an unqualified id. Their list and count queries join other tables that also have an id column. The ID check is only generated for specific IDs, so wildcard allow lists (template:*) and tokens without allow lists were not affected.

This PR qualifies the column in each affected converter in coderd/rbac/regosql/configs.go: workspaces.id, t.id, audit_logs.id and connection_logs.id. This follows the existing pattern used by chatResourceIDMatcher() (chats_expanded.id) and ChatModelConfigConverter (cmc.id).

Decision log
  • Inline qualified matchers instead of changing resourceIDMatcher(). Other converters share the helper and query different tables and aliases, so no single prefix inside it is correct for all of them.
  • Remaining converters checked; none affected. UserConverter, MCPServerConfigConverter and OrganizationSkillConverter filter single-table queries. AIBridgeInterceptionConverter's queries either read one table or join subqueries that do not expose an id column. NoACLConverter and DefaultVariableConverter are only used in tests. This was checked against the query SQL, not run against Postgres.
  • AIBridgeInterceptionConverter must keep a bare id. Its queries refer to the table both as aibridge_interceptions and by the alias ai, so qualifying it with either name would break the others.
  • Possible follow-up, not in scope: change resourceIDMatcher() to take a column argument so each converter names its column explicitly. Pending team discussion.
  • Tests: string-match cases in compile_test.go document the exact SQL each converter generates, and need no database fixtures. A Postgres-backed test (TestAllowListIDScopedListEndpoints) also runs all 4 affected queries, so a later alias or join change that breaks the qualified column is caught. Both were kept after review discussion.

Testing Done

  • SQL generation tests: added WorkspaceAllowList, TemplateAllowList, AuditLogAllowList and ConnectionLogAllowList to TestRegoQueries in coderd/rbac/regosql/compile_test.go. Each compiles an ID-scoped allow list with the affected converter and checks the exact generated SQL.
  • Postgres regression test: added TestAllowListIDScopedListEndpoints in coderd/database/dbauthz/allowlist_test.go. It runs GetWorkspaces, GetTemplatesWithFilter, GetAuditLogsOffset and GetConnectionLogsOffset against Postgres with the real RBAC authorizer and an allow list naming one row of each type. Each subtest checks that the query succeeds and returns only the allow-listed row, out of two. This catches future alias or join changes that the string tests cannot.
  • Confirmed both tests catch the bug: with configs.go reverted to main, all 4 TestRegoQueries cases fail because the generated SQL contains the bare id, and all 4 Postgres subtests fail with pq: column reference "id" is ambiguous. With the fix, all pass.
  • Existing tests: go test ./coderd/rbac/... ./coderd/database/dbauthz/... passes.
  • Lint: the repo's pre-commit checks (make pre-commit, including golangci-lint) pass.
  • CI: <fill in once checks finish on e64c7f69c9>

…low lists

The SQL authorization filters for workspaces and templates matched the
resource ID against an unqualified "id" column. When an API key scope
has an ID-scoped allow list, the compiled filter references that
column, and the workspace and template list queries join other tables
with an "id" column. Postgres rejects the query with 'column reference
"id" is ambiguous', so the list endpoints return 500.

Qualify the column as workspaces.id in WorkspaceConverter and t.id in
TemplateConverter. Add a Postgres-backed regression test that lists
workspaces and templates with an ID-scoped allow list.

Fixes CORE-780
@ksrinija
ksrinija temporarily deployed to main November 12, 2026 23:38 — with GitHub Actions Inactive
@linear-code

linear-code Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

CORE-780

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@ksrinija

Copy link
Copy Markdown
Collaborator Author

I have read the CLA Document and I hereby sign the CLA

cdrci2 added a commit to coder/cla that referenced this pull request Nov 12, 2026
@ksrinija
ksrinija temporarily deployed to main November 13, 2026 00:01 — with GitHub Actions Inactive
@ksrinija
ksrinija temporarily deployed to main November 13, 2026 00:44 — with GitHub Actions Inactive
@ksrinija
ksrinija temporarily deployed to main November 13, 2026 00:51 — with GitHub Actions Inactive
@ksrinija
ksrinija temporarily deployed to main November 13, 2026 16:25 — with GitHub Actions Inactive
@ksrinija
ksrinija temporarily deployed to main November 13, 2026 16:25 — with GitHub Actions Inactive
@ksrinija
ksrinija temporarily deployed to main November 13, 2026 16:36 — with GitHub Actions Inactive
@ksrinija
ksrinija temporarily deployed to main November 13, 2026 16:44 — with GitHub Actions Inactive
@ksrinija

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review Please limit the review to P0, P1, and P2 issues only.

@coder-agents-review

coder-agents-review Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-11-13 16:54 UTC by @ksrinija
Spend: $8.58 / $100.00

Review history
  • R1 (2026-11-13): 13 reviewers, COMMENT. Review

deep-review v0.13.0 | Round 1 | e6a57f3..e9685cd

Last posted: Round 1, no findings, COMMENT. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P4 Dropped by orchestrator (below the P0-P2 threshold the author requested; query verified working at head by 6 reviewers) +coderd/rbac/regosql/configs.go:45 No test runs GetAuthorizedWorkspacesAndAgentsByOwnerID with an ID-scoped allow list R1 Bisky P4, Mafu-san Note No
CRF-2 Nit Dropped by orchestrator (downgraded from P2: wording only, no behavior consequence; below requested threshold) +coderd/database/dbauthz/allowlist_test.go:20 Test doc comment first sentence restates the body R1 Gon P2 No
CRF-3 Nit Dropped by orchestrator (downgraded from P2: wording only; "the others" is accurate for one workspace plus one template) +coderd/database/dbauthz/allowlist_test.go:29 Setup comment repeats allow list contents R1 Gon P2 No
CRF-4 P4 Dropped by orchestrator (below requested threshold) +coderd/database/dbauthz/allowlist_test.go:23 Test name says Endpoints but tests store queries R1 Gon No
CRF-5 P4 Dropped by orchestrator (below requested threshold) +coderd/rbac/regosql/configs.go:31 TemplateConverter hardcodes t alias without naming the query R1 Gon No
CRF-6 P3 Dropped by orchestrator (below requested threshold; one sentence in review body) +coderd/rbac/regosql/configs.go:31 PR title says "list endpoints" and states the bug; fix covers workspaces and templates only R1 Razor Note, Leorio Nit No
CRF-7 OOS Out of scope (body) coderd/rbac/regosql/configs.go:130 AuditLogConverter unqualified id; audit log list and count return ambiguous column error R1 Mafu-san P2, Pariston P3, Netero, Knuckle, Kurapika, Ryosuke, Mafuuu, Bisky, Leorio, Razor, Kite No
CRF-8 OOS Out of scope (body) coderd/rbac/regosql/configs.go:144 ConnectionLogConverter unqualified id; connection log list and count return ambiguous column error R1 Mafu-san P2, Pariston P3, Netero, Knuckle, Kurapika, Ryosuke, Mafuuu, Bisky, Razor, Kite No
CRF-9 OOS Out of scope (body) coderd/rbac/regosql/configs.go:5 resourceIDMatcher emits unqualified id; no test executes compiled filters for the remaining converters; follow-up has no ticket R1 Leorio P3, Ryosuke, Razor, Bisky, Gon, Knuckle, Kurapika, Mafuuu No
CRF-10 OOS Out of scope (body) coderd/rbac/regosql/configs.go:17 userOwnerMatcher emits unqualified owner_id R1 Gon No

Contested and acknowledged

None.

Round log

Round 1

Full panel (round 1). Netero: no findings. Law not run (74 effective additions). Panel: ging-go, knuckle, kurapika, ryosuke (domain specialists: Go, Go/SQL boundary, RBAC); pariston, mafuuu (core); bisky, gon, leorio, komugi, razor, mafu-san (pool); kite (wildcard). Multi-domain target 9-12 because the change is RBAC authorization SQL; 12 plus wildcard.
Author comment requested P0, P1, and P2 issues only. No in-scope finding at P2 or above after cross-check. Mafu-san's P2 (audit and connection log converters) moved to out of scope: other instances of the same problem in unchanged functions; the PR description limits the fix to workspaces and templates. Keep-argument recorded: same user-facing 500 as the ticket, reproduced by 8 reviewers, two-line fix in the same file, untracked. Gon's two P2 comment-wording findings downgraded to Nit (no behavior consequence). P3 and below not posted per the author's request.
Reviewed against e6a57f3..e9685cd.

Law analysis

Not run. Effective additions 74.

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
Komugi flake/determinism
Kurapika security
Law decomposition
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.

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

This PR qualifies the id matcher in WorkspaceConverter and TemplateConverter, so the workspace and template list queries no longer fail with column reference "id" is ambiguous for API keys with ID-scoped allow lists. No P0, P1, or P2 findings.

Lower-severity findings are omitted as requested. One of them affects the merged commit: the title says "list endpoints", but the audit log and connection log list endpoints still return this 500 (first two items below), so a title scoped to workspaces and templates keeps the changelog accurate.

Out of scope (needs a ticket or explicit acceptance by a human):

  • coderd/rbac/regosql/configs.go:130: AuditLogConverter emits unqualified id. GetAuditLogsOffset and CountAuditLogs return pq: column reference "id" is ambiguous for an API key whose allow list holds an audit_log:<uuid> or *:<uuid> entry (reproduced), so the audit log list endpoint returns 500 for that key.
  • coderd/rbac/regosql/configs.go:144: ConnectionLogConverter emits unqualified id. GetConnectionLogsOffset and CountConnectionLogs return the same error for a connection_log:<uuid> or *:<uuid> entry (reproduced), so the connection log list endpoint returns 500 for that key.
  • coderd/rbac/regosql/configs.go:5: resourceIDMatcher() emits unqualified id, and no test executes the compiled filters of the converters that still use it. A query that later joins a table with an id column returns the same 500; if the target table has no id column, the filter compares against the joined table's ID with no error. The decision log defers this to a follow-up with no linked ticket, so this needs a human decision.
  • coderd/rbac/regosql/configs.go:17: userOwnerMatcher() emits unqualified owner_id and WorkspaceConverter still uses it. A join that adds a table with an owner_id column produces the same ambiguity error.

🤖 This review was automatically generated with Coder Agents.

@ksrinija
ksrinija marked this pull request as ready for review November 13, 2026 19:35
@ksrinija
ksrinija temporarily deployed to main November 13, 2026 19:35 — with GitHub Actions Inactive
@ksrinija
ksrinija requested review from a team and BobbyHo November 13, 2026 19:41
BobbyHo
BobbyHo previously approved these changes Nov 13, 2026

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

Nice fix! One small thing I noticed: the same issue seems to affect the audit log and connection log lists, as AuditLogConverter and ConnectionLogConverter still use the unqualified resourceIDMatcher(). Not a blocker, but I wonder if it might be worth addressing those here as well, or perhaps in a follow-up PR.

@ksrinija

Copy link
Copy Markdown
Collaborator Author

Nice fix! One small thing I noticed: the same issue seems to affect the audit log and connection log lists, as AuditLogConverter and ConnectionLogConverter still use the unqualified resourceIDMatcher(). Not a blocker, but I wonder if it might be worth addressing those here as well, or perhaps in a follow-up PR.

i think it's a small enough change so i can roll it into this PR!

…ters

AuditLogConverter and ConnectionLogConverter matched the resource ID
against an unqualified "id" column. The audit log and connection log
list and count queries join users, organizations and other tables that
also have an "id" column, so an ID-scoped allow list makes the compiled
filter ambiguous. Qualify the column as audit_logs.id and
connection_logs.id.

Replace the Postgres-backed regression test with string-matching cases
in TestRegoQueries for the workspace, template, audit log and connection
log converters. Each case fails without the qualified column.

Refs CORE-780
@ksrinija

Copy link
Copy Markdown
Collaborator Author

I have read the CLA Document and I hereby sign the CLA

@ksrinija

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review Please limit the review to P0, P1, and P2 issues only.

@ksrinija
ksrinija requested a review from BobbyHo November 16, 2026 18:17
BobbyHo
BobbyHo previously approved these changes Nov 16, 2026

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

Thanks for adding the audit log and connection log fixes!

Just one small question: I noticed that the database test (allowlist_test.go) was removed in the latest commit. I was curious if there was a particular reason for removing it. I thought it was useful to have a test that actually runs the queries, since the new string-based tests might not catch future changes to aliases or joins.

I wonder if there might still be some value in keeping both, but happy to go with your approach. Not a blocker at all!

…st Postgres

Restore the Postgres-backed TestAllowListIDScopedListEndpoints and
extend it to the audit log and connection log list queries. The
string-matching cases in TestRegoQueries check the generated SQL, but
only running the queries catches a later alias or join change that
makes the qualified column invalid or ambiguous again.

Each subtest fails with 'column reference "id" is ambiguous' without
the qualified ID matchers.

Refs CORE-780
@ksrinija

Copy link
Copy Markdown
Collaborator Author

@BobbyHo i accidentally removed that test file when i updated the PR to include fixes for AuditLogConverter and ConnectionLogConverter! Added it back

@ksrinija
ksrinija temporarily deployed to main November 16, 2026 18:56 — with GitHub Actions Inactive

@BobbyHo BobbyHo 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, Thanks for addressing my comments.

@ksrinija
ksrinija temporarily deployed to main November 16, 2026 23:27 — with GitHub Actions Inactive
@ksrinija
ksrinija merged commit 05d8c8d into main Nov 18, 2026
31 of 32 checks passed
@ksrinija
ksrinija deleted the sk/core-780 branch November 18, 2026 14:58
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 18, 2026
@ksrinija ksrinija added backport backport/v2.39 Backport PR targeting release/2.39 labels Nov 18, 2026
@ksrinija ksrinija removed the backport label Nov 18, 2026

This branch had an error being deployed

1 failed and 1 inactive deployments
main — e64c7f69 Deployed Nov 18, 2026 by ksrinija via Backport to release/2.37 #7129
docs-preview — e64c7f69 Deployed Nov 18, 2026 by ksrinija via cleanup #209
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backport/v2.39 Backport PR targeting release/2.39

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants