Interface policy: the questions snapd asks
policy overview for app developers for Ubuntu Core developers for snapd developers
snapd asks three policy questions about interfaces - may a snap be installed with its plugs and slots, may a plug be connected to a slot, and should it be connected automatically. One rule answers each, taken from the store's snap-declaration if it has one for that interface or else from the base declaration built into snapd. Only the interface manager asks, inside the tasks of a change.
On the map: policy
01 Three questions, two layers
Install, connect and auto-connect are three separate questions. One rule answers each: the snap-declaration's rule for that interface if the store issued one, otherwise the base declaration's. Only the interface manager asks, from the tasks of a change.
You've put the photo editor in the store. It plugs network, home and camera. Network connects by itself; camera waits for you to say yes. Who decides? Snapd asks three questions: may the snap be installed with these plugs and slots, may a plug be connected to a slot, and should that happen automatically? One rule answers each. It comes from the photo editor's snap-declaration, if the store put a rule there, and otherwise from the base declaration built into snapd. The answer is allowed, denied or not allowed, and only the interface manager asks, inside a change.
02 Where the two layers come from
The base declaration is assembled from every interface when snapd starts, and only a new snapd changes it. The snap-declaration comes with the snap and is fetched again before each refresh. A store rule replaces the base rule for that interface; nothing is merged.
So where do those two layers live? The base declaration isn't a file you can edit. Each of snapd's two hundred and twenty two interfaces carries its own rule text, and when snapd starts it joins them all into one built-in assertion. snap debug base-declaration prints it. The store can't replace it, so it changes only when snapd does. The photo editor's snap-declaration is the store's part. It's signed for that one snap, fetched with the snap, and fetched again before every refresh. If it has a rule for camera, that rule replaces the base rule for camera, for this snap, whole. Nothing is merged.
03 What each answer looks like
Install and connect refusals fail the change with installation not allowed by ... or connection denied by .... An auto-connection that is not allowed leaves the plug disconnected without an error. No message names the constraint that failed.
What does a no look like from your side? Say a build of the photo editor adds a snapd-control plug. Its mount-snap task fails and the change is undone: the snap stays absent, or at its old revision. A refused snap connect is accepted at first; then its connect task fails and no connection is made. A refused auto-connection isn't an error at all. Camera just stays disconnected; at most, the task log mentions it. Denied means a deny rule matched; not allowed means no allow rule did. The message names the rule, the side and the interface, but not the constraint that failed.
04 Predicting what happens to your snap for app developers for Ubuntu Core developers
The base rule predicts the three answers: network auto-connects, camera is manual, home is manual on Ubuntu Core, content auto-connects only within one publisher, and snapd-control needs a store rule to install. A store rule replaces the whole base rule.
Before you upload, read the base rule of each interface the photo editor plugs; it predicts all three answers. Network installs and auto-connects everywhere. Camera installs and connects, but waits for snap connect. Home auto-connects on classic and not on Ubuntu Core, and a plug with read: all needs a store rule even to connect. Content connects when the content tags match, and auto-connects only within one publisher, to a single provider. A snapd-control plug wouldn't even install from the store. If you ask the store for more, remember that its rule replaces the whole base rule, and anything it leaves out is allowed.
05 A store snap and a local build
With --dangerous: the install check covers slots only, snap connect evaluates no rule if either side has no snap-declaration, auto-connect follows the other side's store rule or the base declaration but publisher constraints never match, and gadget connections are skipped.
You're testing your own build of the photo editor, installed with --dangerous. With no snap-id it has no snap-declaration, and each question changes. The install check looks only at its slots, against the base rule's snap types and whether this is classic or Ubuntu Core. Plugs aren't checked, so even a snapd-control plug installs. Snap connect evaluates no rule when either snap lacks a snap-declaration. For auto-connect there's no publisher to compare, so the content plug won't auto-connect to your own plugin pack. Gadget connections skip the snap. Snap try and an unasserted devmode sideload are treated the same.
06 Answers are kept, not revisited
Existing connections are not re-judged when a snap-declaration changes; the rules only decide whether new attribute values from a refresh are adopted. The next refresh to a new revision is checked against the new declaration; a revert is not. A newly allowed auto-connection is made at the next install, refresh or revert of either snap, unless the user disconnected it.
Snapd answers a policy question once. Say the store later issues a stricter snap-declaration for the photo editor. Snapd fetches it before the next refresh and stores it. Existing connections are restored at every start and setup-profiles without a policy check, except to decide whether a refresh's new attribute values are adopted. A stricter installation rule applies at the next refresh to a new revision: if the install check refuses it, revision 42 stays. A stricter connection rule removes no connection, and a revert isn't checked again. A newly allowed auto-connection appears at the next install, refresh or revert of either snap, unless you disconnected it.
07 Where to go from here
Roads: the base declaration, snap-declaration rules, evaluation and when snapd asks; next door, the implementation, the interfaces overview, assertions and interface classes.
Three questions, two layers, and answers that stay put. Four decks in this district take each piece apart. The base declaration shows the rule every interface starts with and the shapes those rules take. The snap-declaration rules deck covers what the store can grant one snap, and its constraints. How a rule is evaluated follows one question from candidate to answer. When snapd asks places each question in the tasks of a change. Next door, the implementation deck shows the policy package in code, the interfaces overview introduces plugs and slots, the assertions deck explains how a snap-declaration is trusted, and interface classes says what super-privileged means.
Read more
The three questions
| Question | Asked in | Sub-rules read | A refusal shows as |
|---|---|---|---|
| May the snap be installed with its plugs and slots? | mount-snap, before the snap is mounted | deny-installation, then allow-installation, per plug and slot | the change fails: installation denied by ... or installation not allowed by ...; the snap stays absent or at its old revision |
| May this plug be connected to this slot? | the connect task of a snap connect change, and gadget connections | deny-connection, then allow-connection | the connect task fails: connection denied by ... or connection not allowed by ... |
| Should this pair be connected automatically? | the auto-connect task of an install, refresh or revert, again in each injected connect task, and hotplug-connect | deny-auto-connection, then allow-auto-connection | nothing: the plug stays disconnected; the task log names the candidates only when several were found and none was used |
Only the interface manager asks these questions, always from a task. The answer is allowed, denied (a deny sub-rule matched) or not allowed (no allow sub-rule matched). No message names the constraint that failed.
Which rule answers
| Question | Rules looked up, first found decides |
|---|---|
| installation of a plug | the snap's own snap-declaration plug rule, then the base plug rule; with neither, allowed |
| installation of a slot | the snap's own snap-declaration slot rule, then the base slot rule; with neither, allowed |
| connection and auto-connection | the plug snap's snap-declaration plug rule, the slot snap's snap-declaration slot rule, the base plug rule, the base slot rule; with none, allowed |
A store rule replaces the base rule for that interface on that side, whole. Sub-rules it does not state take the defaults: an absent allow-* is true and an absent deny-* is false.
Error messages
| Form | Meaning |
|---|---|
installation denied by "<name>" plug rule of interface "<iface>" (or slot rule) | a deny-installation alternative matched for the plug or slot named |
installation not allowed by "<name>" slot rule of interface "<iface>" (or plug rule) | no allow-installation alternative matched |
connection denied by plug rule of interface "<iface>" (or slot rule; not allowed likewise) | a deny-connection alternative matched |
auto-connection not allowed by ..., auto-connection denied by ... | not shown; the pair is dropped |
suffix for "<snap>" snap | the rule came from that snap's snap-declaration |
A store snap and a local build
| From the store | --dangerous, snap try, unasserted --devmode | |
|---|---|---|
| snap-id, snap-declaration | yes | no |
| Install check | every plug and slot, store rule or base rule | slots only, the base allow-installation only, and only its snap type, on-classic and on-core-desktop constraints |
snap connect | the rule in force | no rule evaluated if either snap has no snap-declaration |
| Auto-connect | the rule in force | the other snap's store rule or the base declaration; publisher constraints never match |
| Gadget connections | applied at seeding or in a remodel | skipped |
The --devmode and --classic flags do not change any of the questions.
When a snap-declaration changes later
| Situation | Effect |
|---|---|
| New snap-declaration fetched | before every refresh and auto-refresh; stored, nothing else happens |
| Existing connections | restored at every start and in every setup-profiles without a policy check |
| Stricter installation rule | the next refresh to a new revision fails in mount-snap; the old revision stays |
| Stricter connection or auto-connection rule | no existing connection is removed |
snap revert | not checked again |
| Newly allowed auto-connection | made at the next install, refresh or revert of either snap, unless the user disconnected it |
Further reading
- Interface auto-connection: the lookup order and the "exactly one candidate" rule as the docs describe them.
- Super-privileged interfaces: which interfaces need store approval before a snap that plugs them can be installed.
- Process for aliases, auto-connections and tracks: how a publisher asks the store for a rule, and the criteria reviewers apply.
- Connect interfaces:
snap connect,snap disconnectandsnap connectionsfrom the command line. - snap-declaration: the assertion that carries the store's rules.
Roads from here
INTERFACES AND CONFINEMENT
- How interfaces are implemented — the policy package beside the repository and the backends
- Interfaces — back to the interfaces overview
- Interfaces by classification — super-privileged and the other interface classes
ASSERTIONS · signed statements snapd trusts
- Assertions: how they work — how snapd trusts the snap-declaration assertion
POLICY · who may install and connect what
- The base declaration — the built-in rule every interface starts with
- Snap-declaration rules — the per-snap rules the store issues
- How a rule is evaluated — how the one rule is found and evaluated
- When snapd asks — where in a change each question is asked