Title: bug: token allow-list with a specific template ID returns 500 "column reference \"id\" is ambiguous" · Issue #32059 · coder/coder · GitHub
Open Graph Title: bug: token allow-list with a specific template ID returns 500 "column reference \"id\" is ambiguous" · Issue #32059 · coder/coder
X Title: bug: token allow-list with a specific template ID returns 500 "column reference \"id\" is ambiguous" · Issue #32059 · coder/coder
Description: Is there an existing issue for this? I have searched the existing issues Current Behavior When testing API-token allow-lists, a token whose allow-list names a specific template (template:
Open Graph Description: Is there an existing issue for this? I have searched the existing issues Current Behavior When testing API-token allow-lists, a token whose allow-list names a specific template (template: X Description: Is there an existing issue for this? I have searched the existing issues Current Behavior When testing API-token allow-lists, a token whose allow-list names a specific template (template:<templa...
Opengraph URL: https://github.com/coder/coder/issues/32059
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bug: token allow-list with a specific template ID returns 500 \"column reference \\\"id\\\" is ambiguous\"","articleBody":"### Is there an existing issue for this?\n\n- [x] I have searched the existing issues\n\n### Current Behavior\n\nWhen testing API-token allow-lists, a token whose allow-list names a specific template (`template:\u003ctemplate-uuid>`) gets an HTTP 500 from any request that runs the authorized templates query. Workspace creation with the same token succeeds. Reading the workspace back afterwards fails, because building the workspace response loads templates through `GetAuthorizedTemplates`.\n\nThe same token with `template:*` instead works.\n\n### Relevant Log Output\n\n```shell\nGET /api/v2/workspaces/\u003cworkspace-id>\n500 {\"message\":\"Internal error fetching workspace resources.\",\"detail\":\"get templates: pq: column reference \\\"id\\\" is ambiguous\"}\n```\n\n### Expected Behavior\n\nRequests for templates named in the token's allow-list are authorized normally (here, `GET /api/v2/workspaces/\u003cworkspace-id>` returns 200), and templates outside the allow-list are filtered out.\n\n### Steps to Reproduce\n\n1. As an admin, create a regular user `\u003cuser>` with the default Member role in the default organization.\n2. Create a scoped token for that user with a template-specific allow-list:\n ```\n coder tokens create --user \u003cuser> --lifetime 1d \\\n --scope coder:workspaces.create --scope coder:workspaces.access \\\n --allow template:\u003ctemplate-uuid> \\\n --allow workspace:* \\\n --allow organization_member:\u003cuser-uuid>\n ```\n3. With that token, `POST /api/v2/users/\u003cuser>/workspaces` using a version of `\u003ctemplate-uuid>`. This returns 201.\n4. With that token, `GET /api/v2/workspaces/\u003cworkspace-id>`. This returns the 500 above.\n5. Repeat with `--allow template:*` instead of `--allow template:\u003ctemplate-uuid>`. Step 4 then returns 200.\n\n### Root cause\n\n`TemplateConverter()` in `coderd/rbac/regosql/configs.go` registers `resourceIDMatcher()`, which emits an unqualified column:\n\n```go\nfunc resourceIDMatcher() sqltypes.VariableMatcher {\n\treturn sqltypes.StringVarMatcher(\"id :: text\", []string{\"input\", \"object\", \"id\"})\n}\n```\n\n`GetAuthorizedTemplates` in `coderd/database/modelqueries.go` appends the compiled filter to `GetTemplatesWithFilter`, which joins a second table that also has an `id` column:\n\n```sql\nSELECT t.*\nFROM template_with_names AS t\nLEFT JOIN template_versions tv ON t.active_version_id = tv.id\nWHERE ...\n```\n\nThe ID predicate is only emitted when the allow-list names a specific template ID. That is why wildcard allow-lists, and tokens without allow-lists, are not affected. The same converter already qualifies the organization column (`t.organization_id :: text`), so the likely fix is a template-qualified ID matcher in `TemplateConverter`, such as `t.id :: text`. A regression test that compiles a non-wildcard template allow-list against this query would cover it.\n\n### Workaround\n\nUse `--allow template:*`. The token can then read and use any template the user's role can already access, so pinning to one template has to be enforced by the client.\n\n### Environment\n\n- Host OS: macOS (arm64), Coder server with built-in PostgreSQL\n- Coder version: v2.38.7. The same code is present in v2.39.1 and on `main` at 1126533c3169aaea7b44824363375edbf480a742 (`resourceIDMatcher` and `TemplateConverter` in `coderd/rbac/regosql/configs.go`, `GetTemplatesWithFilter` in `coderd/database/queries/templates.sql`).\n\n### Additional Context\n\nThe issue occurs consistently. Possibly related to the broader compiled-SQL audit in #25982, but this is a specific query failure rather than an ACL semantics difference.\n","author":{"url":"https://github.com/factory-brandon-callender","@type":"Person","name":"factory-brandon-callender"},"datePublished":"2026-11-11T16:49:01Z","url":"https://github.com/coder/coder/issues/32059"}
react-profiling 0 react-import-map react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 route-pattern /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) route-controller voltron_issues_fragments route-action issue_layout fetch-nonce v2:962947f9-9538-5b68-e3e6-35c02be2bed3 current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id D316:291B58:9D33570:C8EA953:6B042D96 html-safe-nonce 222d3648d36f48497dced5e2381d94c3f4de3170858c93fd7d6556c535dfc1f4 visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzE2OjI5MUI1ODo5RDMzNTcwOkM4RUE5NTM6NkIwNDJEOTYiLCJ2aXNpdG9yX2lkIjoiMTk3MjQ0NzQ1NDU1NzM4NDA4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 visitor-hmac 49f694263541e6e461f56620b115b13f86cd5a52fd445a09bb752dd09b3c621c hovercard-subject-tag issue:6333065993 github-keyboard-shortcuts repository,issues,copilot google-site-verification Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I octolytics-url https://collector.github.com/github/collect analytics-location / fb:app_id 1401488693436528 apple-itunes-app app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/coder/coder/32059/issue_layout twitter:image https://opengraph.githubassets.com/cc572e67dce7018702dc428f531cb9728e5d6686ee3e58588208c9fc8f4fc606/coder/coder/issues/32059 twitter:card summary_large_image og:image https://opengraph.githubassets.com/cc572e67dce7018702dc428f531cb9728e5d6686ee3e58588208c9fc8f4fc606/coder/coder/issues/32059 og:image:alt Is there an existing issue for this? I have searched the existing issues Current Behavior When testing API-token allow-lists, a token whose allow-list names a specific template (template: og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username factory-brandon-callender hostname github.com expected-hostname github.com None b7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e turbo-cache-control no-preview go-import github.com/coder/coder git https://github.com/coder/coder.git octolytics-dimension-user_id 95932066 octolytics-dimension-user_login coder octolytics-dimension-repository_id 440752086 octolytics-dimension-repository_nwo coder/coder octolytics-dimension-repository_public true octolytics-dimension-repository_is_fork false octolytics-dimension-repository_network_root_id 440752086 octolytics-dimension-repository_network_root_nwo coder/coder turbo-body-classes logged-out env-production page-responsive disable-turbo false browser-stats-url https://api.github.com/_private/browser/stats browser-errors-url https://api.github.com/_private/browser/errors release c3dd496c3da6ea6b77e69c09279d2b81604654f1 ui-target full theme-color #1e2327 color-scheme light dark react-app-name issues
Response headers:
Server github.com Content-Type text/html; charset=utf-8 Cache-Control max-age=0, private, must-revalidate
URLs of crawlers that visited me.