Conditions and policies
Write conditions for denies and policies, permit or forbid access account-wide, and grant access for a limited time.
Conditions and policies
Conditions decide when a deny or a policy applies. They use a subset of CEL. The editor checks a condition as you type and completes the names it can read.
What a condition can read
| Value | Type | Notes |
|---|---|---|
request.time | timestamp | When the request is decided |
request.permission | string | The permission being decided, such as table.read |
request.ip | string | The client address. Absent on work Logship does itself; guard with has() |
request.authMethod | string | How the caller authenticated; values below. Absent on work Logship does itself; guard with has() |
request.tokenId | guid | The ID of the token used. Absent on work Logship does itself; guard with has() |
resource.<attribute> | The attributes on the resource's page, such as a table's Name (access reference) | |
principal.<attribute> | The caller's attributes, such as IsDisabled |
request.authMethod | Credential |
|---|---|
interactive | A sign-in session (password, certificate or identity provider) |
oauth | An external OAuth bearer token |
api_token | A personal access token |
inflow_token | An inflow token |
agent_token | An agent's token |
service_account_token | A service account token |
evaluator | An alert run |
Custom roles, policies and grant exceptions cannot read self-asserted attributes, such as a user's email or an agent's host name. Attributes set by a resource's editors, such as a dashboard's name, can be read but can be changed by those editors; prefer table names, resource types and relationships (conditions).
Language
- Operators:
==,!=,<,<=,>,>=,in,&&,||,!,? :,+,-,*,/,%, lists[...]. has(x.y): whether an optional value is present.- Strings:
startsWith,endsWith,contains,lowerAscii,upperAscii,size. - Conversions:
int,double,string,bool,timestamp("2030-01-01T00:00:00Z"),duration("8h"). - Time:
getHours,getMinutes,getDayOfWeek,getDayOfMonth,getMonth,getFullYearand others, with an optional time zone:request.time.getHours("Europe/Berlin"). - Addresses:
inIpRange(request.ip, "10.0.0.0/8").
Not supported: map literals (use a list and in), byte literals and matches() (use startsWith, endsWith or contains). A condition is at most 4,096 characters, nests at most 32 levels and has at most 512 terms. A condition that
cannot be evaluated, such as one reading an absent value, denies.
Policies
A policy applies to every matching request in the account, whoever holds what. Managing policies needs account.manage_policies (Policy administrator). An account holds at most 500 policies.
- Forbid blocks its permissions unless its condition is false, over any role, relationship or permit: a condition
that cannot be evaluated, or reads a value that is not set, blocks as if it held. Guard every optional value with
has(). - Permit allows its permissions when its condition holds, to principals that already hold the permission named under Requires.
Open Settings → Account → Policies, select New policy, and fill in Effect, Permissions, Applies to
principals (none ticked applies to all), Requires (permit only), Scope and Condition. Set a Scope to
read the resource's attributes when the permissions span several types. Use the Test tab to explain a decision as
if the draft were saved, then select Create policy. Policies cannot name manage_access, manage_roles or manage_policies.
Example: forbid destructive changes from API tokens
| Field | Value |
|---|---|
| Effect | Forbid |
| Permissions | table.drop, table.alter, table.alter_retention |
| Scope | Table |
| Condition | has(request.authMethod) && request.authMethod in ["api_token", "service_account_token"] |
Tables can then be dropped or changed only from a sign-in session.
Example: permit everyone to read shared tables
| Field | Value |
|---|---|
| Effect | Permit |
| Permissions | table.read |
| Applies to principals | User |
| Requires | account.query |
| Scope | Table |
| Condition | resource.Name.startsWith("shared.") |
Every user who can query the account reads tables whose names start with shared., without a grant on each.
Time-bound grants
Grants and dashboard viewers can be limited in time without writing a condition. In the Grant access dialog, set Condition to:
- Until a date: the grant holds until Expires at (local time).
- During a time window: the grant holds from Starts at until Ends at (local time).
An expired grant grants nothing and shows Expired in the grants list, with Extend to give it a new end. Expired grants are removed 366 days after they expire.
Example: give an on-call engineer Incident editor on the account During a time window covering their shift.