mirror of
https://github.com/coder/coder.git
synced 2026-11-22 03:18:31 +08:00
5dde49dffbd02a0adbdefabecedb247cfc8cf5da
579
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
5dde49dffb |
feat: add chat workspace file upload endpoint (#27079)
## What
Adds `POST /api/v2/chats/{chat}/workspace-files`, which streams the
request body to the chat's bound workspace agent and returns the final
path/name/size, plus the `workspace-file-reference` message part type
that carries the uploaded file's metadata through chat messages:
- `coderd/exp_chats.go`: owner-only middleware (chat RBAC update +
reject archived), workspace exec authorization (403/409 like the
existing chat exec paths), agent selection (prefer the chat's bound
agent, else deterministic `agentselect.FindChatAgent`, without
persisting a binding), 30s dial timeout, chat/ancestor tracking headers
on the agent connection, and agent error passthrough (agent HTTP status
preserved, 502 with a generic detail for transport failures; the real
error is logged). Deleted and non-running workspaces get a specific 409
("Workspace is stopped. Start the workspace before uploading files.")
before agent lookup. Each failed upload logs one structured warning, and
`coderd_chat_workspace_upload_total{status}` counts outcomes. The route
shares the files rate limit and documents its 429.
- Input validation: client-supplied `workspace-file-reference` parts
must point inside `/.coder/chats/<chat-id>/files/` with a matching
basename, non-negative size, and a `workspace_file_workspace_id` equal
to the chat's currently bound workspace (the upload response echoes it
as `workspace_id`). References uploaded before a workspace rebind are
rejected instead of silently sending the agent an unreadable path. The
file name must already be in sanitized form
(`SanitizeWorkspaceUploadName(name) == name`), and the cleaned path and
base media type are what gets persisted; message edits share the same
validation. Parts are rejected on chat creation (no chat ID exists yet).
- `coderd/x/chatd/chatprompt`: references render into the prompt as text
only, `[workspace file: <name> (<size>) at <path>]`; file bytes never
reach the LLM. Title derivation (`TitleText`) uses the bare file name,
so fallback titles carry no internal marker.
- `codersdk`: part-type constants/fields,
`ChatMessageWorkspaceFileReference` builder, and
`Client.UploadChatWorkspaceFile` (RFC 5987 filename in
`Content-Disposition`).
No DB migration: parts persist as JSON in `chat_messages.content`.
## Why
Bridges chat and the workspace filesystem for CODAGT-211: users drop a
file in chat, the bytes land where the agent's tools can operate on
them, and the model learns the path from the reference part.
## How tested
- `go test ./coderd -run 'WorkspaceFile|ChatInput|UploadChat'` including
an integration test that runs a real in-memory agent, uploads through
the coderd route, verifies bytes on disk, and exercises collision
suffixes.
- `go test ./codersdk ./coderd/x/chatd/...`, `make gen`
(swagger/types/docs), `make lint`.
- Rebased onto main 2026-09-21: the chat API moved from
`/api/experimental` to `/api/v2`, so the route is registered in
`coderd/chat_routes.go` and the SDK method lives on `codersdk.Client`.
## Follow-ups
- The files rate limit counts requests, not bytes or concurrency;
whether this route should use a per-user concurrency cap instead, and
whether the new-chat page should keep partial successes on a 429, is
still open
([CODAGT-1171](https://linear.app/codercom/issue/CODAGT-1171)).
Part of CODAGT-211. Stack: agent API -> coderd endpoint (this PR) -> UI.
> This PR was authored by Mux (AI) working on Mike's behalf.
|
||
|
|
282365b23a | feat: report clicks on the workspace build debug action to telemetry (#29853) | ||
|
|
46ccaf3764 |
chore: mark organization AI spend users endpoint as experimental (#29842)
## Description
Move `GET /organizations/{organization}/ai/spend/users` under
`/api/experimental` so the per-user spend report is not part of the
stable API for this release. The endpoint behavior is unchanged.
Related to [internal Slack
thread](https://codercom.slack.com/archives/C04M9CNGHGF/p1790190171687059?thread_ts=1790190121.005749&cid=C04M9CNGHGF).
## Changes
- Register the route on the experimental handler and mark it
`@x-apidocgen {"skip": true}`, which removes it from the generated API
reference.
- Move the Go SDK method to `ExperimentalClient` and the frontend method
to `API.experimental`.
- Drop the docs link to the removed API reference section. The link is
commented out with a TODO so it can be restored later.
User-facing docs for the **User spend** page are updated upstack in
#29844.
> [!NOTE]
> Generated by Coder Agents on behalf of @ssncferreira.
|
||
|
|
702b13112d | feat: add Debug with Coder Agents action for failed workspace builds (#29811) | ||
|
|
f64ccfb836 |
feat: add experimental inline MCP servers (#29546)
Closes CODAGT-1131 Fifth PR in the inline MCP servers stack, on top of #29520. A chat owner can now declare MCP servers by URL and headers on their own chat, and chatd connects to them every turn alongside the org-configured ones. They go in a new `inline_mcp_servers` field on `POST /api/v2/chats` and `POST /api/v2/chats/{chat}/messages`, which replaces the whole set (omit to keep, `[]` to remove). Root chats only. `GET /api/v2/chats/{chat}` returns them, with the URL blanked for non-owners and header values never returned. Subagents only get servers marked `allow_in_subagents`, a root chat in explore mode gets none, and a root chat in plan mode gets all of them. URLs must be `https`, or `http` to an IP literal in `CODER_MCP_ALLOWED_PRIVATE_CIDRS`. Header values have no minimum length, so anything under the redactor's 8 byte floor from #29518 is accepted but not redacted, which the docs call out. Every cap is exported from `codersdk`. It's behind the `chat-inline-mcp-servers` experiment, and the `--disable-chat-caller-supplied-tools` kill switch from #29466 covers it too. With either off, declaring servers gets a 403 and existing chats stop connecting to theirs, but `[]` still works so a client can detach. Load failures show up in the chat debug panel as failed connections, as do org servers with an invalid config. Docs are hand-written in `mcp-servers.md`. |
||
|
|
c1af0793e5 |
feat: add caller-supplied tools kill switch for chats (#29466)
This is the first PR in a stack that adds experimental support for attaching MCP servers to a chat when it's created, and then deprecates `unsafe_dynamic_tools` in favour of them. Both are "caller-supplied tools", i.e. tools the client hands to coderd at chat creation rather than tools an admin has configured, so we want a single switch admins can use to turn all of them off. This PR adds that switch: `--disable-chat-caller-supplied-tools` (`CODER_DISABLE_CHAT_CALLER_SUPPLIED_TOOLS`). It follows the existing `disable-*` deployment flag pattern (`--disable-chat-sharing` etc.), so there's no new API route and it's independent of any experiment. When set, `POST /api/v2/chats` returns a `403` if the request includes `unsafe_dynamic_tools`, and chats that already have dynamic tools run without them; a call to one gets a tool error result and the model just continues. Later in the stack, chat-attached MCP servers are gated behind the same flag. It's unset by default, so nothing changes unless you opt in. Part of CODAGT-1131 |
||
|
|
2de1f8b111 |
feat: link promoted chat messages to their queue entry (#29859)
Signed-off-by: Thomas Kosiewski <tk@coder.com> |
||
|
|
5393f9d5f4 |
feat: stream advisor reasoning in tool cards (#29742)
Show the advisor’s live reasoning under **Thinking**, separately from **Advice**, in one tool card with the original question and title. Keep nested reasoning out of the parent assistant’s reasoning and saved chat history. Clear both live channels on retry and remove transient reasoning when the call finishes. Cover streaming, retry, error, and interrupted-output behavior with regression tests, and regenerate the SDK and API schemas. This also changes a shared seam for every tool, not only the advisor: live output for a tool call that is already saved now completes that call's card, and the separate live-row card for it is removed. Remote UAT passed on `a39bbe4c21`: deterministic provider tests covered streamed reasoning, retry, errors, and refresh; a real-provider run confirmed advice streaming and card association. The real model did not emit reasoning. The intermittent, unattributed React console warning is tracked in #29741. <details> <summary>Remote UAT evidence (deterministic provider)</summary>  Streaming, completion, and refresh: https://github.com/user-attachments/assets/dd1f3a24-a365-40c8-a1d9-b78cd17ef4c5 </details> --- <details> <summary>📋 Implementation Plan</summary> # Plan: Stream advisor reasoning in Coder Agents ## Goal and delivery boundary Show nested advisor reasoning as live **Thinking** in its advisor tool card. Keep it separate from live **Advice**, normal parent-assistant reasoning, and the final persisted advisor result. Deliver one focused PR: optional SDK field, nested publisher, transient frontend state, existing card rendering, generated API artifacts, and regression tests. Do not add provider features, persistence, new stream event types, UI redesigns, or unrelated cleanup. The implementation already exists and has been reconciled with current main. The implement-flow implementation phase is an acceptance audit, not a rewrite. Preserve correct behavior and current architecture. Change only demonstrated gaps. A no-op implementation result is valid; do not manufacture an empty commit. ## Current integration points 1. `codersdk/chats.go`: add optional `ReasoningDelta string` with `json:"reasoning_delta,omitempty" variants:"tool-result?"`. Preserve it in `StripInternal` alongside other live fields. Register the same NUL-encoding policy as `ResultDelta` in `chatprompt` so the SDK field coverage and round-trip tests remain complete. Regenerate SDK types and API documentation with `make gen`. 2. `coderd/x/chatd/chatadvisor/runner.go`: route assistant text and reasoning through separate optional callbacks on `RunAdvisorOptions`. Install the publisher if either callback exists. Preserve empty-delta and role guards. Use current `GenerateAssistant` and `chatretry.Retry`. Rename the reset callback to `OnLiveOutputReset` because it clears advice and reasoning. Keep `extractAdvisorText` text-only and existing budget/refund behavior. 3. `coderd/x/chatd/chatadvisor/tool.go`: use the current context-injected `MessagePartPublisherFromContext`; do not reintroduce the old ToolOptions publishing callbacks or chatd.go wiring. Preserve the missing-publisher error and the nonempty tool-call-ID guard. Publish reasoning as role `tool`, part type `tool-result`, tool name `advisor`, matching `tool_call_id`, and `reasoning_delta`. Use existing `result_reset` to reset both live channels on retry. 4. `site/src/pages/AgentsPage/components/ChatConversation/streamState.ts` and `types.ts`: retain a single transient reasoning string. Append deltas exactly as plain text, never JSON-parse or trim them during accumulation. Reasoning makes the tool streaming. An empty `result_delta` must not swallow a nonempty `reasoning_delta`. Reset removes the entry. A final result or `is_error` clears reasoning and streaming state. Pass reasoning through `buildStreamTools` into `MergedTool`. 5. `MessageBlocks.tsx` and `ChatElements/tools/Tool.tsx`: forward reasoning at both current Tool instantiation paths and through AdvisorRenderer. Do not restore the old ConversationTimeline rendering implementation. 6. `AdvisorTool.tsx`: use current `ToolCall.Root`, `ScrollArea`, `Response`, and semantic theme tokens. Display Thinking only when running and trimmed reasoning is nonempty. Display live advice separately when present. Keep completed advice, empty/loading, limit, and error behavior unchanged. Reasoning-only running cards must not show the empty-advice fallback. Do not restore removed MUI dependencies. 7. `messageParsing.ts`, `streamState.ts`, and `ChatPageContent.tsx`: associate live tool results with matching durable tool calls. Preserve the invocation's question, intent, and metadata. A durable final result remains authoritative, including explicit null results. Remove only the overlaid result and its block from the separate live row; keep unrelated results and live call/result pairs unchanged. This closes the durable-call/live-result split found during integration testing. ## Acceptance criteria 1. Nested reasoning reaches the dedicated runner callback and the client as tool-scoped live output for the same advisor call as advice. 2. Advisor reasoning is not parent assistant reasoning, final advice, input to the parent's continuation, or persisted chat history. 3. Retry clears stale reasoning and advice before fresh output. Final success and bare error clear transient reasoning. 4. Raw whitespace and JSON-looking reasoning survive concatenation unchanged. Empty advice deltas do not hide reasoning. 5. Reasoning-only and reasoning-plus-advice states render in exactly one existing advisor card per invocation, retaining its question and intent title when the call is already durable. Completed cards never display transient thinking, even if handed a stale prop. Other tool and normal assistant reasoning behavior is unchanged. 6. Generated artifacts match source. Final candidate passes relevant Go tests, frontend tests, stories, typecheck, lint, and pre-commit checks, or has explicit verified blockers. Old evidence is not final-candidate evidence. ## Phases and quality gates 1. Reconcile existing work onto current main while retaining a recovery snapshot. Remove obsolete workarounds, not current upstream behavior. Gate: no conflicts, focused diff, preserved original work. 2. Audit regressions at the existing runner, tool publisher, parent-chat stream, and frontend state boundaries. Add one missing behavior at a time. Reproduce failures before fixes. Gate: failing tests demonstrate the defect and pass after the smallest fix. 3. Simplify only within this feature. Use one reasoning string and existing publishers/components. Gate: tests remain green, generated diff is scoped, FE1 through FE10 pass. 4. Commit the candidate with repository hooks enabled, then run the packaged implement-flow audit, validation, remote UAT, and polish stages. Gate: readyForPr and verified remote evidence for the exact final candidate. If polish changes HEAD, refresh the UAT evidence for that SHA. 5. Create a reviewable PR and complete green CI plus bounded Codex review on its exact head. Get one fresh independent readiness recommendation. Gate: no unresolved review threads, required evidence recorded, and a justified readiness decision. Do not merge. ## Regression coverage - Runner: reasoning and advice callbacks remain separate; final advice and usage count stay correct. Retain existing retry/refund tests. - Tool: all reasoning/advice events carry role tool, type tool-result, advisor name, and the invocation ID. Without an ID, emit no live output. Retry emits stale reasoning/advice, reset, then fresh reasoning/advice. - Chatd: extend `TestAdvisorHappyPath_RootChat` with deterministic `openai-compat` reasoning chunks. Hold the nested response until the live subscriber captures expected reasoning and advice. Observe the complete relevant event set, assert no parent-assistant reasoning, and check continuation and persisted content contain no advisor reasoning. Extend only the test fixture needed to emit `reasoning_content`; do not change production adapters. - Frontend: extend streamState tests for exact accumulation, whitespace, JSON-looking text, reasoning-only streaming, empty advice delta, reset, final result, and bare error. - Durable/live integration: replay a durable assistant tool call followed by live reasoning and advice results. Assert the durable card receives both channels and the live row no longer owns the same result or block. Preserve unrelated IDs and live calls. Clear the overlay on reset; prefer durable final results, including null. Cover the complete display path with a real-store ChatPageContent story. - Visual stories: running reasoning-only, running reasoning-plus-advice, and completed with stale reasoning. Keep existing limit/error stories. Stories set up visual states without assertions, following current FE1. ## Validation Run targeted checks while iterating, then the broader gates: ```sh umask 022 go test ./coderd/x/chatd/chatadvisor ./coderd/x/chatd ./codersdk -run 'Advisor|ChatMessagePart|ChatStream' -count=1 pnpm -C site exec vitest run --project=unit src/pages/AgentsPage/components/ChatConversation/streamState.test.ts pnpm -C site exec vitest run --project=storybook src/pages/AgentsPage/components/ChatElements/tools/AdvisorTool.stories.tsx make gen make fmt make test RUN='Advisor|ChatMessagePart|ChatStream' pnpm -C site lint:types pnpm -C site check pnpm -C site lint make lint make pre-commit ``` Keep native exit codes and logs. Do not hide a failed check, bypass hooks, or fix unrelated baseline problems in this PR. Stage intentional generated/formatting changes before pre-commit's clean-diff checks. Report exact blockers and risks. ## Remote dogfood UAT Use the coder-agents-uat skill and an independent critical Coder Agent, not a local-only substitute. Push only the named feature branch. Test its exact SHA in an isolated workspace/deployment without changing shared model credentials or configuration. Use an isolated user, chat, and model config. Setup: 1. Read the branch diff and UAT scope. Record the branch and SHA. 2. Start Coder with the repository-supported `./scripts/develop.sh --port-offset` (or `CODER_DEV_PORT_OFFSET=true`). Do not replace it with a manual server launch. Record effective API/UI URLs and wait for readiness. 3. Prefer a deterministic mock OpenAI-compatible provider that emits advisor reasoning and advice separately, and a retry after stale output. Use only isolated configuration. Never print or capture secrets. 4. Start a named agent-browser session. Attempt `agent-browser skills get core`; record the installed version/fallback if unavailable. Record video before the scenario, then install any stream capture since recording may recreate browser context. Scenario: 1. Create a normal advisor-enabled root chat. Do not use Plan Mode: current product behavior excludes the advisor there. 2. Capture the initial state. Prompt the parent to call advisor. 3. While the tool is running, capture reasoning-only and reasoning-plus-advice states. Verify exactly one advisor card per tool-call ID, with its original question and intent title. Verify Thinking and Advice stay separate inside that card and the parent thinking area does not receive nested reasoning. 4. Capture the relevant WebSocket event set. Verify role tool, type tool-result, advisor name, matching tool-call ID, and reasoning_delta. An advisor-filtered subset is insufficient to prove absence of parent reasoning. 5. Let the advisor finish. Verify final advice remains, Thinking disappears, and refresh does not restore transient reasoning. 6. Exercise retry with the deterministic provider if feasible. Verify stale reasoning/advice clears before fresh output. If not exercised, record the omission and remaining test evidence; do not claim it was dogfooded. 7. Capture console errors before and after. Inspect the screenshots and semantic video frames, not only successful media decoding. Required evidence: exact tested SHA; remote chat URL; setup command and effective URLs; non-secret provider/model names; before/thinking/thinking-plus-advice/completed screenshots; a short streaming video; complete relevant stream evidence; refresh and retry observations; console results; explicit omissions; and owned-resource cleanup receipts. Keep evidence under `.mux-uat/round-<n>/`, excluded from source commits. When publishing evidence to GitHub, use native `gh --attach`, not cookie-based uploads or gh-image. Cleanup: stop only owned develop/provider processes and named browser sessions. Do not use unscoped process sweeps, shared database resets, or `agent-browser close --all`. </details> --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `coder:openai/gpt-6-astra` • Thinking: `xhigh`_ --------- Signed-off-by: Thomas Kosiewski <tk@coder.com> |
||
|
|
c95a87cea7 |
feat: warn before narrowing a self-registered OAuth2 app's scope allowlist (#29777)
- Warn rather than block when admins narrow a self-registered OAuth2 app's scope allowlist. Clients requesting all advertised scopes may receive `invalid_scope` on new authorizations; existing tokens retain their scopes. - Expose `dynamically_registered` in API responses and display registration type on the app page. - Show no warning for widening or clearing allowlists, or for admin-created apps. - Update scope and `invalid_scope` troubleshooting docs and remove the outdated note that the UI cannot set allowlists. Closes PLAT-664. |
||
|
|
bacb4fc6ed |
feat: expose per-app session counts (#29351)
Track individual applications across deployment statistics, Prometheus, telemetry, and the dashboard instead of exposing only fixed family totals. Preserve existing fields and gauges so current consumers can migrate without breaking. - Add per-app counts with normalized identifiers and registry-backed display names, families, and bundled icons. Unrecognized apps retain their identifiers. - Limit each statistics report to 64 distinct app names, combining excess names into an explicit overflow bucket. - Group dashboard connections by family, including an Other category, with alphabetical per-app tooltips and distinct loading and empty states. - Export app-keyed Prometheus counts separately from current family metadata, allowing queries to enrich historical counts without rewriting stored samples. - Document family queries with unknown fallback, deployment isolation, and replica handling, alongside collection behavior and migration guidance. - Include per-app counts in telemetry, update API schemas and documentation, and add regression coverage across collection, metrics, and dashboard behavior. Closes #27411 |
||
|
|
528dd3cc44 |
feat: edit an OAuth2 app's redirect URIs as an ordered list (#29603)
Completes PLAT-619, following #29440 and #29502. - Replace the OAuth2 app’s single callback field with an editable `redirect_uris` list supporting 1–32 entries, with the first labeled “Default callback.” - Show a `+N` badge for additional redirect URIs in the applications table. - Remove `omitempty` from request `redirect_uris` so explicit empty lists reach the server. - Add tests and stories for adding, editing, removing, and requiring at least one URI. |
||
|
|
395e8032dc |
fix: reject client_secret in the OAuth2 token and revocation URL (#29508)
Reject non-empty `client_secret` query parameters on token and revocation endpoints with `400 invalid_request`, enforcing OAuth 2.1 §2.4.1 (D6-04). - **Breaking:** Send secrets in the request body or `Authorization` header, and rotate any previously sent in URLs. Rejections consume nothing, so clients can retry without reauthorization. - Empty query secrets count as absent, but token requests also supplying a body secret still fail duplicate-parameter validation. Authorize ignores query secrets and logs a warning without the value. - Sanitize and cap revocation parse errors, correctly report repeated token parameters, and update tests and API docs. Refusal logs include the app ID, never the secret. - Other query parameters (`client_id`, `refresh_token`, `code`, and revocation tokens) remain accepted; body-only credential parsing is tracked in PLAT-660. No migration or new error codes. Refs PLAT-602. |
||
|
|
5e41baf73c |
docs: normalize control plane, coderd, and coder server terminology (#28960)
Normalizes the three overlapping names for the thing that serves the Coder API and dashboard. This is step 1 of the Install/Deploy and Administration refactor ([DOCS-685](https://linear.app/codercom/issue/DOCS-685), [DOCS-738](https://linear.app/codercom/issue/DOCS-738)) and lands first because every later page depends on settled terminology. Resolves [DOCS-871](https://linear.app/codercom/issue/DOCS-871). ## The rule | Term | Means | Use when | |---|---|---| | control plane | The component that serves the Coder API and dashboard, brokers connections, and coordinates provisioners | Default in prose, diagrams, planning, sizing, security | | `coderd` | The process that implements it | Architecture internals, metrics, logs, flags, troubleshooting | | `coder server` | The literal CLI command | Only when the reader will type it | Retired: "the Coder server" as a name for the component, and "a service" as a standalone description of it. ## What changed - **`docs/.style/style-guide/word-choice.md`**: new "Naming Coder's components" rule, with do/don't examples. Also fixes a "Do" example on that page that itself used "the Coder server". - **`docs/reference/glossary.md`**: rewrote `coderd` and Control plane, added a `coder server` entry. The existing Control plane entry defined it as "the collective term for `coderd`, its provisioners, and its database", which made it indistinguishable from the Deployment entry two sections later. Control plane is now the component; Deployment remains the whole installation. - **65 pages** across `docs/admin`, `docs/install`, `docs/get-started`, `docs/tutorials`, `docs/user-guides`, `docs/ai-coder`, and `docs/about`: roughly 154 component-sense "Coder server" usages, 21 bare "the server" usages meaning the control plane, 3 "a service" descriptions, and 43 unbackticked `coderd` mentions in prose. - One real bug caught in passing: `docs/tutorials/best-practices/security-best-practices.md` documented `coderd server --disable-path-apps`, which is not a command. Now `coder server`. Generated files were not touched: `configuration-reference.md`, `prometheus.md`, `audit-logs.md`, `reference/cli/*`, `reference/api/*`, and the generated blocks inside `feature-stages.md`. Those still contain the retired term and need generator-side changes; see the deferred list below. ## Reviewer attention, please **Anchor changes.** 11 headings were renamed, so their fragments change. No in-repo link targets any of them (the one internal link that did was updated), but external deep links from tickets or blog posts would break, and fragments cannot be fixed with a redirect. Happy to revert any of these if you would rather they ride along with the page moves in [DOCS-869](https://linear.app/codercom/issue/DOCS-869), which changes those URLs anyway. <details> <summary>Renamed headings and their old fragments</summary> | File | Old fragment | New heading | |---|---|---| | `admin/networking/index.md` | `#coder-server` | `## Control plane` | | `install/index.md` | `#starting-the-coder-server` | `## Starting the control plane` | | `install/uninstall.md` | `#the-coder-server-binary-and-cli` | `## The Coder binary and CLI` | | `install/registry-mirror-artifactory.md` | `#step-5-configure-coder-server-or-provisioners` | `## Step 5: Configure the control plane or provisioners` | | `install/cloud/compute-engine.md` | `#configuring-coder-server` | `## Configuring the control plane` | | `get-started/index.md` | `#cant-start-coder-server-address-already-in-use` | ``### Can't start `coder server`: Address already in use`` | | `tutorials/external-database.md` | `#coder-server-fails-startup-with-...` | ``### `coder server` fails startup with ...`` | | `tutorials/faqs.md` | `#how-do-i-change-the-access-url-for-my-coder-server` | `## How do I change the access URL for my control plane?` | | `tutorials/best-practices/security-best-practices.md` | `#coder-server` | `## Control plane` | | `tutorials/best-practices/security-best-practices.md` | `#server-logs-and-audit-logs` | `### Control plane logs and audit logs` | | `tutorials/best-practices/scale-coder.md` | `#coder-server`, `#how-to-capture-coder-server-metrics-with-prometheus` | `## Control plane`, `### How to capture control plane metrics with Prometheus` | </details> **One deliberate deviation from the issue.** DOCS-871 proposed reserving "sub-agent" for the Coder Agents sense and using "devcontainer agent" for the workspace sense. I did not make that change. The glossary already disambiguates with "Sub-agent (Coder Agents)" and "Sub-agent (dev containers)", and "devcontainer agent" would violate the existing dev container spelling rule in the same style guide, which requires "dev container" as two lowercase words. The current split reads correctly and costs no churn. Happy to revisit if you disagree. <details> <summary>Deferred, with reasons</summary> - **Generated content still says "Coder server".** `reference/cli/*` comes from Go command help text, `configuration-reference.md` from `configdocgen`, and `reference/api/*` from Swagger annotations. Fixing those means changing Go source, which belongs in its own PR so a docs review does not turn into a backend review. - **`validated-architectures/index.md` "also known as `coderd`"** is fixed here, but the page's larger problem is that it holds four documents in one file. That split is [DOCS-868](https://linear.app/codercom/issue/DOCS-868). - **"server flag" phrasing** in `admin/users/idp-sync.md` and `admin/users/oidc-auth/index.md` means `coder server` flags. Left alone; rewording those sentences is a copy edit, not a substitution. - **Metric and UI labels** such as "Dashboard-to-server latency" in `admin/networking/index.md`. Renaming risks diverging from what the dashboard shows. - **Pre-existing `Coder.GerundHeading` warnings** on headings this PR touches, and a "from from" typo in `scale-coder.md`. Out of scope for a terminology pass. - **Peer-sense "server"** in NAT traversal prose, where "client or server" describes the connection roles rather than the control plane. Needs restructuring, not substitution. </details> ## Verification | Check | Result | |---|---| | `make lint/emdash` | pass | | `make lint/markdown` | pass, 504 files, 0 errors | | `make lint/docs-html` | pass | | `make lint/prose` | pass, findings identical to the `main` baseline (1 intentional demo error, 145 warnings, 1 suggestion; only Vale's file ordering and one line-number shift in `glossary.md` differ) | | `make gen` | clean, no drift | | `make fmt/markdown` | applied | No redirects needed: no page moved or was renamed in this PR. <details> <summary>Merged main, 2026-09-14</summary> One conflict, in `docs/ai-coder/ai-gateway/providers.md`. Both hunks were text this PR had edited and `main` had since deleted in #29053, which removed env-based AI provider configuration: - The deprecated provider seeding note, which held a `coderd` backtick fix, is gone. Took `main`. - The failure-mode table lost its env-drift row. Took `main`'s two rows and reapplied the `coderd` logs wording. `main` also landed new prose carrying the retired terms, so the pass was extended to cover it: - `docs/admin/integrations/oauth2-provider.md`: two "the server log(s)" in the scope-enforcement sections added by #29144 are now "the `coderd` log(s)"; "a `scope` the server will not grant" is now "the control plane". - `docs/reference/cli/index.md` gained "the server" from #29104, and stays deferred as generated content. The new `docs/ai-coder/agent-relay/claude-code.md` needed no change, and no page `main` added links to a heading this PR renamed. </details> <details> <summary>Decision log for the wider refactor</summary> Agreed with @nickvigilante before implementation, recorded on DOCS-685 and in the Notion outline: 1. Feature stages and release channels move to Reference; ESR upgrade guides move under Operate. No new top-level Releases section. 2. `data-retention.md` moves to Administration > Security; `chat-lifecycle-hooks.md` moves into the Coder Agents docs. `admin/setup/` therefore survives as "Deployment configuration" and `configdocgen` is not touched. 3. Prepare is advisory, not a gate, framed as "don't know where to start? Start here", with lead times and owners per item. 4. One actor table, on the Install overview, spanning all five phases, noting that one person can be several actors and several people can be one actor. 5. The quickstart stays independent and is mentioned once, on the Install overview. The proposed `server/single-machine` page is dropped. 6. Coder Validated Architecture keeps its name in nav, defined in-page, with a glossary entry. 7. PR 3 is split: moves only, then prose, so the riskiest change reads as a pure rename diff. 8. For every PR that moves a page, the coder.com `redirects.json` change merges first. 9. There is no Download section and no CLI page in docs. Per-OS CLI steps live on coder.com/download and the Install overview links to it. </details> Generated with Coder Agents on behalf of @nickvigilante. |
||
|
|
9fd0131d04 |
feat: accept redirect_uris on the OAuth2 app admin API and deprecate callback_url (#29502)
- Add `redirect_uris` to admin OAuth2 app responses and create/update requests. - Deprecate `callback_url` while preserving compatibility; it maps to the first redirect URI. - Reject empty `redirect_uris` lists instead of silently ignoring them. - Update fixtures, tests, and docs. Part of PLAT-619. Builds on #29440; admin UI support follows in #29603. |
||
|
|
80eee58d1d |
feat: add the organization AI spend client method and report fixture (#29627)
Adds `API.getOrganizationAISpendUsers(organizationId, params)` for `GET
/api/v2/organizations/{organization}/ai/spend/users` (period, provider,
model, client filters plus `limit`/`offset`), the
`MockOrganizationAISpendReport` fixture, and a shared
`codersdk.MaxAISpendPeriodDays` constant that the enterprise export
handler now reads and that `make gen` emits into `typesGenerated.ts`.
The model-list endpoint also accepts a literal `model` prefix. The
backend escapes SQL LIKE characters, while `q` keeps its existing search
syntax. Supplying both nonempty parameters returns 400. The filter menu
adopts this parameter in #29632.
## Why
The frontend caps custom ranges at the same 31-day limit the server
enforces; one SDK constant keeps the two from drifting. The fixture is
what every later test and story renders. Literal model identifiers
should not require search-language quoting or SQL escaping in the
frontend.
## What to scrutinize
- `enterprise/coderd/aibridge.go`: `maxAISpendExportPeriod` is now
derived from the SDK constant, same value as before.
- `MockOrganizationAISpendUser` is not exported yet; the table PR
exports it for its stories (knip fails on exports without a consumer).
## Generated files
`site/src/api/typesGenerated.ts`, `coderd/apidoc/docs.go`,
`coderd/apidoc/swagger.json`, and `docs/reference/api/aigateway.md` via
`make gen`.
## Validation
`pnpm test src/api/api.test.ts -t getOrganizationAISpendUsers` (new
case), `go test ./enterprise/coderd/ -run TestAIBridgeListModels
-count=1 -v`, repository pre-commit including `make gen` with no drift.
Model tests cover literal punctuation, prefix matching, existing `q`
behavior, and conflicting parameters.
## Delivery record
Published head `8d9a4faa0aa` passed per-layer integration checks and
commit hooks. The composed head `d899228f798` passed format, check, full
frontend lint, 125 unit tests, and 86 story tests. Pre-push hooks were
skipped as requested. See #28964 for audit findings, their disposition,
and historical UAT limits. No exact-head live UAT or new independent
re-review is claimed.
## Stack context
PR 3 of 9. The stack adds a **User spend** page under **Admin settings**
> **AI** > **User spend**: total and per-user AI Gateway spend for one
organization over a reporting period, read from `GET
/api/v2/organizations/{organization}/ai/spend/users` (#29129, merged).
It is #28964 split into one-concern PRs. Historical UAT covers earlier
heads only; live UAT has not been rerun after these review fixes. Bottom
to top: DateRangePicker limits, shared dimension badge, API client
method, spend table, page view, page container, reporting period,
dimension filters, route and navigation (#28964).
> Xum prepared this PR on behalf of @ibetitsmike.
|
||
|
|
60cc826f2b | feat: sign forwarded MCP identity headers (#29669) | ||
|
|
af0ef00f91 |
feat: add owner_id to CreateChatRequest to create chats for another user (#29581)
Owners and owner-level service accounts can now start a Coder Agents
chat on behalf of another user by setting `owner_id` on `POST
/api/v2/chats`. The field is optional and defaults to the caller, so
existing clients are unaffected. A delegated owner must be an active,
non-system member of the requested organization; anything else returns
400 `Chat owner must be an active member of the organization.` once the
caller has passed the authorization gates below.
A chat runs entirely with its owner's credentials (synthetic API key,
workspace access, OIDC and provider tokens), so creating one for someone
else is acting as that user. On top of org-scoped `chat:create` for the
owner, the caller must hold the authority to create API keys for that
user, which is what the token endpoint demands to mint their session.
Org admins therefore cannot use it; site owners and owner-role service
accounts can. For the same reason the workspace binding, model config,
and MCP server IDs are validated as the owner rather than the caller,
and the owner must themselves hold `chat:create` (organization service
accounts do not). The initial user message is attributed to the caller
through `chatd.CreateOptions.CreatedBy`.
An earlier revision of this PR exposed the same behavior as `POST
/api/v2/users/{user}/chats`; that route and
`codersdk.Client.CreateUserChat` were removed in `62a8be3dd32` in favor
of the request field. An explicit zero `owner_id` is rejected with 400
rather than silently defaulting to the caller. Coverage lives in
`TestPostChats_OwnerID`.
<details>
<summary>Review record (path-based revision, gates unchanged)</summary>
- Two-axis code review (Standards, Spec) plus a simplicity audit ran as
Xum sub-agents on `1f3189898f0`. The Spec axis found the workspace
binding was authorized as the caller, fixed in `363d45281d8` with
red-green coverage in `WorkspaceNotAccessibleToOwner`. The additional
API-key gate and the `CreatedBy` attribution go beyond the workspaces
pattern and were kept deliberately for the reasons above.
- Codex review on `363d45281d8`: one P2, suspended, dormant, or system
users could be targeted and would get a chat that can never run because
AI Bridge refuses to authorize them. Fixed in `c065437e359` with
`OwnerSuspended` (red on the old head); thread replied to and resolved.
- Codex review on `c065437e359`: one P2, an explicit or
personal-override model config the caller can read but the owner cannot
was accepted and chatd would silently fall back to the default model at
run time. Fixed in `aa88b608182` by resolving the model config and MCP
server IDs under the owner's context, with
`ModelConfigNotAccessibleToOwner` (red on the old head); thread replied
to and resolved.
- Codex review on `aa88b608182`: one P2, an organization service account
(which deliberately holds no chat permissions) could be targeted because
the chat permission check ran as the caller. Fixed in `a6fe8075c30` by
also requiring the owner subject to hold `chat:create`, with
`OwnerWithoutChatPermission` (red on the old head); thread replied to
and resolved.
- Codex review on `a6fe8075c30`: one P2, the active/non-system check was
skipped when the caller could not read the owner's user object. Fixed in
`0dd8bb4dd44` by moving the check behind the authorization gates with a
system-restricted lookup; thread replied to and resolved. In
`62a8be3dd32` that lookup became a single `OrganizationMembers` query,
which also covers membership and excludes system and deleted users.
- Codex review on `62a8be3dd32` (the `owner_id` revision): two P2s. An
explicit zero `owner_id` was treated as omitted and created the chat for
the caller; fixed in `f54b4f33d36` with a 400 and `OwnerIDNil` (red on
the old head). Creation and the read-back still ran as the caller while
the preflight ran as the owner; fixed in the same commit by passing
`ownerCtx` to `CreateChat`, `GetChatByID`, title generation, and the
file-metadata fetch. That second scenario is unreachable today (only the
built-in `owner` role holds `api_key:create` for others, and site-wide
custom roles are refused by both the API and dbauthz), so it has no
dedicated red test. Both threads replied to and resolved.
</details>
<details>
<summary>Remote UAT record (path-based revision)</summary>
Remote UAT on dogfood (chat `d7442df3-693f-4403-805f-2de52f7bdbed`, Xum
sub-agent as critical runner) tested head `21ed6b389cc`, the last
path-based revision. Licensed dev server, real Haiku 4.5 model, 77
logged API requests, 23 inspected screenshots. Endorsed verdict:
**PASS**. Site owner creates a chat for member X: X sees it, gets real
answers to the admin prompt and to follow-ups, and state survives reload
and mid-response refresh. The creating admin gets `403 Only the chat
owner may send messages.` and a read-only view; an unrelated member gets
404. Org admin, member, user-admin, and template-admin callers get 403;
owner-role service account 201. Suspended, dormant, and service-account
targets 400; owner-inaccessible workspace, model config, or MCP server
400; 300 KiB body 413. The `owner_id` revision changes only how the
owner is supplied and the non-member response (400 instead of 404); the
authorization and eligibility gates it exercised are unchanged and
covered by `TestPostChats_OwnerID`.
Non-blocking findings for the author's judgment, none of them
regressions of this PR:
1. X's UI shows no author on the admin-written first message and offers
X "Edit" on it; `created_by` carries the admin but the frontend does not
surface it.
2. A site owner who is not a member of the organization can still create
a chat for its members (201), while a self-owned `POST /chats` returns
403 for the same organization; same asymmetry as `postUserWorkspaces`.
3. The creating admin can archive, rename, and interrupt X's chat
although it cannot message it (pre-existing chat authz).
4. Owner-inaccessible model config or MCP server is reported as "not
found or disabled" with no hint that the owner, not the caller, lacks
access.
5. Dormant (never logged in) targets are refused because AI Bridge
rejects non-active users; a new hire cannot be given a chat until first
login.
6. The endpoint docs list only 201 and 413.
</details>
> Xum (an AI agent) acted on behalf of @ibetitsmike for this PR.
|
||
|
|
2bf0f567d8 |
feat: add OpenAI Pro reasoning mode to chat model configs (#29584)
Adds `provider_options.openai.reasoning_mode` (`pro`) to chat model configs so admins can turn on OpenAI's Pro reasoning mode for a model, alongside the other OpenAI request options on the model form such as `service_tier`. The field is offered for any model on an OpenAI provider; the field description says Pro is supported from the GPT-5.6 Sol generation and that requests fail when Pro is set on a model that does not support it. There is deliberately no supported-model list anywhere: a newly released model that supports Pro works with no code change, and OpenAI rejects the request when the model does not. Validation rejects only values other than `pro`, non-OpenAI providers, and configs that explicitly force plain sampling (`reasoning_model=false`) or Chat Completions (`use_responses_api=false`), including partial updates that move a configured model onto such a provider or transport. A configured mode implies the Responses API and reasoning-model treatment when `openai_config` leaves those unset (`chatprovider.effectiveOpenAIConfig`), so an alias the pinned SDK has never seen, such as `gpt-daybreak-blue-latest`, still gets `effort` and `summary` and drops `temperature`. The same effective config feeds the client options and the recorded transport, so the two cannot disagree. The pinned fantasy OpenAI provider options do not carry `reasoning.mode`, so the mode is applied as a client-scoped `openai-go` request option when the model client is built rather than per call. The SDK merges pre-serialization `WithJSONSet` overlays by top-level key, so the key is escaped (`reasoning\.mode`) to add `mode` to the existing `reasoning` object instead of replacing `effort` and `summary`. `TestResolveModelCallReasoningModeWire` pins the resulting request body for streaming and non-streaming calls and checks that the fixed computer-use model does not inherit the mode; AI Gateway forwarding of the `reasoning` object is covered in `aibridge`. Because the option is bound to the model client, every call made through a Pro model config carries it, including title generation and quick generation when those fall back to the chat's model; deployments that want cheaper auxiliary calls should point the title generation override at another model. Frontend: the field renders through the existing schema-driven provider options with no hand-written field logic. Two generic changes: `visible_for_providers` is now honored for provider fields the way it already was for general fields (render and payload), so the OpenAI-scoped select does not appear or serialize for Azure, which shares the OpenAI field group; and the add/update model save toasts now carry the server's error detail, so a rejected combination such as Pro with Use Responses API at Off tells the admin which field to change. Docs: `docs/ai-coder/agents/models.md` gains a Reasoning Mode row in the OpenAI provider-specific options table (from the documentation check comment https://github.com/coder/coder/pull/29584#issuecomment-5752457808), and its Azure note now says Azure OpenAI lacks that one option. Not changed: `coderd/x/chatd/ARCHITECTURE.md`. Its OpenAI transport selection table needs a `reasoning_mode` row (client-applied, neither transport) to match `TestProviderOptionsTransportParity`; left for the human author. <details> <summary>Delivery record</summary> - Local validation on every pushed head: targeted Go tests (chatopenai, chatprovider, chatd wire test, aibridge integration test, coderd DB tests for persistence, invalid input, and partial updates), red/green on the wire test (injection removed, and unescaped key), Vitest (`modelConfigFormLogic`, `ModelForm`), Storybook tests for `ModelFormProviderConfig`, biome, tsc, oxlint, golangci-lint on touched packages, pre-commit hook. - Codex round 1 on `e7dbaefeafc`: 3 findings (Storybook assertions, ARCHITECTURE.md TODO, `gpt-daybreak-blue-latest` alias). Disposition: assertions moved to Vitest and alias accepted in `8fccf111111`; ARCHITECTURE.md left untouched by author instruction. Threads replied to and resolved. - Codex round 2 on `8fccf111111`: 1 finding (fixture naming, FE9), renamed in `23449e92317`. Round 3 on `23449e92317`: 1 finding (fixture location, FE9), moved to `testHelpers/chatModels.ts` in `c3bd5aa370f`. Round 4 on `c3bd5aa370f`: "Didn't find any major issues" (https://github.com/coder/coder/pull/29584#issuecomment-5735119236). All threads resolved. - Remote UAT round 1 (chat https://dogfood.cdr.dev/agents/f5ed1d16-be1d-4d39-952b-126a6a829ef1) exercised `e7dbaefeafc`: endorsed PASS. Real `gpt-5.6-sol` turns showed `"mode": "pro"` / `"standard"` / no key in the Debug tab with effort and summary intact; 14 POST and 6 PATCH rejections captured; UI select visibility, persistence, reload, and clearing verified. Low, non-blocking notes: the `gpt-5.6` alias revert in the model identifier field is pre-existing; Pro is dropped silently when a model or transport change makes it unsupported; Pro applies to auxiliary calls (see above). - Remote UAT round 2 on `c3bd5aa370f` (same chat, alias and core re-verify): core PASS, alias FAIL. With `gpt-daybreak-blue-latest` the request carried `{"mode": "pro"}` without the configured effort and summary and kept sending `temperature` (provider 400 then retry on quick generation and title calls), because the SDK does not classify the alias as a reasoning model. Fixed in `d4c338de767`: a configured mode now implies a reasoning model unless `openai_config.reasoning_model` is set, and a mode on a config that forces plain sampling is rejected. Alias UI/API behavior, rejections, and known-model Pro/Default turns all passed on `c3bd5aa370f`. - Codex round 5 on `d4c338de767`: "Didn't find any major issues" (https://github.com/coder/coder/pull/29584#issuecomment-5736190356). Zero unresolved threads. CI green on `d4c338de767`. - Remote UAT round 3 on `d4c338de767` (same chat): endorsed PASS. Alias runs are single-attempt 200s with `{"effort", "summary", "mode": "pro"}` and no `temperature` (quick generation and title calls no longer retry); `reasoning_model=false` plus a mode is rejected by POST and PATCH with the stored config unchanged; the Reasoning Model override at Off hides the select and drops the mode on save; `gpt-5.6-sol` Pro turn unchanged. Remaining low notes, none introduced here: rejection detail for a non-OpenAI provider names the model rather than the provider; Pro is dropped silently when an override makes it unsupported; `PATCH model_config` replaces the whole object (pre-existing on main). - coder-frontend-review on `d4c338de767` (8 role reviewers, 3 passes): 13 failing checkpoints, chiefly a TS mirror of the Go model regex, the `json_name === "reasoning_mode"` gate duplicated in the render filter and payload builder, a defaulted `model` parameter, and comment and type nits. Fixed in `554c90d5fd9`: the pattern and provider scope are generated onto the field schema, one predicate is shared by both call sites, `buildModelConfigFromForm(provider, model, form)` requires the model, and the ModelForm test also asserts the select disappears for an unsupported model. Red/green: stripping `supported_models` or `visible_for_providers` from the generated schema fails 21 and 1 Vitest cases respectively. Declined with rationale: RO4 (move the fixture to `ModelsPage/testFixtures.ts`; FE9 in `FRONTEND_PATTERNS.md` names `testHelpers/chatModels.ts`, and Codex round 3 required it) and a DF5 nit to gate on the committed identifier and warn when a saved mode is dropped (behavior change, separate follow-up). Final pass: all checkpoints PASS or N/A. - Remote UAT round 4 on `554c90d5fd9` (same chat, focused regression after the frontend-review refactor): endorsed PASS. All six claims held (Pro round trip with effort and tier intact; unsupported identifiers hide the select and a save drops the stale mode while keeping the other options; Azure never shows or saves it; the alias shows it only with the Responses override On; Reasoning Model Off hides it and drops it; three real `gpt-5.6-sol` Pro turns were single-attempt 200s with `{"effort","summary","mode":"pro"}` and no `temperature`). Probes aimed at the refactor also passed: `gpt-5X6-sol` is rejected (dot escaping survived the JSON round trip), whitespace-padded identifiers still match, the other 11 OpenAI fields and the Anthropic section still render. Remaining low notes are carried over from round 3 plus one naming note ("Reasoning Mode" versus "Reasoning Model"). The final head `abb58df77d8` differs from `554c90d5fd9` only in `ModelForm.test.tsx`, so it ships the same production code. - Codex round 6 on `554c90d5fd9`: 1 finding (https://github.com/coder/coder/pull/29584#pullrequestreview-5260492465): the two `toBeInTheDocument` assertions added in the frontend-review round violate FE1. Confirmed against `site/AGENTS.md`; removed in `abb58df77d8` (test-only, 7 deletions; the payload assertion keeps the behavior coverage and the `ProviderConfigOpenAI` story captures the hidden state). Thread replied to and resolved. - Codex round 7 on `abb58df77d8`: "Didn't find any major issues" (https://github.com/coder/coder/pull/29584#issuecomment-5749626071). Zero unresolved threads. CI green on `abb58df77d8` (23 success, 8 skipped, `required` pass). - Design change on `e99152e5c57` (owner direction: no model gating; "none or pro" for any model; tooltip states the GPT-5.6 Sol constraint and that requests fail on unsupported models). Removed `codersdk.ChatModelReasoningModeModels`, the generated `supported_models`, `isFieldApplicableToModel`, the `gpt-daybreak-blue-latest` special case, and the `standard` enum value; `ValidateReasoningMode(provider, config)` no longer takes the model; `effectiveOpenAIConfig` makes a mode imply Responses and reasoning-model treatment. PR footprint went from +1130/-22 to +769/-18. Local validation: `go test` for chatopenai, chatprovider, chatd wire test, and the coderd API tests (persistence now covers `gpt-5.6-sol`, `gpt-4o`, `gpt-daybreak-blue-latest`, `gpt-7-nova`; invalid input now rejects `standard`), golangci-lint on touched packages, Vitest (187 tests across `modules/aiModels` and `ModelsPage`), biome, tsc, pre-commit hook. - coder-frontend-review on `e99152e5c57` (8 roles, 1 pass plus a TS and CD confirmation pass): 9 failing checkpoints (SD4, CD1, CD3, CD4, TS3, TS7 x2, RO3, RO5, TN4, DF5). Fixed in `e06bfbe4299`: the ModelForm test edits `mockGPT5` so its provider matches the selected provider state, types the update mock like the sibling story, and drops an unused route; the story spreads `mockGPT5` with a saved mode instead of a dedicated shared fixture (`MockGPT56Pro` removed, `testHelpers/chatModels.ts` back to base); a `ProviderConfigAzure` story captures the panel without `reasoning_mode`; comment nits. Left as a nit with justification: RO3 (the one-line `!hidden && isFieldVisibleForProvider` predicate now appears in both `getVisibleProviderFields` and `getVisibleGeneralFields`; hoisting a helper for two call sites is not worth it). Confirmation pass: TS all PASS; CD flagged one wording nit, fixed before commit. - CI green on `e06bfbe4299` (23 success, 8 skipped, `required` pass). - Codex round 8 on `e06bfbe4299`: 1 P2 finding (https://github.com/coder/coder/pull/29584#discussion_r4057659673): the form still offers Pro with Use Responses API or Reasoning Model at Off, a combination the server rejects, and the failure was not actionable. Disposition: the select stays visible by owner direction (no client-side gating of this field beyond the provider scope; an explicit rejection is preferred over the earlier silent drop), and `e2b43c3aee7` makes the add/update save toasts show the server detail so the admin sees which field to change. Thread replied to and resolved; zero unresolved threads. - Remote UAT round 5 on `e06bfbe4299` (same chat): endorsed PASS with two UI issues to land before release. All seven probes passed: the select offers only Default and Pro for `gpt-5.6-sol` and `gpt-4o` with the tooltip text verbatim; Pro saves on `gpt-4o` and the real turn fails visibly with the provider's "reasoning.mode is not supported with this model" after a single 400 attempt, and works again once Pro is cleared; `gpt-daybreak-blue-latest` with Pro and no overrides is a single 200 to `/v1/responses` with `{effort, summary, mode: "pro"}` and no `temperature`; the `gpt-5.6-sol` Pro turn is unchanged; POST and PATCH reject `standard`, `PRO`, empty, Responses Off, Reasoning Model Off, and Azure, openai-compat, and Anthropic providers with the stored config unchanged, while a model-only PATCH to `gpt-4o` now succeeds; the Azure form shows no Reasoning Mode; the alias with an explicit Responses override still works. Reservations: (1) medium, the UI conflict path only showed "Invalid model config." without the detail (fixed in `e2b43c3aee7`, not yet UAT-exercised); (2) low-medium, a dev-DB row still holding `standard` from round 2 renders an empty red select whose message is the whole field description plus "has an invalid value." and blocks saving unrelated fields (pre-existing generic behavior of `yupTestForField` using the description as the label; no released data can hold `standard`, so no migration); (3) low, no hint next to older identifiers (documented design); (4) low, a chat on such a stored row fails with a generic headline (pre-existing). - Final head `e2b43c3aee7` differs from `e06bfbe4299` only in the two save-toast handlers (`AddModelPage.tsx`, `UpdateModelPage.tsx`, 8 insertions). CI is green on `e2b43c3aee7` (skipped=8, success=23, `required` success). Codex has not run on `e2b43c3aee7`. - Remote UAT round 6 on `e2b43c3aee7` (same chat, https://dogfood.cdr.dev/agents/f5ed1d16-be1d-4d39-952b-126a6a829ef1, settled 2026-09-20T19:02Z): endorsed PASS on the exact final head. Build proven by `/api/v2/buildinfo` (`v2.37.2-devel+e2b43c3aee`, `external_url` at the full SHA) and the UI badge. The round 5 toast issue is resolved: Add and Update saves with Pro plus Use Responses API Off or Reasoning Model Off show "Invalid model config." with the server detail as the description, one 400 each, nothing stored. Compact regression of every round 5 probe held (dropdown and tooltip; Pro on `gpt-4o` fails visibly with the provider's `reasoning.mode is not supported with this model` and works after clearing; alias with and without the Responses override and `gpt-5.6-sol` all send `{effort, summary, mode: "pro"}` with no `temperature` in a single 200; POST and PATCH rejection matrices with stored config unchanged; Azure form without the field). Legacy `standard` row: fails closed on chat, and re-picking Pro or Default saves. Remaining notes, none blocking: the malformed validation copy for an invalid stored enum (pre-existing `yupTestForField` label choice, dev-DB rows only), Pro offered for models that cannot accept it (documented design), and a pre-existing `quickgen` status quirk on `gpt-4o` unrelated to this field. Secret scan clean. - Final head `4f3c6106dfe` adds one docs-only commit on top of `e2b43c3aee7` (`docs/ai-coder/agents/models.md`, 9 insertions, 8 deletions, no code). Remote UAT round 6 exercised `e2b43c3aee7`; the docs commit is not UAT-relevant. Validated with `markdown-table-formatter`, `markdownlint-cli2`, and the pre-commit hook (`fmt/markdown`, `lint/markdown`, `lint/emdash`, `lint/typos`). CI is green on `4f3c6106dfe` (success=24, skipped=7, `required` success) and the documentation check re-run marked its item addressed (https://github.com/coder/coder/pull/29584#issuecomment-5752457808). - Review tally for this PR: Codex 8 completed rounds; coder-frontend-review 34 role passes (24 on `d4c338de767`, 10 on `e99152e5c57`); remote UAT 5 rounds; no human review yet. This is far past the six-review guardrail, so no further Codex or agent review has been requested. Whether to spend another Codex pass on `e2b43c3aee7` is an owner decision; human review is still required before merge. </details> > Xum acted on behalf of @ibetitsmike. |
||
|
|
29ae50d9c9 |
feat: accept include_related query param on get workspace by ID (#29539)
Part of the lite `codersdk.Workspace` work ([GRU-82](https://linear.app/codercom/issue/GRU-82), [RFC](https://app.notion.com/p/coderhq/Lite-Workspace-API-Requests-3aad579be5928060b5e7cc65c539717f)). Follows #28639, which added the `wsrelated` package and parser. Wires the `include_related` query parameter into `GET /api/v2/workspaces/{workspace}`, the first endpoint to accept it. When present, the value is parsed with `wsrelated.Parse` and the resulting selection is threaded into `workspaceData`, so only the requested related data is queried. Omitting the parameter is backward compatible and returns everything (`wsrelated.All`). An invalid value returns `400`. Because related data can now be omitted, the handler no longer assumes the build and template are present: it uses zero values when they are absent, and only enforces the template read-authorization check (`403`) when the template was actually requested. ### Partial-build conversion `convertWorkspaceBuilds` now tolerates a build whose provisioner job or template version was deliberately omitted from the selection, so selections such as `latest_build` (build only) or `latest_build.resources.*` (resources without the job) convert correctly instead of erroring. The omitted fields are left zero (empty `Job`, empty `TemplateVersionName`). Resources are keyed by the build's `JobID` rather than the fetched job row, so they load independently of whether the job is selected. The integrity error is preserved for full-data callers: when a job or template version is requested but missing, conversion still fails. The selection config (`wsrelated.LatestBuild`) is threaded into `convertWorkspaceBuilds` to distinguish "not requested" from "missing". Only this endpoint is wired; the other endpoints that produce `codersdk.Workspace` objects, and the codersdk client functions, come in later PRs. --- *Generated by Coder Agents on behalf of @spikecurtis.* |
||
|
|
9974294ca9 |
feat: report arbitrary workspace agent session types (#28338)
Report session counts as a dynamic app-name map from the agent, the SSH CLI, and the workspace usage API, so a new IDE flows end to end without a schema, proto, or server change. - Report through `Stats.session_counts` on Agent API v2.11. Older agents keep reporting through the deprecated count fields. - Accept arbitrary names from `coder ssh --usage-app` and the workspace usage API. A name the registry does not recognize keeps its identity and is attributed to the `unknown` family. - Add reconnecting PTY counts to the map without overwriting the counts SSH reported. - Normalize and merge names before applying the deterministic 64-name cap, ordered by known apps, then count, then name. Overflow sums into `unknown`, and non-positive counts cannot cancel valid activity. - Strip control characters, treat whitespace-only HTTP app names as absent, and require the exact environment variable prefix when you extract an SSH session type. - Count overflow entries in `coderd_agentstats_session_counts_overflow_total` and keep raw payloads out of logs. - Change the usage API's `app_name` to a string, and update the SDK types and API reference. closes #27410 |
||
|
|
55da502938 |
feat: allow admins to configure an OAuth2 app's scope allowlist (#29313)
Add backend support for scope allowlists on admin-created OAuth2 apps, previously available only through DCR. - Add optional, space-separated `scope` to create/update requests and return canonicalized, deduplicated scopes in app responses. - On create, omitted or empty `scope` means unrestricted. On update, `scope` replaces the allowlist; omission preserves it, and an empty string clears it to unrestricted. - Keep scope enforcement unchanged. Add tests for scope round-trips, DCR canonicalization parity, and authorization narrowing. - Include generated SDK and docs updates. The UI scope picker follows in a separate PR. Part of [PLAT-475](https://linear.app/codercom/issue/PLAT-475). |
||
|
|
8e159a8053 | chore: remove stale TODO shims and dead code (#29252) | ||
|
|
c8b22a9d80 |
feat: add filters to the AI spend CSV endpoint (#29414)
## Description Update the existing CSV export endpoint and SDK to accept user, effective group, provider name, and model filters. ## Changes - Pass the requested filters to the database query. - Validate filters alongside the existing time window. - Continue downloading all matching rows without pagination. > [!NOTE] > Generated by Coder Agents on behalf of @ssncferreira. |
||
|
|
19076beb8d |
feat: attribute AI Gateway usage to workspaces (#29235)
- Adds nullable `workspace_id` to AI Gateway interceptions without a foreign key or index. - Derives direct attribution from strictly parsed server-minted workspace session-token names, excluding user-created tokens and validating the embedded owner. - Derives delegated Coder Agents attribution from the persisted chat workspace ID. - Records `workspace_id` through the additive v1.3 gateway protocol and structured interception logs. - Exposes attribution in session details through `interception_attributions`, including tool-less interceptions and null values for unknown attribution. Closes AIGOV-637 Generated by Coder Agents. |
||
|
|
aae145bdc9 |
feat: make NATS pubsub opt-out via no_nats_pubsub experiment (#29283)
Makes the embedded NATS pubsub an opt-out feature instead of opt-in. The `nats_pubsub` experiment is removed and replaced with a `no_nats_pubsub` experiment, so NATS pubsub is now the default and can be disabled to fall back to PostgreSQL pubsub. NATS clustering requires this replica's routable address, resolved into `clusterHost` from either `--cluster-host` (`CODER_CLUSTER_HOST`) or the DERP relay URL. When neither is set (allowed when DERP is disabled on the primary), NATS cannot form a cluster, so startup logs a big error and falls back to PostgreSQL pubsub. The NATS cluster CA is only minted/rotated when NATS clustering is actually active (experiment not set and a cluster host is present). <details> <summary>Implementation notes</summary> - `codersdk/deployment.go`: removed `ExperimentNATSPubsub` (`nats_pubsub`), added `ExperimentNoNATSPubsub` (`no_nats_pubsub`, display name "No NATS Pubsub"). - `cli/server.go`: NATS is used by default unless `no_nats_pubsub` is enabled; if `clusterHost` is empty, log an error and keep the PostgreSQL pubsub. - `coderd/coderd.go`: gate NATS CA minting/rotation on `!ExperimentNoNATSPubsub && ClusterHost != ""` (i.e. only when NATS clustering is active). - `enterprise/coderd/licenses.go`: updated a stale comment. - `enterprise/coderd/coderd_test.go`: `TestMultiReplica_NATSPubsubPeers` no longer sets the removed experiment. - Regenerated `coderd/apidoc/docs.go`, `coderd/apidoc/swagger.json`, `docs/reference/api/schemas.md`, `site/src/api/typesGenerated.ts`. </details> --- *This PR was generated by Coder Agents on behalf of @spikecurtis.* |
||
|
|
77479408b4 |
feat: make the Coder Agents stream silence timeout configurable (#29394)
The `chatloop` stream silence guard cancels and retries a model attempt after `10m` of silence, and it was hard-coded. It's armed before the request opens, so it also bounds time to first token, and slow local models (e.g. `llama-server` on a large prompt) can spend longer than that on prompt processing alone, meaning every attempt just gets cancelled and retried. This PR adds `--chat-stream-silence-timeout` / `CODER_CHAT_STREAM_SILENCE_TIMEOUT` (default `10m`) and passes it to both the main loop and the advisor. Setting it to `0` disables the guard entirely, and anything above `24h` is rejected, which also keeps the watchdog arithmetic below from overflowing. Whilst doing this I ran into the runner's `15m` task watchdog, which kept counting during an open stream. That silently cancelled any healthy stream longer than `15m`, and would've stopped a silence timeout above `15m` from ever firing. To fix, the silence guard now kicks the watchdog out to `max(15m, silence + 5m)` whenever it arms or sees a part. Silent streams still fail through the guard, healthy streams can run for as long as they like, and hang detection is unchanged everywhere else. With the guard disabled there's nothing to kick against, so arming it just stops the watchdog for the rest of the attempt. That does mean the DB write after the stream isn't bounded either when `0` is set; I think that's fine for an opt-in setting, and a user can still stop the chat from the UI if it wedges there. I did consider removing the guard entirely, but the provider HTTP clients have no timeout, so a provider that holds the connection open would only ever be caught as a generic task hang, which is what #25782 was fixing. |
||
|
|
a90ad83af3 |
feat!: add a hidden flag to disable dynamic parameter closure evaluation (#29356)
**What changed** Dynamic parameter rendering now evaluates only the coder parameter blocks and what they reference. Other root-module resources are skipped. Parameter, preset, and tag values are unchanged; optimizing rendering on large templates. **How to revert** Set `CODER_DYNAMIC_PARAMETERS_FULL_EVALUATION=true` (or `--dynamic-parameters-full-evaluation`) on `coder server` to restore full evaluation. The flag is hidden and needs no restart of workspaces. If you need it, please [open an issue](https://github.com/coder/coder/issues/new) with the template so we can fix the root cause. **Troubleshooting** Symptoms would be a parameter default, option list, preset value, or workspace tag that shows as unknown or empty after upgrading, when it was populated before. Confirm by setting the flag above; if the value comes back, report it. Templates written in `.tf.json` are not affected (they always use full evaluation). **Why** Rendering re-ran the entire template graph on every parameter change in the workspace form, which dominated latency on large templates. Resources a workspace would create cannot feed a parameter, so evaluating them is wasted work. The optimization lives in coder/preview#226 (coder/trivy#74); this PR adds the deployment-level escape hatch. --- - `CODER_DYNAMIC_PARAMETERS_FULL_EVALUATION` / `--dynamic-parameters-full-evaluation` (hidden, default `false`) on `DeploymentValues`. - `dynamicparameters.PreviewOptions(dv)` maps it to `preview.OptionFullEvaluation()`; `dynamicparameters.WithPreviewOptions` threads it through the loader to `preview.Preview`. - Wired at the three render paths that hold deployment values: the template version tags extractor, the dynamic parameters websocket, and `wsbuilder` builds created from `coderd` (which call `.DeploymentValues(...)`). Not covered: the autobuild lifecycle executor and the enterprise prebuilds reconciler construct `wsbuilder` without deployment values, so builds started from those paths use preview's default regardless of the flag. Those only re-render for builds, not the keystroke websocket path the optimization targets. Prepared with Coder Agents assistance. |
||
|
|
dd4f5ae48a |
fix: load AI Gateway session provider filter without AIProvider read (#28966)
> 🤖 This PR was modified by Coder Agents on behalf of Jake Howell.
The Provider filter on `/ai-gateway` called the owner-only
provider-config API (`GET /api/v2/ai/providers`). Site auditors can read
sessions but not that config, so the dropdown was empty, and typing
`provider_name:…` failed the whole sessions list because search looked
up the name with the same permission.
- Add `GET /api/v2/ai-gateway/providers`, returning display metadata
only (`name`, `type`, `display_name`, `icon`) from `ai_providers`,
including disabled and soft-deleted rows that past sessions still
reference. When a name was reused, the live row wins.
- Authorize it in `dbauthz` on `aibridge_interception` read rather than
`ai_provider` read, so owners and auditors get labels and icons without
access to configuration. Members get 404.
- Match `provider_name` as a plain string in session search instead of
looking up `ai_providers`. Unknown names return an empty page, not a
validation error.
- Point the Provider dropdown at the new endpoint; filter by name, show
`display_name`, and render the icon from `type`/`icon`.
The endpoint reads the small `ai_providers` table instead of grouping
`aibridge_interceptions`, so it needs no new index and does not inherit
the scan cost noted for the models/clients lists. It is registered only
under `/ai-gateway`, not the legacy `/aibridge` alias.
|
||
|
|
263f2c207e |
feat: register AI Gateway proxy experiment and share provider helpers (#29347)
- Add `ai-gateway-reverse-proxy` experiment and update generated API types and documentation. The experiment has no runtime effect yet. - Extract shared (will be used by next PRs in stack) provider routing and key-pool enumeration helpers. - Log unsupported routes at Debug level. |
||
|
|
9d97337277 |
feat: list organization AI spend by user (#29129)
Third of a four-PR stack that reworks the AI spend page onto the
released organization spend export, `GET
/api/v2/organizations/{organization}/ai/spend/export`, and a sibling
per-user endpoint, `GET
/api/v2/organizations/{organization}/ai/spend/users`, instead of the
deployment-wide `/api/v2/ai-gateway/spend/*` endpoints this stack
previously proposed. Every PR in the stack was rewritten in place from
current main; the head branch name predates the rework. The export's
accounting rules are unchanged: token usage by `created_at` in
`[period_start, period_end)`, attributed to the organization through the
effective budget group, so the page reconciles with the CSV and with
daily budget accounting.
Adds `GET /api/v2/organizations/{organization}/ai/spend/users`, a
paginated per-user report beside the CSV export. It accepts the export's
period parameters and the optional `provider_name`, `model`, and
`client` filters (`client` matches after `COALESCE(client, 'Unknown')`,
as the AI Gateway sessions listing does), and it authorizes identically
through `ResourceGroupMember` in the organization. The response is
`OrganizationAISpendReport`: the applied period bounds,
`retention_start` when retention is enabled (so the page can bound its
date picker), the user count, a `totals` object over every matching
user, and one page of users (`limit` default 10, max 100; `offset` >=
0), each with cost, unpriced usage count, providers, and clients. Each
user row also lists the sorted distinct models they spent through
(e73049f, added on request after the review round).
The period rules (provided together, at most 31 days, within retention,
default narrowed to retention) are shared with the export through the
caller's query parser. As a result the export now rejects unknown query
parameters whether or not a period is given; previously the
excess-parameter check only ran in the explicit-period branch. The
export's parameters and output are otherwise unchanged; the CSV itself
is not filterable.
The JSON rows are per user while the CSV keeps its user x group x
provider x model grain. That is deliberate: the page is the only JSON
consumer, and an explicit `group_by` can be added later without changing
this contract. A page past the last user still carries the window
totals, read from the first page.
Query cost, measured on PostgreSQL 13 with 400k token usages and 200k
interceptions across 4 organizations (31-day window of about 52k usages
for the target organization): `ListOrganizationAISpendUsers` 128 ms
unfiltered and 68 ms filtered by provider. Token usage is read through
the existing partial index on `(effective_group_id, created_at)`; no new
index is needed. The provider and client aggregates were added after
this measurement.
Tests cover pagination validation (including the export rejecting page
parameters), report contents and filters against the CSV, retention
narrowing and rejection, retention disabled, and the role matrix (Owner,
User Admin, Auditor, Org Admin, Org User Admin OK; member 403; other
organization 404).
Previous revisions served this report from the export endpoint through
`Accept` negotiation and also added the dimension filters to the CSV
export (#29220, #29224); the separate endpoint replaces the former, and
the CSV filters were dropped because the page does not use them.
> Xum prepared this PR on behalf of @ibetitsmike.
Codex on e73049f: P2 on the moving `now - retention` lower bound for
clients that echo the default window while paging. Declined: it is the
released CSV export's contract, the report echoes `retention_start`, and
the page never echoes the default window; the handler and tests now use
`OrganizationAISpendPage` (
|
||
|
|
6c7f6b855b |
feat: add openai_config.reasoning_model override and bump fantasy (#29230)
## Why The coder/fantasy fork classifies OpenAI reasoning models by name. The pinned version did not know `gpt-6-astra`, so the Responses client omitted the `reasoning` parameter (the reasoning effort picker did nothing) and forwarded `temperature` (quickgen title calls got HTTP 400 `Unsupported parameter: 'temperature'` and retried). Every new model generation would need a fork release to fix this. Admins need a switch in the model config instead. ## What - Bump `charm.land/fantasy` to coder/fantasy `a511353f83eb`, the `coder_2_33` commit that squash-merged coder/fantasy#57 (the pin also carries coder/fantasy#58, Gemini media tool results): gpt-6 and later generations are recognized as reasoning models, and the provider gains `WithReasoningModelFunc` to override the classification. - New tri-state `openai_config.reasoning_model` on `ChatModelCallConfig`: unset keeps fantasy's name heuristics, `true` forces reasoning-model handling (effort and summary sent, temperature/top_p dropped), `false` forces plain sampling. It is applied once at client construction next to `use_responses_api`. The generated model editor shows it for `openai` and `bedrock` providers, since Bedrock Mantle also serves OpenAI-format models; it is ignored for Anthropic models on Bedrock. - Remove the `IsGPT6Astra` transport fallback in `chatopenai.UsesResponsesAPI`; the bumped SDK recognizes gpt-6 itself (`IsGPT6Astra` stays for the effort clamp). - Regenerated API docs, swagger, TypeScript types, and the model options schema; ARCHITECTURE.md documents the flag. ## Validation - New tests: `TestChatModelCallConfig_ReasoningModelRoundTrip`, `TestModelFromConfig_OpenAIReasoningModelOverride` (request body has `reasoning` and no `temperature` when forced on an unknown model; forced off on gpt-5 drops `reasoning` and keeps `temperature`; unset unchanged), `TestAIGatewayModelBedrockReasoningModelOverride` (Bedrock provider path), `TestIsZeroChatModelCallConfigReasoningModel`, and form-logic cases serializing the field for openai and bedrock. Red-green: removing the constructor wiring fails the request-body assertions. - `go test ./coderd/x/chatd/... -count=1` (full), `go test ./codersdk/... -run ChatModel`, `go test ./coderd/ -run 'ChatModel|Chats'`, `golangci-lint run ./coderd/x/chatd/... ./codersdk/... ./coderd/` (0 issues), `make gen` (stable on rerun), Vitest for `src/modules/aiModels` and `src/api/chatModelOptions` (174 tests), Biome, `tsc --noEmit`, `make pre-commit`. - Remote dogfood UAT (Coder Agents) exercised the editor and chat on the dev AI gateway: the switch shows for OpenAI and Bedrock providers only, persists true/false/unset, and `gpt-daybreak-blue-latest` (an alias the SDK does not recognize) sends `reasoning` without `temperature` when forced on and gets OpenAI's temperature 400 when off or unset. UAT also found the new switch colliding with `Use Responses API` at 375px; tri-state switches now take the full row below `sm`. One open observation for follow-up: in Coder chats on `gpt-6-astra` the upstream stream carried no reasoning-summary events even though `reasoning.summary=detailed` was sent, while the same model returns summaries to a standalone fantasy client; not attributed to this change. - Merged `origin/main` (`eceae296e8d`; the only conflict was the ARCHITECTURE.md TODO block, resolved by keeping main's transport-selection prose and adding a TODO for the GPT-6 Astra sentence this PR makes stale) and moved the pin (`553bfb86bf5`). On that head: `go build ./...`, `go vet ./coderd/x/chatd/... ./codersdk/`, `go test ./coderd/x/chatd/ -run 'ReasoningModel|TestAIGateway|Bedrock|ChatModelCallConfig|Quickgen|Transport'`, `go test ./coderd/x/chatd/chatopenai/... ./coderd/x/chatd/chatprovider/... ./coderd/x/chatd/chatdebug/...`, `go test ./codersdk/ -run 'ChatModel|Reasoning'`, and the pre-commit hook on both commits. The `providers/openai` tree at `a511353f83eb` is byte-identical to the previously pinned PR head `f5b3f253c112`. - The local `pre-push` hook fails in this checkout only on unrelated tests (umask-dependent `TestGetModulesArchive`, two untouched site tests), so the push bypassed it; CI is the gate. For the pin-bump push the hook ran once in full (31,276 tests passed; the only 2 failures were `TestGetModulesArchive`, proven to be this checkout's 0600 file modes: passes after normalizing modes and on an untouched `origin/main` worktree) and was then opted out for this worktree per Mike's instruction. coder/fantasy#57 is merged (`a511353f83eb` on `coder_2_33`) and the pin points at it. Related: #29229 (Bedrock `reasoning_summary` coercion). > Xum acted on behalf of @ibetitsmike for this PR. |
||
|
|
feca38ec74 |
fix: bound OAuth2 request bodies and report the rejection per RFC (#28175)
- Enforce a 4 MiB body limit on `/oauth2/tokens` and `/oauth2/revoke` before parsing, replacing Go’s 10 MiB default. Oversized bodies now return `413 invalid_request` instead of misleading missing-`client_id` errors. - Preserve `/oauth2/register`’s existing body limit while returning protocol-specific `413 invalid_request` errors rather than `codersdk.Response`. - Include JSON decoder details in registration’s malformed-body `400` responses and add raw-body tests to verify the error shape. |
||
|
|
86e43de5f6 |
fix!: authenticate confidential clients at OAuth2 token revocation (#29208)
- Require confidential-client authentication for OAuth2 token revocation, preventing revocation with only a token and public `client_id`. - Accept `client_secret` via form fields or HTTP Basic; reject conflicting credentials. - **Breaking:** Missing or invalid secrets now return 401 `invalid_client` without revoking tokens. `codersdk.RevokeOAuth2Token` requires a `clientSecret` argument (empty for public clients). - Preserve public-client behavior and existing token ownership checks. - Add revocation documentation and regression tests for authentication failures, HTTP Basic, and session preservation. Completes SEC-348. Closes PLAT-507 (CDR-59). |
||
|
|
070a91c1d9 |
feat: hide client secrets for public OAuth2 clients (#29312)
Fix the OAuth2 app edit page for public clients by replacing the secrets table and “Generate secret” button with an explanation and skipping secrets requests, including on initial load. Expose client_type in OAuth2 app API responses and regenerate TypeScript types and API docs. Confidential client behavior remains unchanged. Fixes PLAT-504. |
||
|
|
f5be7ae660 |
feat: remove the oauth2 experiment in favor of CODER_OAUTH2_PROVIDER_ENABLE (#29257)
Third of five for PLAT-492. Removes the oauth2 experiment entirely; CODER_EXPERIMENTS=oauth2 is now treated as an unknown experiment and nothing depends on it. Stacked on #29251. No migration. Removes ExperimentOAuth2 and its generated/API references. Removed outright per review, consistent with experiments having no compatibility guarantee. Migration guidance is covered by the startup logging in #29267 and docs/release notes in #29268, both pointing to CODER_OAUTH2_PROVIDER_ENABLE. Existing unknown-experiment handling and tests already cover leftover oauth2 values. After this merges, main is safe to cut a release from. |
||
|
|
f46ff158c5 |
feat!: remove the Coder Tasks RBAC resource, scopes and permissions (#28750)
Removes the `task` RBAC resource, its five `task:*` API key scopes, and every persisted reference to them. Custom role permission arrays drop their `task` entries; API keys and OAuth2 codes and tokens lose task scopes, and task-only ones are revoked; OAuth2 apps whose scope list named only task scopes get a whitespace-only scope so they stay restricted instead of reading as unconfigured; then `api_key_scope` is recreated without the task values. Generated RBAC, SDK, site and API doc artifacts are regenerated. The `resource_type` enum keeps `task` so historical audit log rows remain queryable. **Breaking change:** migration 000595 revokes task-only keys and grants. The down migration restores the enum values only. **Review changes:** the api_keys scope cleanup deletes any key left without a non-task scope (redundant EXISTS dropped), the allow-list comment states the real reason (`allow_list` cannot be empty), and the migration test keeps each fixture next to its expected post-migration value. Renumbered from 000594 to 000595. **Stack context:** Coder Tasks removal stack (CODAGT-642): #28743 frontend → #28788 CLI → #28789 API → #28790 provisioner → #29084 notifications → #29085 build reasons → #29086 tables → **#28750 permissions**. The last four PRs replace the single data-drop migration that used to live in #28750; each carries one concern and its own migration number. > Created by Xum (AI agent) on behalf of @ibetitsmike. ## Delivery record **Status (2026-09-11 16:30Z): not merged; awaiting re-review.** Head `80ee30141ee81287a03de3f46407f6a421387778` on `main`. **Review history relevant to this diff:** 10 completed Codex code reviews on the monolithic diff (2026-08-28 to 2026-09-01) plus spikecurtis CHANGES_REQUESTED (2026-09-04, asked for the split), spikecurtis COMMENTED 2026-09-08 (three findings on the migration and test, all applied and resolved) and spikecurtis COMMENTED 2026-09-11 ([r3990045458](https://github.com/coder/coder/pull/28750#discussion_r3990045458), [r3990067224](https://github.com/coder/coder/pull/28750#discussion_r3990067224), both applied in `80ee30141ee` and resolved). The review budget is exhausted, so no further discretionary review or final advisory was commissioned; a fresh independent final advisory for the final diff does not exist and remains a documented gap. The reviewer's own re-review is the remaining gate. **Findings and dispositions on the current head:** - OAuth-linked API key fixtures were confusing (deletion came from the token trigger, not the migration): removed from `keys`; the grants loop creates its backing api_keys row inline and asserts only code/token rows. - Missing cases: added `multi-task-scopes-key`, `multi-task-allows-key`, and `task-only-key` (only task scopes and only task allows, deleted). - Earlier round: redundant EXISTS on the api_keys scope DELETE dropped; allow-list comment corrected (`allow_list` cannot be empty); test restructured as before/after tables; renumbered to 000595. **Test evidence for `80ee30141ee`:** `TestMigration000595RemoveTaskPermissions` passes (up, down, re-up); red-green: removing the token DELETE and UPDATE from the migration fails the test at the grants/tokens assertion, file restored byte-identically. Full repository pre-push hook passed before the push (`test` 97s, `test-js` 45s, site build; `pre-push passed (143s)`). Note: this workspace runs a service on loopback:3000, jsdom's default origin, which made `test-js` fail on unmocked inbox requests for any commit; the hook run used an `LD_PRELOAD` shim that only makes `connect()` to loopback:3000 return `ECONNREFUSED`, matching CI, with no change to sources, tests, config, or the host. Exact-head CI: run [34622204759](https://github.com/coder/coder/actions/runs/34622204759) in progress at the time of writing. **Deferred:** `AI Documentation Check` failures on this stack come from the dormant `doc-check-pr-*` workspace (CODAGT-1025), not code. |
||
|
|
1cc73bc43f |
feat: add the CODER_OAUTH2_PROVIDER_ENABLE deployment flag (#29248)
First of five PRs for PLAT-492, adding the opt-in CODER_OAUTH2_PROVIDER_ENABLE flag for the OAuth 2.1 provider. It defaults to false and is not enforced yet, so there is no behavior change. Adds the CLI/env/YAML flag and exposes oauth2_provider in build info. Enables it by default in tests to prepare for route gating. Updates tests, golden files, and frontend fixtures. Follow-ups will gate routes/UI, retire the experiment, add startup logging, and update docs. |
||
|
|
2cf819bfca |
feat: add break-glass user email update (#29256)
Adds an owner-only experimental API and hidden CLI command for break-glass user email corrections. The operation verifies the existing email, updates it transactionally, clears outstanding password-reset state, revokes the target user's Coder sessions and API tokens, and records successful and failed authenticated attempts in the audit log. External-auth links remain unchanged. Generated by Coder Agents. |
||
|
|
940f988cfb |
feat: add deployment-level option to disable Terraform module caching (#29187)
<!-- Generated by Coder Agents on behalf of @Emyrk. --> <img width="762" height="239" alt="Screenshot From 2026-09-11 17-09-41" src="https://github.com/user-attachments/assets/9f31fd1e-4cb2-47ab-8d37-4073df9f0a7c" /> Closes #22834. Adds `CODER_PROVISIONER_DISABLE_MODULE_CACHE` so an admin can disable Terraform module caching for every template at once instead of toggling ~100 templates by hand. - The deployment setting wins. Templates cannot opt back in, and the per-template toggle becomes read-only while the deployment setting is on. - Modules stay cached at template import, so dynamic parameter rendering still resolves module-defined parameters. Only the workspace build is denied the cached files. - Templates report `module_cache_disabled_by_deployment`, and template settings shows why the checkbox is locked. <details><summary>Agent context</summary> Decisions taken with @Emyrk before implementing: 1. **Precedence.** `deployment || template`, no per-template override, so no migration and no nullable column. The rule lives in one place, `codersdk.ModuleCacheDisabled`. 2. **Import-time caching untouched.** `dynamicparameters/render.go` overlays `cached_module_files` at `.terraform/modules` to render module-defined parameters. Skipping the cache there would reproduce the `Module not loaded. Did you run terraform init?` failure reported by a customer, so the deployment setting only affects what `AcquireJob` hands the provisioner. 3. **Write path.** A PATCH carrying `disable_module_cache` is discarded while the deployment setting is on, rather than persisted. Persisting it would silently keep templates opted out after the deployment setting is removed. 4. **API shape.** `disable_module_cache` keeps its meaning (this template's stored value) and the new read-only `module_cache_disabled_by_deployment` reports the deployment state. Reading the effective value from `/deployment/config` was rejected because template admins may lack deployment-config read permission. 5. **Naming.** `CODER_PROVISIONER_DISABLE_MODULE_CACHE` over the issue's `CODER_DISABLE_TERRAFORM_MODULE_CACHE`, to match the provisioning option group. Note: `InsertTemplateParams` has no `disable_module_cache` binding, so new templates always store `false`. With deployment precedence they still behave as opted out, so the create path needed no change. Out of scope and tracked elsewhere: the `coderd_template` Terraform provider attribute (separate repo) and backporting the per-template toggle to `release/2.30`. </details> --- <sub>Coder Agents on behalf of @Emyrk.</sub> |
||
|
|
9cd38b5373 |
feat!: remove the Tasks API from coderd and codersdk (#28789)
Removes the Tasks API and task orchestration from coderd and codersdk: the `/api/v2/tasks` handlers, task middleware and search filters, task name generation, autobuild pause/resume logic, task notification enqueues, telemetry, and the codersdk task types. Regenerates apidoc, the API reference docs, and `typesGenerated.ts`. **Breaking change:** the Tasks API is removed; requests to `/api/v2/tasks` fail. Tasks was deprecated in v2.34. **Stack context:** Coder Tasks removal stack (CODAGT-642): #28743 frontend → #28788 CLI → #28789 API → #28790 provisioner → #29084 notifications → #29085 build reasons → #29086 tables → #28750 permissions. The last four PRs replace the single data-drop migration that used to live in #28750; each carries one concern and its own migration number. **Why:** with the UI (#28743) and CLI (#28788) gone, this deletes the server surface. Database tables, RBAC, and notification templates stay until the top of the stack so every layer builds and migrates independently. **What to scrutinize:** - The `enable-ai-tasks` option is removed outright (review feedback): configs still carrying `enableAITasks` fail to parse until the key is deleted. - provisionerdserver now writes `HasAITask: false` on template/build flags; the column and these lines are dropped in #29085. - `codersdk.ResourceTypeTask` stays so audit logs recorded before the removal keep rendering. **Validation:** `go build ./...`, `go vet ./...`, `go test ./codersdk/...`, site biome and tsc, CLI goldens regenerated, pre-commit hooks. **Size:** +242/-10,792 over 76 files; additions are regenerated docs/goldens and test fixture updates. > Created by Xum (AI agent) on behalf of @ibetitsmike. |
||
|
|
fef0763820 | feat: report template builder build failure reasons in telemetry (#28586) | ||
|
|
8472a6884f |
chore!: remove env-based AI provider configuration (#29053)
> AI tools were used to create this PR Removes deprecated AI provider configuration through environment variables, CLI flags, and YAML. Deletion includes indexed providers and legacy OpenAI, Anthropic, and Bedrock options under both AI Gateway and AI Bridge branding, eg. `CODER_AI_GATEWAY_PROVIDER_<N>_*` or `CODER_AI_GATEWAY_ANTHROPIC_KEY`. Removes the associated startup-seeding code. Updates tests and documentation. **Breaking change:** Remove [obsolete AI provider CLI flags and YAML keys](https://coder.com/docs/ai-coder/ai-gateway/providers#database-management-of-providers) before upgrading, otherwise Coder will fail to start with an `unknown flag` or `unknown option` error. Provider environment variables are ignored and no longer seed the database. Existing database-stored provider configuration is preserved. |
||
|
|
68ca033d67 |
fix: deliver the rest of the invalid_request class to the client (#28736)
**TL;DR** Fifth of the stack, split out of #28045. #28450 delivered the errors raised *after* the callback is trusted and left the parameter failures behind. This PR delivers those, and replaces the implicit ordering that decided where an answer went with an explicit classification. | PR | What it does | |---|---| | #28007 | Schema: `codes.scope` and `tokens.scope`, so a negotiated scope has somewhere to live. | | #28167 | `ScopesCover` compares an allowlist against a request by permission coverage rather than by name. | | #28178 | The authorize endpoint negotiates the scope against the app's allowlist and persists it on the code. | | #28179 | The consent page lists the negotiated permissions, and `invalid_scope` reaches the client's callback. | | #28450 | The same delivery for every other error raised once the callback is trusted. | | **#28736 (this)** | The parameter failures #28450 left behind, and the classification that decides where each answer goes. | - Stacked on #28450. Review that first. - Nothing about what a token can do changes here. This is delivery, not enforcement. **Contract change** A rejected parameter now arrives at the app's registered callback with `error=invalid_request`, a description naming every failing field, and the request's `state`. Both verbs. | Verb | Was | |---|---| | GET | static "Invalid Query Parameters" page, 400 | | POST | `WriteOAuth2Error`, 400 | An integrator watching for either now reads the error from its own callback instead. **Two failures still answer on Coder**, because in neither case is the callback trustworthy yet: - A `redirect_uri` that does not parse, or does not exactly match the registration. Redirecting to it would defeat the check that just rejected it. - A `client_id` sent more than once, or naming something other than the app the callback was matched against. Coder cannot tell whose registration it is about to redirect to. An absent query `client_id` is **not** in that group. `httpmw` also reads the POST form body and the §2.3.1 Basic credential, so an absent query parameter still names a client and its failure is deliverable. **Precedence change.** An app whose *registered* callback does not parse, or uses a rejected scheme, now answers 500 even when the request also carries parameter errors; that used to answer 400. Decided before any parameter is read, so the others are never detected. Only reachable for an app row that bypassed registration. `DangerousCallbackSchemeOutranksParseFailure` pins it. **Also in this PR** - **Unrecognized parameters are ignored**, as §3.1 requires, rather than rejected by `ErrorExcessParams`. An OIDC `nonce` or a vendor extension no longer fails the request. Repeats of parameters the endpoint does read are still rejected. - **Every unsupported `response_type` gets one code.** Read as text rather than through the SDK enum, so a value with no Go constant behind it answers `unsupported_response_type` like `token` does, instead of splitting on whether the SDK names it. - **A malformed `resource` answers `invalid_target`** (RFC 8707 §2), but only when nothing else failed. A client retrying on `invalid_target` would otherwise resend a request still broken in a field it never heard about. - **`error_description` is bounded and readable.** Capped at 2048 characters and marked `(truncated)` before the log field or the `Location` header is written. Entries read `field: reason` joined with `; `, not the parser's debug shape, whose details contain commas and cannot be split apart again. - **A repeated `state` is charged to the client, not the callback.** Reading `state` shares a function with the `redirect_uri` match, so it used to fall into that carve-out and answer on Coder. **Where in the OAuth Flow** <details> <summary>Diagram: the three-way dispatch, and what licenses a redirect</summary> ```mermaid flowchart TD NEW["newAuthorizeResponse<br/>parses the registered callback, checks its scheme,<br/>exact-matches any redirect_uri, reads state"] NEW -->|"registration unusable"| C500["500 on Coder<br/>server_error, value logged not echoed"] NEW --> PARSE["extractAuthorizeParams<br/>reads every parameter, collects all failures"] PARSE -->|"no failure"| OK["GET: consent page<br/>POST: authorization code"] PARSE -->|"failure"| KIND{"authorizeFailure.kind()"} KIND -->|"corrupt registration"| C500 KIND -->|"redirect_uri or client_id at fault"| CODER["400 on Coder<br/>RFC 6749 4.1.2.1 carve-out"] KIND -->|"anything else"| CLIENT["302 to the callback<br/>invalid_request or invalid_target, with state"] ``` </details> - Authorize endpoint only, both verbs. Token exchange, refresh, and revocation are untouched, and `ErrorExcessParams` still guards the token endpoint. - `validatedCallbackURL` becomes `authorizeResponse`, built only by `newAuthorizeResponse`, which runs the scheme check and the exact match in that order. Holding one is what licenses a redirect, so the ordering is structural rather than a convention each call site remembers. - The scheme is checked on the *registered* URL, since `p.RedirectURL` returns the client's URI on a mismatch and checking that would blame the app for a request it never made. - `state` moves onto the type, out of the parameter lists of `withQuery`, `errorURL`, `codeURL`, and `redirectAuthorizeError`, so no call site can emit a response the client cannot correlate. - `extractAuthorizeParams` returns one `authorizeFailure` instead of two trailing values, and both handlers dispatch on `kind()` rather than re-deriving precedence from field checks. **What it satisfies** - RFC 6749 §4.1.2.1: a failure that is not a bad redirection URI or client identifier is reported through the redirection URI. That is the whole PR. Its two exceptions "MUST NOT" be redirected to, hence the carve-outs. - RFC 6749 §3.1: unrecognized parameters MUST be ignored, and no parameter may appear more than once. Both now hold here. - RFC 6749 Appendix A: `error_description` is confined to the permitted set, on the decoded value. - RFC 8707 §2: a `resource` that is not an absolute URI without a fragment answers `invalid_target`. - RFC 7636 §4.4.1: a malformed `code_challenge` is rejected at the authorization request rather than deferred to token exchange, where the error would point at the `code_verifier`. - Not yet: CRF-26 (the `server_error` sites) and CRF-13 (fragment delivery), both as in #28450. **Docs and Swagger.** `docs/admin/integrations/oauth2-provider.md` gains entries for the redirected parameter errors, `invalid_target`, and the two failures that stay on Coder. Both authorize verbs document their 400 and 500 responses and stop advertising `response_type=token`, which meant declaring the parameter as a `string`, since `Enums` appends to what swaggo derives from the type. --- Split out of #28045 ([PLAT-479](https://linear.app/codercom/issue/PLAT-479)). Fifth of the stack, stacked on #28450. ## Manual Tests Verified by hand against a local dev deployment (`v2.37.0-devel+1145d35a47`, dev Postgres), in addition to the automated suite. The build string was checked first, because `develop.sh` builds from whatever the tree held when it started and every result below would otherwise be describing the wrong binary. Two scenario groups need state the API cannot produce. The scope allowlist is reachable only through dynamic client registration, which was enabled for the run and disabled again at the end. A registered callback that does not parse, or that uses a blocked scheme, is refused at registration, so those rows were planted directly with `psql` on a purpose-built client and restored afterwards. **28 scenarios, all passing.** No correctness or security defect was found in the code this PR changes. Seven observations came out of the run: six are consistency, documentation or diagnosability points, and one is a small defect that predates this PR. <details> <summary><b>Scenario summary, all 28</b></summary> | # | Scenario | Result | |---|----------|--------| | 1 | A well-formed request still succeeds on both verbs, and the consent page renders | Pass | | 2 | A rejected parameter now reaches the client's callback on `POST` | Pass | | 3 | The same on `GET`, and the consent page does not render first | Pass | | 4 | The description names every failing field, joined with `; ` | Pass | | 5 | A mismatched `redirect_uri` is answered on Coder with no `Location` on either verb | Pass | | 6 | An unparseable `redirect_uri` likewise, and the echoed value is HTML escaped | Pass | | 7 | A repeated `client_id` is answered on Coder although the callback was valid | Pass | | 8 | A single query `client_id` cannot disagree with the resolved app over HTTP | Pass | | 9 | A `client_id` supplied only in the `POST` form body is delivered, not withheld | Pass | | 10 | A `{UPPERCASE}` `client_id` is delivered, and also succeeds end to end | Pass | | 11 | A repeated `state` is delivered rather than charged to the redirect carve-out | Pass | | 12 | A registered callback with a blocked scheme answers 500 on both verbs | Pass | | 13 | An unparseable registered callback answers 500, indistinguishably to the caller | Pass | | 14 | Corrupt registration outranks a deliverable failure and both carve-outs | Pass | | 15 | The corrupt value is logged with the app ID and never appears in a response | Pass | | 16 | Restoring the row restores normal behaviour with no restart | Pass | | 17 | Every unsupported `response_type` gets one code; an empty one is `invalid_request` | Pass | | 18 | An unsupported `response_type` is not recast as a missing `code_challenge` | Pass | | 19 | Unrecognized parameters are ignored, including a case-variant `REDIRECT_URI` | Pass | | 20 | A misspelled `redirect_url` is ignored and cannot smuggle a destination | Pass | | 21 | Repeated known parameters are still rejected | Pass | | 22 | `resource` answers `invalid_target` alone and `invalid_request` in company | Pass | | 23 | A fragment in `resource` is rejected | Pass, with one gap | | 24 | A long description is capped at 2048 and marked `(truncated)`, on both verbs | Pass | | 25 | The description is sanitized to the RFC 6749 §4.1.2.1 character set | Pass | | 26 | The registered callback query is retained except the reserved names | Pass | | 27 | Scope rejections still reach the callback, and no consent page renders | Pass | | 28 | Declining consent carries `access_denied` and issues no code | Pass | </details> <details> <summary><b>Observations, all 7</b></summary> | # | Observation | Severity | |---|-------------|----------| | 1 | `invalid_request` is returned in three description shapes: the parser's `Invalid query params: field: reason; ...` aggregate, the PKCE validator's single message, and `scopeFailureResponse`'s. A client cannot parse all three with one rule. | Consistency, reviewer call | | 2 | The phase 2 runbook for #28045 asserts the old `field: x detail: y` message shape, which this PR replaces. That doc needs a one-line update. | Docs follow-up | | 3 | `clientIDInDoubt`'s `default` branch is unreachable over HTTP, because `httpmw` derives `app.ID` from the same query value the parser reads. Defensive rather than dead, but the comment does not say so. | Comment clarity | | 4 | A `POST` supplying `client_id` only in the form body always fails with `client_id ... is required and cannot be empty`, naming a parameter it did supply. `httpmw` reads the body, `RequiredNotEmpty` reads the query. Pre-existing. | Misleading diagnostic | | 5 | A misspelled parameter is invisible from every angle at default verbosity. The client gets a 302 with a code, its redirect is silently replaced by the registered one, and the `ignoring unrecognized authorization parameters` line is `logger.Debug` so it is not emitted. | Diagnosability | | 6 | `resource` sent twice answers `invalid_target` rather than `invalid_request`. RFC 8707 §2 frames `invalid_target` as being about the resource value; a duplicated parameter is a malformed request under RFC 6749 §3.1. | Low, error code choice | | 7 | `resource=https://api.example.com/#` (trailing `#`, empty fragment) is accepted and stored with the `#` intact, so the persisted audience is not textually equal to the fragment-free form. `url.Parse` maps empty and absent fragments both to `Fragment == ""`. Pre-existing, in `tokens.go`. | Defect, low severity | </details> **One note for anyone re-running this.** Every request below depends on `$CHALLENGE` from the most recent `new_pkce` call. Forgetting to call it sends an empty `code_challenge`, which fails with the fixed "is required and cannot be empty" message at 98 characters and looks exactly like a cap or a validator failing to fire. That cost one wrong measurement during this run before the numbers below were taken. <details> <summary><b>Shell helpers used throughout</b></summary> ```bash export BASE_URL=http://localhost:3000 export AUTH_HEADER="Coder-Session-Token: $(cat ./.coderv2/session)" export PGPASSWORD=$(cat ./.coderv2/postgres/password) export PGPORT=$(cat ./.coderv2/postgres/port) pg() { psql -h localhost -p "$PGPORT" -U coder -d coder -tAc "$1"; } plant_callback() { pg "UPDATE oauth2_provider_apps SET callback_url = '$2' WHERE id = '$1';"; } urlenc() { jq -rn --arg v "$1" '$v|@uri'; } # 43 unreserved characters every time. Base64url of the raw 32 bytes. new_pkce() { VERIFIER=$(openssl rand 32 | base64 | tr -d '\n=' | tr '+/' '-_') CHALLENGE=$(printf '%s' "$VERIFIER" | openssl dgst -sha256 -binary | base64 | tr -d "=" | tr '+/' '-_') STATE=$(openssl rand -hex 16) } authz_url() { local url="$BASE_URL/oauth2/authorize?client_id=$1&response_type=code" url="$url&redirect_uri=$(urlenc "$2")&state=$STATE" url="$url&code_challenge=$CHALLENGE&code_challenge_method=S256" printf '%s' "$url" } # The core assertion of the whole run: what answer, delivered where. answer() { curl -s -o /dev/null -D - -X "$1" "$2" -H "$AUTH_HEADER" | grep -iE '^HTTP/|^location:'; } show_callback() { python3 - "$1" <<'PY' import sys, urllib.parse q = urllib.parse.urlparse(sys.argv[1]).query for k, v in urllib.parse.parse_qsl(q, keep_blank_values=True): print(f"{k} = {v}") PY } ``` Fixtures, all registered through DCR: ```text plat479-plain http://localhost:9876/callback plat479-query http://localhost:9876/callback?tenant=acme&error=stale plat479-corrupt http://localhost:9876/callback (overwritten by psql in 12 to 16) plat479-reserved http://localhost:9876/callback?tenant=acme&code=FAKECODE&error=stale&error_description=oldmsg&state=oldstate&keep=yes plat479-ci http://localhost:9876/callback (scope allowlist coder:workspaces.access) ``` </details> <details> <summary><b>1. Baseline: a well-formed request still succeeds</b></summary> ```bash new_pkce; answer GET "$(authz_url "$APP_ID" http://localhost:9876/callback)" new_pkce; answer POST "$(authz_url "$APP_ID" http://localhost:9876/callback)" ``` ```text === GET === HTTP/1.1 200 OK === POST === HTTP/1.1 302 Found Location: http://localhost:9876/callback?code=coder_dzvaCPf9W1_...&state=e321bd5d5b594a1fae8a2d5da654b84a ``` `GET` carries no `Location` at all, so the consent page really rendered rather than redirecting. The `state` echoed is the one sent. The code persisted as `coder:all`, this app having no allowlist, with `redirect_uri` recorded because the request supplied one. Also driven through a real browser rather than curl, so the consent form's `nosurf` token is the one submitted rather than the session-token header alone. Clicking **Allow** delivered `code` and `state` to the callback. Both request shapes agree on the success case. Not to be misread: `oauth2_provider_app_codes` holds one row after both POSTs, not two. `ProcessAuthorize` opens its transaction with `DeleteOAuth2ProviderAppCodesByAppAndUserID`, so a row count is not a count of successful authorizations. That predates this PR. </details> <details> <summary><b>2 to 4. A rejected parameter now reaches the client's callback</b></summary> ```bash new_pkce BAD="$BASE_URL/oauth2/authorize?client_id=$APP_ID&response_type=code" BAD="$BAD&redirect_uri=$(urlenc http://localhost:9876/callback)&state=$STATE" BAD="$BAD&code_challenge=short&code_challenge_method=S256" answer POST "$BAD" answer GET "$BAD" ``` ```text HTTP/1.1 302 Found Location: http://localhost:9876/callback?error=invalid_request&error_description=Invalid+query+params%3A+code_challenge%3A+must+be+43+to+128+characters+from+the+unreserved+character+set+%5BA-Za-z0-9-._~%5D&state=e89f4d98d4c8c347e5ae25175748b731 ``` Identical on both verbs. Decoded: ```text error = invalid_request error_description = Invalid query params: code_challenge: must be 43 to 128 characters from the unreserved character set [A-Za-z0-9-._~] state = e89f4d98d4c8c347e5ae25175748b731 ``` The `GET` body confirms no page was rendered, against the baseline: | Request | Body size | Occurrences of "Allow" | |---|---|---| | Malformed `code_challenge` | 263 bytes | 0 | | Well formed (scenario 1) | 4928 bytes | 2 | 263 bytes is Go's redirect stub. There is no consent form in it, so there is no Allow button to press for a request the server has already refused. Multiple failures are reported together (scenario 4): ```text error_description = Invalid query params: code_challenge: must be 43 to 128 characters from the unreserved character set [A-Za-z0-9-._~]; resource: must be an absolute URI without fragment ``` The separator is `; `, and no entry uses the older `field: x detail: y` shape. The code is `invalid_request` rather than `invalid_target` even though `resource` is one of the two failures, which is the scenario 22 guard firing. The same request also carried `code_challenge_method=plain`, which is invalid and is *not* mentioned, because the method is validated after `extractAuthorizeParams` returns and a parse failure short-circuits first. Sent alone it is rejected as `code_challenge_method 'plain' is not supported; use 'S256'`, with no `Invalid query params: ` prefix. That difference is observation 1. </details> <details> <summary><b>5 and 6. The redirect_uri carve-out keeps the answer here</b></summary> ```bash new_pkce EVIL="$BASE_URL/oauth2/authorize?client_id=$APP_ID&response_type=code" EVIL="$EVIL&redirect_uri=$(urlenc http://evil.example/steal)&state=$STATE" EVIL="$EVIL&code_challenge=$CHALLENGE&code_challenge_method=S256" answer POST "$EVIL"; answer GET "$EVIL" ``` ```text HTTP/1.1 400 Bad Request HTTP/1.1 400 Bad Request ``` **The absence in that output is the assertion**: no `Location` on either verb, so nothing redirects to `evil.example`. Stronger, `evil.example` appears zero times in either full response, headers and body together, so the attacker-supplied host is not reflected into the page either. ```json {"error":"invalid_request","error_description":"Invalid query params: redirect_uri: Query param \"redirect_uri\" must exactly match http://localhost:9876/callback"} ``` The `GET` page names the *registered* callback as the value the parameter had to match, which is the app's own configuration and safe to display. An unparseable `redirect_uri` reaches the same outcome by a different route, having never parsed at all: ```json {"error":"invalid_request","error_description":"Invalid query params: redirect_uri: Query param \"redirect_uri\" must be a valid url: parse \"http://%zz\": invalid URL escape \"%zz\""} ``` That message echoes the caller's value, unlike the mismatch case, so the `GET` path was probed with markup in it: ```text input: http://%zz"><img src=x onerror=BAD> page: ...must be a valid url: parse "http://%zz\"><img src=x onerror=BAD>"... literal `<img` in body: 0 entity encoded `<img`: 1 ``` Escaped correctly by the template layer. Recorded as a negative result so a future change to the error page has something to regress against. One note for the docs: this detail contains colons, so a client splitting `field: reason` entries must split each on its **first** colon only. </details> <details> <summary><b>7 to 10. The client_id carve-out, and its negatives</b></summary> A repeated `client_id` in an otherwise perfect request: ```text HTTP/1.1 400 Bad Request (both verbs, no Location) {"error":"invalid_request","error_description":"Invalid query params: client_id: Query param \"client_id\" provided more than once, found 2 times. Only provide 1 instance of this query param."} ``` This is the one carve-out not implied by the response's shape. The `redirect_uri` matched the registration, so `canRedirect()` was true and there *was* somewhere to send the answer; it was withheld because `extractAuthorizeParams` assigns `failure.redirect` only when `clientIDInDoubt` is false. **The `default` branch of that function is unreachable over HTTP** (observation 3). `httpmw` resolves the app from `r.URL.Query().Get("client_id")`, so `app.ID` and the parsed value derive from the same string and cannot disagree. Three experiments: ```text one query client_id, bad challenge -> 302 delivered two DIFFERENT client_id values -> 400, caught by the repeated branch query names app A, form body names app B -> 302 to app A; the body is ignored ``` The negatives matter as much as the positives. An identifier absent from the query but present in the `POST` form body is **delivered**, correctly: ```text HTTP/1.1 302 Found Location: ...error=invalid_request&error_description=Invalid+query+params%3A+client_id%3A+...is+required+and+cannot+be+empty%3B+code_challenge%3A+... ``` That is observation 4: the description says `client_id` is required for a request that supplied it. With everything else valid the same shape still fails, while the identical request carrying `client_id` in the query succeeds with a code. `RequiredNotEmpty` reads the query; `httpmw` reads the body. Pre-existing, and arguably the parser is the layer in the right, since RFC 6749 §4.1.1 puts authorization parameters in the query string and §3.2.1 is the endpoint that uses a form body. A braced upper-case UUID is delivered, and succeeds end to end: ```text {UPPERCASE} client_id, bad challenge -> 302, description names ONLY code_challenge {UPPERCASE} client_id, all valid -> 302 with a real code GET, all valid -> 200, consent page, heading resolves to the app's real name ``` `uuid.Parse` accepts that spelling and `httpmw` resolved through it, so a string comparison here would withhold an answer the client is entitled to, for no reason it could diagnose. </details> <details> <summary><b>11. A repeated state is delivered, not withheld</b></summary> ```text HTTP/1.1 302 Found (both verbs) error = invalid_request error_description = Invalid query params: state: Query param 'state' provided more than once, found 2 times. Only provide 1 instance of this query param. ``` Reading `state` happens inside `newAuthorizeResponse`, the same function that runs the `redirect_uri` match. A count of errors across those two lines would charge this to the redirect carve-out and answer 400. It answered 302, so the field-specific test is doing the work. The asymmetry with scenario 7 is deliberate: a repeated `client_id` leaves the server unsure whose callback it holds, a repeated `state` leaves the callback fully settled. The response carries **no `state`**, since `parseSingle` collapsed the repeat to the empty string and `withQuery` only sets it when non-empty. Unavoidable rather than wrong: picking one of two values could satisfy a CSRF check the client meant to be strict. </details> <details> <summary><b>12 to 16. A corrupt registration outranks everything</b></summary> DCR refuses both planted values, which is why `psql` is needed and why 500 is the right answer: a stored one is not something a client did. ```json {"error":"invalid_client_metadata","error_description":"invalid redirect_uris: redirect URI at index 0: redirect URI uses dangerous scheme javascript which is not allowed"} {"error":"invalid_client_metadata","error_description":"invalid redirect_uris: redirect URI at index 0 is not a valid URL: parse \"http://%zz\": invalid URL escape \"%zz\""} ``` ```bash plant_callback "$APP_CORRUPT_ID" 'javascript:alert(1)' new_pkce CORRUPT="$BASE_URL/oauth2/authorize?client_id=$APP_CORRUPT_ID&response_type=code&state=$STATE" CORRUPT="$CORRUPT&code_challenge=$CHALLENGE&code_challenge_method=S256" answer POST "$CORRUPT"; answer GET "$CORRUPT" ``` ```text HTTP/1.1 500 Internal Server Error {"error":"server_error","error_description":"The application's registered callback URL is not usable"} GET: HTTP/1.1 500, page reads "500 - Invalid Callback URL", 3346 bytes, 0 Allow buttons ``` The unparseable callback is **indistinguishable to the caller**: same description, and a `GET` page of exactly 3346 bytes, matching byte for byte. Two different defects in stored state, one answer. Correct, since neither is actionable by the client. Note the request carried no `redirect_uri` of its own and still failed, because the scheme is checked on the *registered* URL before the client's value is consulted. Precedence was tested against all three competitors, not one: | Also wrong in the request | Would answer alone | Actually answered | |---|---|---| | `code_challenge=short` | 302 to the callback | **500** | | `client_id` repeated | 400 kept here | **500** | | `redirect_uri` mismatched | 400 kept here | **500** | Reading the source, this is stronger than precedence. `newAuthorizeResponse` runs at `authorize.go:250`, before any of `client_id`, `code_challenge`, `scope` or `resource` is read, and the early return discards whatever `p.Errors` already held. In rows two and three those failures are never detected at all, so `kind()` ranking `failureCorruptRegistration` first is belt and braces for a failure constructed some other way. **The value is logged and never echoed.** A distinctive marker was planted and five requests fired: ```text [erro] coderd: oauth2 app has an unusable registered callback URL request_id=01ca4796-c743-4923-a06b-afc1f3decc95 app_id=12f9ca3b-7a2c-4c54-8ed7-723698c62bd1 callback_url="javascript:alert(\"plat479-6d-marker\")" error= redirect URI uses dangerous scheme javascript which is not allowed: codersdk/oauth2_validation.go:116 ``` Five requests, five lines, in request order. Occurrences of the marker in the POST body, the rendered GET page, and the response headers: **0, 0, 0**. The `request_id` joins that line to the request log entry whose `response_body` field holds the vague message, so the server's own record confirms what it sent for the same request rather than a replay. The log is also where the two causes diverge, naming `validateScheme` and its source line, which the response cannot do. Restoring the row restores normal behaviour immediately, with no restart: ```text POST -> 302 with a code GET -> 200 consent page ``` That is a control rather than housekeeping: it rules out the app having been poisoned lastingly, and rules out a cached parse outliving the `UPDATE`. </details> <details> <summary><b>17 and 18. Every unsupported response_type gets one code</b></summary> | `response_type` sent | `error` | `error_description` | |---|---|---| | `token` | `unsupported_response_type` | Only response_type=code is supported | | `banana` | `unsupported_response_type` | Only response_type=code is supported | | `code token` | `unsupported_response_type` | Only response_type=code is supported | | `CODE` | `unsupported_response_type` | Only response_type=code is supported | | `code_extra` | `unsupported_response_type` | Only response_type=code is supported | | empty string | `invalid_request` | Invalid query params: response_type: Query param 'response_type' is required and cannot be empty | `token` has a Go constant behind it and `banana` does not, so their agreement is what reading the value as text bought. Three rows are more interesting than `banana`: `code token` is a legal RFC 6749 §3.1.1 space-delimited list used by OIDC's hybrid flow, `CODE` confirms the comparison is case sensitive, and `code_extra` confirms it is equality rather than a prefix match. The empty string is correctly the exception. A valueless parameter is *missing*, not unsupported, and RFC 6749 §3.1 requires it be treated as omitted. **The error is in the query, not the fragment.** `response_type=token` is the implicit grant's own value, so a fragment would be arguable, but this deployment advertises `"response_types_supported":["code"]` alone, and a fragment is never sent to the server, so it would be unreadable to the client's backend. PKCE is not recast, which the controls show: | `response_type`, no `code_challenge` sent | `error` | |---|---| | `token` | `unsupported_response_type`, zero mentions of `code_challenge` | | `banana` | `unsupported_response_type`, zero mentions of `code_challenge` | | `code` | `invalid_request`, naming `code_challenge` | Without the `if params.responseType == responseTypeCode` guard, a client sending `token` would be told its `code_challenge` was missing, add one, resend, and be told the same thing again. </details> <details> <summary><b>19 to 21. Unrecognized parameters ignored, repeats still rejected</b></summary> Eight unknown parameters, each on an otherwise valid request, every one issuing a code: | Unknown parameter | Result | |---|---| | `nonce`, `prompt`, `login_hint`, `acr_values`, `max_age`, `ui_locales` | code issued | | `code_challenge_methods=S256` | code issued | | `REDIRECT_URI=http://evil.example/steal` | code issued, **to the registered callback** | Five of those are OpenID Connect Core parameters, so an OIDC client pointed here degrades to plain OAuth2 rather than failing. The ignored parameters are **dropped, not forwarded**: the callback receives only `code` and `state`. The last two rows are the ones with teeth. Query parameter names are case sensitive, so `REDIRECT_URI` must be ignored, and a misspelled `redirect_url` likewise: ```text case variant alongside a valid redirect_uri : Location host localhost:9876 case variant as the only redirect parameter : Location host localhost:9876 redirect_url typo, no valid redirect_uri : Location host localhost:9876, code issued evil.example occurrences in any Location : 0 ``` The consent page renders for the typo case too, and even its cancel link targets the registered callback. A parser matching names case-insensitively would have redirected to `evil.example` with a valid code attached. **Observation 5.** The `ignoring unrecognized authorization parameters` line was never emitted. Three requests carrying a distinctive marker produced no new server output at all, because the call is `logger.Debug` (`authorize.go:307`) and the deployment runs with `verbose: null`. The behaviour is correct and required by RFC 6749 §3.1, but at default verbosity the misspelling is invisible from every angle: the client sees a 302 with a code, its redirect is silently replaced, and nothing is logged. The comment claiming the typo "surfaces here" is optimistic. Repeats of known parameters are still rejected, which the replacement of `ErrorExcessParams` had to leave alone: | Repeated parameter | HTTP | `error` | Answered at | |---|---|---|---| | `code_challenge` | 302 | `invalid_request`, two entries one field | client callback | | `code_challenge_method` | 302 | `invalid_request` | client callback | | `response_type` | 302 | `invalid_request` | client callback | | `redirect_uri` | 400 | withheld | **Coder** | | `scope` | 302 | `invalid_request` | client callback | | `resource` | 302 | `invalid_target` | client callback | `redirect_uri` being withheld confirms the carve-out keys on the field name rather than the kind of mistake. `code_challenge` collects two entries for one mistake, because `parseSingle` collapses the value to empty and the PKCE block then reports it missing. The `resource` row is observation 6. </details> <details> <summary><b>22 and 23. resource, its own code, and the fragment rule</b></summary> Both sides of the rule, since a check enforced too broadly would reject a valid URN: | `resource` sent | `error` | Stored `resource_uri` | |---|---|---| | `not a uri` | `invalid_target` | not stored | | `/api` relative | `invalid_target` | not stored | | `https://api.example.com` | none, code issued | as sent | | `https://api.example.com/v1?q=1` | none, code issued | as sent, query is not a fragment | | `urn:example:resource` | none, code issued | as sent | | empty string | none, code issued | `NULL`, same as omitted | `invalid_target` applies only when `resource` is the sole failure. Add any second failure in any other field and the code becomes `invalid_request` naming both, which is the retry-loop guard: ```text resource + bad code_challenge -> invalid_request, both named resource + repeated scope -> invalid_request, both named resource + repeated state -> invalid_request, both named resource alone (control) -> invalid_target ``` Fragments are rejected in all three placements, with or without a path: ```text https://api.example.com/#x -> invalid_target https://api.example.com#x -> invalid_target https://api.example.com/v1#frag -> invalid_target https://api.example.com/# -> code issued, stored as https://api.example.com/# ``` **The last row is observation 7, and it predates this PR.** Go cannot represent the distinction: ```text https://a.example.com/ Fragment="" String()="https://a.example.com/" https://a.example.com/# Fragment="" String()="https://a.example.com/" https://a.example.com/#x Fragment="x" String()="https://a.example.com/#x" ``` `url.Parse` collapses "no fragment" and "empty fragment", so `if u.Fragment != ""` in `validateResourceParameter` (`coderd/oauth2provider/tokens.go:591`) cannot see a trailing `#`. RFC 3986 §3.5 permits a zero-length fragment, which RFC 8707 §2's "MUST NOT include a fragment component" reads as forbidding. Validation parses the value but persistence stores the raw string, so the `#` reaches `resource_uri` and the stored audience is not textually equal to the fragment-free form. A client appending a harmless-looking `#` would get a token bound to an audience nothing matches. The authorize-side call to `validateResourceParameter` is context in this diff rather than an added line; this PR added the `invalid_target` code for the failure. </details> <details> <summary><b>24 and 25. The description cap and character set</b></summary> The obvious probe does not exercise the cap: a 4000-character `code_challenge` produces a 116-character description, because that message is fixed text and never quotes the offending value. The descriptions that echo caller input come from a validator's own error. | Request | `error` | Description length | Truncated | `Location` length | |---|---|---|---|---| | `code_challenge_method` = 4000 chars | `invalid_request` | 2060 | **yes** | 2176 | | `scope` = 4000 chars | `invalid_scope` | 2060 | **yes** | 2174 | | `code_challenge_method` = 2000 chars | `invalid_request` | 2035 | no | 2147 | | `code_challenge` = 4000 chars | `invalid_request` | 116 | no | 234 | 2060 is exactly `maxErrorDescription` plus `" (truncated)"`. Row three is the boundary control, so the cap fires on length rather than on the presence of echoed input. Measured from the `Location` header rather than a log line, since the stated reason for the cap is that the header must survive intermediary proxies; the longest observed was 2176 bytes. Both verbs agree, the cap living in the shared `redirectAuthorizeError`: ```text GET, long method : desc_len=2060 truncated=True GET, long scope : desc_len=2060 truncated=True ``` The character set is enforced independently, later, in `errorURL`: ```text input: pl"ain\back<newline>tab<tab>end~unicode description: unsupported code_challenge_method: pl'ainback tab end~ nicode chars outside the RFC 6749 §4.1.2.1 set: [] ``` `"` becomes `'`, `\` is dropped so it cannot escape the rewritten quote, and anything below 0x20 or above 0x7E becomes a space. Checked programmatically rather than by eye. The RFC sets no length limit, so the 2048 cap is policy; the character set is conformance. </details> <details> <summary><b>26. The registered callback query, retained except reserved names</b></summary> `plat479-reserved` registers a callback carrying all four reserved names plus two ordinary ones, and DCR stores it unchanged: ```text http://localhost:9876/callback?tenant=acme&code=FAKECODE&error=stale&error_description=oldmsg&state=oldstate&keep=yes ``` Success response, no `redirect_uri` sent: ```text code = coder_WXwBpvYR5u_... keep = yes state = 516abeea9976119eb33ddc10f0ca04ed tenant = acme ``` Failure response, same app: ```text error = invalid_request error_description = Invalid query params: code_challenge: must be 43 to 128 characters... keep = yes state = 3a17bdd75dfcf740bda36124cd161fb7 tenant = acme ``` Stale registered values in either response: `FAKECODE` 0, `stale` 0, `oldmsg` 0, `oldstate` 0. Without the deletion step a registered `error=stale` would ride out on the **success** response, and a client reading `error` before `code`, the conventional order, would discard a valid authorization code. `FAKECODE` is the mirror image on a failure response. The cancel link obeys the same rule, being built by the same `withQuery` path: ```text http://localhost:9876/callback?error=access_denied&error_description=The+resource+owner...&keep=yes&state=e15b5f0f...&tenant=acme ``` RFC 6749 §3.1.2 requires the registered query be retained when adding parameters, which is the `tenant` and `keep` half. It does not say what to do when the registered query collides with the response parameters §4.1.2 adds, so dropping the registered copies is the resolution that keeps the client's read unambiguous. </details> <details> <summary><b>27 and 28. Scope rejections, and declining consent</b></summary> `plat479-ci` carries the allowlist `coder:workspaces.access`. ```text scope=template:update (outside) -> error = invalid_scope 'template:update': scope requests permissions beyond this app's allowed scopes GET, same request -> 302, 225 bytes, 0 Allow buttons, no consent page scope=workspace:ssh (covered) -> code issued, persisted scope workspace:ssh GET, same request -> 200, 5182 bytes, consent page naming the scope ``` `workspace:ssh` is granted although the allowlist names the composite rather than that scope, which is the coverage-not-spelling rule from #28045. This run only checks that the changes here left it delivering the same answers. The consent page for a narrow scope reads differently from the unrestricted one: "to access your **admin** account with these permissions?", the scope as `<li role="listitem">workspace:ssh`, and the caution "These are technical permission names. Grant them only to an application you trust." The scope description shape differs from the parser's, coming from `scopeFailureResponse` rather than the field join, which is the third producer behind observation 1. Declining consent, clicked in a real browser: ```text error = access_denied error_description = The resource owner or authorization server denied the request state = a8bd538b365b61f54586892c73968b80 ``` The page carries exactly one `href` and it is the cancel link. The `state` matches, there is no `code`, and the code count for the app is unchanged, the link being a plain `GET` to the client's callback that never reaches `ProcessAuthorize`. The description is RFC 6749 §4.1.2.1's own definition of `access_denied`, word for word. That shared construction is what makes the `#nosec G203` annotation on `CancelURI` sound: the URL is injected as a trusted `htmltemplate.URL`, safe only because `newAuthorizeResponse` validated the registered scheme before the response object could exist. Scenario 12 is the other half, an app with a rejected scheme never reaching this page at all. </details> <details> <summary><b>Where the consent page renders, across every GET case</b></summary> Only `GET` can render anything, and body size identifies which of four renderers ran, so this is the table to check when a status code alone looks right. | Case | Status | Body bytes | Allow buttons | Rendered | |---|---|---|---|---| | well formed | 200 | 4928 | 1 | **consent page** | | bad `code_challenge` | 302 | 263 | 0 | redirect stub | | two bad fields | 302 | 319 | 0 | redirect stub | | mismatched `redirect_uri` | 400 | 3814 | 0 | 400 error page | | unparseable `redirect_uri` | 400 | 3846 | 0 | 400 error page | | repeated `client_id` | 400 | 3846 | 0 | 400 error page | | `client_id` in form body only | 400 | 77 | 0 | `httpmw` JSON, unstyled | | `{UPPERCASE}` `client_id` | 200 | 4940 | 1 | **consent page** | | repeated `state` | 302 | 239 | 0 | redirect stub | | corrupt callback, blocked scheme | 500 | 3346 | 0 | 500 error page | | corrupt callback, unparseable | 500 | 3346 | 0 | 500 error page | | `response_type=token` | 302 | 187 | 0 | redirect stub | | `banana` / `code token` / `CODE` | 302 | 187 | 0 | redirect stub | | empty `response_type` | 302 | 243 | 0 | redirect stub | | `token`, no PKCE | 302 | 187 | 0 | redirect stub | | `code`, no PKCE | 302 | 245 | 0 | redirect stub | | unknown params, valid request | 200 | 4932 | 1 | **consent page** | | `redirect_url` typo, valid request | 200 | 4932 | 1 | **consent page** | | `resource` malformed | 302 | 214 | 0 | redirect stub | | `resource` valid absolute URI | 200 | 4932 | 1 | **consent page** | | `resource=.../#` empty fragment | 200 | 4932 | 1 | **consent page**, observation 7 | | reserved params in registered callback | 200 | 4973 | 1 | **consent page** | | `scope` outside allowlist | 302 | 225 | 0 | redirect stub | | `scope` covered by allowlist | 200 | 5182 | 1 | **consent page** | The invariant: the page renders if and only if `extractAuthorizeParams` returned no failure, so no input asks the owner to approve a request the server has already refused. The `evil.example` rows are worth reading carefully rather than alarming: RFC 6749 §3.1 requires a case variant and a typo to be ignored, so from the server's view nothing was wrong with either request, and both cancel links target the registered callback. About 4930 bytes is the consent page, about 3800 the 400 page, 3346 the 500 page, 77 the unstyled `httpmw` JSON, and low hundreds is Go's redirect stub, whose length tracks the `Location` it embeds. Every `unsupported_response_type` answer is exactly 187 bytes because they share one description. Small variations within a renderer are expected: the consent page moves 4928 to 4940 with a fresh CSRF token and the app name. As a regression signal, body size is more sensitive than the status line. A change that rendered a page alongside a redirect would still report 302, but the stub would come back at thousands of bytes rather than hundreds. </details> <details> <summary><b>Cleanup</b></summary> ```bash for id in $(pg "SELECT id FROM oauth2_provider_apps WHERE name LIKE 'plat479%';"); do curl -s -X DELETE "$BASE_URL/api/v2/oauth2-provider/apps/$id" -H "$AUTH_HEADER" \ -o /dev/null -w "$id -> %{http_code}\n" done pg "SELECT count(*) FROM oauth2_provider_apps WHERE name LIKE 'plat479%';" ./scripts/coder-dev.sh oauth2-provider dcr disable ``` All planted callback rows were restored before deletion, so no fixture was left holding a value DCR would refuse. </details> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com> |
||
|
|
e035967ef1 |
feat: mint access tokens with the negotiated scope (#28237)
**TL;DR** First of PLAT-480, continuing the merged PLAT-479 stack. #28178 decided what the scope is and #28179 reported it; this PR is the one that makes it bind. Until now the scope negotiated at `/oauth2/authorize` was recorded on the grant but never reached the token: every OAuth2 access key was minted with `coder:all`, so a client that asked for `coder:workspaces.access` still got full API access. | PR | What it does | |---|---| | #28167 | `ScopesCover` compares an allowlist against a request by permission coverage rather than by name. Merged. | | #28178 | The authorize endpoint checks the request against the scope catalog, grants it only if the app's filtered allowlist covers it, and persists the result on the code. Merged. | | #28179 | The consent page lists the negotiated permissions, and `invalid_scope` reaches the client's own callback per RFC 6749 §4.1.2.1. Merged. | | **#28237 (this)** | The exchange mints the API key with the stored scope, and the token response states what was granted. | | #28740 | Re-checks the app allowlist at redemption, for a code whose app was narrowed after the code was issued. | | #28751 | Lets a refresh narrow the granted scope, which is the `scope` request parameter this PR still ignores. | - #28179 has merged, so this diff is against main and reviews on its own. - **This is the first PR in the stack where a token's authority actually changes.** Everything before it recorded and reported. That is the blast radius worth reviewing: a grant that negotiated a narrow scope now gets a key that is genuinely narrower, and anything that was quietly relying on `coder:all` will start seeing 403. - Grants that predate the scope columns carry what migration 000569 backfilled, `coder:all`, so they refresh unrestricted and reach what they reached before. Pinned by `BackfilledScopeRefreshesUnrestricted`, seeded the way the migration leaves a row rather than exchanged. - The actor that writes the key stays `rbac.ScopeAll`. Narrowing it to the granted scope would deny `api_key:create` and fail the exchange. The bound lives on `api_keys.scopes`, which dbauthz reads on every request, not on the actor doing the insert. **Where in the flow** <details> <summary>Diagram: where the stored scope turns into a bound on the token</summary> ```mermaid flowchart TD AZ["GET or POST /oauth2/authorize<br/>negotiates the scope and persists it on the code<br/>PR 28178, merged"] AZ --> TK["POST /oauth2/tokens"] TK --> GT{"grant_type"} GT -->|authorization_code| S1["scope read from codes.scope"] GT -->|refresh_token| S2["scope read from tokens.scope<br/>req.Scope is parsed and ignored, PR 28751"] S1 --> CV["scopeStringToAPIKeyScopes, this PR<br/>every name must be in the api_key_scope enum<br/>an empty list is an error, not coder:all"] S2 --> CV CV -->|"unknown name, or empty"| ERR["400 invalid_grant, this PR<br/>error_description names the offending value"] CV -->|mintable| GEN["apikey.Generate with Scopes, this PR<br/>was: no Scopes, so every key defaulted to coder:all"] GEN --> KEY["api_keys.scopes<br/>read by dbauthz on every later request:<br/>this is where the grant becomes a bound"] GEN --> ROW["the new tokens row carries the same scope,<br/>so the next refresh reads back the same grant"] KEY --> RESP["200 with scope in the token response, this PR<br/>RFC 6749 5.1, OAuth 2.1 1.4.1"] ROW --> RESP ``` </details> - Token endpoint only, both grants. Authorize is untouched apart from two comments that said the scope was not yet enforced. - `scopeStringToAPIKeyScopes` turns the stored scope string into `database.APIKeyScopes` for `apikey.Generate`. Names are checked there rather than inside `apikey.Generate`, whose error would surface as a 500 rather than an OAuth2 error. - An empty list is an error, not an unrestricted key. `apikey.Generate` defaults an empty scope list to `coder:all`, so an empty stored scope would silently widen the grant instead of failing it. The same reasoning is why the `expandRBACScope` comment in `modelmethods.go` was stale: that function already errored on an empty list while its comment still promised `rbac.ScopeAll`. - A stored scope outside the `api_key_scope` enum answers 400 `invalid_grant` rather than 500, with the offending name in `error_description`. Not `invalid_scope`: RFC 6749 §5.2 and OAuth 2.1 §3.2.4 both scope that code to what the client requested, and this value is server state the client cannot change by asking differently. The grant is what is unusable, and re-authorizing is the only way out. - Refresh copies the presented token's scope onto both the new API key and the rotated refresh row. `req.Scope` is parsed but ignored; #28751 is where it starts being honoured. - The swagger annotation moves from `oauth2.Token` to `codersdk.OAuth2TokenResponse`, because `oauth2.Token` has no `scope` field to document. - `EveryCatalogNameMintable` pins the catalog against the `api_key_scope` enum. The two are maintained separately, and a name negotiable at authorization but unmintable at exchange would leave a client holding a code it can never redeem. **What it satisfies** Checked against both RFC 6749 and the OAuth 2.1 draft (draft-ietf-oauth-v2-1-15). The 2.1 draft moves the scope-reporting rule from RFC 6749 §5.1 into §1.4.1 and grades it in §3.2.3, but the requirement is the same one. - RFC 6749 §5.1, OAuth 2.1 §1.4.1 — "If the issued access token scope is different from the one requested by the client, the authorization server MUST include the `scope` response parameter in the token response". OAuth 2.1 §3.2.3 grades `scope` as "RECOMMENDED, if identical to the scope requested by the client; otherwise, REQUIRED". Both grants set it unconditionally, which covers both grades. Without it, a client whose request was narrowed against the app's allowlist, or defaulted because it requested nothing, first learns its bounds from an unexplained 403. Pinned by `IssuedTokenBoundsTheAPI`, which requests no scope and asserts the response names what it got. - OAuth 2.1 §1.4.1 — "The authorization server MAY fully or partially ignore the scope requested by the client, based on the authorization server policy or the resource owner's instructions." This is what licenses ignoring `scope` on a refresh, and the licence is conditional on reporting the actual grant. Before this PR the exchange both ignored the request and said nothing, which is the half that was not defensible. - OAuth 2.1 §4.3.1, RFC 6749 §6 — the refresh `scope` parameter is OPTIONAL and "if omitted is treated as equal to the scope originally granted by the resource owner". Exactly what `refreshTokenGrant` does with `dbToken.Scope`. - OAuth 2.1 §4.3.3 — "If a new refresh token is issued, the refresh token scope MUST be identical to that of the refresh token included by the client in the request." Rotation copies `dbToken.Scope` onto the new refresh row. - OAuth 2.1 §3.2.3 — "If refresh tokens are issued, those refresh tokens MUST be bound to the scope and resource servers as consented by the resource owner. This is to prevent privilege escalation by the legitimate client". The refresh row has carried the negotiated scope since #28178; this PR is what makes the access token minted from it carry the same bound. Pinned by `RefreshDoesNotWidenTheScope`. - OAuth 2.1 §1.4.1 — a client that omits `scope` must be met with "a pre-defined default value or fail the request indicating an invalid scope", and the server "SHOULD document its scope requirements and default value". #28178 chose the default; `scopes_supported` and the integration guide document it. Unchanged here, but it is why `IssuedTokenBoundsTheAPI` can request nothing and still receive a bounded token. - Not yet: OAuth 2.1 §4.3.1 also says "The requested scope MUST NOT include any scope not originally granted by the resource owner." A refresh naming a narrower scope is ignored rather than honoured, and one naming a wider scope is ignored rather than rejected with `invalid_scope` (§3.2.4, "exceeds the scope granted by the resource owner"). Neither case widens a token, so there is no escalation, and §1.4.1's MAY plus the `scope` response parameter keep the client correctly informed in the meantime. #28751 is where narrowing lands. Documented under Limitations until then. --- First of three, [PLAT-480](https://linear.app/codercom/issue/PLAT-480). Depends on #28179, which has merged, so this reviews against main. #28178 decided the scope and #28179 reported it. This PR is the one that makes a token feel it. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com> |
||
|
|
54e21f29a1 |
fix: deliver four more authorize errors to the client (#28450)
**TL;DR** Fourth of the stack, split out of #28045. #28179 sent `invalid_scope` to the client's own callback; this PR sends the rest of the errors raised after the callback has been verified, behind one URL builder they all now share. | PR | What it does | |---|---| | #28007 | Schema: `codes.scope` and `tokens.scope`, so a negotiated scope has somewhere to live. | | #28167 | `ScopesCover` compares an allowlist against a request by permission coverage rather than by name. | | #28178 | The authorize endpoint negotiates the scope against the app's allowlist and persists it on the code. | | #28179 | The consent page lists the negotiated permissions, and `invalid_scope` reaches the client's callback per RFC 6749 §4.1.2.1. | | **#28450 (this)** | The same delivery for every other error raised once the callback is trusted. | - #28179 has merged, so this diff is against main and reviews on its own. - Nothing about what a token can do changes here. This is delivery, not enforcement. **Contract change** Four failures now arrive at the app's registered callback instead of terminating on Coder, so an integrator with error handling on its callback starts seeing codes it never received. | Verb | Condition | Error code | Was | |------|-----------|------------|-----| | GET | `response_type != code` | `unsupported_response_type` | static "Unsupported Response Type" page, 400 | | POST | `response_type != code` | `unsupported_response_type` | `WriteOAuth2Error`, 400 | | POST | `code_challenge_method=plain` | `invalid_request` | `WriteOAuth2Error`, 400 | | GET | `code_challenge_method=plain` | `invalid_request` | consent page, 200, refused after Allow | The GET static error page loses its only caller. The last row is what review found: the method was checked on POST only, so the user approved a request that could never succeed. **Where in the OAuth Flow** <details> <summary>Diagram: where these errors are raised, and what licenses the redirect</summary> ```mermaid flowchart TD EX["GET or POST /oauth2/authorize<br/>extractAuthorizeParams exact-matches redirect_uri<br/>against the app's registered callback"] EX -->|"no match, rejected scheme, unparsable,<br/>other param failures"| CODER["Answers on Coder<br/>RFC 6749 3.1.2.4: MUST NOT redirect"] EX -->|"matched: a validatedCallbackURL,<br/>which is what licenses a redirect"| RT{"response_type == code?"} RT -->|no| E1["unsupported_response_type (this PR)"] RT -->|yes| PK{"code_challenge_method S256 or omitted?"} PK -->|no| E2["invalid_request (this PR, and newly checked on GET)"] PK -->|yes| SC{"scope negotiable?"} SC -->|no| E3["invalid_scope (previous PR)"] SC -->|yes| OK["GET: consent page, cancel link is access_denied<br/>POST: authorization code"] E1 --> OUT E2 --> OUT E3 --> OUT OK --> OUT["One builder produces every URL the flow emits:<br/>error redirect, cancel link, success code"] ``` </details> - Authorize endpoint only, both verbs. The token exchange, refresh, and revocation are untouched. - Every redirect is licensed by a `validatedCallbackURL`, a type produced only where `extractAuthorizeParams` exact-matches the URI against the app's registration. A guard, not a proof: no other package can fabricate one, this one still can. - One builder now produces every response URL, including the consent page's cancel link, which rolled its own and edited the shared URL in place rather than copying it. - Each rejection logs. The error leaves in a `Location` header, which `loggermw` does not record, so a failed authorization used to look exactly like a successful one. **Three smaller behavior changes** - A callback registered with `code`, `error`, `error_description`, or `state` in its own query no longer receives that value back. A registered `error=` rode out on the success redirect, where a client that reads `error` first discards a valid code. The rest of the registered query is kept, as §3.1.2 requires. - `error_description` is confined to the NQSCHAR set Appendix A permits. Descriptions name the offending value with `%q`, so every `invalid_scope` Coder emits today carries excluded characters. Quotes now render as apostrophes. - An unparsable `redirect_uri` returns 400 instead of 500. It reached a nil dereference in `httpapi.RedirectURL`, which `POST /oauth2/tokens` also uses, and that endpoint takes no API key. **What it satisfies** - RFC 6749 §4.1.2.1 — on a failure that is not a bad redirection URI, the server informs the client through the redirection URI. That is the whole PR. - RFC 6749 §3.1.2.4 and §4.1.2.1 — a missing, invalid, or mismatching redirection URI "MUST NOT" be redirected to. A mismatched URI, and a registered URI with a rejected scheme, still answer on Coder. Pinned by `MismatchedRedirectURINotRedirected` and `DangerousCallbackSchemeNotRedirected`. - RFC 6749 Appendix A — `error_description` is NQSCHAR, and the rule is on the decoded value, so percent-encoding on the wire does not satisfy it. - RFC 6749 §4.1.2 and §3.1.2 — the four reserved response parameters are dropped from the registered query; everything else in it is retained. - Not yet: the remaining parameter failures do have a trusted callback in hand, but the parser reports one verdict for every field at once, so the caller cannot say which field failed. A follow-up classifies them. The two `server_error` sites also stay put: sending an internal fault outbound with a Coder-written description wants its own review. **Docs and Swagger.** `docs/admin/integrations/oauth2-provider.md` gains a Common Issues entry per newly redirected code, and the implicit-grant limitation now says where the error arrives. Both authorize verbs document the 302, the GET side for the first time. --- Split out of #28045 ([PLAT-479](https://linear.app/codercom/issue/PLAT-479)). Fourth of the stack. #28179 has merged, so this reviews against main. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com> |
||
|
|
8b8c80614d |
feat: expose template builder agents and per-module agent (#28905)
Part of [DEVEX-556](https://linear.app/codercom/issue/DEVEX-556). Builds on the base agent metadata added in #28794. ## Summary Surfaces the backend multi-agent support through the SDK and HTTP API: the bases endpoint returns each base's agents, and compose/create-template accept a per-module `agent_name`. ## What changed - `codersdk/templatebuilder.go`: added `TemplateBuilderBaseAgent`, `TemplateBuilderBase.Agents`, and `TemplateBuilderComposeModule.AgentName` (`agent_name,omitempty`). - `coderd/templatebuilder_handler.go`: added `baseAgentsToSDK`; the bases endpoint returns agents, and the compose and create-template endpoints forward `AgentName`. - `make gen` regenerated `site/src/api/typesGenerated.ts`, `coderd/apidoc/docs.go`, `coderd/apidoc/swagger.json`, `docs/reference/api/schemas.md`, and `docs/reference/api/templatebuilder.md`. - `wizardState.test.ts`: added `agents: []` to the base fixture now that the field is required on the generated type. ## Scope SDK/API plumbing only. `ComposeModule.AgentName` now has a producer (the handlers) but no caller sets it yet — the wizard UI (follow-up) is what will populate it. No DB change, so `enterprise/audit/table.go` is unaffected. ## Testing - Bases endpoint asserts each base returns agents with exactly one default (and the `dev`/`main` names). - Per-module `agent_name` round-trip and unknown-agent (400) compose tests. - `make gen` (idempotent), `make fmt` (no changes), `golangci-lint ./coderd/... ./codersdk/...`, the Go template-builder tests, frontend `tsc` + `biome check`, and docs markdownlint all pass. <details> <summary>Design note</summary> `display_name` is intentionally returned as `""` for now: every base is single-agent, so no base authors a per-agent label. The field exists for multi-agent bases where the wizard radio needs a human-readable name; consumers fall back to the agent `name` when it is empty. </details> --- 🤖 Generated by Coder Agents on behalf of @jeremyruppel. Co-authored-by: Coder Agents <agents@coder.com> |
||
|
|
4875ae218a |
feat: enforce user secret file policy (#28518)
Adds the deployment option `--user-secrets-disable-file-path` / `CODER_USER_SECRETS_DISABLE_FILE_PATH` / `userSecretsDisableFilePath` (default `false`). When it is set, the create and batch-create user-secret endpoints reject requests with a non-empty file path, and PATCH validates the post-update state under a `SELECT ... FOR UPDATE` row lock, rejecting a new or changed file path as well as enabled states that would have no effective delivery target. Legacy stored paths are preserved, so users can still edit, disable, clear the path, or migrate the secret to env delivery. This is PR 1 of a 4-PR stack; follow-ups cover manifest filtering, the dashboard, and CLI/docs. Refs #27488 Reviewed and updated by Coder Agents on behalf of @dylanhuff-at-coder. |
||
|
|
55340de360 |
feat: add deployment setting to disable the Codernauts game (#27662)
Adds a `codernauts_enabled` runtime setting (default: enabled) that controls whether the Codernauts game link appears in the user dropdown menu. A toggle at the bottom of the Deployment > Appearance page controls it, and the value persists in `site_configs`, so it survives restarts and upgrades without any CLI flags or environment variables. The setting works on all licenses: `GET /api/v2/appearance` reports it from both the enterprise and the default (AGPL) appearance fetchers, and `PUT /api/v2/appearance` persists it gated only by the deployment-config RBAC permission, not by an entitlement. On the Appearance page the toggle renders outside the Premium paywall introduced in #27948; the other appearance fields keep their existing licensing behavior. Note: a pure AGPL-only build of coderd does not register the `/api/v2/appearance` routes at all, so the toggle cannot be saved there. The standard `coder server` binary is unaffected regardless of license state. <details> <summary>Implementation notes</summary> - `coderd/database/queries/siteconfig.sql`: new `GetCodernautsEnabled` / `UpsertCodernautsEnabled` queries backed by a `codernauts_enabled` key in `site_configs`; defaults to `true` when unset (no migration needed). - `coderd/database/dbauthz`: read has no authz checks (matching other appearance reads); write requires `ResourceDeploymentConfig` update. Coverage added to `dbauthz_test.go`. - `codersdk`: `codernauts_enabled` added to `AppearanceConfig` and `UpdateAppearanceConfig`. - `coderd/appearance`: the default fetcher takes a `database.Store` and reads the setting from the database so unlicensed deployments serve it too. - `enterprise/coderd/appearance.go`: fetches the value in `Fetch` and persists it in `putAppearance`. - Frontend: "Codernauts game" toggle section on Deployment > Appearance saving immediately via the existing appearance mutation; `codernauts_enabled` threaded from `useDashboard().appearance` through Navbar to `UserDropdownContent`, which renders the menu item only when enabled. Storybook stories with `play` functions cover toggling (entitled and not) and the dropdown hiding the link when disabled. </details> --- 🤖 This PR was generated by Coder Agents on behalf of @bartekgatzcoder. |
||
|
|
20a41c067e |
feat: reject secret creation and fix reporting for public clients (#28097)
**TL;DR** On top of #28047, closing the last two gaps in the stack split out of #27873. A public client can now register (#28046) and exchange a code (#28047), but the admin secrets API will still issue it a secret that authenticates nothing, and the registration responses still report an auth method the token endpoint will not accept. | PR | What it does | |---|---| | #27712 | Schema: `app_secret_id` becomes nullable and tokens gain an always-populated `app_id`, so ownership checks work without a secret row. | | #28041 | Accepts bare custom-scheme redirect URIs (`vscode://`, `cursor://`) that native apps actually register. | | #28043 | Derives and stores `client_type` (public vs confidential) from the requested `token_endpoint_auth_method`, and pins it across updates. | | #28046 | Registration issues no secret for a public client and returns no `client_secret`. | | #28047 | The token endpoint accepts the exchange without a `client_secret`. Discovery advertises `none`. | | **#28097 (this)** | The admin secrets API refuses to create a secret for a public client, and registration, read, and update report the auth method the token endpoint actually enforces. | A public client can only come into existence through dynamic client registration, which is off by default, so neither guard is reachable until DCR is enabled. **Where in the flow** - `POST /oauth2-provider/apps/{app}/secrets`, the admin secrets API. The rest of the secret lifecycle is untouched: `GET` and `DELETE` are unchanged, and a confidential app behaves exactly as before. - The three RFC 7591 and 7592 responses that carry `token_endpoint_auth_method`: registration (`POST`), read (`GET`), and update (`PUT`). Only what is reported changes; the stored column is left as the client sent it. - Authorize, token exchange, refresh, and revocation are untouched. **What it satisfies** - RFC 7591 §2: `none` means the client is public and "does not have a client secret", so the secrets API should not create one for it. - RFC 7591 §3.2.1: the server MUST return all registered metadata and MAY replace a requested value with a suitable one. Reporting the enforced method in place of a stored one that contradicts `client_type` is that substitution. - RFC 7592 §2.2: an update MUST include all metadata as returned by a previous registration, read, or update. Because clients echo back what Coder reports, reporting the enforced method is what lets a legacy row heal on the client's next `PUT`. - RFC 7591 §2 default: an app with no stored method reports `client_secret_basic`, which is both the RFC default and what `ApplyDefaults` substitutes on update. - OAuth 2.1 §3.2.1: the token endpoint enforces on `client_type`, so a reported method that disagrees with it tells a client to authenticate in a way the server will reject. --- - `CreateAppSecret` returns 400 for a public client before generating anything. The secret would authenticate nothing, since the token endpoint no longer checks one for a public client. Deleting it would be worse: `oauth2_provider_app_tokens.app_secret_id` is `ON DELETE CASCADE`, so removing a confidential app's secret takes its tokens with it, but a public client's tokens carry a NULL `app_secret_id` (#27712) and survive. An admin who deleted the secret would think they had cut off the client when they had not. - `reportedAuthMethod()` replaces the raw stored value in all three registration responses. It returns the stored method when it agrees with `client_type`, `none` for a public app, and `client_secret_basic` otherwise. - The rows that can disagree are clients registered before #28043 derived the type from the method: the method was stored as sent while the type was always `confidential`. Such a client holds a secret its exchange still requires, while `GET` reported `none` and told it to drop that secret. - The stored column is deliberately not rewritten, so the response can still differ from the row. That divergence is what a read-modify-write client resolves on its next update, and the test asserts the row keeps what the client sent. - Coverage: the secrets guard asserts the 400 and that no partial secret row was left behind. A table test walks `GET` then `PUT` over six stored-method and client-type pairs: the legacy mismatch in both resend shapes, the reverse mismatch that registration cannot produce but the function still handles, an empty stored method, and the single pair that already agrees and must be reported as stored. - Docs: the client type is fixed at registration and a type-changing update is rejected with `invalid_client_metadata` (behavior from #28043 that was never written down), plus what a legacy `none` client now sees. Refs https://linear.app/codercom/issue/ENG-3029/oauth2-support-public-client ## Manual Tests Verified by hand against a local dev deployment (`v2.36.3-devel+c85e4621ef`, dev Postgres), in addition to the automated suite. Both guards are reachable only through dynamic client registration, which was confirmed off by default on this deployment and enabled for the run. Two of the scenarios need a row where `client_type` and `token_endpoint_auth_method` disagree, which registration cannot produce since #28043 derives one from the other, so those rows were seeded by updating the method column directly on a purpose-built client. | # | Scenario | Result | |---|----------|--------| | 1 | Secrets API refuses a public client, with the guard's own message | Pass | | 2 | No partial secret row is left behind by the rejection | Pass | | 3 | A confidential app's secret create, list, and delete are unchanged | Pass | | 4 | Admin-created apps are always confidential, so the guard is unreachable there | Pass | | 5 | When stored method and client type agree, the stored value is reported unchanged | Pass | | 6 | A legacy confidential row storing `none` reports `client_secret_basic` | Pass | | 7 | The reported method is the one the token endpoint enforces, in both directions | Pass | | 8 | An update resending the stored value is accepted and leaves the row alone | Pass | | 9 | An update resending the reported value heals the row | Pass | | 10 | The reverse mismatch, a public row storing a secret method, reports `none` | Pass | | 11 | An empty or unrecognized stored method falls back to `client_secret_basic` | Pass | | 12 | Type-changing updates are rejected both ways, `client_secret_basic` to `client_secret_post` is allowed | Pass | | 13 | Regression sweep of the merged stack, discovery through revocation | Pass | | 14 | Every claim in the new docs paragraphs matches observed behavior | Pass | No correctness defects found. Commands and captured output for each scenario below. **Two notes for anyone re-running this.** The previous runbook for this stack asserts the opposite of scenario 12: it flips a confidential client to public with a `PUT` and records `200`. That was correct before #28043 pinned the client type. The `400` here is the fix, not a regression. Generate the PKCE verifier with enough entropy that stripping `=+/` still leaves 43 characters. The `openssl rand -base64 32 | tr -d "=+/" | cut -c -43` recipe yields 38 to 43, so most runs are rejected by the token endpoint under RFC 7636 section 4.1 with an error that looks unrelated. Same trap noted in #28045. <details> <summary>Shell helpers used throughout</summary> ```bash export BASE_URL=http://localhost:3000 export AUTH_HEADER="Coder-Session-Token: $(cat ./.coderv2/session)" export PGURL="postgres://coder@localhost:$(cat ./.coderv2/postgres/port)/coder?sslmode=disable&password=$(cat ./.coderv2/postgres/password)" # Enable DCR; both guards are unreachable without it. curl -s -X PUT "$BASE_URL/api/v2/oauth2-provider/settings" -H "$AUTH_HEADER" \ -H "Content-Type: application/json" \ -d '{"dynamic_client_registration_enabled": true}' # Print "HTTP <code>" then the body. show() { local out; out=$(curl -s -w '\n%{http_code}' "$@") echo "HTTP $(printf '%s\n' "$out" | tail -n1)" printf '%s\n' "$out" | sed '$d' | jq . 2>/dev/null || printf '%s\n' "$out" | sed '$d' } # $1=name, $2=auth method ("" to omit the field). register() { local body if [ -z "$2" ]; then body=$(jq -nc --arg n "$1" '{client_name:$n,redirect_uris:["http://localhost:9876/callback"]}') else body=$(jq -nc --arg n "$1" --arg m "$2" '{client_name:$n,redirect_uris:["http://localhost:9876/callback"],token_endpoint_auth_method:$m}') fi curl -s -X POST "$BASE_URL/oauth2/register" -H "Content-Type: application/json" -d "$body" } # The stored row, as opposed to what the API reports. stored() { psql "$PGURL" -At -c "select client_type || ' | ' || coalesce(token_endpoint_auth_method,'<NULL>') from oauth2_provider_apps where id = '$1';" } # 43 characters from the unreserved set, always. See the note above. gen_verifier() { openssl rand -base64 96 | tr -d "=+/\n" | cut -c -43; } challenge_for() { printf '%s' "$1" | openssl dgst -sha256 -binary | base64 | tr -d "=" | tr '+/' '-_'; } # Full PKCE authorize plus exchange. $1=client_id, $2=client_secret ("" for none). exchange() { local verifier challenge redirect code args verifier=$(gen_verifier); challenge=$(challenge_for "$verifier") redirect=$(curl -s -X POST \ "$BASE_URL/oauth2/authorize?client_id=$1&response_type=code&redirect_uri=http://localhost:9876/callback&state=$(openssl rand -hex 16)&code_challenge=$challenge&code_challenge_method=S256" \ -H "$AUTH_HEADER" -w '\n%{redirect_url}' -o /dev/null) code=$(printf '%s' "$redirect" | grep -oE 'code=[^&]+' | sed 's/code=//') args=(-d "grant_type=authorization_code" -d "code=$code" -d "client_id=$1" -d "redirect_uri=http://localhost:9876/callback" -d "code_verifier=$verifier") [ -n "$2" ] && args+=(-d "client_secret=$2") curl -s -X POST "$BASE_URL/oauth2/tokens" -H "Content-Type: application/x-www-form-urlencoded" "${args[@]}" } ``` </details> <details> <summary>1. Secrets API refuses a public client</summary> A bare non-`201` would also be produced by a request that failed on authentication, routing, or a malformed UUID before reaching the guard, so the status and the message are both asserted. ```bash PUB=$(register manual-28097-public none) PUB_ID=$(echo "$PUB" | jq -r '.client_id') stored "$PUB_ID" show -X POST "$BASE_URL/api/v2/oauth2-provider/apps/$PUB_ID/secrets" -H "$AUTH_HEADER" ``` ```text public | none HTTP 400 { "message": "Cannot create a client secret for a public OAuth2 app.", "detail": "Public clients authenticate with PKCE and have no client secret. The client type is fixed at registration, so register a new confidential client instead." } ``` The message is the guard's own, so execution reached `CreateAppSecret` and returned at the `IsPublic()` check. The detail points at registering a new confidential client, which scenario 12 confirms is the only remedy. </details> <details> <summary>2. No partial secret row is left behind</summary> The guard returns before `GenerateSecret()`, so nothing should exist at either layer. The count was already `0` at registration, and a confidential app is queried the same way as a control, so `0` is not merely what this query always returns. ```bash curl -s "$BASE_URL/api/v2/oauth2-provider/apps/$PUB_ID/secrets" -H "$AUTH_HEADER" | jq -c . psql "$PGURL" -At -c "select count(*) from oauth2_provider_app_secrets where app_id = '$PUB_ID';" psql "$PGURL" -At -c "select count(*) from oauth2_provider_app_secrets where app_id = '$CONF_ID';" ``` ```text [] 0 1 ``` </details> <details> <summary>3. A confidential app's secret lifecycle is unchanged</summary> ```bash CONF=$(register manual-28097-confidential "") CONF_ID=$(echo "$CONF" | jq -r '.client_id') show -X POST "$BASE_URL/api/v2/oauth2-provider/apps/$CONF_ID/secrets" -H "$AUTH_HEADER" curl -s "$BASE_URL/api/v2/oauth2-provider/apps/$CONF_ID/secrets" -H "$AUTH_HEADER" | jq -c '[.[].id]' curl -s -X DELETE "$BASE_URL/api/v2/oauth2-provider/apps/$CONF_ID/secrets/$SECRET_ID" \ -H "$AUTH_HEADER" -o /dev/null -w "delete: HTTP %{http_code}\n" ``` ```text HTTP 201 { "id": "da7a1029-47c4-435e-988a-557ffa4aeacf", "client_secret_full": "coder_POUtoElODM_<redacted>" } ["b2fc55b6-...","da7a1029-...","24f8f8c2-..."] delete: HTTP 204 ["b2fc55b6-...","da7a1029-..."] ``` Create, list, and delete all behave as before. The guard keys on `client_type` and nothing else on this path changed. Unrelated observation, not a finding against this PR: the listing returns two different `client_secret_truncated` formats. Secrets issued at registration are asterisk-padded (`***...TzqEOt`, from `createDisplaySecret`), while secrets issued through the admin API show the bare last six characters (`Rixs60`). Both write the same column and surface through the same field. Cosmetic and pre-existing, but a UI listing both kinds together would render them inconsistently. </details> <details> <summary>4. Admin-created apps are always confidential</summary> `postOAuth2ProviderApp` hardcodes the client type, so the guard is unreachable through the admin create path. ```bash ADMIN_APP=$(curl -s -X POST "$BASE_URL/api/v2/oauth2-provider/apps" -H "$AUTH_HEADER" \ -H "Content-Type: application/json" \ -d '{"name":"manual-28097-admin","callback_url":"http://localhost:9876/callback"}') ADMIN_ID=$(echo "$ADMIN_APP" | jq -r '.id') stored "$ADMIN_ID" show -X POST "$BASE_URL/api/v2/oauth2-provider/apps/$ADMIN_ID/secrets" -H "$AUTH_HEADER" ``` ```text confidential | client_secret_post HTTP 201 { "id": "a77ab276-ea74-4711-ba8b-955a8cb97951", "client_secret_full": "coder_eGlt04LhYg_<redacted>" } ``` Together with scenario 1 this brackets the guard: it fires for a dynamically registered public client and for nothing else. Note the admin API stores `client_secret_post`, not the RFC 7591 section 2 default, so every admin-created app is an agreement case for scenario 5. Such apps carry no registration access token, so they cannot reach the RFC 7592 endpoints where the reporting change applies at all. </details> <details> <summary>5. Agreement cases report the stored value unchanged</summary> The `client_secret_post` case is the one that matters. An implementation that substituted the type default on every call would still pass the public case, since `none` is the public default, but would rewrite this client to `client_secret_basic` and tell it to send its secret in the wrong place. ```bash curl -s "$BASE_URL/oauth2/clients/$PUB_ID" -H "Authorization: Bearer $PUB_RAT" \ | jq -c '{reported: .token_endpoint_auth_method}' POST_REG=$(register manual-28097-post client_secret_post) POST_ID=$(echo "$POST_REG" | jq -r '.client_id') echo "$POST_REG" | jq -c '{reported_on_register: .token_endpoint_auth_method}' curl -s "$BASE_URL/oauth2/clients/$POST_ID" -H "Authorization: Bearer $POST_RAT" \ | jq -c '.token_endpoint_auth_method' stored "$POST_ID" ``` ```text {"reported":"none"} {"reported_on_register":"client_secret_post"} "client_secret_post" confidential | client_secret_post ``` Registration and read both report the stored value. The update site is covered by scenarios 8 and 9. </details> <details> <summary>6. A legacy confidential row storing `none` reports `client_secret_basic`</summary> Seeded from a real confidential client so it genuinely holds the secret its exchange requires, with only the method column rewritten. This is the pre-#28043 shape and cannot be produced through the API any more. ```bash LEGACY=$(register manual-28097-legacy "") LEGACY_ID=$(echo "$LEGACY" | jq -r '.client_id') LEGACY_SECRET=$(echo "$LEGACY" | jq -r '.client_secret') stored "$LEGACY_ID" psql "$PGURL" -c "update oauth2_provider_apps set token_endpoint_auth_method = 'none' where id = '$LEGACY_ID';" stored "$LEGACY_ID" psql "$PGURL" -At -c "select count(*) from oauth2_provider_app_secrets where app_id = '$LEGACY_ID';" curl -s "$BASE_URL/oauth2/clients/$LEGACY_ID" -H "Authorization: Bearer $LEGACY_RAT" \ | jq -c '{reported: .token_endpoint_auth_method}' stored "$LEGACY_ID" ``` ```text confidential | client_secret_basic UPDATE 1 confidential | none 1 {"reported":"client_secret_basic"} confidential | none ``` The response substitutes and the row is deliberately not rewritten. A read has no side effects. </details> <details> <summary>7. The reported method is the one actually enforced</summary> The token endpoint enforces on `client_type`, which is still confidential, so the secret is required regardless of what the method column says. ```bash exchange "$LEGACY_ID" "$LEGACY_SECRET" | jq -c '{has_access: has("access_token"), error, error_description}' exchange "$LEGACY_ID" "" | jq -c '{has_access: has("access_token"), error, error_description}' ``` ```text {"has_access":true,"error":null,"error_description":null} {"has_access":false,"error":"invalid_request","error_description":"Missing required parameter: client_secret"} ``` The second line is the pre-fix breakage reproduced. A client that read `"token_endpoint_auth_method": "none"` from `GET` and dropped its secret accordingly, which is what RFC 7592 tells it to do, would have hit exactly this on its next exchange. The old response was not internally inconsistent, it was actionable and wrong. Scenario 10 shows the same property in the opposite direction. </details> <details> <summary>8. An update resending the stored value is accepted and changes nothing</summary> ```bash show -X PUT "$BASE_URL/oauth2/clients/$LEGACY_ID" \ -H "Authorization: Bearer $LEGACY_RAT" -H "Content-Type: application/json" \ -d '{"client_name":"manual-28097-legacy","redirect_uris":["http://localhost:9876/callback"],"token_endpoint_auth_method":"none"}' stored "$LEGACY_ID" ``` ```text HTTP 200 "token_endpoint_auth_method": "client_secret_basic", confidential | none ``` Three things at once. The update is accepted, which is why the type-change guard requires the auth method to actually change: the requested `none` implies a public client while the row is confidential, so a guard keyed on the type mismatch alone would reject this and lock a legacy client out of managing its own registration. The `PUT` reports the same substituted value as the `GET`, covering the third call site. The row keeps what the client sent, so the divergence persists until scenario 9. </details> <details> <summary>9. An update resending the reported value heals the row</summary> ```bash show -X PUT "$BASE_URL/oauth2/clients/$LEGACY_ID" \ -H "Authorization: Bearer $LEGACY_RAT" -H "Content-Type: application/json" \ -d '{"client_name":"manual-28097-legacy","redirect_uris":["http://localhost:9876/callback"],"token_endpoint_auth_method":"client_secret_basic"}' stored "$LEGACY_ID" curl -s "$BASE_URL/oauth2/clients/$LEGACY_ID" -H "Authorization: Bearer $LEGACY_RAT" \ | jq -c '{reported: .token_endpoint_auth_method}' exchange "$LEGACY_ID" "$LEGACY_SECRET" | jq -c '{has_access: has("access_token")}' ``` ```text HTTP 200 "token_endpoint_auth_method": "client_secret_basic", confidential | client_secret_basic {"reported":"client_secret_basic"} {"has_access":true} ``` The row healed through an ordinary read-modify-write cycle, with no migration, backfill, or admin action. That works only because scenario 8 keeps the door open and this response gives the client a correct value to echo back; remove either and the row stays inconsistent indefinitely. </details> <details> <summary>10. The reverse mismatch reports `none`</summary> Registration cannot produce this direction either, but `reportedAuthMethod` branches on the general disagreement rather than the one shape known to exist, so it is covered. ```bash REVERSE=$(register manual-28097-reverse none) REVERSE_ID=$(echo "$REVERSE" | jq -r '.client_id') psql "$PGURL" -c "update oauth2_provider_apps set token_endpoint_auth_method = 'client_secret_basic' where id = '$REVERSE_ID';" stored "$REVERSE_ID" curl -s "$BASE_URL/oauth2/clients/$REVERSE_ID" -H "Authorization: Bearer $REVERSE_RAT" \ | jq -c '{reported: .token_endpoint_auth_method}' exchange "$REVERSE_ID" "" | jq -c '{has_access: has("access_token"), error}' ``` ```text public | client_secret_basic {"reported":"none"} {"has_access":true,"error":null} ``` This client has no secret row at all and the token endpoint does not ask for one, so `none` is what the response should say. Reporting the stored `client_secret_basic` would have instructed it to send a secret that does not exist. Both resend shapes behave symmetrically with scenarios 8 and 9: ```text resend stored (client_secret_basic) -> reported "none", row unchanged resend reported (none) -> reported "none", row now public | none ``` </details> <details> <summary>11. Empty or unrecognized stored methods fall back to the default</summary> `NULL` and `''` are indistinguishable once read into `sql.NullString`. A third case was added because the function gates on validity rather than emptiness. ```bash for v in "null" "''" "'private_key_jwt'"; do psql "$PGURL" -At -c "update oauth2_provider_apps set token_endpoint_auth_method = $v where id = '$CONF_ID';" stored "$CONF_ID" curl -s "$BASE_URL/oauth2/clients/$CONF_ID" -H "Authorization: Bearer $CONF_RAT" \ | jq -c '.token_endpoint_auth_method' done ``` ```text confidential | <NULL> "client_secret_basic" confidential | "client_secret_basic" confidential | private_key_jwt "client_secret_basic" ``` `private_key_jwt` is a real RFC 7591 method that Coder does not implement. Reporting it back would advertise an authentication scheme the token endpoint cannot honor, which is the same class of problem as the legacy `none` report in scenario 7. </details> <details> <summary>12. Type-changing updates are rejected both ways</summary> ```bash show -X PUT "$BASE_URL/oauth2/clients/$CONF_ID" \ -H "Authorization: Bearer $CONF_RAT" -H "Content-Type: application/json" \ -d '{"client_name":"manual-28097-confidential","redirect_uris":["http://localhost:9876/callback"],"token_endpoint_auth_method":"none"}' stored "$CONF_ID" show -X PUT "$BASE_URL/oauth2/clients/$PUB_ID" \ -H "Authorization: Bearer $PUB_RAT" -H "Content-Type: application/json" \ -d '{"client_name":"manual-28097-public","redirect_uris":["http://localhost:9876/callback"],"token_endpoint_auth_method":"client_secret_basic"}' stored "$PUB_ID" show -X PUT "$BASE_URL/oauth2/clients/$CONF_ID" \ -H "Authorization: Bearer $CONF_RAT" -H "Content-Type: application/json" \ -d '{"client_name":"manual-28097-confidential","redirect_uris":["http://localhost:9876/callback"],"token_endpoint_auth_method":"client_secret_post"}' stored "$CONF_ID" ``` ```text HTTP 400 { "error": "invalid_client_metadata", "error_description": "token_endpoint_auth_method cannot move an existing client between public and confidential (stored \"client_secret_basic\", requested \"none\"); the client type is fixed at registration, so register a new client instead" } confidential | client_secret_basic HTTP 400 { "error": "invalid_client_metadata", "error_description": "token_endpoint_auth_method cannot move an existing client between public and confidential (stored \"none\", requested \"client_secret_basic\"); the client type is fixed at registration, so register a new client instead" } public | none HTTP 200 "token_endpoint_auth_method": "client_secret_post", confidential | client_secret_post ``` Both rejections leave the row and its secrets untouched. A partial application would be the dangerous outcome here, a client left confidential while its caller believes it went public. The third case is the control. Two `400`s alone would be equally consistent with a guard that rejects every `token_endpoint_auth_method` change, a considerably more disruptive rule than the documented one. The `200` pins the guard to the derived client type rather than the method string. The second case is also what backs scenario 1. If public to confidential were permitted, the workaround to a refused secret request would be to flip the type and ask again. The two guards close that loop, which is why the same remedy appears in both error messages. </details> <details> <summary>13. Regression sweep of the merged stack</summary> Nothing here is new in this PR, but the guards sit on top of it. ```text discovery token_endpoint_auth_methods_supported : ["client_secret_basic","client_secret_post","none"] public registration, client_secret key present : false confidential registration, secret issued : true, method defaulted to client_secret_basic PKCE-only exchange, no client_secret sent : access + refresh issued access token against /api/v2/users/me : 200 token row app_id / app_secret_id : populated / NULL RFC 7009 revoke of own refresh token : 200, access token then 401 authorized-apps listing while a token is live : [{"name":"manual-28097-public"}] bulk DELETE /oauth2/tokens : 204, listing then [] ``` The NULL `app_secret_id` is what makes the secrets guard necessary. That column is `ON DELETE CASCADE`, so deleting a confidential app's secret takes its tokens with it, while a public client's tokens would survive. An admin who deleted such a secret would believe access was cut off when it was not. PKCE failure modes were checked separately, since the token endpoint distinguishes two the previous runbook treated as one: ```text verifier omitted : invalid_request, RFC 7636 section 4.1 bounds well-formed 43 chars but wrong : invalid_grant, "The PKCE code verifier is invalid" correct verifier, replaying that code: invalid_grant, "invalid or expired" ``` The third confirms the failed check destroys the code, so a leaked code cannot absorb repeated verifier guesses. </details> <details> <summary>14. The new docs paragraphs match observed behavior</summary> `pnpm run lint-docs` reports 0 errors across 501 files, `pnpm run format-docs` rewrites nothing, and Vale reports 0 errors with 2 warnings, both on pre-existing gerund headings that the same file on `main` also produces. The new prose is one sentence per line. | Documented claim | Verified by | |---|---| | A client's type is fixed when it registers | 12 | | A type-changing update is rejected with `invalid_client_metadata` | 12, both directions | | The client either holds a secret that would stop being required or has none and no way to be issued one | 12 (2 secrets), 1 and 12 (0 secrets, issuance refused) | | Switching between `client_secret_basic` and `client_secret_post` is allowed | 12 | | To change type, register a new client | matches the remedy in both errors and in scenario 1's detail | | Legacy `none` clients are stored as confidential and still require their `client_secret` | 6, 7 | | Coder reports `client_secret_basic` for those clients | 6 | | So that what it reports matches what it enforces | 7, both directions | | The mismatch clears itself the next time the client updates its registration | 9 | One wording note. Scenario 8 shows the mismatch does not clear on an update that resends the stored value, so strictly it clears on the next update carrying the reported value. A read-modify-write client, which is what RFC 7592 section 2.2 prescribes, always carries the reported value, so the sentence holds for the client it describes. A client that hardcodes its own metadata would not self-heal, but it would also not be following RFC 7592. </details> <details> <summary>Cleanup</summary> ```bash for id in "$PUB_ID" "$CONF_ID" "$POST_ID" "$LEGACY_ID" "$REVERSE_ID" "$ADMIN_ID"; do curl -s -X DELETE "$BASE_URL/api/v2/oauth2-provider/apps/$id" -H "$AUTH_HEADER" \ -o /dev/null -w "%{http_code}\n" done curl -s -X PUT "$BASE_URL/api/v2/oauth2-provider/settings" -H "$AUTH_HEADER" \ -H "Content-Type: application/json" -d '{"dynamic_client_registration_enabled": false}' show -X POST "$BASE_URL/oauth2/register" -H "Content-Type: application/json" \ -d '{"client_name":"should-fail","redirect_uris":["http://localhost:9876/callback"],"token_endpoint_auth_method":"none"}' ``` ```text 204 (x6) {"dynamic_client_registration_enabled":false} HTTP 403 {"error":"invalid_request","error_description":"Dynamic client registration is disabled on this deployment"} ``` All six test apps deleted with no orphaned secret or token rows. Both seeded rows had already healed to a consistent state before deletion. DCR is back off, confirmed by a registration attempt rather than by reading the flag back. </details> |
||
|
|
9be61a0c65 |
feat: accept PKCE-only token exchange for public clients (#28047)
**TL;DR** Last of the stack, split out of #27873, that makes Coder usable by public OAuth2 clients (CLIs, IDE plugins, MCP clients), which cannot hold a secret and authenticate with PKCE alone. | PR | What it does | |---|---| | #27712 | Schema: `app_secret_id` becomes nullable and tokens gain an always-populated `app_id`, so ownership checks work without a secret row. | | #28041 | Accepts bare custom-scheme redirect URIs (`vscode://`, `cursor://`) that native apps actually register. | | #28043 | Derives and stores `client_type` (public vs confidential) from the requested `token_endpoint_auth_method`, and pins it across updates. | | #28046 | Registration issues no secret for a public client and returns no `client_secret`. | | **#28047 (this)** | The token endpoint accepts the exchange without a `client_secret`, so a public client can finally get a token. Discovery now advertises `none`. | Each of the earlier PRs is inert on its own: until this one, a registered public client still could not complete a flow. Dynamic client registration is off by default, so nothing here is user-visible until it is enabled. **Where in the flow** - Token endpoint only — the `authorization_code` exchange. Authorize, consent, and code issuance are untouched. - Refresh and revocation come along for free: both already bind by app_id, so a secretless token row works as-is. - Discovery starts advertising `none`. **What it satisfies** - OAuth 2.1 §3.2.1 — only *confidential* clients must authenticate at the token endpoint. A public client is no longer rejected for a missing secret. - OAuth 2.1 §4.1.3 — for a public client the server must instead ensure the code was issued to the request's client_id. That check already existed; here it becomes the sole binding. - OAuth 2.1 §4.1.3 — client_id is required when the client does not authenticate, and a code yields a token at most once: a failed PKCE comparison consumes the code, so a leaked one cannot be brute-forced. - OAuth 2.1 §2.1 + RFC 7591 §2 — `none` means public client with no secret. The type is derived at registration (#28043) and read here. - RFC 7636 §4.1 / §4.6 — a malformed verifier is `invalid_request`, a wrong one `invalid_grant`. PKCE was already mandatory for every code flow, so public clients inherit it. - RFC 8414 §2 — advertised auth methods now match what the token endpoint actually accepts. - RFC 7009 — a cross-app revoke of a public client's token still returns 200 without revoking. --- - The token endpoint stops requiring client_secret for a public client, in both the presence check and secret validation. PKCE was already mandatory for every authorization_code flow, so public clients inherit it with no new validation code. - The code ownership check (dbCode.AppID != app.ID) becomes the only binding between the exchange and the app named by client_id for a public client, where it was defense in depth for confidential ones. Retained, now covered with a public client on both sides. - Public client tokens carry a NULL app_secret_id rather than referencing a secret row that does not exist. Refresh and revocation already verify ownership via app_id, so they change only comments and coverage. - Discovery advertises `none` now that the token endpoint honors it. - Valid() derives from the single canonical auth method list, so what registration accepts and what discovery advertises cannot disagree. - Swagger marks client_secret confidential-only. Refs https://linear.app/codercom/issue/ENG-3029/oauth2-support-public-client |