Skip to main content

Permissions in code

Preview

The deploy API and the Autessa CDK are in preview and not yet released. Names and shapes may change before they are generally available.

Who can see and use each resource is part of your project. Every diff shows permission changes, and marks any change that gives someone more access as WIDENS.

What you can define​

ResourceWhat it controls
RoleWhich table rows people see. Used with RowLevelSecurity, or with permissions strings like tickets_READ. Not a company role.
GrantGives an existing company role, a group, or a person access to one resource at a level.
RowLevelSecurityOn a Table: which rows each Role can read, write or delete.
App grantsWhat a hosted app's visitors may reach: tools, agents, managers and tables. See App grants.
Column masked / sensitiveOn a Table column: hide or protect the value.
ApiKeyScopeWhat API keys with this scope may reach.
FirewallPolicyA named AI Application Firewall policy.

Access levels​

LevelMeaning
VIEWSee it.
USERun it: call the tool, chat with the agent, open the app.
EDITChange it.
ADMINChange it, share it and delete it.

Levels go from narrowest to widest: VIEW, USE, EDIT, ADMIN.

Define permissions​

A grant to a company role, a grant to one person, and a row rule for a project role. agent and tickets are resources defined earlier in the project. A grant's principal is an existing company role by name, a group, or a person. A project Role only controls table rows, so it can't be a grant's principal.

from autessa.cdk import Grant, Role, RowLevelSecurity, company_role, member

Grant(project, "supportUsesAgent", principal=company_role("Support"), resource=agent, level="USE")

lead = project.variable("supportLeadEmail")
Grant(project, "leadEditsTickets", principal=member(lead), resource=tickets, level="EDIT")

emea = Role(project, "emeaAgents", name="EMEA agents")
RowLevelSecurity(project, "ticketsInRegion", table=tickets,
operations=["READ", "WRITE"],
predicate={"column": "region", "equals": "EMEA"},
roles=[emea])

Use group("name") for a group of people.

Use a variable for people. Email addresses differ between tenants, so keep them out of code.

In autessa.yaml, these go under permissions.roles, permissions.grants, permissions.rowLevelSecurity and permissions.apiKeyScopes. A grant's principal is a company role, a group or a person. Firewall policies go under the top-level firewallPolicies, each with a policy object.

App grants​

A hosted app's grants are the tools, agents, managers and tables its visitors may reach. They live in the project, next to the app's code, so a change that adds a tool to the app can grant it in the same pull request.

App(project, "Portal", dir="apps/portal", auth={"mode": "PUBLIC", "public_slug": "bills"},
grants={"tools": [pay_bill, lookup_bill], "agents": [helper],
"tables": [{"table": bills, "operations": ["READ"]}]})
  • Every deploy applies them. Autessa saves exactly these grants as the app's access. Nothing goes beyond what the deploy key's owner can reach. An unchanged set writes nothing.
  • The diff shows them. You see a line like grants of app Portal: <before> -> <after>. It is marked WIDENS when it adds anything, and not when it only removes.
  • Leave grants out and the app is left alone. Its grants stay as they are, so older projects keep working. An empty grants grants nothing.
  • Grants are explicit. An app's tools, agents and tables settings only say what its code uses. They grant nothing.
  • Checked before deploy. build and the offline checks refuse a grant to a name that isn't in the project, and grants on an app whose sign-in is COMPANY_MEMBERS. Those apps act as each signed-in member, so grants don't apply.
  • Table operations are READ, WRITE and DELETE.

In autessa.yaml, they go under each app's grants, by logical ID.

WIDENS​

diff compares each permission before and after. The server marks a change that gives someone more access than before. The CDK also marks, on its own:

  • a new grant, and
  • a level that goes up, like VIEW to EDIT.
! access Grant supportUsesAgent ROLE:support VIEW -> ROLE:support EDIT WIDENS

Narrowing changes are listed too, without the mark. The TypeScript CLI and the deploy action print WIDENS ACCESS. In CI, the deploy action posts the diff on the pull request, and each runner has a flag that fails when access widens (see Commands).

A key reaching a resource this same deploy creates isn't marked WIDENS, because nothing that exists today becomes reachable. Grants on a new resource still are, and so is a key gaining anything that already exists, including an adopted resource.

Drift​

Someone may change a permission by hand in the UI. That is drift. diff lists drifted permissions in their own section, and marks the ones that widen access.

Each stage in autessa.stages.yaml takes permissions: { drift: report } (the default) or permissions: { drift: reset }. In this preview, rely on report: review the drift in the diff, then either update your code to match or change the permission back.