feat(access): list roles as roles, show allow-all, one membership source - #435
Merged
Merged
Conversation
The Database Access screens read the catalog incompletely, so the most powerful accounts looked like they held nothing and roles looked like users. Catalog (packages/sql db-access): - MySQL/TiDB: a locked, passwordless mysql.user row is a role. MariaDB: is_role, named bare (no host), members from roles_mapping. - MySQL family: read USER_PRIVILEGES as GLOBAL (*.*) rows and role memberships as ROLE rows, with fallbacks for logins that cannot read mysql.*. - Postgres family: read rolsuper; read schema and database ACLs with aclexplode (the usage_privileges WHERE object_type = 'SCHEMA' branch could never match). Old forms kept as fallbacks. - ClickHouse: memberships from system.role_grants; *.* is GLOBAL, not SYSTEM. - Db2: list OS groups (GRANTEETYPE 'G'). SQL Server: sysadmin as superuser, and what db_owner / db_datareader / db_datawriter imply. - reconcileDbAccess fills memberOf/members and ROLE rows from each other, so the list and the detail pane can no longer disagree. - Role grants honour WITH ADMIN OPTION; MySQL roles are named 'r'@'%'. UI: - Database Access: allow-all/superuser tag and banner (followed through roles), filter by "allow-all", a full privilege set collapsed to one ALL PRIVILEGES row with Revoke all, "grantable" instead of "*", a role picker for membership, and an "All privileges" grant kind per engine with typed-name confirmation. - User Management: allow-all tag, and Add can put the account in existing roles (UserRequest.roles), with SET DEFAULT ROLE on the MySQL family. - Permissions tab: allow-all banner on the account. Also: effective.ts used literal NUL bytes as a key separator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_e0b6f285-10f9-4b59-8360-bec4e485810f) |
The modal tests clicked db-access-principal-alice as soon as fetchDbAccess had been called. The mock resolves a tick later, so on a slow runner the list was still empty and CI failed 'lists the membership under Role memberships' with no element to click. Wait for the row itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_b7585e4b-91a2-47ee-a2f2-0b92ee5d47ae) |
huyplb
added a commit
that referenced
this pull request
Sep 27, 2026
refactor(access): simplify the roles and allow-all code from #435
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implements the Database Access Review. There were three complaints:
*permission.The root cause was mostly the catalog read, so that's fixed first, then the UI.
1. The catalog read (
packages/sql/src/modules/access/db-access.ts)Checked live against the local containers by running
probeDbAccesswith throwaway accounts on each engine:GRANT ALL ON *.*showed as "No object privileges".USER_PRIVILEGESread as GLOBAL rows.role_edgesread as ROLE rows.r@.is_role, bare role names,membersfromroles_mapping.*.*read.ALL ON DATABASEandALL ON SCHEMAall read as nothing. The schema branch (usage_privileges WHERE object_type='SCHEMA') could never match.rolsuperread. Schema and database ACLs read viaaclexplode. The old forms are kept as fallbacks.*.*shown asSYSTEM.system.role_grantsread.*.*shown as GLOBAL.GRANTEETYPE 'G'listed as groups.sysadminanddb_ownershowed as nothing.IS_SRVROLEMEMBER('sysadmin')read as superuser. Fixed roles' implied permissions added (source: 'implied').reconcileDbAccess(called indb-access.service.ts) fillsmemberOf/membersand the ROLE rows from each other. Every screen now gets one answer about membership. Before, the list said "member of X" while the detail pane said "Belongs to no roles".Each MySQL-family query has a fallback ladder. I checked a low-privilege MySQL login live: it still gets its own grants, plus a warning naming what it couldn't read.
2. UI
allow-all/superusertag and a banner, followed through role chains ("Inherited through ops → admin");allow-allin the filter lists only those accounts;ALL PRIVILEGESrow, which expands and has Revoke all;grantablereplaces the*marker, which clashed with the SQL wildcard;UserRequest.roles. It also emitsSET DEFAULT ROLE ALLon MySQL/TiDB, orSET DEFAULT ROLE r FORon MariaDB, because a granted role is otherwise inactive at login. All three engines ran these statements live. MySQL/TiDB roles now parse asname@host, so Drop emitsDROP ROLE 'r'@'%'.3. Allow-all grants
A new "All privileges (allow-all)" grant kind uses
allPrivilegeTargets. Each engine gets its own widest form, with a note on what it really confers:*.*, ordb.*CONTROLALL PRIVILEGESDBADMIt's marked critical, and Run stays disabled until the principal's name is typed. I checked grant and Revoke all end to end in the browser on MySQL.
This differs from the review doc. The doc proposed a new
allpermission and aninstancescope inside the intent builder. A newAccessScopetype would touch about ten files of scope-switching logic (emitters, diff, matrix, sections). I made allow-all its own deliberate grant kind instead, on the catalog grant path that already emittedALL/*.*correctly.Also fixed along the way
db.*. A baredbnames a table.effective.tsused literal NUL bytes as a key separator, which madegreptreat the file as binary.Tests: each one fails without its fix
database-access-dialects.test.tscreates a role, a member and an allow-all grant through/api/sql/execute, asserts what the Users screen shows, then cleans up.ROLE_ADMIN.rolsuperfails Postgres (no superuser tag).role_grantsfails the roles column. Reverting MySQL*.*fails the allow-all tag.privilege-groups.test.tsandreconcileDbAccess/ query-shape tests indb-access.test.ts.user-sql.test.ts.findAllowAllfrom following roles fails 4 tests.DatabaseAccessModal.test.tsx(ALL row and Revoke all, inherited superuser plus filter, grantable, role picker, typed allow-all confirm),AccessView.test.tsx(member-of picker, superuser tag, MySQL role drop) andAccessPermissionPanel.test.tsx(banner).cd apps/web && npx tsc --noEmitis clean. The e2e tsc is clean. The unit tests forpackages/sql, access and naming pass 1,663, and web-ui passes 243.Not done, or unverified
information_schema.SCHEMA_PRIVILEGESempty even for root (the grant is only inmysql.db), so TiDBdb.*grants still don't show. This predates this PR; it needs amysql.dbread.pg_group, and I have no way to verify against it locally.npx vitest runon macOS has 41 failures in workflow-engine / workflow-server file-pipe tests. They reproduce on unmodifiedorigin/main. The cause is c20efd3's path confinement meeting the/var→/private/varsymlink, and it's unrelated to this PR. I've flagged it as a separate task.🤖 Generated with Claude Code
Note
Medium Risk
Changes cross-engine GRANT catalog queries, reconciliation, and grant/revoke SQL generation—security-sensitive database access behavior with wide dialect surface area.
Overview
Fixes database access catalog reads and UI so roles list as roles, membership is consistent everywhere, and superuser /
ON *.*/ db-wide control show up instead of looking like empty privilege sets.Catalog (
@foxschema/sql+ server probe): Dialect probes now pull MySQL-family roles, globalUSER_PRIVILEGES, Postgresrolsuperand schema/database ACLs, ClickHouserole_grants/GLOBAL, SQL Serversysadmin, and more.reconcileDbAccessmergesmemberOf/memberswith ROLE privilege rows (and adds implied SQL Server fixed-role privileges). Newprivilege-groupshelpers collapse expanded ALL grants, detect allow-all (including via roles), and drive dialect-specific “grant everything” targets.UI: Database Access and User Management show
allow-all/superuserbadges and banners, filter by those terms, group privileges as collapsible ALL PRIVILEGES with Revoke all, and add an All privileges grant flow with name-to-confirm. Add user can pick Member of roles (SQL includes MySQL/MariaDB SET DEFAULT ROLE). MySQL/TiDB roles usename@hostfor drop/grant. Permissions account stage shows the same allow-all banner.Tests & docs: E2E step for roles/tags per dialect, broad unit/component coverage, and USER_GUIDE updates.
Reviewed by Cursor Bugbot for commit a0e4c35. Bugbot is set up for automated code reviews on this repo. Configure here.