The network interface

one interface for users for app developers

Client network access through AppArmor and seccomp rules. The slot is implicit on every system and nothing in the rule denies so the plug auto-connects at install on classic and on Ubuntu Core. Listening for connections and configuring the network are separate interfaces.

On the map: a postern south of the gatehouse

▶ Watch this deck — 3 scenes, ~2 min

01 What network grants

NETWORK acme-agenton the gatewaynetwork its server, as a client AppArmorname lookups · IPv4 and IPv6 socketsthe system's certificates seccompa few calls, such as bind not included:network-bind · network-control
acme-agent with the network plug reaching its server as a client; AppArmor and seccomp carry the rules; listening and configuring the network are the separate interfaces network-bind and network-control

Client network access: name lookups, IPv4 and IPv6 sockets and the system certificates through AppArmor, a few extra system calls through seccomp. Listening is network-bind; configuring the network is network-control.

On the gateway, acme-agent sends its readings to a server, the one named in its server setting. To reach it, the snap needs the network plug. What that grants is client access. Its AppArmor rules let the agent look up names, open IPv4 and IPv6 sockets, and read the system's certificates for TLS. Its seccomp rules add a few system calls, such as bind. What network doesn't give is the server side, listening for connections and accepting them: that's network-bind. And changing how the network itself is set up is network-control.

02 Auto-connects everywhere general version

THE RULE base-declaration, slots:network:allow-installation:slot-snap-type: [core] nothing denies, so the defaults holdallow-connection: trueallow-auto-connection: true auto-connects on the gateway and on a laptop the slot is implicit: snapd creates it, no snap.yaml declares it WHERE THE IMPLICIT SLOT LIVEScore snap (in the past) → snapd snap where it is installedstate.json still says "core" · snap connections shows "system"
The minimal base-declaration rule for network, the defaults that follow, auto-connection on every system, and where the implicit slot lives

The rule only places the slot on the system; with no deny rules, network auto-connects at install on every system. The implicit slot is on the snapd snap where it is installed; state records it as core and the CLI shows system.

Unlike home, network asks for nothing. Its rule in the base declaration only says where the slot lives: on the system. Nothing in it denies, so installation, connection and auto-connection all fall back to allowed. On the gateway, the plug connects the moment acme-agent is installed, and on a laptop just the same. The slot is implicit: snapd makes it itself, and no snap.yaml declares it. It used to sit on the core snap. Where the snapd snap is installed, that snap carries it now, while the state still says core and the command line says system.

03 Connected everywhere for users in place of the general version

NETWORK · FOR USERS connected automatically, on every system $ snap connections acme-agentnetwork acme-agent:network :network - :network, with no snap name before the colon: the system's own slot $ snap disconnect acme-agent:networkcuts the app off from the network; remembered across refreshes
network is connected everywhere; snap connections shows acme-agent:network connected to the system slot :network; snap disconnect cuts the app off and is remembered

Connected automatically on every system. The system's slot shows as :network. Disconnecting is possible and remembered across refreshes.

On the gateway, acme-agent was connected to the network the moment it was installed, and the same happens on any laptop or desktop. snap connections shows it: acme-agent's network plug is connected to :network. There's no snap name before the colon, because the slot belongs to the system itself. If you want an app off the network, snap disconnect does that, and snapd remembers your choice, so a refresh won't reconnect it.

Read more

What you give a snap

Name lookups, outgoing connections and the system's certificates; not listening for connections.

for app developers for snapd developers

What the plug allows

ThroughAllows
AppArmorthe nameservice abstraction (name lookups and IPv4 and IPv6 stream and datagram sockets), /run/systemd/resolve/stub-resolv.conf, /etc/mdns.allow, netlink datagram sockets, the Resolve* calls of systemd-resolved and the dynamic-user lookups of systemd over D-Bus, the ssl_certs abstraction, two /proc/sys/net values, and running nc as a client
seccompbind, socket for AF_NETLINK with NETLINK_ROUTE, and socket for AF_CONN (SCTP in user space)

Without the plug, AppArmor denies IPv4 and IPv6 sockets. connect and socket for most families are already in the default seccomp filter; listen and accept are not.

Neighbours

InterfaceAddsAuto-connects
networkclient accessyes
network-bindlisten, accept, accept4: operating as a server. a socket-activated service needs ityes
network-statusasking whether the system is onlineyes
network-observereading network stateno
network-controlchanging network configurationno

The rest of the family is in the network family.

Connecting

  • The plug connects when the snap is installed, on classic systems and on Ubuntu Core.
  • snap connections <snap> shows the slot as :network.
  • snap disconnect <snap>:network cuts the app off. Because the connection was automatic, snapd records it as undesired and a refresh does not reconnect it. snap connect <snap>:network connects it again.

for app developers

The rule and the implicit slot

The base declaration says only allow-installation: slot-snap-type: [core] for the slot. With no deny rules, connection and auto-connection fall back to allowed.

The slot is implicit on classic and on Ubuntu Core. Where the snapd snap is installed, snapd hosts the implicit slots on it; the state records them on core, as before the snapd snap existed, and the API and snap command show them on system. A request may name the slot as :network, system:network or core:network.

Further reading

Roads from here

INTERFACES AND CONFINEMENT

INTERFACE FAMILIES · every interface, grouped by what it touches