-
Notifications
You must be signed in to change notification settings - Fork 10
fix(auth): reject reserved role-permission names as database names + complete cluster_user handling #1913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kylebernhardy
wants to merge
5
commits into
main
Choose a base branch
from
fix/reserved-schema-names-1016
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix(auth): reject reserved role-permission names as database names + complete cluster_user handling #1913
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6a14dfc
fix(auth): reject reserved role-permission names as database names
nizzlenitz 4894330
fix(auth): complete cluster_user role-flag handling
nizzlenitz ec635b9
test(auth): use plain node:assert per house style (reserved-names test)
nizzlenitz 560e5dd
docs(auth): note access-key exclusion and why the reserved-name check…
nizzlenitz 54962ed
fix(auth): gate the su/cu boolean check on key presence, not truthine…
nizzlenitz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| const assert = require('node:assert'); | ||
| const schema = require('#src/dataLayer/schema'); | ||
| const { table } = require('#src/resources/databases'); | ||
|
|
||
| // harper#1016: a role's `permission` object keys per-database permissions by | ||
| // database name alongside named flags (super_user / cluster_user / | ||
| // structure_user / operations / _expandedOperations). A database named after one | ||
| // of those flags collides with it, so those names are rejected as database | ||
| // identifiers — at both the operations API (create_schema / create_table) and | ||
| // the schema-authoring path (graphql `@table(database:)` / programmatic table()). | ||
| const RESERVED = ['super_user', 'cluster_user', 'structure_user', 'operations', '_expandedOperations']; | ||
|
|
||
| describe('#1016 reserved database names', () => { | ||
| for (const name of RESERVED) { | ||
| it(`create_schema rejects reserved name '${name}'`, async () => { | ||
| await assert.rejects( | ||
| () => schema.createSchemaStructure({ operation: 'create_schema', schema: name }), | ||
| /reserved name/, | ||
| `create_schema accepted reserved name '${name}'` | ||
| ); | ||
| }); | ||
|
|
||
| it(`create_table rejects reserved database '${name}'`, async () => { | ||
| await assert.rejects( | ||
| () => schema.createTableStructure({ operation: 'create_table', schema: name, table: 't', primary_key: 'id' }), | ||
| /reserved name/, | ||
| `create_table accepted reserved database '${name}'` | ||
| ); | ||
| }); | ||
|
|
||
| it(`schema authoring (table()) rejects reserved database '${name}'`, () => { | ||
| // graphql `@table(database:)` and programmatic table() funnel through here, | ||
| // bypassing the operations-API validation. The check throws before any store IO. | ||
| assert.throws( | ||
| () => table({ database: name, table: 't', attributes: [{ name: 'id', isPrimaryKey: true }] }), | ||
| /reserved name/, | ||
| `table() accepted reserved database '${name}'` | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| it('does not reject a non-reserved database name as reserved', async () => { | ||
| // A normal name must pass the reserved-name check. It may still fail later | ||
| // (no schema metadata / bridge in this unit context) — just not as reserved. | ||
| let err; | ||
| try { | ||
| await schema.createSchemaStructure({ operation: 'create_schema', schema: 'my_normal_db' }); | ||
| } catch (e) { | ||
| err = e; | ||
| } | ||
| if (err) assert.doesNotMatch(err.message, /reserved name/); | ||
| }); | ||
| }); |
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
cluster_usertoROLE_TYPEScorrectly stops treating it as a database, but it exposes the existing truthiness gate inrole_validation.ts(if (object.permission[role] && !validate.isBoolean(...))). Falsey non-booleans such as0,'', andnullnow skip both that check and the database-permission loop, so add/alter role accepts them despite the boolean contract. Could we check key presence/definedness instead and add at least0/nullregression cases? That would also close the latentsuper_uservariant.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch — you're right, the
&&truthiness prefix let0/''/nullskip both the boolean check and (since the key is a role type) the database-permission loop. Fixed in 54962ed by gating on key presence instead:role in object.permission && !isBoolean(...), so a defined-but-falsey non-boolean is now rejected with the boolean error. Added regression cases for0/''/nullon bothcluster_userandsuper_user(the latent variant you flagged). Thanks for the thorough review!Comment generated by kAIle (Claude Opus 4.8)