Skip to content

feat: restore agents-access as a default organization role - #30004

Merged
ibetitsmike merged 10 commits into
mainfrom
mike/agents-access-default-role
Sep 27, 2026
Merged

ibetitsmike merged 10 commits into
mainfrom
mike/agents-access-default-role

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Restores agents-access (Coder Agents User) as a built-in organization role and adds it to every organization's default_org_member_roles. Members keep Coder Agents by default, and admins can now restrict it per organization by removing the role from the defaults and granting it through IdP role sync or direct assignment.

Since #28186, chat permissions lived in the organization-member floor, so the only way to limit Coder Agents was narrowing per-model access lists, which did not hide the feature.

  • Migration 000602 appends agents-access to every organization's defaults, so upgrading keeps every member's access. New organizations get it from rbac.DefaultOrgMemberRoles().
  • Service accounts do not inherit the role from the defaults (GetAuthorizationUserRoles), so they still need an explicit grant for chat.
  • Owners and Organization Admins keep chat access regardless of defaults. Chats shared with a user stay readable without the role.
  • Role sync is unchanged. It does not store default roles, so after the default is removed a mapped user gets agents-access at their next sign-in.
  • The retired-role mechanism (IsRetiredRoleName) is removed.
  • PATCH /api/v2/organizations/{organization} rejects duplicate default_org_member_roles entries (the CLI already de-duplicated them).
  • Custom organization role requests treat built-in role names case-insensitively, since custom role names are stored lowercase and Agents-Access would otherwise become an undeletable shadow of the built-in role.
  • The Agents permission alert tells restricted members their chats are kept, and the model selector for users without chat permission no longer claims that no models are configured.

Docs add "Control who can use Coder Agents" to the Agents getting-started guide.

NOTE: Migration 000602 deletes custom roles named agents-access, which the built-in role would shadow. The down migration does not restore them. Stored member grants of agents-access from the earlier built-in role or a deleted custom role stay and now grant chat access.

Validation

  • Remote dogfood UAT passed on fb441df, covering case variants of built-in role names on create, update, delete, default roles, and member grants. The previous round, on a6fef66, passed the upgrade from main 5dde49d on a fresh database. 6b7f107 only changes wording (docs, comments, UI copy, CLI help) and did not go through UAT.
  • Local: rbac, dbauthz, idpsync, migrations (chain including 000602 down and up), querier, httpmw, provisionerdserver, coderd and enterprise chat, role, and organization tests, chatd, toolsdk, CLI; frontend vitest, story tests, biome, oxlint, tsc.

Known issues (not changed here)

  • Sending from a chat page that was already open when access was removed shows a generic 404 panel until reload.
  • The members page role editor is not locked for OIDC users under org role sync; the API rejects the change with 400.
  • Creating a custom role named after a system role (organization-member, organization-service-account) returns 400 with a raw database unique-constraint error.
Review record
  • Remote UAT (UAT Critic sub-agent 6636c855ec): round 1 on 8bec029 passed with issues, fixed in d7ba937 and e0f16e1; round 2 on a6fef66 passed; round 3 on fb441df passed.
  • Codex: round 1 on a6fef66 found one P2 (case variants of built-in role names), fixed in fb441df with a red-green test. Rounds 2 and 3 on fb441df found no major issues.
  • mafredri on fb441df (PR text only): nine wording suggestions applied in 6b7f107; NOTE extended for stored grants; description trimmed.
  • Frontend: FE1 to FE10 and coder-frontend-review checkpoints self-audited.

🤖 This PR was opened by Xum on behalf of @ibetitsmike.

