Skip to content

refactor(coderd): restore agents-access cleanup migration - #28587

Merged
ibetitsmike merged 22 commits into
mainfrom
mike/codagt-554-agents-access-cleanup
Aug 26, 2026
Merged

refactor(coderd): restore agents-access cleanup migration#28587
ibetitsmike merged 22 commits into
mainfrom
mike/codagt-554-agents-access-cleanup

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • restore the agents-access data cleanup migration as 000587 (renumbered from 000585; main advanced past that number)
  • revert the temporary RBAC tolerance for retired role names now that the migration strips stale grants
  • make the migration test discover its predecessor dynamically, since this branch does not carry main's 000585/000586

Stack context

Stacked on #28186, which retires the agents-access role but intentionally ships without a migration so it can be backported across diverged migration numbers. This layer completes the retirement on main: it cleans up stale role grants in users.rbac_roles, organization_members.roles, and organizations.default_org_member_roles, then reverts the interim leniency (role expansion dropping legacy names, assignment validation ignoring them) that existed only to keep the migration-less base safe. rbac.ReservedRoleName still reserves the retired name so custom roles cannot shadow it on rollback. Do not backport this PR alongside the base PR.

Rollback note

The down migration restores effective access broadly because it cannot reconstruct which users previously held the removed role.

Validation

  • go build ./coderd/... ./enterprise/...
  • full coderd/database/migrations, coderd/rbac/..., and coderd/database/dbauthz suites
  • targeted members tests in coderd
  • repository pre-commit checks (lint/go, lint/ts, etc.)

Mux created this pull request on Mike's behalf.

Keep this PR migration-free so it backports cleanly across diverged
migration numbers. Stale agents-access grants may now linger in role
arrays and org default role lists, so treat retired role names as
grants of nothing: role expansion drops them and assignment
validation ignores them. A follow-up PR will clean up the stale data.
Reinstate the data cleanup that the base PR dropped to stay
backportable, renumbered to 000587 because main advanced past 585.
With stale grants migrated away, revert the temporary RBAC tolerance
for retired role names: role expansion is strict again and assignment
validation no longer filters legacy names. The migration test steps
to the highest existing version below the target because this branch
does not contain migrations 585 and 586 from main.
@linear-code

linear-code Bot commented Aug 25, 2026

Copy link
Copy Markdown

CODAGT-554

@ibetitsmike
ibetitsmike marked this pull request as ready for review August 25, 2026 17:38

@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: b722a80a34

ℹ️ 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 coderd/rbac/roles.go
@ibetitsmike ibetitsmike reopened this Aug 25, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 25, 2026
# Conflicts:
#	docs/ai-coder/agents/getting-started.md
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

…ment listings

Also renames IsLegacyRoleName to IsRetiredRoleName so the helpers are named for behavior rather than history.
…-default' into HEAD

# Conflicts:
#	coderd/database/db2sdk/db2sdk.go
#	coderd/database/dbauthz/dbauthz.go
#	coderd/members.go
#	coderd/members_test.go
#	coderd/rbac/roles.go
#	coderd/rbac/roles_test.go
#	coderd/rbac/rolestore/rolestore.go
#	coderd/rbac/rolestore/rolestore_test.go
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@coder coder unlocked this conversation Aug 26, 2026
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Base automatically changed from mike/codagt-554-enable-agents-by-default to main August 26, 2026 11:33
@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

coder/coderd/roles.go

Lines 103 to 104 in 86b3eef

for _, role := range customRoles {
canAssign := rbac.CanAssignRole(actorRoles, rbac.CustomSiteRole())

P2 Badge Keep retired custom roles out of assignment flows

On deployments where a custom role named agents-access predates the reservation, migration 587 leaves its custom_roles row intact, but removing this filter makes the role appear assignable again. The corresponding changes in canAssignRoles and rolestore.Expand then validate it as a custom role and activate its stored permissions after assignment, resurrecting a role that is intended to remain available only for deletion. Continue excluding retired names from assignment and expansion even after cleaning existing grants.

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Posted by Xum, acting on Mike's behalf.

Addressed in b33e339 (the branch is also restacked onto main now that #28186 merged):

  • Kept every assignment/expansion exclusion from feat: enable Coder Agents for organization members #28186: the assignable-roles filter in coderd/roles.go, the retired-name skips in rbac.rolesByNames and rolestore.Expand, and the dbauthz rejections of explicit retired-name grants and newly added org defaults. A pre-reservation custom_roles row named agents-access therefore cannot be offered, granted, expanded, or re-created; it remains deletable only.
  • Narrowed this PR's revert to response-side filtering (members.go, users.go, db2sdk.go) and the stale-data integration test, since migration 000587 removes the stored grants and defaults those filters existed to hide.
  • Updated the coderd/rbac/roles.go comments to document the resurrection-guard rationale now that the cleanup migration exists.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: b33e3394d8

ℹ️ 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".

@ibetitsmike
ibetitsmike merged commit 45f2eb4 into main Aug 26, 2026
28 checks passed
@ibetitsmike
ibetitsmike deleted the mike/codagt-554-agents-access-cleanup branch August 26, 2026 13:29
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 26, 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