Commit Graph

319 Commits

Author SHA1 Message Date
Michael Vogt
d826c315a8 Merge pull request #11427 from bboozzoo/bboozzoo/selinux-snap-exec-systemctl
data/selinux: allow the snap command to run systemctl
2022-03-04 08:39:30 +01:00
Maciej Borzecki
bd629832e2 data/env: cosmetic tweak for fish
@faho pointed out in https://github.com/snapcore/snapd/pull/11416 this can be
done in a single set call

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-02-23 11:48:48 +01:00
Maciej Borzecki
b6126cf4ee data/env: more workarounds for even older fish shells, provide reasonable defaults (#11416)
Tweak snapd.fish to be compatible with even older releases of fish, going back to 2.7, which was shipped with Ubuntu 18.04.

* data/env: make fish setup compatible with fish 2.7

Make the environment setup script compatible with fish 2.7 which was shipped
with Ubuntu 18.04.

Thanks to @faho for the review.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* tests/main/user-session-env: verify env in fish shell

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* tests/main/user-session-env: tweak comments

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* data/env: provide reasonable default if XDG_DATA_DIRS is unset in fish shell

Fixes: https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1960702

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* tests/main/user-session-env: verify that XDG_DATA_DIRS contains reasonable defaults

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-02-23 11:42:13 +01:00
Maciej Borzecki
e995e0fafe data/selinux: allow the snap command to run systemctl
Which can happen when there is a system key mismatch. Caught in the wild on
Fedora.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2057103

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-02-23 07:32:45 +01:00
Maciej Borzecki
2a94f057cf data/env: fix fish env for all versions of fish, unexport local vars, export XDG_DATA_DIRS
Make the fish env setup script compatible with old versions of fish 3.0.x which
was released back in 2019, but is still shipped by recent releases of distros
eg. Ubuntu 21.10.

While doing so, make sure that helper variables used in the script stay local.

Since only newer versions of fish (3.1+) are aware of XDG_DATA_DIRS make sure
that it's exported.

Fixes:
https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1958022
https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1957948
https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1960492

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-02-10 12:22:25 +01:00
Michael Vogt
44fd502110 Merge pull request #11290 from bboozzoo/bboozzoo/maybe-mount-bpffs
cmd/snap-confine: mount bpffs under /sys/fs/bpf if needed
2022-02-03 11:04:52 +01:00
Maciej Borzecki
7a9ec10b91 data/selinux: snap-confine may getattr device nodes when setting up /dev in the snap namespace
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-02-02 13:20:04 +01:00
Maciej Borzecki
7bed5e4a7f data/selinux: update SELinux policy with more bpf allowances
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-02-02 13:17:01 +01:00
Maciej Borzecki
72f956a582 data/selinux: update the policy to allow creating/removing dir under /etc/dbus-1
It is possible that system.d may be missing if no services were installed on the
system yet. In which case, snapd will create the directory and thus trigger the
denial.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-02-02 12:47:16 +01:00
Dimitri John Ledkov
5f44956e01 data/systemd/snapd.service: start after socket
During boot, the initial transaction may contain both snapd.socket and
snapd.service at the same time. In such cases, snapd.service should be
started strictly after snapd.socket (After+Requires), instead of just
simultaniously with it (Requires alone).

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
2022-01-24 15:51:11 +00:00
Jakub Duchateau
77cb1707f8 Threat XDG_DATA_DIRS like PATH
Tell fish to treat XDG_DATA_DIRS as a column separated list and not space separated (default).
Otherwise, get corrupted list with mixed separators:
XDG_DATA_DIRS=/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop /var/lib/snapd/desktop /var/lib/snapd/desktop
2022-01-08 11:07:36 +01:00
Maciej Borzecki
c839afa28d data/selinux: allow poking /proc/xen
When running in a Xen guest, systemd-detect-virt when invoked by snapd may
trigger the following denial:

type=PROCTITLE msg=audit(1640771959.147:236972): proctitle="systemd-detect-virt"
type=AVC msg=audit(1640771959.147:236972): avc:  denied  { search } for pid=21113
         comm="systemd-detect-" name="xen" dev="proc"
         ino=4026532003
         scontext=system_u:system_r:snappy_t:s0
         tcontext=system_u:object_r:proc_xen_t:s0
         tclass=dir permissive=1

See https://forum.snapcraft.io/t/snapd-unavailable-red-hat-enterprise-linux/28004/15
for details.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-01-03 11:45:09 +01:00
Maciej Borzecki
85a02832f8 data/selinux: allow snapd to access /etc/modprobe.d
The kernel-module-load interface may trigger accesses to /etc/modprobe.d as seen
in the following denials:

type=AVC msg=audit(120721 16:27:22.859:25079) : avc: denied { getattr } for
pid=97494 comm=snapd path=/etc/modprobe.d dev="sda5" ino=13371
scontext=system_u:system_r:snappy_t:s0
tcontext=system_u:object_r:modules_conf_t:s0 tclass=dir permissive=1

type=AVC msg=audit(120721 16:27:22.859:25080) : avc: denied { read } for
pid=97494 comm=snapd name=modprobe.d dev="sda5" ino=13371
scontext=system_u:system_r:snappy_t:s0
tcontext=system_u:object_r:modules_conf_t:s0 tclass=dir permissive=1

type=AVC msg=audit(120721 16:27:22.859:25081) : avc: denied { open } for
pid=97494 comm=snapd path=/etc/modprobe.d dev="sda5" ino=13371
scontext=system_u:system_r:snappy_t:s0
tcontext=system_u:object_r:modules_conf_t:s0 tclass=dir permissive=1

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-12-08 11:24:10 +01:00
Maciej Borzecki
f9dd306a07 data/env: improve fish shell env setup
Based on comments in https://github.com/snapcore/snapd/pull/11071 the way to add
$SNAP_MOUNT_DIR/bin to fish PATH can be simplified.

Thanks to @Karrq for the suggestion.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-12-02 12:49:46 +01:00
Maciej Borzecki
73f39f4996 data/env: provide profile setup for fish shell
Profile profile setup for fish shell, which does not load /etc/profile.d.

Fixes: https://bugs.launchpad.net/snapd/+bug/1951145

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-11-17 12:08:33 +01:00
Maciej Borzecki
e4024d1f60 data/selinux: update the policy to allow snapd to talk to org.freedesktop.timedate1
Snapd needs to poke the org.freedesktop.timedate1 service to find out whether
NTP was synchronized. That DBus API is provide by systemd-timesyncd (most
systems) or timedatex (CentOS mostly). The SELinux policy does not currently
allow talking to either service, so upon startup snapd will enter a deadlock
after getting blocked in the timeutil.IsNTPSynchronized() waiting for dbus
messages, while this is called in a code path that acquired state.Lock(), thus
blocking all Ensure() calls and interaction through the snapd socket.

Extend the SELinux policy to allow dbus communication to either timedate1
provider service.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-11-05 12:27:52 +01:00
Maciej Borzecki
463edb3694 data/selinux: allow snap-confine to read udev's database
These denials occasionally pop up when snap-confine starts inspecting assigned
devices:

----
type=AVC msg=audit(10/28/21 06:54:05.000:11501) : avc:  denied  { read } for  pid=56565 comm=snap-confine name=c1:7 dev="tmpfs" ino=17684 scontext=system_u:system_r:snappy_confine_t:s0 tcontext=system_u:object_r:udev_var_run_t:s0 tclass=file permissive=1
----
type=AVC msg=audit(10/28/21 06:54:05.000:11502) : avc:  denied  { open } for  pid=56565 comm=snap-confine path=/run/udev/data/c1:7 dev="tmpfs" ino=17684 scontext=system_u:system_r:snappy_confine_t:s0 tcontext=system_u:object_r:udev_var_run_t:s0 tclass=file permissive=1
----
type=AVC msg=audit(10/28/21 06:54:05.000:11503) : avc:  denied  { getattr } for  pid=56565 comm=snap-confine path=/run/udev/data/c1:7 dev="tmpfs" ino=17684 scontext=system_u:system_r:snappy_confine_t:s0 tcontext=system_u:object_r:udev_var_run_t:s0 tclass=file permissive=1
-----

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-10-28 12:03:40 +02:00
Maciej Borzecki
425887648c data/selinux: tweak comments
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-09-20 08:54:32 +02:00
Maciej Borzecki
94e20f0fdf data/selinux: update the policy to allow s-c to manipulate BPF map and programs
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-09-17 09:41:18 +02:00
Ian Johnson
2168429f03 data/systemd/snapd.snap-repair.*: rm obsolete TODO:UC20's
We decided to have snap-repair run in recover mode, so this TODO is obsolete.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-02-23 16:43:41 -06:00
Maciej Borzecki
d11486b4cd data/selinux: allow system dbus to watch /var/lib/snapd/dbus-1
The SELinux reference policy has a new set of access vectors for watch*. The
support in core policy landed in
https://github.com/fedora-selinux/selinux-policy/pull/546 on 07.02.2021. Present
in selinux-policy 3.14.7 in Fedora 34 and Rawhide.

Snapd sets up /var/lib/snapd/dbus-1/services to be watched by the system dbus.
However, dbus trying to watch those directories triggers new watch permissions
to be checked. The snappy.te policy does not allow this access, thus on Rawhide
dbus fails like this:

systemd[1]: Starting D-Bus System Message Bus...
dbus-broker-launch[7728]: ERROR dirwatch_add @ ../src/util/dirwatch.c +122: Permission denied
dbus-broker-launch[7728]:       launcher_load_service_dir @ ../src/launch/launcher.c +763
dbus-broker-launch[7728]:       launcher_load_services @ ../src/launch/launcher.c +978
dbus-broker-launch[7728]:       launcher_run @ ../src/launch/launcher.c +1306
dbus-broker-launch[7728]:       run @ ../src/launch/main.c +152
dbus-broker-launch[7728]:       main @ ../src/launch/main.c +178
dbus-broker-launch[7728]: Exiting due to fatal error: -13
systemd[1]: dbus-broker.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: dbus-broker.service: Failed with result 'exit-code'.

Triggering the following denial:

type=AVC msg=audit(1613393808.456:478): avc:  denied  { watch } for
         pid=7728 comm="dbus-broker-lau"
         path="/var/lib/snapd/dbus-1/system-services" ...
         scontext=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023
         tcontext=system_u:object_r:snappy_var_lib_t:s0
         tclass=dir permissive=0

Fixes: https://bugs.launchpad.net/snappy/+bug/1915642

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-02-16 10:46:57 +01:00
Maciej Borzecki
ae84b651f4 data/env/snapd: use quoting in case PATH contains spaces
When PATH contain spaces, which is a really bad idea anyway, the export will
most likely set it to a value up to the first space. Use quoting to prevent
that.

Note, shellcheck does not complain about that, but try this:

sh-5.1$ export foo=foo bar baz
sh-5.1$ echo $foo
foo
sh-5.1$ export foo="foo bar baz"
sh-5.1$ echo $foo
foo bar baz
sh-5.1$

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-02-02 09:56:48 +01:00
Maciej Borzecki
3ebc50d5b5 data/selinux: update the policy to allow operations on non-tmpfs /tmp
Some distros, eg. CentOS 7 do not have /tmp on tmpfs. Because of this, the
policy rules for tmpfs are not effective and the following denial can be
observed when disconnecting the x11 interface (which mounts /tmp/.X11-unix from
the host):

type=AVC msg=audit(1606220902.660:1383): avc:  denied  { rmdir } for
         pid=28575 comm="snap-update-ns" name=".X11-unix" dev="sda2"
         ino=17552915
         scontext=system_u:system_r:snappy_mount_t:s0
         tcontext=system_u:object_r:tmp_t:s0
         tclass=dir permissive=1

We need to extend the policy to explicitly allow poking generic tmp_t files and
directories.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-11-24 14:15:13 +01:00
Michael Vogt
fa973d5047 Merge pull request #9497 from jhenstridge/session-agent-connect-to-bus
usersession/agent: have session agent connect to the D-Bus session bus
2020-11-19 10:49:35 +01:00
Sergio Cazzolato
7e906450da tests: testing new fedora 33 image (#9556)
* Testing new fedora 33 image

* packaging/fedora: align with Fedora source tree

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* Skip tests on f33 due to it uses cgroupv2

* data/selinux: account for s-c unmounting things

The snap-confine helper unmounts some locations which are actually a tmpfs with
a different label. Update the policy to allow that.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* tests/main: Fedora 33 nsswitch uses resolved first for host resolution

Make sure that we also stop or flush resolved caches when disabling blocking DNS
or clearing resolve.conf.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* tests/main/snap-network-errors: tweak to account for older systemd versions

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

* spread: Fedora 31 is EOL on 24.11

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>

Co-authored-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-11-18 23:28:00 -03:00