Skip to content

sql: implement DROP PROVISIONED ROLES execution#166958

Draft
souravcrl wants to merge 3 commits intocockroachdb:masterfrom
souravcrl:fork/drop-provisioned-roles-execution
Draft

sql: implement DROP PROVISIONED ROLES execution#166958
souravcrl wants to merge 3 commits intocockroachdb:masterfrom
souravcrl:fork/drop-provisioned-roles-execution

Conversation

@souravcrl
Copy link
Copy Markdown
Contributor

Add DropProvisionedRolesNode in a new drop_provisioned_roles.go file
that implements the plan node for the DROP PROVISIONED ROLES statement.

The execution logic:

  1. Requires CREATEROLE privilege.
  2. Builds a filtered SQL query against system.users joined with
    system.role_options to find users with PROVISIONSRC, optionally
    filtered by SOURCE value and LAST ACCESS TIME OLDER THAN timestamp.
  3. For each matched user, checks dependencies (owned objects, grants,
    default privileges, scheduled jobs, system privileges). Users with
    dependencies are skipped with a client NOTICE rather than failing
    the entire operation.
  4. Deletes the role from system.users, system.role_members,
    system.role_options, system.database_role_settings, and revokes
    web sessions.
  5. Bumps role-related table versions and logs per-user DropRole audit
    events.

Note: This plan node is not yet wired into opaque.go dispatch; that
happens in a subsequent PR.

Epic CRDB-52460

fixes: CRDB-52797
Release note: None

souravcrl and others added 3 commits March 27, 2026 18:27
Add the `DropProvisionedRoles` AST struct and `DropProvisionedRolesOptions`
to `pkg/sql/sem/tree/drop.go`, along with statement metadata methods in
`stmt.go`.

The new statement supports optional filter clauses:

  DROP PROVISIONED ROLES
    WITH SOURCE = 'ldap:ldap.example.com',
         LAST ACCESS TIME OLDER THAN '2025-01-01'
    LIMIT 10

`DropProvisionedRolesOptions` has its own `Format`, `CombineWith`, and
`IsDefault` methods, mirroring the pattern used by `ShowUsersOptions`.

Epic CRDB-52460
fixes CRDB-52797

Release note: None

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extend the SQL parser grammar to support the DROP PROVISIONED ROLES
statement with optional WITH clauses and LIMIT:

  DROP PROVISIONED ROLES [WITH <options>] [LIMIT <n>]

Options (comma-separated):
  SOURCE = <string>
  LAST ACCESS TIME OLDER THAN <expr>

Add `PROVISIONED` as an unreserved keyword. Define dedicated grammar
rules (`opt_with_drop_provisioned_roles_options`,
`drop_provisioned_roles_options_list`, `drop_provisioned_roles_option`)
and wire the new `drop_provisioned_roles_stmt` production into `drop_stmt`.

Add parse roundtrip tests covering all option combinations.

Epic CRDB-52460

fixes: CRDB-52797

Release note: None

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `DropProvisionedRolesNode` in a new `drop_provisioned_roles.go` file
that implements the plan node for the DROP PROVISIONED ROLES statement.

The execution logic:
1. Requires CREATEROLE privilege.
2. Builds a filtered SQL query against system.users joined with
   system.role_options to find users with PROVISIONSRC, optionally
   filtered by SOURCE value and LAST ACCESS TIME OLDER THAN timestamp.
3. For each matched user, checks dependencies (owned objects, grants,
   default privileges, scheduled jobs, system privileges). Users with
   dependencies are skipped with a client NOTICE rather than failing
   the entire operation.
4. Deletes the role from system.users, system.role_members,
   system.role_options, system.database_role_settings, and revokes
   web sessions.
5. Bumps role-related table versions and logs per-user DropRole audit
   events.

Note: This plan node is not yet wired into opaque.go dispatch; that
happens in a subsequent PR.

Epic CRDB-52460

fixes: CRDB-52797
Release note: None

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@souravcrl souravcrl requested a review from a team March 28, 2026 02:25
@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented Mar 28, 2026

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants