# Access control

`shako access` shows and changes who can do what in a tenant, as Account › Permissions in the workspace.

## Roles

- **Owner**: all. Only the owner adds credit, gets invoices, invites and removes members, gives a VM access, makes API
  keys and deletes the tenant. A tenant has one owner: the account that made it.
- **Contributor**: the VMs, ports, devices, secrets, agent memory, sessions and screens; it reads the credit and the
  usage. It can take a VM's access away, and leave the tenant.
- **None**: a VM with no access. It runs no `shako` commands and no SSH to other VMs. SSH into it and its URLs still
  work.

## Who has a role

- **Account**: a person. Your SSH keys (`shako login`, `shako key add`) and your web login prove it, in each of your
  tenants.
- **VM**: its own key, `vm-<vm>` in `shako key ls`, proves the VM, not you. Each program in the VM acts only in the
  VM's tenant, with the VM's role. `shako key rm vm-<vm>` gives the VM the role none.
- **API key**: a program outside Shako, with its role on the key (https://shako.dev/api.md,
  `shako api-key ls`). No key gives or takes access.

## Commands

```sh
# TENANT ROLE KIND NAME, for each of your tenants
shako access ls
shako access grant member bob@example.com --role contributor --tenant acme
shako access revoke member bob@example.com --tenant acme
# leave
shako access revoke member you@example.com --tenant acme
shako access grant vm agent1 --role contributor
shako access revoke vm agent1
```

- `grant` needs `--role contributor`. The role owner cannot be given yet.
- `--tenant` is necessary with more than one tenant. In a VM, the default is its tenant.
- The invited account must have logged in once. It accepts with the link in the email.
- A revoked member's devices stop working in the tenant, and the VMs that it made there get the role none.
- Only the owner grants and removes others. A contributor revokes a VM, or leaves.
- A VM change is at once. The account that grants becomes the VM's maker.
- An untrusted agent: `shako vm create agent1 --role none` has no access from its first second. `shako vm cp` keeps
  the source's role.

## Access denied

Each refusal gives the reason, then `See shako access ls, https://shako.dev/docs/access-control.md`.

| Error starts with | What to do |
|---|---|
| `this key is off: its VM <vm> has the role none` | The owner runs `shako access grant vm <vm> --role contributor`. |
| `only the owner of <tenant> can run` | Ask the owner (`shako access ls`). |
| `a VM key cannot`, `an API key cannot` | Use your computer or the workspace. |
| `API key <name> needs the role owner` | Use a key with `--role owner`. |
| `no tenant '<tenant>'` | You have no role there. Ask its owner for an invite. |

## Related

- https://shako.dev/cli.md
