Skip to content

fix(coderd): qualify template ID in RBAC SQL filter - #32103

Draft
stirby wants to merge 1 commit into
mainfrom
fix/issue-32059-template-id-ambiguous
Draft

stirby wants to merge 1 commit into
mainfrom
fix/issue-32059-template-id-ambiguous

Conversation

@stirby

@stirby stirby commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

A token whose allow-list names a specific template (template:<uuid>) got a 500 from anything that loads templates through GetAuthorizedTemplates, for example GET /api/v2/workspaces/<id>, failing with pq: column reference "id" is ambiguous.

TemplateConverter used the shared resourceIDMatcher(), which emits an unqualified id :: text. GetTemplatesWithFilter joins template_versions, which also has an id column. The ID predicate only appears when the allow-list names a concrete ID, so wildcard allow-lists were unaffected. The converter now emits t.id :: text, matching the existing t.organization_id matcher.

Adds a DB regression test that runs GetAuthorizedTemplates with a single-template allow-list against Postgres (fails on main with the ambiguous-column error), plus a regosql compile case.

Fixes #32059

Implementation notes
  • Only TemplateConverter is changed. Other converters that still use the unqualified resourceIDMatcher() and back queries with joins could hit the same error with a specific-ID allow-list. AuditLogConverter (audit log queries join users, organizations, workspaces, workspace_builds) and ConnectionLogConverter (join users, organizations) look likely. AIBridgeInterceptionConverter may be affected too. These are unverified and left for a follow-up.
  • Checks run: go test ./coderd/rbac/regosql/..., targeted ./coderd/database tests (TestGetAuthorizedTemplatesAllowList, TestGetTemplatesWithAgentsAllowedFilter), ./coderd/database/dbauthz, ./coderd/rbac, go vet, golangci-lint.

Generated by Coder Agents on behalf of @stirby.

TemplateConverter used the unqualified "id :: text" resource ID matcher,
but GetTemplatesWithFilter joins template_versions, which also has an id
column. A token allow-list naming a specific template therefore made
GetAuthorizedTemplates fail with `column reference "id" is ambiguous`.
Qualify the ID as "t.id", matching the existing t.organization_id.

Fixes #32059
@stirby
stirby temporarily deployed to main November 12, 2026 17:51 — with GitHub Actions Inactive
@stirby
stirby temporarily deployed to main November 12, 2026 17:51 — with GitHub Actions Inactive

This branch was previously deployed

1 inactive deployment
main — e44d95df Deployed Nov 12, 2026 by stirby via cla #255120
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.

bug: token allow-list with a specific template ID returns 500 "column reference \"id\" is ambiguous"

1 participant