Skip to content

fix(cli): allow site admins to use coder create --org for any organization#21528

Merged
ethanndickson merged 1 commit intomainfrom
provisioning-6pcv
Feb 16, 2026
Merged

fix(cli): allow site admins to use coder create --org for any organization#21528
ethanndickson merged 1 commit intomainfrom
provisioning-6pcv

Conversation

@ethanndickson
Copy link
Member

@ethanndickson ethanndickson commented Jan 15, 2026

Problem

Site-wide admins (e.g., Owners) could not use coder create --org <org> to create workspaces in organizations they are not members of. The error was:

$ coder create my-workspace -t docker --org data-science
error: organization "data-science" not found, are you sure you are a member of this organization?

This was inconsistent with the web UI, where Owners can create workspaces in any organization.

Root Cause

The CLI's OrganizationContext.Selected() function only checked the user's membership list, ignoring site-wide RBAC permissions that grant Owners access to all organizations.

Solution

Added a fallback in OrganizationContext.Selected() that fetches the org directly via the API when not found in the membership list. This works because the API endpoint applies RBAC filtering, allowing Owners to read any org.

Impact

This fixes coder create --org and all other CLI commands that use OrganizationContext.Selected() (29+ commands), including:

  • coder templates push --org <any-org>
  • coder organizations members add --org <any-org>
  • coder provisioner list --org <any-org>

Testing

Added TestEnterpriseCreate/OwnerCanCreateInNonMemberOrg which:

  • Creates an Owner user who is NOT a member of a second org
  • Verifies they can create a workspace there using --org
  • Properly fails without the code fix, passes with it

This PR was generated by mux but reviewed by a human.

@ethanndickson ethanndickson changed the title fix(cli): allow site admins to use --org for any organization fix(cli): allow site admins to use coder create --org for any organization Jan 15, 2026
Site-wide admins (e.g., Owners) can now use the --org flag to select
organizations they are not members of. Previously, OrganizationContext.Selected()
only checked the user's membership list, causing 'organization not found' errors
even when the user had RBAC permission to access the org.

The fix adds a fallback that fetches the org directly via the API when not found
in the membership list. This works because the API endpoint applies RBAC filtering,
allowing Owners to read any org.

This fixes all 29+ CLI commands that use OrganizationContext.Selected(), including:
- coder create --org <any-org>
- coder templates push --org <any-org>
- coder organizations members add --org <any-org>
@ethanndickson
Copy link
Member Author

I ran into this working on mux, figured I'd fix it.

@ethanndickson ethanndickson requested a review from Emyrk January 15, 2026 23:17
@github-actions github-actions bot added the stale This issue is like stale bread. label Jan 23, 2026
@ethanndickson ethanndickson removed the stale This issue is like stale bread. label Jan 26, 2026
@github-actions github-actions bot added the stale This issue is like stale bread. label Feb 3, 2026
@ethanndickson ethanndickson removed the stale This issue is like stale bread. label Feb 3, 2026
@geokat
Copy link
Contributor

geokat commented Feb 6, 2026

Code LGTM.
Looks like a useful fix. I’m not stamping since I don’t have enough context on why this approach wasn’t used originally.
EDIT: Would it possibly be a breaking change for people who use it in scripts? Very unlikely though 🤔

Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

LGTM. This does mean a user might be able to see another org, but not make a workspace or something. As long as these orgs are not discoverable, and only addressable by knowing the name, this is fine

@github-actions github-actions bot added the stale This issue is like stale bread. label Feb 14, 2026
@ethanndickson ethanndickson merged commit 4b3889e into main Feb 16, 2026
29 checks passed
@ethanndickson ethanndickson deleted the provisioning-6pcv branch February 16, 2026 01:16
@github-actions github-actions bot locked and limited conversation to collaborators Feb 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

stale This issue is like stale bread.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants