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

Skip to content

fix: show selected owner's external auth when creating a workspace - #26653

Merged
aslilac merged 12 commits into
mainfrom
lilac/external-auth-owner
Jul 23, 2026
Merged

fix: show selected owner's external auth when creating a workspace#26653
aslilac merged 12 commits into
mainfrom
lilac/external-auth-owner

Conversation

@aslilac

@aslilac aslilac commented Jun 24, 2026

Copy link
Copy Markdown
Member

When an admin creates a workspace for another user, the External Authentication section now reflects the selected owner's auth state instead of the admin's.

Previously the form always reported the requesting admin's external auth, so an admin connected to a provider saw "Authenticated" and could submit even when the target owner had never connected it.

Behavior

  • The form reports the selected owner's external auth state.
  • When creating for another user, the "Login with ..." button is replaced with a read-only status, since logging in would authenticate the admin rather than the owner. A short note explains the owner must connect it themselves.
  • Required-but-unconnected providers still block submission, as before.
Implementation details & decisions

Root cause. External auth was keyed by template version only. The backend endpoint looked up links using the requester's ID, and the form never passed the selected owner.

Backend. GET /templateversions/{ver}/external-auth accepts an optional user_id. When it differs from the requester, the requester is authorized for create workspace as that owner (mirroring workspace creation). The owner's link status is then read under an elevated read-only context, so admins who can create for others but lack personal read access (e.g. org admins) still work. The build path already resolves external auth per owner, so this only corrects the form.

Decisions / tradeoffs.

  • Another user's token is never refreshed from this read-only status check (refresh mutates). Status is based on link existence; the build refreshes and skips invalid tokens at provision time.
  • authenticate_url is omitted for non-self responses so the UI cannot offer a login action that would authenticate the wrong account.
  • Submission stays blocked when a required provider is unconnected for the selected owner (least-surprising, avoids builds that would be missing required auth).

Tests. Backend: an org admin (create-for-owner, no personal read) sees the owner's state; a plain member is forbidden. Frontend: Storybook play tests cover the read-only status and the "another user" form state.


Generated by Coder Agents on behalf of @aslilac.

When an admin created a workspace for another user, the external
authentication section reflected the admin's own auth state instead of
the selected owner's, because the endpoint and form keyed external auth
by template version only.

The external-auth endpoint now accepts an optional user_id. When it
differs from the requester, it authorizes create-workspace-for-owner,
reads the owner's link status under an elevated read-only context, and
omits the authenticate URL. The create form threads the selected owner
through the query and shows a read-only status for other users instead
of a login button that would authenticate the admin.
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Docs preview

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

aslilac added 2 commits June 26, 2026 22:48
…wner

# Conflicts:
#	coderd/templateversions.go
Replace AsSystemRestricted with a new AsExternalAuthChecker actor when
reporting or validating a workspace owner's external auth state. The new
subject can only read and refresh a user's external auth links
(ResourceUser personal read/update) instead of granting read on every
resource plus broad writes.

Applied to both call sites of templateVersionExternalAuthForUser: the
create-workspace form endpoint and the create-time owner check.
@aslilac
aslilac requested a review from Emyrk as a code owner June 27, 2026 00:29
aslilac and others added 2 commits June 27, 2026 00:53
…ok arg

Give getTemplateVersionExternalAuth and the templateVersionExternalAuth
query/key a userId = "me" default instead of an optional param, and make
useExternalAuth's userId required so callers must say whose external auth
they want. Update TaskPrompt to pass "me" explicitly.

@code-asher code-asher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested and looks good to me!

Comment thread coderd/database/dbauthz/dbauthz.go Outdated
@github-actions github-actions Bot added the stale This issue is like stale bread. label Jul 14, 2026
@github-actions github-actions Bot closed this Jul 17, 2026
@aslilac aslilac reopened this Jul 23, 2026
@aslilac
aslilac requested a review from a team as a code owner July 23, 2026 20:50
@aslilac aslilac removed the stale This issue is like stale bread. label Jul 23, 2026

@nickvigilante nickvigilante 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.

docs/reference/api/templates.md LGTM

@aslilac
aslilac merged commit 3cf97ff into main Jul 23, 2026
32 checks passed
@aslilac
aslilac deleted the lilac/external-auth-owner branch July 23, 2026 22:39
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 23, 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.

3 participants