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

Skip to content

fix(coderd): enforce required external auth on task create - #26718

Merged
dylanhuff-at-coder merged 4 commits into
mainfrom
dylan/plat-298-enforce-required-external-auth-at-the-coder-agents-api-level
Jul 9, 2026
Merged

fix(coderd): enforce required external auth on task create#26718
dylanhuff-at-coder merged 4 commits into
mainfrom
dylan/plat-298-enforce-required-external-auth-at-the-coder-agents-api-level

Conversation

@dylanhuff-at-coder

@dylanhuff-at-coder dylanhuff-at-coder commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Tasks created through the API now enforce required external auth: tasksCreate rejects an owner who is missing a required (non-optional) provider with a 403 before generating a task name or inserting any rows, matching the gate createWorkspace already applies to workspaces. Adds TestCreateTaskExternalAuth covering the required and optional-provider cases.

Fixes PLAT-298.

Coder Agents generated.

@linear-code

linear-code Bot commented Jun 25, 2026

Copy link
Copy Markdown

PLAT-298

Base automatically changed from dylan/plat-241-api-workspace-creation-bypasses-required-external-auth to main June 25, 2026 22:47
@dylanhuff-at-coder
dylanhuff-at-coder force-pushed the dylan/plat-298-enforce-required-external-auth-at-the-coder-agents-api-level branch from 04f3449 to 9045664 Compare June 25, 2026 22:51
@dylanhuff-at-coder
dylanhuff-at-coder marked this pull request as ready for review June 25, 2026 23:43
Comment thread coderd/aitasks.go Outdated
httperror.WriteResponseError(ctx, rw, err)
return
}
if !api.HTTPAuth.AuthorizeContext(ctx, policy.ActionCreate,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now duplicate the preflight checks applied by createWorkspace here, which may result in the checks diverging. I'll usually apply a rough rule-of-three when it comes to duplication, but given that this is an authorization check, it's probably worth consolidating the checks in a single function.

Comment thread coderd/aitasks.go
// Required external auth is otherwise only enforced once createWorkspace
// runs. Validate it here so the Tasks API rejects an owner who is missing a
// required provider before any task name generation or row insertion.
if err := api.requireWorkspaceOwnerExternalAuth(ctx, templateVersion, owner.ID); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're now calling this twice (here and createWorkspace), adding latency and additional upstream risk from the IdPs. We can probably live with it for now, but we should create a follow-up issue to see if we can break up createWorkspace to tease out the duplicate check.

Comment thread coderd/aitasks_test.go
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.

@jscottmiller jscottmiller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Some of the comments feel overly-focused on this specific change; the models tend to do this and I'll usually dial it back so the comment stays focused on the local functionality and not broader gotchas.

@dylanhuff-at-coder

Copy link
Copy Markdown
Contributor Author

Looks good. Some of the comments feel overly-focused on this specific change; the models tend to do this and I'll usually dial it back so the comment stays focused on the local functionality and not broader gotchas.

All good @jscottmiller sorry I didn't respond directly, meant to before PTO. Thanks for the review :)

@dylanhuff-at-coder
dylanhuff-at-coder merged commit 5fed583 into main Jul 9, 2026
28 of 29 checks passed
@dylanhuff-at-coder
dylanhuff-at-coder deleted the dylan/plat-298-enforce-required-external-auth-at-the-coder-agents-api-level branch July 9, 2026 20:59
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants