Permissions, walked
This page shows the permissions model by example, in the order you meet it. The model itself is perms.md: one owner for each node, grants on the records, and one check on every write and read. The detail is in reference/perms.md.
Most of what you own in a viff instance, you never wrote by hand: a task record that the runtime mirrored, a question that a rule posed, a branch that an iod reflected. The permissions on those things follow from who asked for the work, not from who typed. This surprises people, so the page walks it in five steps:
- your own data;
- a task you run, and its gates;
- a charter, and what it owns;
- a gate with no resolver behind it;
- a gate with a resolver behind it.
Before the first step: who you are
Every request that the CLI makes carries a principal: a name. Viff checks every write and read against what its place permits for that name. So first, settle what the name is.
The CLI reads its config in layers (reference/up.md). Each layer is patched over the one before:
/etc/viff.tony;~/.config/viff.tony;- the environment;
- the flag on the command.
user: in the file is who every command acts as:
# ~/.config/viff.tony addr: "localhost:9797" user: "you@example.com"
| Setting | What it overrides |
|---|---|
VIFF_USER in the environment |
the file, for one shell |
-as |
both, on the commands that take it. Use it to act as somebody else for one command and see what they see. |
VIFF_CONFIG=<file> |
both file layers, outright. So a second viff instance gets a second file, and not a second identity in one file. |
With no user anywhere, who the CLI acts as depends on where the viff instance is:
- A viff instance on this machine (
localhost,127.0.0.1,::1): the CLI acts as the local user,user:<login>@localhost.<login>is your login name. This is who you are in the tutorial before you configure anything. - Any other viff instance: the request names nobody. It reads what
*may read, and it writes nothing. Viff refuses every request that is not a read with400 Viff-Principal is required, because a write by nobody would be recorded as the system’s.
The server refuses a write that names nobody, wherever it comes from. The local user is only the CLI’s default. So a program of your own that writes must name somebody itself.
viff data spaces you notes -put '{todo: [buy milk]}' viff perms spaces you notes | grep owner # owner: user:you@example.com VIFF_USER=ana@example.com viff perms spaces you notes | grep owner # the same record, read as ana
A name carries its kind before the colon. A request presents one of three kinds:
| Kind | Who | How it is set |
|---|---|---|
user:you@example.com |
a person | user: or -as. A bare email is read as this kind. |
agent:<name> |
a harness that drives viff from outside | agent: in its config, instead of user: |
runner:<identity> |
a worker | it claims work as -as runner:<identity>. A runner reached by url acts as the identity its registration names. |
Viff refuses a bare word such as -as viff-runner, and the refusal gives the grammar.
reference/perms.md has the whole grammar. The name is
self-asserted: everything below is about what a name may do,
not about who holds it.
You are also somebody in Slack and on GitHub. When you answer a viff question in a Slack thread or in a pull request comment, the iod that heard you asks viff to count the answer as yours. Viff does that only through an account binding: a record that says this Slack member, or this GitHub login, is this principal. You make the binding yourself, once for each system, by proving to the app that you are the viff user:
viff account -link slack # prints: /viff link <nonce> viff account -link github -account your-login viff account # the bindings that are you
Say the line it prints from your own account. For Slack, say /viff link <nonce> to the app,
and the Slack iod reports that your account said it. For GitHub, say it in a comment on any
issue or pull request in a repository viff reflects; the command lists them, and waits until
viff has read your comment. Either way, viff binds the account to you. From then on, your replies there
count as you. The ballot records that you answered through Slack or GitHub, and through which
iod. Nobody but you can make the binding: a nonce said by anyone else binds nothing.
A viff instance can verify a person instead of taking their word. Where its config names an
identity provider, viff account login logs you in there. The CLI then sends the token it got
in place of a name. Viff checks the token, and acts as the person it proves. viff whoami
says how viff knows you: the provider’s name, or asserted for a name it took as given. -as,
and agent: in the config, still send a bare name. A viff instance with mode: required refuses a
person who carries no token, with 401 and a line that says to log in. People are verified, and
so are the deployment’s own iods, which present their own tokens, and a runner whose
registration names the subject of its token, which every registration does. An agent is not
verified: it is whoever it says it is.
Who a request is from has the rules.
Two things to know before the first step. Each is a reasonable guess, and wrong:
- A group is not a principal.
group:<name>is a grantee. It appears on a grant line, in a gate’sanswerers, or behind a resolver. It admits the group’s members, and each member acts as themselves. Nothing ever acts as a group. No request can present a group, and a group owns nothing. - The
agentkind exists, and grants treat it as a person. A harness that drives viff from outside can present itself as an agent (agent:in the CLI’s config). Viff lists it under its own kind, and grants it exactly what a person is granted. So read[user:*, agent:*]as “people”.
Step 1: your own data, and who wrote it
With user: set, everything you type is yours. The data that
the tutorial seeds is a good place to start. So is an address of your own:
viff data spaces you notes -put '{todo: [buy milk]}' viff perms spaces you notes
at: spaces.you.notes grants: - read: ["*"] owner: user:you@example.com
spaces.you.notes is yours because you created it, and it holds out the root’s
child-grants, read: ["*"] (perms.md).
Viff refuses the write of another user, and says why:
VIFF_USER=ana@example.com viff data spaces you notes -put '{todo: []}'
→ 403 refused: user:ana@example.com holds read at spaces.you.notes and writing it needs
read-write; the nearest owner on record is user:you@example.com at spaces.you.notes
A refusal always says the three things that perms.md lists. The last is the record that decided. When viff refuses something you expected to pass, read that record.
Take a place. viff perms on a node you may create under gives the node a record of its
own. What you set there governs what is made beneath it
(where a place can be taken).
viff perms spaces you -child-grants '{}' -grants '[]' # nothing held out beneath, nothing on it viff data spaces you private -put '{…}' # yours alone: no read for anyone viff perms spaces you -grant '{read: [ana@example.com]}' viff perms spaces you -revoke '{read: [ana@example.com]}'
reference/perms.md lists the flags.
A withdrawn grant stops future acts. It changes nothing that exists.
The store also knows who wrote every commit. How it keeps the author is in perms.md, in the repository.
What is not yours to write. Viff refuses viff data -put under mirror., whatever you
hold. You write there through the verbs that own it: viff c -a, viff task run,
viff question approve, viff perms. Under each verb, the store checks the write against its
place. So nothing that reaches the store can make a task or answer a question for you.
Viff refuses viff data mirror perms too. A person reads records with viff perms, never
from the mirror (perms.md).
Step 2: a task you run, and what it may do for its gates
A task is data that the runtime mirrors. The mirror writes the task as whoever asked for it:
viff task run -f check.tony # a spawn: prompt, subject, environment, autonomy viff perms mirror task instance <id>
The task is yours. The record beneath mirror.task.instance names you as owner for two reasons:
- the seed holds
child-ownerout to everyone there; - the spawn wrote as you.
Viff writes the task’s record as whoever runs it, and that write is the check for run
(levels). The task’s run and claim records follow it. Everyone
may read the task, by the default it was created with. Only you and the runtime write it.
The runner that works the task holds the task and nothing else. A runner reached by url
acts as runner: with the identity its registration names, and that is the claim. What the
task does on viff itself, through the viff system, the runner carries as
the task’s owner, only while the task runs
(a task carried by its runner).
When a worker claims the task, viff grants it read-write and control on the task and on
this run. Every report after that is written as the worker. That grant stops at the task’s
record.
A question that the task raises is an ask, at its own address,
mirror.ask.<id>. A grant on the task does not reach the ask. So the worker may not answer its
own question (perms.md).
What you may say about its questions. Two things, and they answer different questions:
-
The spawn’s
autonomyis which of its steps are refused, asked about or allowed, and what each question takes to settle. It is a list of rows: amatchover a step’s system, verb and params, and athen. For an ask, thethencarriesneed,within,default,answerersandlabels(a row’s question).tony # check.tony prompt: check that the migration in app/db applies to an empty database subject: demo.pr.1 environment: systems: network: {mode: open} git: [{repo: acme/app, fetch: {}}] commands: {} autonomy: - name: shell match: {system: commands, verb: run} then: {ask: {need: 1, within: "4h", default: deny, answerers: [ana@example.com]}} - then: allow
answerersis who may answer. When the question is posed,answerersbecomes the question’sread-writeline, in place of the docket’s default. Leave it off, and the default stands. In the seed, the default is[user:*, agent:*]: any person. -
-as <who>is who the run is. So it is who owns the run, and who co-owns what the run asks.
What the task may do in the world is a different question: push, open a pull request, call a
sub-agent, reach a host. The spawn’s environment says that, system by system, fixed when it
starts, and the runner refuses a launch whose environment goes past what it offers
(who does the work, and with what). A permissions grant says who may touch
data. A task’s environment says what the task may do, and its autonomy what it does unasked.
Answering. You answer your task’s questions as their co-owner, and so does whoever the line names. Viff refuses the runner (perms.md).
Try it as somebody else, and read the refusal:
VIFF_USER=x@example.com viff question <id> --answer proceed → 403 refused: user:x@example.com holds read at mirror.ask."<id>" and answering it needs read-write; the nearest owner on record is system:docket at mirror.ask."<id>"
x holds read, because the docket’s default gives every question read: ["*"]. x does
not hold read-write, because x is not on the line.
A worker may meet something that the task cannot decide. It asks with question-ask, and may
say whom (a question for the person).
Step 3: a charter, and what it owns
A rule acts as whoever installed its charter. So the installer co-owns every question that its rules pose, and may answer them without being named on any line.
perms.md states the rule, and reference/perms.md has the detail. How this step looks on a deployed viff is in platform/perms.md, in the repository.
Step 4: a gate with nobody behind it
A charter gate raises the same record as a task’s question: an ask, at mirror.ask.<id>.
viff perms mirror ask <id> shows who may see it, who may answer it, and who owns it. If the
gate names no answerers:, whoever may write what the question is about may answer, and whoever
may read it sees it. The answerers a gate names must be able to read what it is about, or the
gate is refused when it fires.
- To narrow the questions posed later, name
answererson the gate in the charter, and install the charter again. The install refuses a gate that nobody could settle. - To narrow a question that stands, write its record with
viff perms. You co-own it through the rule. - To bring somebody else in, ask them: an ask of your own, about the same thing.
reference/perms.md has the rules. How this step looks on a deployed viff is in platform/perms.md, in the repository.
Step 5: a resolver that answers for somebody
A resolver is an installed service that answers asks for whoever
grants it (resolvers). It owns nothing, and nothing is moved to it. A
party lets it answer for them with an answer grant, and may still answer for themselves.
viff resolver add - <<'EOF' name: ben-desk match: {about: "viff-dev.merge.train.*"} method: {driver: service} EOF VIFF_USER=ben@example.com viff resolver grant ben-desk
Ben makes the grant, so VIFF_USER names him for that one command. The grant is Ben’s, at
viff.for.user:ben@example.com. From then on, ben-desk serves an ask put to Ben about a
merge train. It may read the ask (answering: on the ask’s read). Its answer, made as the
resolver, is Ben’s ballot, with via naming the resolver. For the asks about a place that name
nobody, the place’s owner on record grants at the place. Two resolvers never answer for one
party on one ask: viff refuses a grant that would let them.
What a service holds. A resolver’s service acts as whoever installed it (platform/perms.md, in the repository).
Groups, here and on a gate. A group is a named set of grantees, and
group:<name> is how anything names it:
viff group add release you@example.com group:qa 'runner:*' # stored at mirror.principal.group.release
A member is any grantee, another group included.
viff group add refuses a member it cannot read, such as a group’s address or a bare word,
and prints the grammar. Only the group’s maker changes it. How viff reads the members when it
checks a grant is in perms.md.
A gate’s answerers: [group:release] puts its question to the group’s members, each answering
as themselves, or through a resolver they grant.
What to check when something surprises you
- A refusal names the record that decided. Read it with
viff perms <path>. If you may not read it, you are outside the node’sread, and that is the first fact. - A question is not under its task. It is an ask: look at
mirror.ask.<id>, not at the task. Viff refuses the runner there on purpose. - A rule acts as its installer. A firing that viff refuses, or a rule that never wakes, is usually the installer’s own grants, seen through the rule.
viff statuscounts.perms: {refused, unreadable, hidden, unparsed}is the check’s count since the process started. reference/perms.md says what each field counts.