-
Notifications
You must be signed in to change notification settings - Fork 93
chore: improvements in TBAC docs #1224
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,9 +17,9 @@ import { | |||||
|
|
||||||
| <DocumentationNotice /> | ||||||
|
|
||||||
| Agents need credentials to interact with APIs. These can be user or service credentials, for internal or third-party systems. In most cases, those permissions grant agents broad access to the system, as the authorization services that issue credentials for those APIs do not support granting fine-grained permissions. Consent prompts and service credentials are too coarse. | ||||||
| Agents need credentials to interact with APIs. These can be user or service credentials, for internal or third-party systems. In most cases, these credentials grant agents broad access because the underlying authorization systems do not support fine-grained permissions. Consent prompts and service credentials are too coarse for agent use cases. | ||||||
|
|
||||||
| Task-Based Authorization grants agents access to perform specific actions only when necessary, without permanent permissions. Agents start with zero permissions and receive only what a given task requires. For example, rather than allowing an agent to create tickets across all projects, you authorize it to "Create a ticket on project X" — scoping permissions to a specific context. | ||||||
| Task-Based Authorization grants agents access to perform specific actions only when necessary, without permanent permissions. Agents start with no permissions and receive only what a given task requires. For example, rather than allowing an agent to create tickets across all projects, you authorize it to "create a ticket in project X" — scoping permissions to a specific context. | ||||||
|
|
||||||
| This guide shows how to model task-based authorization in <ProductName format={ProductNameFormat.ShortForm}/>, progressing from a basic tool-calling model to patterns that support permission hierarchies, session scoping, expiration, and agent binding. | ||||||
|
|
||||||
|
|
@@ -43,7 +43,7 @@ type tool_resource | |||||
| define can_call: [task] or can_call from tool | ||||||
| ``` | ||||||
|
|
||||||
| A `tool` represents a capability (e.g. `slack_send_message`), and a `tool_resource` represents a specific target within that tool (e.g. a Slack channel). Granting `can_call` on a `tool` automatically grants access to all its resources. You can also grant access to individual resources, or use `task:*` to allow any task to call a tool. | ||||||
| A `tool` represents a capability (e.g., `slack_send_message`), and a `tool_resource` represents a specific target within that tool (e.g., a Slack channel). Granting `can_call` on a `tool` automatically grants access to all of its resources. You can also grant access to individual resources, or use `task:*` to allow any task to call a tool. | ||||||
|
|
||||||
| For example, you can grant `task:1` access to send any Slack message, while restricting `task:2` to a specific channel: | ||||||
|
|
||||||
|
|
@@ -85,7 +85,7 @@ When checking whether `task:2` can call `tool_resource:slack_send_message/XGA14F | |||||
|
|
||||||
| ## Domain-specific models | ||||||
|
|
||||||
| The model above is generic. If you are building agents for your own application, the authorization model should reflect your application's domain. Consider a project management system: | ||||||
| The model above is generic. If you are building agents for your own application, your authorization model should reflect your domain. Consider a project management system: | ||||||
|
|
||||||
| ```dsl.openfga | ||||||
| model | ||||||
|
|
@@ -133,11 +133,13 @@ type ticket | |||||
| define can_read: read or write or can_read from project | ||||||
| ``` | ||||||
|
|
||||||
| Here we enrich an existing user-oriented model by adding `task` as a principal. Granting a `task` the `write` relation on a project gives it permission to read/edit the project and all its tickets. You can also grant permissions at the ticket level for more granular control. This makes your application ready for agent authorization with minimal changes to your existing model. | ||||||
| This enriches an existing user-oriented model by adding `task` as a principal. Granting a `task` the `write` relation on a project gives it permission to read and edit the project and all its tickets. You can also grant permissions at the ticket level for more granular control. This makes your application ready for agent authorization with minimal changes to your existing model. | ||||||
|
|
||||||
| If you follow this approach, your application needs to perform both user and task authorization. This means two separate checks: one to verify the user has access to a resource, and another to verify the task has permission to perform the action on behalf of the agent, as described in [Binding agents to tasks](#binding-agents-to-tasks). | ||||||
|
|
||||||
| ## Scoping permissions to sessions and agents | ||||||
|
|
||||||
| In interactive agents, users may create multiple sessions. You can scope permissions to a session so that granting access applies to all tasks within it. You can also scope permissions to an agent, so they persist across sessions. | ||||||
| In interactive scenarios, users may create multiple sessions. You can scope permissions to a session so that access applies to all tasks within it. You can also scope permissions to an agent so they persist across sessions. | ||||||
|
|
||||||
| ```dsl.openfga | ||||||
| model | ||||||
|
|
@@ -182,9 +184,9 @@ tuples: | |||||
| object: tool:slack_send_message | ||||||
| ``` | ||||||
|
|
||||||
| ## Expiration and turn count | ||||||
| ## Expiration and call count | ||||||
|
|
||||||
| You can use <ProductName format={ProductNameFormat.ShortForm}/> [conditions](../../configuration-language.mdx#conditional-relationships) to make permissions expire after a duration or a number of agent turns. | ||||||
| You can use <ProductName format={ProductNameFormat.ShortForm}/> [conditions](../../configuration-language.mdx#conditional-relationships) to make permissions expire after a duration, or limit how many times the tool can be called. | ||||||
|
|
||||||
| ```dsl.openfga | ||||||
| model | ||||||
|
|
@@ -194,18 +196,18 @@ type task | |||||
|
|
||||||
| type tool | ||||||
| relations | ||||||
| define can_call: [task, task with expiration, task with turn_count] | ||||||
| define can_call: [task, task with expiration, task with max_call_count] | ||||||
|
|
||||||
| condition expiration(grant_time: timestamp, grant_duration: duration, current_time: timestamp) { | ||||||
| current_time < grant_time + grant_duration | ||||||
| } | ||||||
|
|
||||||
| condition turn_count(turns_granted: int, current_turn: int) { | ||||||
| current_turn <= turns_granted | ||||||
| condition max_call_count(max_tool_calls: int, current_tool_count: int) { | ||||||
| current_tool_count < max_tool_calls | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| The `expiration` condition grants access for a fixed duration from the grant time. The `turn_count` condition grants access for a fixed number of agent turns. When writing the tuple, you provide the condition parameters: | ||||||
| The `expiration` condition grants access for a fixed duration from the grant time. The `max_call_count` condition limits how many times the tool can be called. When writing the tuple, you provide the condition parameters: | ||||||
|
||||||
| The `expiration` condition grants access for a fixed duration from the grant time. The `max_call_count` condition limits how many times the tool can be called. When writing the tuple, you provide the condition parameters: | |
| The `expiration` condition grants access for a fixed duration from the grant time. The `max_call_count` condition limits how many times the tool can be called. In `max_call_count`, `current_tool_count` means the number of successful calls already made before the current authorization check. For example, pass `current_tool_count: 0` for the first call attempt, `1` for the second, and increment it only after a successful call. When writing the tuple, you provide the static condition parameters such as `grant_time`, `grant_duration`, and `max_tool_calls`; dynamic values such as `current_time` and `current_tool_count` are supplied in the check context: |
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.
The link to “Binding agents to tasks” doesn’t currently describe the “two separate checks” (user authorization vs task authorization). Consider either expanding that section to cover the dual-check flow, or updating this sentence to link to a section that actually explains those checks (or remove the cross-reference).