Policy rules
Every brokered request gets one level, from a service's rules or a floor. What the levels mean day to day: Policy and approvals.
Levels
| Level | Behaviour |
|---|---|
allow | Runs with no approval. |
ask | One approval, reused for the rule's window. |
ask-always | An approval every time. Never reused. |
deny | Refused. |
From least to most strict: allow < ask < ask-always < deny.
There are no risk scores. A rule says what an action is ("Delete repository"); its level is your decision about it.
policy.toml
A service's rules live in policy.toml next to its
service.toml.
[default] # the floor when no rule matches
read = "allow"
write = "ask"
ttl = 900 # optional window, in seconds, for an ask
[[rule]]
id = "delete-repo" # [a-z0-9][a-z0-9_-]*, unique in the file
label = "Delete repository"
method = "DELETE"
path = "/repos/:owner/:repo"
level = "ask-always"
[default] takes read, write and ttl, all optional.
[[rule]] fields:
| Field | Required | Meaning |
|---|---|---|
id | yes | Stable id. Your overrides refer to it. |
label | yes | What the action is, in words. Shown in the console and as the "Rule" on approval cards. |
label_zh | no | label in Chinese. |
method | no | An HTTP method, or a list (any one matches). Unset: any method. |
path | no | A path pattern, or a list (any one matches). Unset: any path. |
condition | no | A CEL expression over the request: "has(request.body.amount) && request.body.amount > 100". Unset: any request. |
level | yes | allow, ask, ask-always or deny. |
ttl | no | The approval window for ask, in seconds. |
consent | no | What the approval card says this request does, over request paths: "Give {{ request.body.type }} {{ request.body.role }} access to this file". The card shows the request line above it, so it doesn't read request.params. The values it reads are covered by the approval. A [requests] shape's consent takes precedence. |
consent_zh | no | consent in Chinese. Needs a consent. |
Unknown keys reject the whole file.
Method and path
A rule matches a request when its method, its path and its condition
all match.
methodis an HTTP method token, stored uppercase:"DELETE"or["PUT", "PATCH"].pathis a URL Pattern pathname starting with/.:namematches one segment; a final/*matches the rest of the path:"/repos/:owner/:repo/branches/*".:name(a|b)limits a segment to those words;{/:name}?makes a segment optional.- A path is matched without its query string and without one trailing
/. - The host is fixed by the connection.
- A rule with no
method,pathorconditionrejects the file; the level for every request is[default]. match(the 2.0"METHOD /path"with*and**) rejects the file. Writemethod = "DELETE"andpath = "/repos/:owner/:repo"instead.whenand a rule'sbodyregex (2.0) reject the file. Writecondition.
Condition
condition reads one object, request:
| Field | Value |
|---|---|
request.host | The host, lowercase, with the port unless it is 443. |
request.query | The query parameters, by name: request.query.addParents. |
request.headers | The headers as forwarded, by lowercase name: request.headers['x-account']. |
request.body | A member of the body (request.body.amount, request.body.order.price), or the body's text when the condition reads request.body itself. |
request.graphql | The calls, fields and request of a GraphQL request, on a path whose request shape says body = "graphql". |
methodandpathselect the method and the path. A condition that readsrequest.method,request.pathorrequest.paramsrejects the file, and so does one that calls a function CEL here lacks, or readsrequest.bodywhole and a member of it.- The body is read as JSON where it parses as JSON, and as a form unless its one Content-Type names another type. Both readings must agree on every value read.
- A request is refused when a value the condition reads is ambiguous: a query
parameter or header given twice, a body with a byte-order mark, JSON with a
duplicate key or with a member that differs from a read name only in case
(
Amountbesideamount). - A value the request leaves out makes the condition an error. An error
matches a
deny,ask-alwaysoraskrule where that makes the decision stricter, and leaves anallowrule unmatched. Guard a value a request may leave out:has(request.body.amount) && …, or'x-account' in request.headers && …for a namehas()can't select.sprott service validatewarns about each read with no guard. - A server may take
"false"forfalse. Compare such a value as text:string(request.body.private) == 'false'.
Limits
ttlis at most 31536000 seconds (one year). A larger value rejects the file; it is never cut down. Your own settings in the console have no cap.- A file is at most 64 KiB, with at most 128 rules and 32 method × path pairs per rule.
- A condition is at most 1024 bytes.
How a request is decided
- Rules. Of all the rules that match, the strictest level wins. Among rules at the same level, the first one decides: the service's rules in file order, then yours.
- Connection floor. No rule matched: the connection's
readorwritefloor decides. - Tag floors. Unset there: the floors of the service's tags. If several tags have one, the strictest wins.
- Global floor. Unset there too: your vault's global floor.
- Last fallback. Every floor unset:
ask-always.
GET, HEAD and OPTIONS are reads. Every other method is a write.
Servers differ in how they read a request, so it is decided on each reading and the strictest decision wins:
- the method on the request line, and the value of each of
X-HTTP-Method-Override,X-HTTP-MethodandX-Method-Override. A value that isn't exactly one method, or a header given twice, is refused. A_methodparameter is not read; on a server that takes one, gatePOSTtoo; - the path as sent, and with an encoded slash (
%2F) read as/; - for a Google batch (a
multipart/mixedbody ofapplication/httpparts), each request in it, on its own method, path, query and body, at the batch's host. A batch whose requests can't be read one by one isask-always.
Out of the box, the global floor and the ai and messaging tag floors are
allow for reads and writes. A key you add works right away, and a service's
rules tighten the actions it names.
Your overrides
On the vault's Permissions tab, per connection, you can:
- change any rule's level and window, or reset it to the service's default;
- set the connection's read and write floors ("Everything else").
Under Vault defaults you set the read and write levels by service type,
how long an approval request waits, and the default window for an ask.
Rules apply per connection, so two connections of the same service are decided separately. On a shared vault, admins edit policy; members see it.
A connection's own rules are a list. Each entry either overrides a service
rule's level and ttl by its id, or is a rule of your own with an id and
any of method, path and condition (none of them: every request). Rules at
the same level are taken in order: the service's, then yours.
Sprott refuses a rule it can't read: 2.0 syntax, a pattern or condition that
doesn't compile, an id already taken, an override with other keys. While the
connection has one, every request on it is ask-always, or deny when the
refused rule is a deny. An override of a rule the service no longer has is
refused the same way when it is deny or ask-always, and is left out
otherwise. The vault's registry (/v/<vault>/registry) lists each such rule
under its connection's rule_notes, with the reason.
Service definitions you add to a vault with sprott service add only
tighten: their allow rules and allow floors are dropped. Loosening is
your setting in the console.
Approval windows
An approval covers only the agent that asked, on that connection and host. What it lets through afterwards:
| What asked | What the approval covers |
|---|---|
ask from a rule | Later requests the same rule decides, for the rule's window, of the same kind (read or write). |
ask from a floor | Later reads (or writes) on that connection that no rule matches, for the floor's window. |
ask on a request a [requests] shape matched | Later requests covered the same way (below), for the window. |
ask-always | This one request. |
With no ttl on the rule or floor, the window is 900 seconds. A read
approval never lets a write through. When the readings that decide a request
fall under different rules or floors, or one reads and one writes, its
approval is for that one request. Locking the vault or changing it ends
every window, and a re-key of the vault ends every approval. An approval
request waits 1800 seconds for a decision.
What an approval covers
An approval covers the method, the host (with its port) and the path, and:
- with no request shape, or a shape with no
scope: the whole request. That is the query string, the headers HTTP defines for a request (content-type,content-language,content-location,content-range,if-match,if-none-match,if-modified-since,if-unmodified-since,if-range,destination,overwrite,depth,prefer), the three method-override headers, every header carrying a phantom, and the body; - with
scope = [...]: the values it lists;scope = []: nothing more;"request"in the list adds the whole request; - always: the values the deciding rules' conditions read and every value the consent shows;
- for a Google batch: the whole batch, besides what covers each deciding request in it.
A request that differs in anything covered asks again. A body is covered by
its content: a multipart body's boundary and its parts' Content-ID, a batch
part's SDK headers, and an email's Date and Message-ID are left out, so a
client that builds the same request again is let through. A one-time approval
from a service added with sprott service add always covers the whole request.
When a request misses a one-time approval made for the same request line, the
agent is told which parts differ, by name only (query, headers.if-match,
body.amount).
Request shapes
A service can say how it reads a request, and which values an approval binds
to, in service.toml:
[requests.purchase]
method = "POST"
path = "/v2/purchase"
body = "json" # json (the default), form, graphql or text
scope = ["request.body.amount", "request.body.merchant"]
consent = "Buy from {{ request.body.merchant }} for {{ request.body.amount }}"
and decide on the request in policy.toml:
[[rule]]
id = "purchase-large"
label = "Large purchase"
method = "POST"
path = "/v2/purchase"
condition = "!has(request.body.amount) || request.body.amount > 100"
level = "ask-always"
method,pathandconditionselect requests, as in a rule. The first shape in the file that selects a request reads it.bodyis the format the service reads the body in. Withgraphql, rules can readrequest.graphql.scopelists the request paths whose values an approval covers (above). Unset: the whole request.consentis the line on the approval card, over request paths, with the filtersemailandgraphql. The values it shows are covered too.encoded."<request path>"names a value that carries encoded media, with JSON Schema'scontentEncodingandcontentMediaType. A built-in service's encoded values are covered by their content.vars(2.0) rejects the file. Name each value by its request path.
Example: Google Drive
[default]
read = "allow"
write = "allow"
[[rule]]
id = "delete-file"
label = "Delete a file permanently (skips Trash) or empty the trash"
method = "DELETE"
path = "/drive/v3/files/:file"
level = "ask-always"
[[rule]]
id = "share-public"
label = "Make a file public or open to a whole domain"
method = ["POST", "PATCH"]
path = ["/drive/v3/files/:file/permissions", "/drive/v3/files/:file/permissions/:permission"]
condition = "has(request.body.type) && (request.body.type == 'anyone' || request.body.type == 'domain')"
level = "ask-always"