Skip to content

Conversation

@ivanauth
Copy link
Contributor

@ivanauth ivanauth commented Nov 26, 2025

Summary

  • Enable underscore prefix (_) for definition, relation, and permission identifiers
  • Establishes a convention for marking identifiers as "private" or "internal"

Description

This PR implements the feature requested in issue #2066 by updating the identifier regex patterns from [a-z] to [a-z_] to allow identifiers to begin with an underscore.

This is 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

Changes

  • Updated regex patterns in proto validation to allow underscore-prefixed identifiers
  • Updated corresponding test expectations

Example Usage

definition document {
    relation viewer: user
    relation _internal_viewer: user
    
    // Private synthetic permission
    permission _can_view = viewer + _internal_viewer
    
    // Public permission
    permission view = _can_view
}

Note

End-user documentation for this feature should be added to authzed/docs at pages/spicedb/concepts/schema.mdx.

Fixes #2066

@ivanauth ivanauth requested a review from a team as a code owner November 26, 2025 23:39
@github-actions github-actions bot added area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Nov 26, 2025
@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.71%. Comparing base (e7390fe) to head (48c6e78).
⚠️ Report is 43 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2733      +/-   ##
==========================================
+ Coverage   77.05%   77.71%   +0.66%     
==========================================
  Files         464      472       +8     
  Lines       49188    49714     +526     
==========================================
+ Hits        37896    38629     +733     
+ Misses       8504     8231     -273     
- Partials     2788     2854      +66     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ivanauth ivanauth force-pushed the feat/issue-2066-underscore-prefix-identifiers branch from 641584f to 835c8e9 Compare November 26, 2025 23:44
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@ivanauth ivanauth changed the title Document underscore prefix for private identifiers feat: allow underscore prefix for private identifiers Dec 1, 2025
ivanauth added a commit to ivanauth/docs that referenced this pull request Dec 1, 2025
Document the ability to use underscore prefixes for definitions,
relations, and permissions to signal that they are private/internal.

This is a naming convention that helps developers distinguish between
public API and internal implementation details in their schemas.

Related: authzed/spicedb#2733

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
ivanauth added a commit to ivanauth/docs that referenced this pull request Dec 1, 2025
Document the ability to use underscore prefixes for definitions,
relations, and permissions to signal that they are private/internal.

This is a naming convention that helps developers distinguish between
public API and internal implementation details in their schemas.

Related: authzed/spicedb#2733

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
ivanauth added a commit to ivanauth/docs that referenced this pull request Dec 1, 2025
Document the ability to use underscore prefixes for definitions,
relations, and permissions to signal that they are private/internal.

This is a naming convention that helps developers distinguish between
public API and internal implementation details in their schemas.

Related: authzed/spicedb#2733

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
ivanauth added a commit to ivanauth/api that referenced this pull request Dec 19, 2025
…n identifiers

Updates regex patterns across all API protos to allow identifiers to
begin with an underscore (`_`). This enables a convention for marking
identifiers as "private" or "internal".

Use cases:
- **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

Example:
```zed
definition document {
    relation viewer: user
    relation _internal_viewer: user

    // Private synthetic permission
    permission _can_view = viewer + _internal_viewer

    // Public permission
    permission view = _can_view
}
```

Companion PR to authzed/spicedb#2733

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@josephschorr
Copy link
Member

I think if we introduce this, we should enforce that private identifiers cannot be accessed outside the scope of either the definition or the file (in composable schemas) and perhaps even enforce that they cannot be used in API calls

The schema-language.md file won't be published from this repo.
Documentation for underscore prefix identifiers should be added
to https://github.com/authzed/docs instead.
@ivanauth ivanauth force-pushed the feat/issue-2066-underscore-prefix-identifiers branch from b624462 to 48c6e78 Compare January 7, 2026 15:44
@ivanauth
Copy link
Contributor Author

ivanauth commented Jan 7, 2026

@josephschorr good point - do you want me to try adding definition-scoped + API rejection by default?

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

Labels

area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Establish a convention for public/private

3 participants