Skip to content

feat: migrate agents-access to org-scoped system role for proper chat RBAC#24438

Merged
johnstcn merged 2 commits intomainfrom
cian/agents-access-org-role
Apr 23, 2026
Merged

feat: migrate agents-access to org-scoped system role for proper chat RBAC#24438
johnstcn merged 2 commits intomainfrom
cian/agents-access-org-role

Conversation

@johnstcn
Copy link
Copy Markdown
Member

@johnstcn johnstcn commented Apr 16, 2026

The agents-access role previously granted chat permissions at user scope, but chats are org-scoped objects. Rego skips user-level perms when org_owner is set, making the grants invisible. Handler-level band-aids used synthetic non-org-scoped objects as a workaround.

  • Migrates agents-access from users.rbac_roles (site-level) to
    organization_members.roles (org-scoped) via DB migration
  • Redefines agents-access as a predefined org-scoped builtin role
    alongside organization-admin, organization-auditor, etc., with
    Member permissions granting chat create/read/update
  • Excludes ResourceChat from OrgMemberPermissions so org membership
    alone no longer grants chat access
  • Fixes handler Authorize checks to use org-scoped objects with
    semantically correct actions (ActionUpdate for message/tool operations)
  • Grants org admins the ability to assign agents-access

Closes #24250
Fixes CODAGT-174

Note: this does not update the "Usage" endpoints. Tracked by CODAGT-161.

🤖

Copy link
Copy Markdown
Member Author

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

self-review round 1

Comment thread coderd/exp_chats.go
Comment thread coderd/exp_chats.go
Comment thread coderd/exp_chats.go
Comment thread coderd/database/dbauthz/dbauthz.go
@johnstcn johnstcn force-pushed the cian/agents-access-org-role branch 2 times, most recently from 075f78c to 2848396 Compare April 17, 2026 17:48
Copy link
Copy Markdown
Member Author

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

self-reviewed

@johnstcn
Copy link
Copy Markdown
Member Author

/coder-agents-review

Copy link
Copy Markdown

@coder-agents-review coder-agents-review Bot left a comment

Choose a reason for hiding this comment

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

Well-structured RBAC migration. The single-gate model (agents-access as sole chat permission source) is cleaner than the previous split where org members had implicit chat CRUD. The handler auth improvements (ActionUpdate on chat.RBACObject() instead of ActionCreate on synthetic resources) are correct. The migration is DML-only, idempotent, and production-safe. The ChatUsageCRU/ChatUsageDelete test split precisely documents the new permission boundary.

Pariston on the design: "I tried to build a case against this and came up short. The problem is correctly understood. The solution is proportional. The fix is at the right causal level: the role definition, not the symptom layer."

1 P2, 5 P3, 4 Nit. The P2 is a cross-org cost data leak via AnyOrganization() that merits attention.

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/database/dbauthz/dbauthz.go Outdated
Comment thread coderd/database/dbauthz/dbauthz.go
Comment thread coderd/exp_chats.go
Comment thread coderd/database/dbauthz/dbauthz.go Outdated
Comment thread coderd/rbac/roles.go
Comment thread coderd/rbac/roles.go
Comment thread coderd/database/migrations/000475_agents_access_org_role.down.sql
Comment thread coderd/exp_chats_test.go Outdated
Comment thread coderd/rbac/roles_test.go Outdated
Comment thread enterprise/coderd/exp_chats_test.go Outdated
@johnstcn johnstcn force-pushed the cian/agents-access-org-role branch from 87b92c3 to 26205a6 Compare April 22, 2026 15:19
@johnstcn
Copy link
Copy Markdown
Member Author

/coder-agents-review

Copy link
Copy Markdown

@coder-agents-review coder-agents-review Bot left a comment

Choose a reason for hiding this comment

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

All 10 posted findings from R1 are resolved: 8 fixed in code, 1 accepted by human reviewer (DEREM-3, cross-org cost queries, with TODO documenting the limitation), 1 deferred with ticket (DEREM-4, CODAGT-161). R2 panel (Bisky, Mafuuu, Kite, Razor) and Netero found no new issues.

Mafuuu on contract fidelity: "Members without agents-access have zero chat access. Tests verify: list returns 0 chats (SQL auth filter), get returns 404 (dbauthz wraps as not-found), update returns 404, message send returns 404."

🤖 This review was automatically generated with Coder Agents.

@johnstcn johnstcn marked this pull request as ready for review April 22, 2026 16:21
@johnstcn johnstcn requested a review from Emyrk as a code owner April 22, 2026 16:21
Copy link
Copy Markdown

@coder-agents-review coder-agents-review Bot left a comment

Choose a reason for hiding this comment

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

R3 re-review after rebase. No new findings from Netero or the panel (Mafuuu, Kite, Razor). The delta since R2 is a merge from main bringing string constant extraction and unrelated changes; no authorization paths were modified. All R1 findings remain resolved. CI passing (11/20 pending at review time, 9 skipped).

🤖 This review was automatically generated with Coder Agents.

… RBAC

The agents-access role previously granted chat permissions at user scope,
but chats are org-scoped objects. Rego skips user-level perms when
org_owner is set, making the grants invisible. Handler-level band-aids
used synthetic non-org-scoped objects as a workaround.

This commit:
- Migrates agents-access from users.rbac_roles (site-level) to
  organization_members.roles (org-scoped) via DB migration
- Redefines agents-access as a predefined org-scoped builtin role
  alongside organization-admin, organization-auditor, etc., with
  Member permissions granting chat create/read/update
- Excludes ResourceChat from OrgMemberPermissions so org membership
  alone no longer grants chat access
- Fixes handler Authorize checks to use org-scoped objects with
  semantically correct actions (ActionUpdate for message/tool operations)
- Grants org admins the ability to assign agents-access

Closes #24250
@johnstcn johnstcn force-pushed the cian/agents-access-org-role branch from ca9ff54 to f844481 Compare April 23, 2026 16:37
@johnstcn
Copy link
Copy Markdown
Member Author

Went through the changes and pruned out all the unnecessary stuff that got added.

@johnstcn johnstcn merged commit b5a6255 into main Apr 23, 2026
29 checks passed
@johnstcn johnstcn deleted the cian/agents-access-org-role branch April 23, 2026 16:59
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 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.

Make agents-access role org-aware for proper chat authorization

2 participants