Re-introduce the built-in organization role `agents-access` ("Coder Agents
User") and add it to every organization's default member roles, so all
members keep Coder Agents access after upgrading. Admins can remove it from
the organization defaults and grant it selectively through member role
edits or IdP role sync. Service accounts do not inherit it from the
defaults.
Replace the RoleSelectorDialog prop capture with a request-body assertion and keep fixture changes to MockOrganization.
Members without agents-access cannot read chats they created earlier; only chats shared with them stay readable.
Renumber the agents-access default role migration to 000602 because main added migrations 000600 and 000601.
…ries

The organization PATCH endpoint stored duplicate default role names verbatim, which made the Roles page render a role twice. The CLI already de-duplicates the flag values.
Tell restricted members that their existing chats are kept and reappear when access is restored, and stop the forbidden composer from claiming that no models are configured when the user simply has no permitted organization.
…RBAC roles

Organization defaults now include agents-access, so the workspace owner's roles gain it. Sort the acquired job's roles before comparing, because the server returns them in database order.
@github-actions

github-actions Bot commented Sep 27, 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.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-27T17:56:29.930027Z fb441df Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a6fef66b3f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread enterprise/coderd/roles.go Resolved
Custom role names are stored lowercase, so a custom role named Agents-Access became an agents-access role that the built-in role shadowed and that could not be deleted.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: fb441dfae5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Reviewed only the PR text: description, docs, CLI help, UI strings, and comments. I didn't review the design or the tests. One check, one suggestion, two minor corrections, three nits, and a suggested description.

Check: migration 000602 deletes custom roles named agents-access but leaves agents-access entries in organization_members.roles. Before this PR, rolesByNames skipped those as retired. Now they resolve to the built-in role, so those members keep Coder Agents after an admin removes the default. If that's intended, I think the NOTE should say so. The diff below adds a sentence.

Suggested PR description, 566 words down to 451:

  • Removes the "Delivery record" section and the round-by-round history. Reviewers can't act on either.
  • Drops the known issues about scripts/testidp and user admins blocked by defaults they can't assign. This PR doesn't touch that code.
  • Credits the upgrade test to a6fef66, the round where it ran.
Description diff
@@ -1,38 +1,29 @@
-Restores `agents-access` (**Coder Agents User**) as a built-in organization role and ships it in every organization's `default_org_member_roles`. Every member keeps Coder Agents by default, and admins can now restrict it per organization by removing the role from the defaults and granting it through IdP organization role sync or direct assignment.
+Restores `agents-access` (**Coder Agents User**) as a built-in organization role and adds it to every organization's `default_org_member_roles`. Members keep Coder Agents by default, and admins can now restrict it per organization by removing the role from the defaults and granting it through IdP role sync or direct assignment.
 
 Since #28186, chat permissions lived in the organization-member floor, so the only way to limit Coder Agents was narrowing per-model access lists, which did not hide the feature.
 
 - Migration 000602 appends `agents-access` to every organization's defaults, so upgrading keeps every member's access. New organizations get it from `rbac.DefaultOrgMemberRoles()`.
-- Service accounts do not inherit the role from the defaults (`GetAuthorizationUserRoles`) and need an explicit grant, matching today's service-account floor without chat.
+- Service accounts do not inherit the role from the defaults (`GetAuthorizationUserRoles`), so they still need an explicit grant for chat.
 - Owners and Organization Admins keep chat access regardless of defaults. Chats shared with a user stay readable without the role.
-- Role sync is unchanged: default roles are implicit, so after the default is removed a mapped user gets `agents-access` at their next sign-in (documented).
+- Role sync is unchanged. It does not store default roles, so after the default is removed a mapped user gets `agents-access` at their next sign-in.
 - The retired-role mechanism (`IsRetiredRoleName`) is removed.
 - `PATCH /api/v2/organizations/{organization}` rejects duplicate `default_org_member_roles` entries (the CLI already de-duplicated them).
 - Custom organization role requests treat built-in role names case-insensitively, since custom role names are stored lowercase and `Agents-Access` would otherwise become an undeletable shadow of the built-in role.
-- The Agents permission alert tells restricted members their chats are kept, and the forbidden composer no longer claims that no models are configured.
+- The Agents permission alert tells restricted members their chats are kept, and the model selector for users without chat permission no longer claims that no models are configured.
 
 Docs add "Control who can use Coder Agents" to the Agents getting-started guide.
 
-**NOTE**: Migration 000602 deletes custom roles named `agents-access`, which the built-in role would shadow. The down migration does not restore them.
+**NOTE**: Migration 000602 deletes custom roles named `agents-access`, which the built-in role would shadow. The down migration does not restore them. Stored member grants of `agents-access` from the earlier built-in role or a deleted custom role stay and now grant chat access.
 
 ## Validation
 
-- Remote dogfood UAT: **PASS on fb441dfae58** (round 3: case variants of built-in names rejected on create, update, delete, default roles, and member grants, plus a regression smoke on the round-2 database). Round 2 PASS on a6fef66b3fe covered the upgrade from main 5dde49dffbd on a fresh database. Screenshots and logs are attached to the [UAT chat](https://dogfood.cdr.dev/agents/e1c18dc6-f6f0-49a1-b6cd-6ce014b51a86).
-- Local: rbac, dbauthz, idpsync, migrations (chain incl. 000602 down/up), querier, httpmw, provisionerdserver, coderd and enterprise chat/role/organization tests, chatd, toolsdk, CLI; frontend vitest, story tests, biome, oxlint, tsc. Red-green on the duplicate-roles test and the forbidden placeholder.
+- Remote dogfood [UAT](https://dogfood.cdr.dev/agents/e1c18dc6-f6f0-49a1-b6cd-6ce014b51a86) passed on fb441dfae58, covering case variants of built-in role names on create, update, delete, default roles, and member grants. The previous round, on a6fef66b3fe, passed the upgrade from main 5dde49dffbd on a fresh database.
+- Local: rbac, dbauthz, idpsync, migrations (chain including 000602 down and up), querier, httpmw, provisionerdserver, coderd and enterprise chat, role, and organization tests, chatd, toolsdk, CLI; frontend vitest, story tests, biome, oxlint, tsc.
 
 ## Known issues (not changed here)
 
 - Sending from a chat page that was already open when access was removed shows a generic 404 panel until reload.
 - The members page role editor is not locked for OIDC users under org role sync; the API rejects the change with 400.
-- User admins cannot change member roles in an org whose defaults include a role they cannot assign (for example `organization-auditor`).
 - Creating a custom role named after a system role (`organization-member`, `organization-service-account`) returns 400 with a raw database unique-constraint error.
-- `scripts/testidp` advertises JWKS `alg: RSA`, which go-oidc v3.21 rejects.
-
-## Delivery record
-
-- Remote UAT (UAT Critic sub-agent `6636c855ec`): round 1 on 8bec029d353 PASS with issues, fixed in d7ba937a108 and e0f16e1a45f; round 2 on a6fef66b3fe PASS; round 3 on fb441dfae58 (current head) PASS, remaining issues listed above.
-- Frontend: FE1 to FE10 and coder-frontend-review checkpoints self-audited in the main thread.
-- Codex round 1 on a6fef66b3fe: one P2 (case variants of built-in role names), confirmed by a probe, fixed in fb441dfae58 with a red-green test, thread resolved. Round 2 on fb441dfae58: no major issues.
 
 > 🤖 This PR was opened by [Xum](https://mux.coder.com) on behalf of @ibetitsmike.
-

I verified these claims against the code at fb441df:

  • Role sync treats default roles as implicit (coderd/idpsync/role.go:183-198).
  • The CLI de-duplicates the role list (parseDefaultOrgMemberRoles).
  • Custom role names are stored lowercase (queries/roles.sql).
  • Owner and Organization Admin roles include chat.
  • Chat ACLs keep shared chats readable.

I couldn't verify "did not hide the feature" or the UAT results.

🤖 This review was automatically generated with Coder Agents.

Comment thread docs/ai-coder/agents/getting-started.md Resolved
Comment thread docs/ai-coder/agents/getting-started.md Resolved
Comment thread docs/admin/users/groups-roles.md Resolved
Comment thread codersdk/rbacroles.go Resolved
Comment thread coderd/rbac/roles.go Resolved
Comment thread cli/organizationmanage.go Resolved
@ibetitsmike
ibetitsmike marked this pull request as ready for review September 27, 2026 17:52
@ibetitsmike
ibetitsmike requested a review from a team as a code owner September 27, 2026 17:52
Move the access-gap explanation ahead of the restriction steps, exclude service accounts from "every member" claims, align the CLI example with the docs wording, and trim comments that restated code.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. All nine suggestions are applied in 6b7f107.

  • Check: yes, that's intended. A stored agents-access grant is an explicit grant, so it counts again now that the role exists; the migration only removes the custom role definitions the built-in role would shadow. The NOTE now says so, and the getting-started text now says that only members who don't hold the role directly lose access when the default is removed.
  • Description: adopted your rewrite, including the NOTE sentence, the shorter known issues list, and crediting the upgrade test to a6fef66. I kept a short review record, collapsed at the end, because Mike keeps one in his PR descriptions.

🤖 Xum replied on behalf of @ibetitsmike.

@coderagents

coderagents Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/admin/users/groups-roles.md (open) - This was addressed. The Coder Agents User entry now says "Members other than service accounts hold this role through the organization's default member roles unless an administrator removes it."

Automated review via Coder Agents

@ibetitsmike
ibetitsmike merged commit 6826da9 into main Sep 27, 2026
36 checks passed
@ibetitsmike
ibetitsmike deleted the mike/agents-access-default-role branch September 27, 2026 21:34
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 27, 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