Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor(coderd): validate workspace create once to dedupe external auth - #26922

Closed
dylanhuff-at-coder wants to merge 5 commits into
mainfrom
dylan/dedupe-workspace-create-external-auth
Closed

refactor(coderd): validate workspace create once to dedupe external auth#26922
dylanhuff-at-coder wants to merge 5 commits into
mainfrom
dylan/dedupe-workspace-create-external-auth

Conversation

@dylanhuff-at-coder

Copy link
Copy Markdown
Contributor

Follow-up to #26718 (PLAT-298). Stacked on that branch, so the base should be retargeted to main once #26718 merges.

Addresses review feedback: requireWorkspaceOwnerExternalAuth ran twice per successful task create (once in tasksCreate, once again inside createWorkspace), contacting the owner's external auth providers twice.

createWorkspace is split into:

  • validateWorkspaceCreate — authorization preflight, required external auth, and schedule/TTL/automatic-updates validation.
  • createValidatedWorkspace — insert/claim + build.

Regular workspace endpoints compose them unchanged. tasksCreate now calls validateWorkspaceCreate once (before task-name generation) and passes the result to createValidatedWorkspace, so external auth runs exactly once and still before any row is inserted.

Design note

createValidatedWorkspace performs no external-auth check of its own; the single authoritative check is validateWorkspaceCreate, which every caller runs first. This is the "break up createWorkspace" the reviewer suggested rather than a skip flag. Open question for reviewers: whether createValidatedWorkspace should assert the passed validation matches the request/owner as a cheap guard against future misuse.

Validated locally: TestCreateWorkspaceExternalAuth, TestCreateTaskExternalAuth (including the new authz-before-external-auth ordering subtest), TestTasksCreate, TestPostWorkspacesByOrganization, and enterprise TestCreateWorkspace pass.

Coder Agents generated.

Add a subtest to TestCreateTaskExternalAuth proving that the workspace
authorization gate short-circuits before the external auth preflight in
tasksCreate. A member banned from creating workspaces is rejected with
the authorization error, not the external auth requirement, even though
the template requires an unsatisfied provider, and no task row is
inserted.

Coder Agents generated.
Extract the shared workspace-create authorization gates (template
resolution, ActionCreate on the workspace, ActionUse on the template,
and the deprecation check) into api.preflightWorkspaceCreate and call it
from both createWorkspace and tasksCreate so the Tasks API and the
workspace API cannot diverge.

This also drops the unreachable second ActionCreate check in
createWorkspace: it used the identical action and RBAC object as the
first check with only auditReq.UpdateOrganizationID between them, so its
ErrResourceNotFound (404) branch could never be reached. The single
remaining check preserves the observable 403 behavior.

Addresses review feedback on #26718.

Coder Agents generated.
Split createWorkspace into validateWorkspaceCreate (authorization
preflight, required external auth, and schedule/TTL/automatic-updates
validation) and createValidatedWorkspace (insert/claim + build). Regular
workspace creation composes them unchanged, while tasksCreate now calls
validateWorkspaceCreate once, before task name generation, and passes the
result to createValidatedWorkspace.

Previously tasksCreate ran requireWorkspaceOwnerExternalAuth and then
createWorkspace ran it again, contacting the owner's external auth
providers twice per successful task create. The check now runs exactly
once while remaining the authoritative gate before any row is inserted.

Coder Agents generated.
Base automatically changed from dylan/plat-298-enforce-required-external-auth-at-the-coder-agents-api-level to main July 9, 2026 20:59
@github-actions github-actions Bot added the stale This issue is like stale bread. label Jul 17, 2026
@github-actions github-actions Bot closed this Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale This issue is like stale bread.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant