Skip to content

docs: rewrite multitenant rbac example with OPL#2545

Open
DavudSafarli wants to merge 2 commits intomasterfrom
keto-d-update-rbac-example
Open

docs: rewrite multitenant rbac example with OPL#2545
DavudSafarli wants to merge 2 commits intomasterfrom
keto-d-update-rbac-example

Conversation

@DavudSafarli
Copy link
Copy Markdown
Contributor

@DavudSafarli DavudSafarli commented May 6, 2026

Replaces the outdated keto RBAC example

Summary by CodeRabbit

  • New Features
    • Expanded permission expression parsing to recognize additional sentence forms.
    • Added support for new keywords in permission statements, enabling more flexible and natural ways to define permissions.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Ory Keto RBAC documentation and associated syntax highlighting to reflect an OPL-based, multi-tenant-friendly modeling approach instead of the older RBAC example.

Changes:

  • Rewrites the RBAC guide to demonstrate tenant-scoped RBAC modeling in OPL, including role management flows.
  • Extends the keto-natural Prism grammar to support dotted permission names (e.g. users.list, reports.view) and the optional perform keyword.
  • Updates Jest Prism tokenization tests and snapshots to cover the new grammar behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
tests/jest/prism/ketoRelationsPermissionsPrism.test.ts Adds a new declarative test case for dotted permission names in keto-natural.
tests/jest/prism/snapshots/ketoRelationsPermissionsPrism.test.ts.snap Refreshes snapshots to match the updated tokenizer behavior and new test case.
src/theme/ketoRelationsPermissionsPrism.js Updates regexes/tokenization rules to accept dotted relations/permits and perform.
docs/keto/guides/rbac.mdx Replaces the RBAC guide content with an OPL-based, multi-tenant RBAC example and guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/keto/guides/rbac.mdx Outdated
Comment thread docs/keto/guides/rbac.mdx
Comment on lines +112 to +116
// Admin role permissions
Organization:org_123#members.invite@Role:admin
Organization:org_123#roles.manage@Role:admin
Organization:org_123#reports.view@Role:admin
Organization:org_123#reports.create@Role:admin
Comment thread docs/keto/guides/rbac.mdx Outdated
Comment thread docs/keto/guides/rbac.mdx Outdated
Comment thread docs/keto/guides/rbac.mdx Outdated
Comment thread docs/keto/guides/rbac.mdx Outdated
Comment thread tests/jest/prism/ketoRelationsPermissionsPrism.test.ts
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Warning

Rate limit exceeded

@DavudSafarli has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 34 minutes and 54 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8a6b54cb-0eb6-400b-9531-d17f343eecb6

📥 Commits

Reviewing files that changed from the base of the PR and between c405eed and 1ef3c76.

