-
Notifications
You must be signed in to change notification settings - Fork 59
feat: abac e2e #125
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
35C4n0r
wants to merge
7
commits into
permitio:main
Choose a base branch
from
35C4n0r:feat-e2e-abac
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
feat: abac e2e #125
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9836976
feat: abac e2e
35C4n0r 025ec96
fix: fix tests
35C4n0r 1e13fb8
feat: add tests
35C4n0r 198fa01
fix: add suggestions
35C4n0r e60ce59
feat: add documentation
35C4n0r 35a58d3
feat: add sample outputs
35C4n0r cdc9e7d
feat: lint
35C4n0r 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 |
|---|---|---|
|
|
@@ -107,7 +107,7 @@ Below is a categorized overview of all available Permit CLI commands: | |
| - [`permit test run audit`](#permit-test-run-audit) – Audit your policy decisions against recent logs. | ||
|
|
||
| - [E2E Tests](#execute-e2e-tests) | ||
| - [`permit test generate e2e`](#permit-test-generate-e2e) – Generate end-to-end policy test configurations and (optionally) test data. | ||
| - [`permit test generate e2e`](#permit-test-generate-e2e) – Generate end-to-end policy test configurations, and (optionally) test data & test-snippets. | ||
|
|
||
| ### [API-First Authorization](#api-first-authorization-1) | ||
|
|
||
|
|
@@ -1180,8 +1180,10 @@ Generate end‑to‑end test configurations (and optionally test data) for your | |
|
|
||
| - `--api-key <string>` - API Key to be used for test generation. | ||
| - `--dry-run <boolean>` - If set, generates test cases and mock data **without** making any changes in Permit. | ||
| - `--models <string_array>` - List of model names to generate tests for. `default: RBAC`. | ||
| - `--models <string_array>` - List of model names to generate tests for. `default: RBAC` `Allowed values: ("RBAC", "ABAC")[]`. | ||
| - `--path <string>` - Filesystem path where the generated JSON config should be saved (recommended). | ||
| - `--snippet <string>` - If set, generates a code snippet for the test. The snippet will be printed to the terminal. `Allowed values: 'pytest' | 'jest', 'vitest'` | ||
| - `--snippet-path <string>` - If set, saves the generated code snippet to the specified file path. | ||
|
|
||
| > Note: All flags are optional. If you omit `--models`, only the default RBAC model will be processed. If you omit `--dry-run`, real data and users will be created in Permit. | ||
|
|
||
|
|
@@ -1193,6 +1195,12 @@ Generate tests for the default RBAC model, and save the config to disk. Creates | |
| $ permit test generate e2e --models=RBAC --path=logb.json | ||
| ``` | ||
|
|
||
| Generate tests for both RBAC and ABAC models, and save the config to disk. Creates end‑to‑end tests for the `RBAC` & `ABAC` model and writes the generated JSON config to `logb.json` | ||
|
|
||
| ```bash | ||
| $ permit test generate e2e --models=RBAC --models=ABAC --path=logb.json | ||
| ``` | ||
|
|
||
| Generate tests for RBAC, save the config, but don't apply changes (dry run). This is the same as above, but in dry‑run mode, so no changes are made in Permit. | ||
|
|
||
| ```bash | ||
|
|
@@ -1211,37 +1219,142 @@ Generate and apply tests for the RBAC model with default settings. Runs end‑to | |
| $ permit test generate e2e --models=RBAC | ||
| ``` | ||
|
|
||
| ## API-First Authorization | ||
|
|
||
| Define and enforce API authorization policies using OpenAPI specifications for a smooth API integration. | ||
|
|
||
| ### URL-based Permissions | ||
|
|
||
| Map API endpoints to policies using simple configurations and FastAPI decorators | ||
| Generate tests for the default RBAC model, and save the config to disk. Creates end‑to‑end tests for the `RBAC` model and writes the generated JSON config to `logb.json`. Also generates a code snippet for the test in `pytest` format and saves it to `test_policy.py`. | ||
|
|
||
| #### `permit pdp check-url` | ||
|
|
||
| Check if a user has permission to access a specific URL. The command verifies URL-based permissions against the PDP using the Permit.io URL authorization API. | ||
| ```bash | ||
| $ permit test generate e2e --models=RBAC --path=logb.json --snippet=pytest --snippet-path=test_policy.py | ||
| ``` | ||
|
|
||
| **Arguments (Required):** | ||
| ### Example outputs: | ||
|
|
||
| - `--user <string>` - the user id to check permissions for (Required) | ||
| - `--url <string>` - the URL to check permissions for (Required) | ||
| #### For RBAC, the generated JSON config might look like this: | ||
|
|
||
| **Arguments (Optional):** | ||
| ```json | ||
| { | ||
| "config": [ | ||
| { | ||
| "user": "dreamyshannon", | ||
| "action": "read", | ||
| "resource": { | ||
| "type": "Document2", | ||
| "tenant": "test-tenant-modestritchie" | ||
| }, | ||
| "result": false | ||
| }, | ||
| { | ||
| "user": "dreamyshannon", | ||
| "action": "create", | ||
| "resource": { | ||
| "type": "Document2", | ||
| "tenant": "test-tenant-modestritchie" | ||
| }, | ||
| "result": false | ||
| } | ||
| ], | ||
| "users": [ | ||
| { | ||
| "key": "dreamyshannon", | ||
| "email": "[email protected]", | ||
| "firstName": "dreamy", | ||
| "lastName": "shannon", | ||
| "roles": [] | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| - `--method <string>` - the HTTP method to check permissions for (default: `GET`) | ||
| - `--tenant <string>` - the tenant to check permissions for (default: `default`) | ||
| - `--user-attributes <string>` - additional user attributes to enrich the authorization check in the format `key1:value1,key2:value2`. Can be specified multiple times. | ||
| - `--pdp-url <string>` - the PDP URL to check authorization against (default: Cloud PDP) | ||
| - `--api-key <string>` - the API key for the Permit env, project or Workspace | ||
| #### For ABAC, the generated JSON config might look like this: | ||
|
|
||
| **Examples:** | ||
| ```json | ||
| { | ||
| "config": [ | ||
| { | ||
| "user": { | ||
| "key": "angrygoodall", | ||
| "attributes": { | ||
| "department": "Engineering", | ||
| "training_status": "certified", | ||
| "key": "c65e70d8-d50b-4ac2-8f0c-ad14ae695d0f", | ||
| "email": "c65e70d8-d50b-4ac2-8f0c-ad14ae695d0f" | ||
| } | ||
| }, | ||
| "resource": { | ||
| "type": "Document2", | ||
| "attributes": { | ||
| "document_type": "classified", | ||
| "priority_level": "high" | ||
| }, | ||
| "tenant": "test-tenant-hardcorebose" | ||
| }, | ||
| "action": "query", | ||
| "result": true | ||
| } | ||
| ], | ||
| "users": [ | ||
| { | ||
| "key": "angrygoodall", | ||
| "email": "[email protected]", | ||
| "firstName": "angry", | ||
| "lastName": "goodall", | ||
| "roles": [] | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| Basic URL permission check: | ||
| #### For combined (both RBAC and ABAC), the generated JSON config might look like this: | ||
|
|
||
| ```bash | ||
| $ permit pdp check-url --user [email protected] --url https://api.example.com/orders | ||
| ```json | ||
| { | ||
| "config": [ | ||
| { | ||
| "user": { | ||
| "key": "angrygoodall", | ||
| "attributes": { | ||
| "department": "Engineering", | ||
| "training_status": "certified", | ||
| "key": "c65e70d8-d50b-4ac2-8f0c-ad14ae695d0f", | ||
| "email": "c65e70d8-d50b-4ac2-8f0c-ad14ae695d0f" | ||
| } | ||
| }, | ||
| "resource": { | ||
| "type": "Document2", | ||
| "attributes": { | ||
| "document_type": "classified", | ||
| "priority_level": "high" | ||
| }, | ||
| "tenant": "test-tenant-hardcorebose" | ||
| }, | ||
| "action": "query", | ||
| "result": true | ||
| }, | ||
| { | ||
| "user": "dreamyshannon", | ||
| "action": "read", | ||
| "resource": { | ||
| "type": "Document2", | ||
| "tenant": "test-tenant-modestritchie" | ||
| }, | ||
| "result": false | ||
| } | ||
| ], | ||
| "users": [ | ||
| { | ||
| "key": "angrygoodall", | ||
| "email": "[email protected]", | ||
| "firstName": "angry", | ||
| "lastName": "goodall", | ||
| "roles": [] | ||
| }, | ||
| { | ||
| "key": "dreamyshannon", | ||
| "email": "[email protected]", | ||
| "firstName": "dreamy", | ||
| "lastName": "shannon", | ||
| "roles": [] | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| Check with specific HTTP method and tenant: | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.