-
Notifications
You must be signed in to change notification settings - Fork 366
feat: allow underscore prefix for private identifiers #2733
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
ivanauth
wants to merge
10
commits into
authzed:main
Choose a base branch
from
ivanauth:feat/issue-2066-underscore-prefix-identifiers
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
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
835c8e9
docs: document underscore prefix for private identifiers
ivanauth 8005a12
fix: add trailing newline to schema-language.md
ivanauth a0b215a
chore: remove in-repo docs (should go to authzed/docs)
ivanauth 48c6e78
chore: trigger CI re-run for flaky E2E test
ivanauth 1eb6d4b
ci: re-run tests
ivanauth 1096f00
feat: allow underscore prefix for private identifiers
ivanauth 0eb64b1
Merge branch 'main' into feat/issue-2066-underscore-prefix-identifiers
ivanauth 0239875
chore: retrigger CI
ivanauth d37ba73
chore: retrigger CI
ivanauth ddd8b7b
ci: bump setup-go action to match go.mod Go 1.25.5 requirement
ivanauth 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # SpiceDB Schema Language Guide | ||
|
|
||
| ## Identifier Naming Conventions | ||
|
|
||
| ### Private/Internal Identifiers | ||
|
|
||
| SpiceDB supports using underscore (`_`) as a prefix for identifiers to establish a convention for marking definitions as "private" or "internal". This is particularly useful for: | ||
|
|
||
| - **Synthetic permissions**: Permissions that exist only to compose other permissions | ||
| - **Internal relations**: Relations not meant to be directly referenced by application code | ||
| - **Implementation details**: Parts of your schema that may change without affecting the public API | ||
|
|
||
| ### Examples | ||
|
|
||
| ```zed | ||
| definition document { | ||
| // Public relation - exposed to application code | ||
| relation viewer: user | ||
|
|
||
| // Private relation - used internally for permission composition | ||
| relation _internal_viewer: user | ||
|
|
||
| // Public permission using private components | ||
| permission view = viewer + _internal_viewer | ||
| } | ||
|
|
||
| definition _internal_resource { | ||
| // This entire resource type is marked as internal | ||
| relation owner: user | ||
| } | ||
| ``` | ||
|
|
||
| ### Best Practices | ||
|
|
||
| 1. **Use underscore prefix for synthetic permissions**: | ||
| ```zed | ||
| definition resource { | ||
| relation owner: user | ||
| relation editor: user | ||
|
|
||
| // Private synthetic permission | ||
| permission _can_write = owner + editor | ||
|
|
||
| // Public permissions built on private ones | ||
| permission edit = _can_write | ||
| permission delete = owner | ||
| } | ||
| ``` | ||
|
|
||
| 2. **Mark implementation details as private**: | ||
| ```zed | ||
| definition folder { | ||
| relation parent: folder | ||
| relation viewer: user | ||
|
|
||
| // Private permission for traversal logic | ||
| permission _parent_view = parent->view | ||
|
|
||
| // Public permission combining direct and inherited access | ||
| permission view = viewer + _parent_view | ||
| } | ||
| ``` | ||
|
|
||
| 3. **Future module system compatibility**: When SpiceDB introduces a module system for composing schemas via libraries, underscore-prefixed identifiers will help clearly distinguish between public and private APIs. | ||
|
|
||
| ### Technical Details | ||
|
|
||
| - Identifiers can begin with either a letter (`a-z`) or underscore (`_`) | ||
| - After the first character, identifiers can contain letters, numbers, and underscores | ||
| - Identifiers must end with an alphanumeric character (not an underscore) | ||
| - Valid: `_private`, `_internal_relation`, `_helper123` | ||
| - Invalid: `_trailing_` (must end with alphanumeric), `123_start` (must start with letter or underscore) | ||
| - Note: `__double` is technically valid by the regex pattern but discouraged for readability | ||
|
|
||
| This naming convention is enforced at the schema level and is compatible with all SpiceDB operations and queries. |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
Why are we writing this doc here? This will not get published anywhere. Maybe we should update https://authzed.com/docs/spicedb/concepts/schema instead?
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.
Thank you, i removed docs from this pr and created a new docs pr.