bug: token allow-list with a specific template ID returns 500 "column reference \"id\" is ambiguous"
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 78/100
Rechercherichtung
Beginne mit TemplateConverter() in coderd/rbac/regosql/configs.go und GetAuthorizedTemplates in coderd/database/modelqueries.go; untersuche, wie der kompilierte Template-ID-Filter auf die verknüpfte Template-Abfrage angewendet wird. Füge einen Regressionstest für eine spezifische Allowlist von Template-IDs hinzu und verwende dafür den Query- oder Autorisierungstest, der diesen Pfad abdeckt. Fertig ist die Änderung, wenn die Abfrage erfolgreich ist und nur Templates zurückgibt, die durch das Token erlaubt sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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:<template-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.
The same token with template:* instead works.
Relevant Log Output
GET /api/v2/workspaces/<workspace-id>
500 {"message":"Internal error fetching workspace resources.","detail":"get templates: pq: column reference \"id\" is ambiguous"}
Expected Behavior
Requests for templates named in the token's allow-list are authorized normally (here, GET /api/v2/workspaces/<workspace-id> returns 200), and templates outside the allow-list are filtered out.
Steps to Reproduce
- As an admin, create a regular user
<user>with the default Member role in the default organization. - Create a scoped token for that user with a template-specific allow-list:
coder tokens create --user <user> --lifetime 1d \ --scope coder:workspaces.create --scope coder:workspaces.access \ --allow template:<template-uuid> \ --allow workspace:* \ --allow organization_member:<user-uuid> - With that token,
POST /api/v2/users/<user>/workspacesusing a version of<template-uuid>. This returns 201. - With that token,
GET /api/v2/workspaces/<workspace-id>. This returns the 500 above. - Repeat with
--allow template:*instead of--allow template:<template-uuid>. Step 4 then returns 200.
Root cause
TemplateConverter() in coderd/rbac/regosql/configs.go registers resourceIDMatcher(), which emits an unqualified column:
func resourceIDMatcher() sqltypes.VariableMatcher {
return sqltypes.StringVarMatcher("id :: text", []string{"input", "object", "id"})
}
GetAuthorizedTemplates in coderd/database/modelqueries.go appends the compiled filter to GetTemplatesWithFilter, which joins a second table that also has an id column:
SELECT t.*
FROM template_with_names AS t
LEFT JOIN template_versions tv ON t.active_version_id = tv.id
WHERE ...
The 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.
Workaround
Use --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.
Environment
- Host OS: macOS (arm64), Coder server with built-in PostgreSQL
- Coder version: v2.38.7. The same code is present in v2.39.1 and on
mainat 1126533c3169aaea7b44824363375edbf480a742 (resourceIDMatcherandTemplateConverterincoderd/rbac/regosql/configs.go,GetTemplatesWithFilterincoderd/database/queries/templates.sql).
Additional Context
The 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.
- Vorherrschende Sprache
- Go
- Sterne
- 17.5k
- Forks
- 1.7k
- Ø Merge
- 2 T. 23 Std.
- Gemergte PRs (30 T.)
- 575
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus coder/coder
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
coder/coder#33007 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
feat(cli): add `--agents-allowed` to `coder templates push`Evtl. vergeben @jeremyruppel hat das vor 4 Tagen übernommen. Offencli
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
coder/coder#32005 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
feat(cli): add `--require-active-version` to `coder templates push`Evtl. vergeben @jeremyruppel hat das vor 4 Tagen übernommen. Offencli
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
coder/coder#32004 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
feat(cli): add `--dormancy-auto-deletion` to `coder templates push`Evtl. vergeben @jeremyruppel hat das vor 4 Tagen übernommen. Offencli
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
coder/coder#32003 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
feat(cli): add `--failure-ttl` to `coder templates push`Evtl. vergeben @jeremyruppel hat das vor 4 Tagen übernommen. Offencli
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
coder/coder#32001 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
neilotoole/sq#1503 ·
Maintainer antworten meist innerhalb von 1 Tag
-
help wanted kind/bug stage/010-actionable
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
kubestellar/kubestellar#4077 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
bot snap/qwen3-6
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
canonical/inference-snaps#463 ·
Maintainer antworten meist innerhalb von 2 Tagen