> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sfcompute.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Grants

> Assign roles to users and tokens

> [!NOTE]
>
> This feature is in [public preview](https://docs.sfcompute.com/preview/roadmap.md#feature-states).

A grant assigns a [role](https://docs.sfcompute.com/preview/roles.md) to a user or [token](https://docs.sfcompute.com/preview/tokens.md) within a
[workspace](https://docs.sfcompute.com/preview/workspaces.md) or across the organization.

## Granting access to a user

Grant a role directly to a user by their email.

```bash theme={null}
sf grants create \
  --workspace production \
  --user alice@acme.co \
  --role admin
```

Alice now has admin access to the `production` workspace.

As with other commands, `-w` and `SF_WORKSPACE` also set the workspace. `--org` overrides
`SF_WORKSPACE`, and can't be combined with `-w` or `--workspace`.

## Organization-wide grants

Use `--org` to grant a role across all workspaces in the organization.

```bash theme={null}
sf grants create \
  --org \
  --user alice@acme.co \
  --role admin
```

Alice now has admin access to every workspace in the organization.

## Listing grants

List all grants in the organization. With a workspace set by `-w` or `SF_WORKSPACE`, the list shows
only the grants scoped to that workspace, not organization-wide ones.

```bash theme={null}
sf grants list
```

```text theme={null}
------------------------------------------------------------------------------------------------------------------
ID                          WORKSPACE   ROLE               TYPE   PRINCIPAL                   CREATED
grnt_k3RnX9vLm7Qp2Yw5JdA4f  (Org-wide)  admin              user   alice@acme.co               Feb 4, 2025, 12:00pm
grnt_8KvQ3mWxYpRtZn6Hb2C7j  production  training-operator  user   bob@acme.co                 Feb 3, 2025, 9:30am
grnt_9QwT4xNbVs2Lm7Cfj3W5d  production  viewer             token  tokn_5DhP2nLqWmKz8XvBt4Jc6  Feb 1, 2025, 8:15am
```

Filter by workspace or by user. Unlike `sf grants create`, which accepts an email, the `--user`
filter takes a user ID.

```bash theme={null}
sf grants list --workspace production
sf grants list --user usr_7d41c2a90b5f83e6
```

## Deleting a grant

Delete a grant by its ID, which `sf grants list` prints in the first column.

```bash theme={null}
sf grants delete grnt_k3RnX9vLm7Qp2Yw5JdA4f
```

You can also delete a workspace-scoped grant by its attributes. As with `sf grants list`, `--user`
takes a user ID.

```bash theme={null}
sf grants delete \
  --workspace production \
  --user usr_3e92f8b06c14da75 \
  --role training-operator
```

Delete an organization-wide grant.

```bash theme={null}
sf grants delete \
  --org \
  --user usr_7d41c2a90b5f83e6 \
  --role admin
```

## Multiple grants

A user or token can have multiple grants. SF Compute combines the permissions from every granted
role (a union).

```bash theme={null}
sf grants create --org --user bob@acme.co --role viewer
sf grants create --workspace production --user bob@acme.co --role training-operator
```

Bob has `viewer` access organization-wide and `training-operator` access in `production`.

## Token grants

Grant roles to tokens for CI/CD pipelines and other automation.

```bash theme={null}
sf grants create \
  --workspace production \
  --token ci-deploy \
  --role training-operator
```

Alternatively, assign a role when creating the token. `sf tokens create` takes the same
`--workspace` and `--org` flags and creates 1 grant per role.

```bash theme={null}
sf tokens create --name ci-deploy --role training-operator --workspace production
```

See [Tokens](https://docs.sfcompute.com/preview/tokens.md#attaching-a-role).

## How grants interact with roles

Grants bind users or tokens to roles. Roles define which actions a user or token can perform.

When a request arrives, SF Compute collects every grant the user or token holds on the target
workspace, including organization-wide grants. It then evaluates the rules from all matched roles.
See [Roles](https://docs.sfcompute.com/preview/roles.md) for the rule effects and evaluation semantics.

## API reference

See the [Grants API](https://docs.sfcompute.com/preview/api-reference/grants/list-grants) for programmatic access.