⛔ Files ignored due to path filters (2)
  • docs/keto/guides/rbac.mdx is excluded by !**/*.mdx
  • tests/jest/prism/__snapshots__/ketoRelationsPermissionsPrism.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/theme/ketoRelationsPermissionsPrism.js
  • tests/jest/prism/ketoRelationsPermissionsPrism.test.ts
📝 Walkthrough

Walkthrough

The PR extends the keto-natural Prism grammar to recognize additional sentence forms, including "allowed to" and "perform" phrases, with refined lookahead-based placeholder matching and adjusted keyword/permit token ordering. Two new test cases validate these expanded patterns.

Changes

Grammar and Test Expansion for "Allowed To" Constructs

Layer / File(s) Summary
Pattern Foundation
src/theme/ketoRelationsPermissionsPrism.js (lines 24–28)
Updated "natural-placeholder" to use lookahead-based regex ensuring presence of Subject/Relation/Object placeholders.
Declarative Grammar Core
src/theme/ketoRelationsPermissionsPrism.js (lines 71–102)
Extended the "natural" block to support broader sentence structures, added "allowed to" and "perform" keywords, introduced flexible permit token, and refined tokenization of subject and object elements.
Permission Check Grammar
src/theme/ketoRelationsPermissionsPrism.js (lines 103–134)
Expanded "natural-check" pattern to support "allowed to" and related constructs with updated keyword sets and reordered permit patterns before keywords.
Test Coverage
tests/jest/prism/ketoRelationsPermissionsPrism.test.ts (lines 50–56)
Added two new declarative test cases: "allowed to access to" and "allowed to perform" with dot-notation relations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 The grammar hops with newfound grace,
"Allowed to" finds its proper place,
With "perform" and dots dancing free,
Prism patterns bloom in harmony!
Regex magic, tests aligned—
A parser's joy, perfectly defined! 🌿

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning Title claims documentation rewrite with OPL, but actual changes are to JavaScript grammar and test files with no documentation modifications. Update title to reflect actual changes: e.g., 'feat: enhance ketoRelationsPermissionsPrism grammar and add test cases' or clarify if documentation changes are missing.
Description check ⚠️ Warning Description is vague and incomplete. It lacks details about actual code changes, missing required sections like related issues, and lacks specificity about what was changed. Expand description to explain grammar enhancements, new test cases added, and include a reference to related issue or design document per template requirements.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch keto-d-update-rbac-example

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
tests/jest/prism/ketoRelationsPermissionsPrism.test.ts (1)

59-72: ⚡ Quick win

Add a question-form test for perform and dotted actions.

natural-check (lines 106 / 130 / 132 in src/theme/ketoRelationsPermissionsPrism.js) was updated to accept (?:perform )? and dotted permits, but questionTestCases doesn't exercise either path. Without a snapshot here, regressions in the question grammar's perform / dotted-action handling will go undetected.

🧪 Suggested additional test cases
   const questionTestCases = [
     {
       name: "simple question: is User:Bob allowed to view on Document:X",
       input: "is User:Bob allowed to view on Document:X",
     },
     {
       name: "question with 'in': is User:Alice in viewers of Document:X",
       input: "is User:Alice in viewers of Document:X",
     },
     {
       name: "question with relation subject: are members of Group:XYZ allowed to view on Document:X",
       input: "are members of Group:XYZ allowed to view on Document:X",
     },
+    {
+      name: "question with 'perform' and dotted action: is User:Bob allowed to perform users.list on Document:X",
+      input: "is User:Bob allowed to perform users.list on Document:X",
+    },
   ]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/jest/prism/ketoRelationsPermissionsPrism.test.ts` around lines 59 - 72,
The questionTestCases array doesn't include cases exercising the new "perform"
optional token and dotted actions; add at least two new test entries to
questionTestCases: one with "perform" (e.g., input "is User:Bob allowed to
perform view on Document:X") and one using a dotted action/permission (e.g.,
input "is User:Bob allowed to view.read on Document:X" or similar dotted permit
form) so the grammar branch in natural-check (the updated rule accepting
(?:perform )? and dotted permits) is exercised by the test suite; update the
questionTestCases array by adding objects with descriptive name fields and the
specified input strings.
src/theme/ketoRelationsPermissionsPrism.js (1)

4-19: 💤 Low value

Update the grammar JSDoc to cover the new sentence forms.

The header docblock still only describes the original declarative/question forms. The grammar now also accepts:

  • <Subject> is allowed to <action> (to|on|of) <Object> (e.g., User:Bob is allowed to access to Document:X)
  • <Subject> is allowed to perform <action> <Object>
  • Dotted actions (e.g., users.list)

Adding a couple of example lines here will keep the file self-documenting and match what the regex on lines 74/106 actually parses.

📝 Proposed doc additions
  * Declarative sentences:
  * - User:Bob is owner of Document:X
  * - Group:group2 is in members of Group:group1
  * - members of Group:Eng are viewers of Document:Xyz
  * - viewers of Group:Eng are in readers of Document:Xyz
  * - User:Bob is allowed to read Document:X
  * - members of Group:Eng is allowed to read Document:X
+ * - User:Bob is allowed to access to Document:X
+ * - User:Bob is allowed to perform users.list on Document:X
  *
  * Question sentences:
  * - is User:Bob allowed to view on Document:X
  * - is User:Alice in viewers of Document:X
  * - are members of Group:XYZ allowed to view on Document:X
+ * - is User:Bob allowed to perform users.list on Document:X
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/theme/ketoRelationsPermissionsPrism.js` around lines 4 - 19, Update the
top JSDoc in src/theme/ketoRelationsPermissionsPrism.js to document the new
sentence patterns parsed by the grammar: add examples for "<Subject> is allowed
to <action> (to|on|of) <Object>" (e.g., "User:Bob is allowed to access to
Document:X"), "<Subject> is allowed to perform <action> <Object>" (e.g.,
"Group:admins is allowed to perform users.list Document:Y"), and show dotted
actions like "users.list" to reflect what the regexes used in the grammar (the
patterns around the action parsing referenced near the action-related regexes)
actually accept; include a couple representative example lines in the header so
the docblock matches the parser behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/theme/ketoRelationsPermissionsPrism.js`:
- Around line 4-19: Update the top JSDoc in
src/theme/ketoRelationsPermissionsPrism.js to document the new sentence patterns
parsed by the grammar: add examples for "<Subject> is allowed to <action>
(to|on|of) <Object>" (e.g., "User:Bob is allowed to access to Document:X"),
"<Subject> is allowed to perform <action> <Object>" (e.g., "Group:admins is
allowed to perform users.list Document:Y"), and show dotted actions like
"users.list" to reflect what the regexes used in the grammar (the patterns
around the action parsing referenced near the action-related regexes) actually
accept; include a couple representative example lines in the header so the
docblock matches the parser behavior.

In `@tests/jest/prism/ketoRelationsPermissionsPrism.test.ts`:
- Around line 59-72: The questionTestCases array doesn't include cases
exercising the new "perform" optional token and dotted actions; add at least two
new test entries to questionTestCases: one with "perform" (e.g., input "is
User:Bob allowed to perform view on Document:X") and one using a dotted
action/permission (e.g., input "is User:Bob allowed to view.read on Document:X"
or similar dotted permit form) so the grammar branch in natural-check (the
updated rule accepting (?:perform )? and dotted permits) is exercised by the
test suite; update the questionTestCases array by adding objects with
descriptive name fields and the specified input strings.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 795dbdb8-3d6c-4bd6-a333-bf4572b2c48a

📥 Commits

Reviewing files that changed from the base of the PR and between 9ac94e6 and c405eed.

⛔ Files ignored due to path filters (2)
  • docs/keto/guides/rbac.mdx is excluded by !**/*.mdx
  • tests/jest/prism/__snapshots__/ketoRelationsPermissionsPrism.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/theme/ketoRelationsPermissionsPrism.js
  • tests/jest/prism/ketoRelationsPermissionsPrism.test.ts

@DavudSafarli DavudSafarli force-pushed the keto-d-update-rbac-example branch from c405eed to 539a7e1 Compare May 6, 2026 14:50
Copy link
Copy Markdown
Member

@zepatrik zepatrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good starting point! Two general improvement ideas:

  1. I first had concerns because the last section on multi-tenancy is quite important and it wasn't obvious at first. Maybe it needs to be more prominent? Or the examples above should not look like a multi-tenant system as much?
  2. I think we should consistently use the Sub is rel of obj notion.

Copy link
Copy Markdown
Member

@vinckr vinckr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some style fixes:

  • Always use Ory Keto, not Keto by itself
  • Active voice in headlines, so for example Create a new organization instead of Creating a new organization
  • Remove numbering in the headlines so Create a custom role instead of 3. Creating a custom role

for some reason I couldn't comment on the individual sections of the text, but I hope this is clear.

stoked to see this merged 🚢

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants