306 Commits

Author SHA1 Message Date
Robert Ancell
fc53358689 interfaces/builtin/home: autoconnect home on core desktop (#14106)
* asserts,i/policy: add on-core-desktop constraint

This is required for interface behaviours that are different on Core Desktop.

* interfaces/builtin/home: autoconnect home on core desktop

Core desktop is much like a classic system in that the user would reasonably
expect to be able to access this home directory.
2024-07-12 09:19:12 +02:00
Miguel Pires
283f8abb6b i/builtin: add registry interface (#14113)
* i/builtin: add registry interface

Add a registry interface that snaps can use to access a particular
registry view.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* registry: constrain registry name

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

---------

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-06-27 11:15:13 +02:00
Miguel Pires
cfcc50a1cf asserts: allow $PLUG_PUBLISHER_ID in plug attribute constraints
Allow plugs to specify the $PLUG_PUBLISHER_ID in attribute constraints
such that interfaces can restrict auto-connection to when certain
attributes match their publisher IDs.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-06-21 15:49:09 +02:00
Andrew Phelps
71d22420df many: add a *SnapAppSet to ConnectedPlug/Slot types and use it to build label expressions in interfaces (#13773)
Now that we have app sets in the interfaces repo, keep a pointer to them in ConnectedPlug/Slot types. Use this to build label expressions in the interfaces. 

* many: add a pointer to a SnapAppSet into Connected(Plug|Slot) to that interfaces can build a complete label expression, including component hooks

* interfaces: update doc comments on ConnectedPlug/Slot.AppSet

* interfaces: remove TODO that has been addressed

* interfaces: use app set pointer for instance name check

* snap: add Runnable type that represents the runnable parts of a snap

* interfaces, o/ifacestate: use snap.Runnable rather than interfaces.Runnable

* interfaces, i/builtin, o/ifacestate: panic on failed invariant check in NewConnectedPlug/Slot

* interfaces: add methods to app set for getting runnables that can connect to plug/slot

* interfaces: build label expressions using runnables

* interfaces: doc comment for SlotRunnables

* interfaces: implement Slot/PlugRunnables with shared helper

* interfaces: log and skip security tags that do not match expected pattern

* snap, interfaces: move runnable constructors to methods on AppInfo and HookInfo

* interfaces: refactor to allow labelExpr to operate directly on a ConnectedPlug/Slot

* snap: move around Runnable methods
2024-06-14 18:37:26 +02:00
Peter Sabaini
35655acbc1 i/b/microceph-support: add microceph-support interface (#13352)
* i/b/microceph-support: add microceph-support interface

Add separate microceph-support interface in order to allow more types
of block devices to be added as an OSD (bcache, indiv. partitions,
device mapper)

Also allow access to the rbd sysfs controls for managing rbd-backed block devices (cf.
https://docs.kernel.org/admin-guide/abi-testing.html#abi-file-testing-sysfs-bus-rbd)

Signed-off-by: Peter Sabaini <peter.sabaini@canonical.com>

* i/b/microceph-support: define slot policy

Address review feedback: define a slot policy

Signed-off-by: Peter Sabaini <peter.sabaini@canonical.com>

* Rebase and fixup unit test

Signed-off-by: Peter Sabaini <peter.sabaini@canonical.com>

---------

Signed-off-by: Peter Sabaini <peter.sabaini@canonical.com>
2024-03-14 19:19:38 +01:00
Buğra Aydoğar
c0059170df interfaces/builtin: add interface for remoteproc 2024-03-09 20:39:56 +01:00
Buğra Aydoğar
db27649340 interfaces/builtin: add interface for kernel-firmware-control 2024-03-07 10:13:42 +01:00
Zeyad Gouda
eba5f39bb4 many: add snap-refresh-observe interface
Snaps with snap-refresh-observe plug connected will have
    read-access to:
    - /v2/notices: to read change-update and refresh-inhibit notices
    - /v2/changes{,/<id>}: to read refresh related changes
    - /v2/snaps: to read snaps whose refresh is inhibited

* many: address review comments (thanks @pedronis)

* daemon: explicitly check for SnapdSocket (thanks @alexmurray)

* daemon: refactor notice api helpers

* daemon: address review comments (thanks @pedronis)

* daemon: give snap-refresh-observe access to refresh-inhibit notices

* Merge branch 'master' of github.com:snapcore/snapd into add-snap-refresh-inhibit-observe-interface

* daemon: filter notice types based on snap interfaces

* daemon: attach snap interfaces to RemoteAddr

* daemon: move single notice checks into noticeReadAccess (thanks @pedronis)

* many: add access check for /v2/notices/{id} (thanks @alexmurray)

* many: address review comments

* many: rename snap-refresh-inhibit-observe interface to snap-refresh-observe (thanks @bboozzoo)

* daemon: rename notice helpers to be more explicit

* daemon: explicitly define access checker for each notice type

* tests/main: add test for snap-refresh-inhibit-observe interface

* daemon: allow snaps with snap-refresh-inhibit-observe plug API read-access

* daemon: add noticeReadAccess checker

* interfaces/builtin: add snap-refresh-inhibit-observe interface

Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
2024-03-04 09:19:43 +01:00
Samuele Pedroni
01dcdd0ece interfaces: we actually expect snaps to auto-connect to desktop
originally desktop was simply allow auto-connect, making the change to not
auto-connect on UC is not that relevant because ultimately there will need to
be a snap providing it and that snap will set policy if allowed from its
snap-declaration

instead let auto-connection only happen with an implicit slot
2024-02-22 16:54:10 +01:00
Mirko Ferrati
132e09261d interfaces: new "ros" host file system support (#13281)
* Add new ros opt interface

* Ros interface: prepare for testing

* adapt test from system-files to ros-opt-data

* complete list of ros files and explanation

* Fix unit tests and formatting

* No need to restore-dir if it's a sub folder of a mocked dir already

* Add spread test for ros-opt-data interface

* Reorder test-snapd-policy-app-consumer snap.yaml file

* Finish the spread test for ros-opt-data

Mounted folder inside is different from the outside,
mocks are now using 2 different values

* Fixup remove unnecessary line in ros-opt-data test

* Do not have ros opt data interface implicit on Core
2024-02-20 10:23:16 +01:00
Alex Murray
d0023970be many: add support for AppArmor unconfined profile mode (#13333)
* sandbox/apparmor: read apparmor kernel sub-features

These are required to be able to detect whether the running kernel supports the
use of the unconfined profile mode amongst others.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* sandbox/apparmor: add support for probing parser for unconfined flag

AppArmor 4.0 introduced a new flag named unconfined - since this is a profile
flag rather than part of the main profile syntax, also add support for probing
for flags within AppArmor profiles.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces/apparmor: add support for unconfined profile flag

Add a new unconfined attribute to the AppArmor specification which is used to
denote that a profile should include the unconfined flag. Then refactor flag
handling within the AppArmor backend so that both this new flag and the complain
flag (used for classic and dev mode snaps) are handled together. Finally, only
emit this flag when we are sure both the AppArmor parser and kernel provide
appropriate support.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces/builtin/lxd_support: add userns and unconfined permissions

LXD requires the use of unprivileged userns and the ability to run unconfined -
so support for both of these to the lxd-support interface.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* tests/main/lxd: verify apparmor profile has expected perms on mantic

On Ubuntu 23.10 the LXD snap should run with the new unconfined profile flag and
with the userns AppArmor permission, so check for these via spread.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces: rework AppArmor unconfined mode to be a static property

As suggested by @pedronis, refactor the implementation of AppArmor unconfined
profile mode to be a static property of an interface so that it is much more
tightly coupled to the interface itself. Add various tests as well to ensure
that only super-privileged interfaces can use this property too.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* tests/main/lxd: add details to the spread test

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* sandbox/apparmor: test kernel sub-features

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces: clarify comment regarding AppArmorUnconfined{Plugs,Slots}

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces/policy: check for unconfined plug/slots outside type loop

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* sandbox/apparmor: fix double space in profiles when probing parser

Thanks for the suggestion @MiguelPires

Signed-off-by: Alex Murray <alex.murray@canonical.com>

---------

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2024-01-03 11:23:48 +00:00
James Henstridge
4528a409a8 interfaces: make AutoConnect of cups-control dependent on presence of cupsd on host system.
This is intended to make auto-connect on classic systems work when the
cups snap is also installed. If the cupsd is installed, application
snaps should connect to system:cups-control. If not, then they should
connect to cups:cups-control.
2023-12-07 12:58:29 +01:00
Buğra Aydoğar
9e84c35e39 interfaces/builtin: modify shutdown interface to allow access to SetRebootParameter method (#12652)
* interfaces/shutdown: allow SetRebootParameter method

* interfaces/shutdown: make shutdown interface super privileged

---------

Co-authored-by: Buğra Aydoğar <bugra.aydogar@canonical.com>
2023-11-17 08:40:10 +02:00
Samuele Pedroni
5a0418459d interfaces: review and extend README.md (#13247)
incorporate into it and update the patterns described in basedeclaration.go

have a few relevant doc comments point to it

* tweaks

* interfaces: incorporate suggestions from @degville with some tweaks

thanks

* interfaces: incorporate fixes from @MiguelPires

thanks
2023-10-09 15:43:15 +02:00
James Henstridge
4dfeea8fce interfaces: add a polkit-agent interface (#10598)
This is a first go at an interface to allow a snap to register as a Polkit agent. The primary use case is for the Ubuntu Core Desktop system we're building. The implicit slot is not available on classic systems, since there is no reasonable way to implement it given the variability in the PAM and NSS configurations found on those systems.

Here's a brief description of how a Polkit agent operates:

The agent registers with polkitd by calling the RegisterAgent D-Bus method. In general, it will register as an agent for all processes that belong to a particular logind session.
When a system daemon makes a CheckAuthorization call to polkitd for a subject that is covered by the agent, polkitd will make a BeginAuthentication call to the agent. This includes the requested action ID, a message to show the user, and a cookie string to identify the authentication request.
The agent runs the setuid polkit-agent-helper-1 executable as a sub-process. The helper begins the PAM authentication process, and delegates any prompts to the agent via messages on stdin/stdout.
On completion of the authentication process (either success or failure), the helper makes an AuthenticationAgentResponse2 method call to polkitd, using the cookie to identify the request. Polkitd trusts the response because the D-Bus connection credentials show that the helper is running as root.
Polkitd responds to the system daemon with this result, allowing it to decide how to respond to its client.
This poses a number of difficulties for a snap based system:

The snap needs to be able to execute a setuid binary.
The setuid binary is going to inherit some security config from its parent process, including:
mount name space: it will be running in the snap's sandbox, so the sandbox will need to provide all the PAM modules referenced by the system's configuration, and have access to all data files and services those modules use.
seccomp filters: the parent's seccomp filter will need to allow all access the setuid helper requires. One obvious case that has come up is access to the kernel audit subsystem.
The need to support the host system's PAM config mostly rules out getting this to work on Classic systems. On Core systems though, things will generally work if the snap uses the same base as the boot file system (or something sufficiently similar).

The interface makes use of AppArmor's ability to switch profiles on exec(). We switch to a sub-profile tailored to what polkit-agent-helper-1 needs. Namely:

Include nameservice and authentication abstractions to enable use of PAM. Also grant access to extrausers shadow files, which aren't currently included in authentication.
Allow audit_write and sys_nice capabilities, which are used by the installed PAM modules
Allow SIGTERM signals from the calling snap: this is sent when the user cancels authentication. The corresponding rule allowing the agent to send the signal is covered by the default snap AppArmor template.
Allow communication with polkitd over the D-Bus system bus to make the AuthenticationAgentResponse2 method call.
The interface is locked down with allow-installation: false on the plug side, since it allows running a privileged process in a mount namespace under the control of the snap. Through the use of layouts, it's possible that the snap could replace shared libraries loaded by the helper. Even though the helper is locked down through an AppArmor sub-profile, it seems reasonable to vet snaps that request this access.

I don't have a spread test for this, as we don't have any ubuntu-core-* systems with polkit integrated, and I'm not all together certain how I'd structure a test for this. We have been manually testing the interface on Core Desktop builds though.

* interfaces: add a polkit-agent interface

* interfaces: use a subprofile to run polkit-agent-helper-1 in polkit-agent interface

* interfaces: only look for polkit-agent-helper-1 in /usr/libexec

Prior to Ubuntu 22.04, the polkit executables were installed in
/usr/lib/policykit-1. As there is practically zero chance of polkit
being integrated into these older Ubuntu Core versions, there's no
benefit checking the old path.
2023-10-02 13:43:32 +02:00
Samuele Pedroni
209479b376 i/policy: fix TestConnection* for qualcomm-ipc-router
it was using snap-slot-type on the slot-side in allow-connection
before it was enabled, that's why this started breaking on master
2023-09-27 18:45:58 +02:00
Samuele Pedroni
709ddf4596 interfaces: upower-observe base policy considers whether the slot is implicit
let connect/auto-connect only to an upower-observe implicit slot by default,
this will require changes to review-tools to detect that for an app slot
dedicated rules in snap-declaration are needed
2023-09-27 14:58:56 +02:00
Samuele Pedroni
c6365a4b8e asserts,i/policy: slot-side slot-snap-type connection constraints
these can be useful in the base-declaration in situations where
a slot can be app-provided or implicit both on classic and core

now we have at least one use case like this for upower-observe

as core/system snaps so far provide only slots there is no use
case for adding plug-side plug-snap-type connection constraints
2023-09-27 14:58:56 +02:00
Alfonso Sánchez-Beato
01bd78fa30 interfaces/qualcomm-ipc-router: split in slot and plug
Split permissions between a slot and a plug that can both be provided
by a snap, but still allow to connect to a system provided slot.
2023-09-15 20:40:02 +02:00
Valentin David
a25b5d6275 i/b/qualcomm_ipc_router.go: switch to plug/slot and add socket permission 2023-09-15 20:40:02 +02:00
James Henstridge
c535590081 interfaces/desktop: allow snaps to provide a desktop slot, granting access to system fonts and xdg-desktop-portal (#10753)
* Mount system fonts via app desktop slot

* interfaces: update desktop tests to match changes to interface

* interfaces: note that desktop interface allows app slot implementations

* tests: add desktop slot to test-snapd-policy-app-provider-core

* interfaces: deny connection of desktop interface by default on Ubuntu Core.

* tests: add a spread test for providing a desktop slot on Ubuntu Core

* interfaces: add support for xdg-desktop-portal to app-provided desktop slot

In this setup, we expect xdg-desktop-portal and xdg-document-portal to
be running outside of confinement (as snap userd does), with the user
interface backend services running in the context of the slot snap.

* interfaces: add a comment about the assumption that a snap providing a
desktop slot uses the boot base snap as its base.

* Fix documents portal not being launched

It uses a different bus name from the desktop portal.

* interfaces: fix up permanent slot rules for desktop interface

* interfaces: update desktop slot declaration to only allow app snaps to provide the slot under the minimal install check

* interfaces: add access to files necessary for xdg-user-dirs to the
desktop slot

* interfaces: add file access covering what the ubuntu-desktop-session:shell-config-files system-files plug granted

* interfaces: add a comment noting the unusual base declaration for desktop

* interfaces: make desktopPermanentSlotAppArmor a constant

---------

Co-authored-by: Marcus Tomlinson <marcus.tomlinson@canonical.com>
Co-authored-by: Robert Ancell <robert.ancell@canonical.com>
Co-authored-by: Ken VanDine <ken.vandine@canonical.com>
2023-09-14 19:42:26 +02:00
Alex Murray
4c01e47f82 interfaces: add new userns interface (#12530)
* sandbox/apparmor: Add probing for userns support in host AppArmor

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces/builtin/userns: Add new userns interface

Add a new super-privileged interface that allows a snap to bypass any AppArmor
restrictions on user namespace creation on the host. Since this is only
supported in very new AppArmor releases, when the host AppArmor does *not*
support this feature, it is implicitly assumed to be allowed.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces/browser-support: Add AppArmor userns with allow-sandbox

When allow-sandbox is true, and the host system's AppArmor supports mediating
userns, ensure we include this permission in the generated AppArmor profile
snippet.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces/docker-support: Add AppArmor userns support

When the host system's AppArmor supports mediating userns, ensure we include
this permission in the generated AppArmor profile snippet.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces/userns: Add clone to seccomp filter

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces/greengrass-support: Add AppArmor userns support

When the host system's AppArmor supports mediating userns, ensure we include
this permission in the generated AppArmor profile snippet for the privileged
mode flavors of this interface. This keeps the AppArmor and seccomp profiles
consistent as we also allow unshare in the seccomp profile for these flavors as
well.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces: Unit test AppArmor userns in [docker|greengrass]-support

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces: propagate error from apparmor_sandbox.ParserFeatures()

If this fails then something is definitely not right so don't silently ignore
it.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces: use nil in-place of []string{} for better readability

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces/userns: rework AppArmorConnectedPlug() error handling

Don't ignore errors from apparmor_sandbox.ParserFeatures() but allow to more
concisely handle the case where the parser does not support userns.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces/userns: use correct super-privileged base declaration

Also declare this slot as implicit on both core and classic since it is provided
by the system's AppArmor parser etc.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

* interfaces/userns: fix to wire up interface declaration properly

Also fix the associated unit tests to properly test that this interface is
super-privileged as expected and is implicit on core / classic too.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

---------

Signed-off-by: Alex Murray <alex.murray@canonical.com>
Co-authored-by: Michael Vogt <mvo@ubuntu.com>
2023-04-20 11:27:23 +02:00
Robert Ancell
c69df736b2 Remove upower-observe from base declaration test, it has a variable implicitOnCore value 2023-03-21 12:33:34 +13:00
Dimitri John Ledkov
a0948bc380 interfaces/nvidia-drivers-support: NVIDIA drivers userspace system setup support (#12591)
* interfaces/nvidia-support: Add support for NVIDIA char devices

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>

* Fix policy tests

* expand nvidiaSupportSummary

* update copyright year

* Rename to nvidia-drivers-support

* Rename files

* go.gofmt fix

---------

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
2023-03-08 17:11:17 +01:00
Valentin David
2e201b740d i/b/udisks2: disallow installation by default if udev-file is set 2023-03-07 17:42:26 +01:00