When snapd asks
policy · call sites for app developers for snapd developers
Only the interface manager asks the policy questions and always inside a task - mount-snap asks about installation, connect about a manual or gadget connection, auto-connect about every candidate pair. A snap without a snap-id is treated differently at each site. Answers are not revisited when a snap-declaration or the model changes later.
On the map: policy
01 Three questions in the task graph
install? in mount-snap; auto-connect? in auto-connect and again in each injected connect; connect? in the connect task of a snap connect change. Only overlord/ifacestate asks.
You install the acme-agent on the gateway. When does snapd ask its three questions? Always from a task, and always in the interface manager. In the install change, validate-snap fetches the snap-declaration, and mount-snap asks whether the snap may be installed, before anything is mounted. Once the snap is linked, the auto-connect task asks about every candidate pair and injects a connect task for each connection it makes; that task asks again, after the prepare hooks. Later you run snap connect for network-control. That's its own change, and its connect task asks whether the pair may be connected. A hotplug-connect task asks too.
02 Which operations are judged for installation
Every new revision is judged in mount-snap against the current snap-declaration; --dangerous, snap try and unasserted --devmode get the reduced check. Reverts and snap enable are not judged.
Which operations on the gateway get judged for installation? Only those that mount a new revision. Store installs, refreshes including auto-refresh, sideloads with acknowledged assertions, seeding, and installs or refreshes in a remodel get the full check, and a refresh is judged against the snap-declaration fetched just before it. A dangerous install, snap try and a devmode sideload without assertions get a reduced check of the base declaration's slot rules. Snap revert, snap enable and component installs mount no new revision and aren't judged. A refusal fails mount-snap before anything is mounted, and a refresh keeps the old revision. The devmode and classic flags change nothing.
03 A manual connect for app developers for snapd developers
The connect task evaluates connection rules after the prepare-* hooks and the interface's own checks, and only when both snaps have snap-declarations. With a --dangerous snap on either side, no rule is evaluated.
The agent's network-control plug waits, so you run snap connect. The daemon resolves the plug and the slot. Mistype the plug name and that fails at once, with no policy involved. Otherwise you get a change. Its connect task runs after the prepare hooks, so the attributes they set count, and after the interface's own checks, whose errors can come first. Only then, and only if both snaps have a snap-declaration, are the connection rules evaluated. network-control has no connection deny, so this one goes through. With a dangerous install on either side no rule is evaluated. A refusal fails the task and undoes the change.
04 Choosing auto-connect candidates for app developers for snapd developers
Candidates must pass the auto-connection rules and the interface's own check; failures are dropped silently. With more than one candidate and any arity other than *, nothing connects and the task logs the candidates. An administrator option filters x11 too.
The acme-agent's content plug, certs, has several possible providers on the gateway. For each plug, the auto-connect task looks at every slot of the same interface in every snap. A pair that fails the auto-connection rules drops out, with no error or log. The interface's own code may refuse too. Duplicates from ubuntu-core and slots of parallel instances go next. Then arity: unless every candidate's rule says slots-per-plug: *, more than one candidate means none, and the task logs them. Otherwise each survivor gets a connect task. A dangerous install brings no snap-declaration, so the other side's or the base declaration decides.
05 Two providers, no connection for app developers for snapd developers
Default arity: two candidates, no connection, a log line. A plug rule for the consumer that restates the base constraints and adds slots-per-plug: * connects both. A second provider installed later is not connected; the existing connection stays.
Here's how that surprises people. Acme ships two certificate snaps, both with a certs slot, and both pass content's rule for the agent's plug. With the default arity of one, neither is connected, and the task log lists both. A store rule on the agent that restates the content and publisher constraints and adds slots-per-plug: * connects both. If one provider's rule says star and the other's doesn't, nothing connects. And if the second provider arrives later, its auto-connect task recomputes every candidate for the plug, finds two, and connects nothing new. The first connection stays.
06 Gadget connections for Ubuntu Core developers for snapd developers
Gadget connections: apply only before seeding completes or in a remodel. They bypass auto-connection rules and are checked against connection rules. Snaps without a snap-id are skipped. snap connections shows them with the note gadget.
On a fleet of gateways nobody will type snap connect. So the acme-gateway's gadget lists the connection, naming the agent by snap-id. Each snap's auto-connect task applies such entries, but only before the system is seeded or during a remodel. No auto-connection rule is consulted. The connect task is marked by-gadget, and judged by the connection rules instead. That's how the agent's network-control plug gets connected, although its base rule denies auto-connection. A refusal by the connection rules fails the connect task, and with it seeding or the remodel. Snaps without a snap-id take no part.
07 Declarations change, connections stay for app developers for snapd developers
New snap-declarations are only stored. Restoring connections at start and in setup-profiles runs no policy check. The next refresh is judged in mount-snap; new auto-connections wait for the next auto-connect, and connections the user disconnected stay disconnected.
Months later the store revises the acme-agent's snap-declaration. What happens on the gateway? Before every refresh, snapd fetches new declarations and stores them; nothing more. Stored connections are restored at start and in every setup-profiles task, unchecked. The rules only decide whether a refreshed snap's new static attributes are adopted. A stricter installation rule takes effect at the next refresh, which fails in mount-snap, keeping the old revision; a stricter connection rule removes nothing. A looser one adds connections at the next auto-connect of either snap, unless someone disconnected them. A remodel judges what it installs or refreshes against the new model.
08 Where to go from here
Evaluation and the overview in this district; changes, users, models, device presets, assertions and the implementation in theirs.
You've followed the acme-agent from mount-snap to a gadget connection and beyond. In this district, the overview returns to the three questions, and the evaluation deck shows what each check does once it's asked. The overlord's deck covers changes, tasks, and how a failed task undoes a change. The users' deck covers snap connect and snap connections from the command line. The model deck covers remodelling and the gadget behind gadget connections, and device presets explains why a gadget carries them. The assertions deck shows when snap-declarations are fetched, and the implementation topic shows the interface manager and its repository.
Read more
Call sites
| Where | Question | Rules | Inputs | On refusal |
|---|---|---|---|---|
mount-snap in an install, refresh, seeding or remodel | installation | installation, per plug and slot | the snap-declaration fetched by validate-snap, the base declaration, the device context of the task | the task fails before the snap is mounted; the change is undone |
connect task of a snap connect change | connection | connection | both snap-declarations, the base declaration, the device context | the task fails and the change is undone |
auto-connect task after link-snap | auto-connection | auto-connection, per candidate pair | as above | the pair is dropped without an error |
connect task injected by auto-connect (auto=true) | auto-connection, again, after the prepare-* hooks | auto-connection | as above, with the attributes the hooks set | the task ends without a connection and without a log line (suspected snapd bug, findings/review/BUGS.md #31) |
connect task with by-gadget=true | connection | connection | as above | the task fails, and with it seeding or the remodel |
hotplug-connect | auto-connection for a new hotplug slot | auto-connection | as above | the pair is dropped |
start-up and setup-profiles | none for existing connections; new static attributes after a refresh are re-checked | connection or auto-connection | the current model | the old static attributes are kept and a notice is logged |
Only overlord/ifacestate imports the policy package.
Which operations are judged for installation
| Operation | Install check |
|---|---|
snap install, snap refresh, auto-refresh | full, against the snap-declaration fetched just before |
snap ack then snap install ./file.snap | full |
| seeding | full, with assertions from the seed |
| install or refresh in a remodel | full, against the new model |
snap install --dangerous, snap try, snap install --devmode without assertions | minimal: base slot rules only |
snap revert, refresh to an installed revision, snap enable, component install, remodel relink | not judged |
Auto-connect candidates
1. Every slot of the plug's interface in every snap, including implicit system slots. 2. Pairs that fail the auto-connection rules drop out, without an error or a log line. 3. Pairs the interface's own code refuses drop out. 4. Slots of the old ubuntu-core snap are dropped when core provides the same, and slots of parallel instances are dropped. 5. Arity: unless every remaining candidate's rule says slots-per-plug: *, more than one candidate means none. The task then logs cannot auto-connect plug <snap>:<plug>, candidates found: .... 6. For x11 only, the system option interface.x11.allow-auto-connection filters the result. It is applied when the plug's snap is installed, not when a new x11 slot appears (a snapd bug). 7. Each remaining pair gets a connect task with auto=true.
When a slot's snap arrives later, its auto-connect recomputes every candidate of each plug. With two candidates and arity one nothing new connects, and an existing connection stays.
Gadget connections
- The gadget's
connections:name the plug and the slot by snap-id orsystem. Without aslot:the system slot of the plug's name is used. - They are applied only before the system is seeded, or during a remodel with the new gadget.
- No auto-connection rule is consulted. The
connecttask is markedby-gadgetand checked against the connection rules, unless either snap has no snap-declaration. - Snaps without a snap-id are skipped.
snap connectionsshows the notegadget.
After a snap-declaration changes
| Situation | Effect |
|---|---|
| New snap-declarations | fetched before every refresh and auto-refresh; stored without a task |
| Existing connections | restored at start and in every setup-profiles without a policy check |
| Stricter installation rule | the next refresh fails in mount-snap; auto-refresh fails the same way |
| Stricter connection rule | no connection is removed |
| Looser auto-connection rule | new connections at the next auto-connect of either snap |
| Auto-connection the user disconnected | stored as undesired and not brought back, unless disconnected with --forget |
| Remodel | snaps installed or refreshed in it are judged against the new model; untouched snaps are not |
Further reading
- Interface auto-connection: when snapd reviews unconnected plugs, and how a disconnect stops a later refresh from reconnecting.
- Connect interfaces:
snap connect,snap disconnectandsnap connectionsin practice. - Gadget snap format: the
connections:section. It says connections are made on first boot only; the code also applies them in a remodel. - Remodeling: what a remodel installs and refreshes.
Roads from here
INTERFACES AND CONFINEMENT
- Interfaces for users — snap connect and snap connections for users
- How interfaces are implemented — the interface manager and the repository
RUNNING SNAPS
- The overlord — changes and tasks and how a failed task undoes a change
ASSERTIONS · signed statements snapd trusts
- Assertions: snaps and validation — when snap-declarations are fetched and refreshed
POLICY · who may install and connect what
- Interface policy: the questions snapd asks — back to the three questions
- How a rule is evaluated — what happens inside each check
UBUNTU CORE · install and recovery
- Model, gadget and kernel — remodel and the gadget behind gadget connections
- A device set up before anyone logs in — connections a gadget makes at install