snapd

overview for everyone

snapd is the daemon that installs, runs and confines snaps; one snap install passes through most districts of this map, and the rest serve Ubuntu Core, the desktop, developers and administrators.

On the map: the whole city

▶ Watch this deck — 4 scenes, ~3 min

01 What snapd is

OVERVIEW snapd $ snap install photo-editor local socketsnapd ask the storedownloadcheck assertions mount read-onlyset up profilesconnect plugs each step is a task recorded in snapd's state: after a restart, snapd carries on $ photo-editorsnap-confinephoto-editor, in its sandbox
snap install photo-editor sends a request over a local socket to snapd; snapd asks the store, downloads, checks assertions, mounts the file read-only, sets up profiles and connects plugs, each step a task in its state; starting the app goes through snap-confine into the sandbox

The snap command asks snapd over a local socket. snapd fetches the snap from the store, verifies its assertions, mounts it read-only, sets up its security profiles and connections, and records each step as a task in its state.

You type snap install photo-editor. The snap command doesn't do the work itself. It sends a request over a local socket to snapd, the daemon that installs, runs and confines snaps. snapd asks the store, downloads the file and checks its signed assertions. It mounts the file read only, writes the security profiles and connects the interfaces the rules allow. Every step is a task recorded in its state, so if snapd restarts halfway, it carries on. And when you start the app, snap-confine puts it in its sandbox.

02 One install crosses the map

ONE INSTALL, MANY DISTRICTS Getting snapsstore · channels · the snap file Assertionsthe signatures snapd checks Policymay it install? what auto-connects? Interfaces and confinement · Sandbox internalsconnections become AppArmor, seccomp and mount profiles Running snapsthe change of tasks that does it all · services · refresh · configuration · snapshots Hooks · snapctl: the snap's own code runs and talks back to snapd
The districts one snap install passes through: getting snaps, assertions, policy, interfaces and confinement with sandbox internals, running snaps, and hooks with snapctl

Getting snaps, assertions, policy, interfaces and confinement, sandbox internals, running snaps, hooks and snapctl: one snap install touches each district.

That one install crosses most of this map. Getting snaps covers the store, channels and the snap file itself. Assertions covers the signatures snapd checks. Policy decides whether the snap may install and which of its plugs connect by themselves. Interfaces and confinement turn connections into a sandbox, and sandbox internals show how it's built. Running snaps covers the change of tasks that does all of this, and then services, refresh, configuration and snapshots. Along the way the snap's own hooks run, and they talk back to snapd through snapctl.

03 How to use the map

HOW TO USE THE MAP Snap userApp developerUbuntu Core developersnapd developeradminEveryonea perspective picks the scenes written for you; Everyone shows all of them a topicdeeper: implementationthe command linea neighbour interface families and a few other decks list every entry below the slides ⚑ flags mark topics you have opened
The perspective picker with five perspectives and Everyone; a topic with roads deeper, out to the command line and sideways; a flag marks opened topics

Go in any order. The perspective picker chooses the scenes; Everyone shows all of them. Each deck ends with roads onward, and flags mark the topics you have opened.

You don't have to go in order. Pick a perspective at the top: snap user, app developer, Ubuntu Core developer, snapd developer or administrator. Each deck then shows the scenes written for you, and Everyone shows them all. Every deck ends with roads that lead on: deeper into the implementation, out to what you see at the command line, or sideways to a neighbour. The interface families and a few other decks list every entry below the slides. And a flag on the map marks each topic you've opened, so you can see where you've been.

04 Where to go from here

ROADS snapd Ubuntu Coreboot · bootloaders · recovery · FDE Desktopprompts · desktop files · portals Developing snapstry · pack · layouts · debug Administrationaliases · quotas · users · warnings Inside snapdREST API · restarts · state · imagesToolssnap debug Why snaps: start here
Roads from the overview to Ubuntu Core with its four districts, Desktop, Developing snaps, Administration, Inside snapd, Tools, and Why snaps

Roads: Ubuntu Core, encryption, desktop, developing snaps, administration, inside snapd, tools, and why snaps.

Beyond the install path, some districts serve one kind of job. Ubuntu Core has four: boot, bootloaders, install and recovery, and full disk encryption, for devices built entirely from snaps. Desktop covers snaps in your session: prompts, desktop files and portals. Developing snaps covers trying, packing, layouts and debugging. Administration covers aliases, parallel installs, quota groups, users and warnings. Inside snapd covers the REST API, restarts, the state and images. Tools covers snap debug. And if you're new, why snaps is the place to start.

Read more

Districts of the map

DistrictStart withWhat it covers
Start hereWhy snapsthe problems snaps solve, and this overview
Getting snapsStorethe store, channels, the snap file, brand stores, epochs
Interfaces and confinementInterfacesplugs, slots, connections, the sandbox, classic confinement
Interface familiesClassificationevery interface, grouped by what it touches
PolicyInterface policythe base declaration, snap-declaration rules and how one rule decides
AssertionsAssertionssigned statements: identity, snaps, devices, validation sets
Running snapsOverlordchanges and tasks, refresh, services, snapshots, configuration, removal
HooksHookscode snapd runs inside a snap at fixed moments
snapctlsnapctlthe command a snap uses to talk to snapd
Ubuntu Core: boot, bootloaders, install and recoveryUbuntu Coremodes, boot path, GRUB and the other bootloaders, seeding, recovery systems, the model
Ubuntu Core: full disk encryptionEncryptionsealing, unlocking, keys, devices without a TPM
AdministrationAliasesaliases, parallel installs, quota groups, users, warnings, components
DesktopAppArmor promptingprompts, desktop files, the session agent, portals and themes
Developing snapsTry and packsnap try and pack, layouts, running and debugging, system usernames
Sandbox internalsMount namespacethe mount namespace, snap-update-ns, the system key, hotplug
Inside snapdREST APIsockets and access, restarts and re-exec, state patches, images
Toolssnap debugcommands for looking inside snapd

for app developers for Ubuntu Core developers for snapd developers for administrators

The daemon and its clients

ItemValue
Daemonsnapd, started by systemd from snapd.service and snapd.socket
Socket for the snap command/run/snapd.socket
Socket for snaps (snapctl)/run/snapd-snap.socket
State/var/lib/snapd/state.json
Snap files/var/lib/snapd/snaps/<name>_<revision>.snap, mounted under /snap/<name>/<revision>

Further reading

Roads from here

START HERE

  • Why snaps — the three problems that shaped snapd

GETTING SNAPS

INTERFACES AND CONFINEMENT

RUNNING SNAPS

SNAPCTL · the snap's API into snapd

ASSERTIONS · signed statements snapd trusts

HOOKS · code snapd runs inside a snap

POLICY · who may install and connect what

TOOLS

UBUNTU CORE · boot

UBUNTU CORE · full disk encryption

ADMINISTRATION · managing a system of snaps

  • Aliases — administration of a system of snaps

DESKTOP · snaps in a user session

DEVELOPING SNAPS · try, pack, run, debug

INSIDE SNAPD · the daemon itself