Commit Graph

300 Commits

Author SHA1 Message Date
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
James Henstridge
9b0c6b1feb Merge remote-tracking branch 'upstream/master' into session-agent-connect-to-bus 2020-11-17 19:19:22 +08:00
Zygmunt Krynicki
56fe6b32cc data/selinux: allow snap run to talk to system bus
This allows snap run to request app tracking.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2020-10-30 19:08:49 +01:00
Zygmunt Krynicki
8c38377acc data/selinux: allow snapd to kill stuck hooks
We stumbled on the fact that snapd cannot effectively kill stuck hooks
while debugging other permissions errors.

Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>
2020-10-30 19:07:06 +01:00
James Henstridge
0bd5b51053 data: mark the session agent as using notifications 2020-10-14 08:56:29 +08:00
James Henstridge
2dadf39870 data: add D-Bus service activation and desktop files for the session agent 2020-10-14 08:56:29 +08:00
Paweł Stołowski
41bcf5b6c6 Workaround for nsfs-related denials on centos8 due to snapshot size estimation for lxd snap. 2020-08-24 15:42:02 +02:00
Paweł Stołowski
0f3ac65fe0 Update SELinux security profile to allow listing of tmpfs_t directory contents for snapd. 2020-08-24 10:35:00 +02:00
James Henstridge
e3e9b1b2b5 Merge remote-tracking branch 'upstream/master' into dbus-activation-config 2020-06-22 13:48:33 +08:00
James Henstridge
6c60e61f58 many: rename /var/lib/snapd/dbus to /var/lib/snapd/dbus-1 2020-06-18 19:04:18 +08:00
Maciej Borzecki
c2091fad6a data/sudo: drop a failed sudo secure_path workaround
The sudo secure_path setting resets the PATH to some predefined value for
commands executed under sudo. We have tried to workaround
https://bugzilla.redhat.com/show_bug.cgi?id=1691996 by trying to extend the
secure_path in a drop in conf files. This approach does not work for 2 reasons:
 - the file is incorrectly named
 - secure_path is a string and += append only works on lists (eg. env_keep)

Since there is no clear way to fix the problem other than talking with
distributions, drop the workaround. We can always revert the patch when needed.

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

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-06-17 12:44:33 +02:00
Maciej Borzecki
5e4d8bd4bb data/selinux: interface for listing/reading /var/lib/snapd, allow system dbus access
Add interface definitions for listing and reading files and directories under
/var/lib/snapd.

Allow system dbus to read snappy_var_lib_t. This enables the dbus-daemon process
to service definition files under /var/lib/snapd/dbus.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-06-15 15:12:37 +02:00
James Henstridge
4b315f0fb0 data: install config files to extend D-Bus service activation search paths 2020-06-15 17:34:07 +08:00
Maciej Borzecki
2f4d7d5af5 data/selinux, packaging/fedora: exclude fwupd policy on RHEL7
The fwupd_search_cache() interface template is not defined on RHEL7.

In theory we should be able to use the `optional_policy(..)` block to capture
that, but based on investigation, the optional block is not correctly handled
when expanding the policy in kernel policy language. After m4 preprocessing is
done, the interface is not expanded and causes a compilation error further down
the stack. Based on feedback from #selinux, this works in CIL (should we ever
use it).

Make the relevant policy bit ifdef()'ed based on the distro.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-06-04 12:12:58 +02:00
Maciej Borzecki
69fa1e2865 data/selinux: allow checking /var/cache/app-info
The appstream-metadata interface sets up access to the host's
/var/cache/app-info. When the interface gets connected, both snapd and
snap-update-ns, check the directory. On SELinux systems, that location is
labeled as fwupd_cache_t. Update the policy to allow searching that location.

The denials are:

----
time->Wed Jun  3 14:11:06 2020
type=AVC msg=audit(1591186266.798:588): avc:  denied  { getattr } for  pid=1596 comm="snapd" path="/var/cache/app-info" dev="dm-0" ino=1182576 scontext=system_u:system_r:snappy_t:s0 tcontext=system_u:object_r:fwupd_cache_t:s0 tclass=dir permissive=1
----
time->Wed Jun  3 14:11:06 2020
type=AVC msg=audit(1591186266.857:589): avc:  denied  { getattr } for  pid=3530 comm="snap-update-ns" path="/var/lib/snapd/hostfs/var/cache/app-info" dev="dm-0" ino=1182576 scontext=system_u:system_r:snappy_mount_t:s0 tcontext=system_u:object_r:fwupd_cache_t:s0 tclass=dir permissive=1

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-06-03 14:30:12 +02:00
Vladimir Jelovac
576a30285b Merge remote-tracking branch 'upstream/master' 2020-05-28 16:19:09 +02:00
Maciej Borzecki
3192141bc8 data/selinux: update policy to allow forked processes to call getpw*()
When a process forked by snapd (eg. unsquashfs) calls getpw*() it may eventually
go through NSS. Depending on host configuration, it is possible that it will hit
nss-systemd and poke systemd-userdb.service. With current policy this triggers
the following denials:

type=AVC msg=audit(05/22/20 03:37:54.119:665) : avc: denied { read } for
         pid=27932 comm=unsquashfs name=userdb dev="tmpfs"
         ino=13308 scontext=system_u:system_r:snappy_t:s0
         tcontext=system_u:object_r:systemd_userdbd_runtime_t:s0
         tclass=dir permissive=1

type=AVC msg=audit(05/22/20 03:37:54.119:666) : avc: denied { write } for
         pid=27932 comm=unsquashfs name=io.systemd.DynamicUser
         dev="tmpfs" ino=63792 scontext=system_u:system_r:snappy_t:s0
         tcontext=system_u:object_r:systemd_userdbd_runtime_t:s0
         tclass=sock_file permissive=1

type=AVC msg=audit(05/22/20 03:37:54.120:667) : avc: denied { sendto } for
         pid=27932 comm=unsquashfs path=userdb-0f2255de09b5cbb97ed30ae81eda322e
         scontext=system_u:system_r:snappy_t:s0 tcontext=system_u:system_r:snappy_t:s0
         tclass=unix_dgram_socket permissive=1

Update the policy to allow use of nss.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-05-26 10:45:54 +02:00
Maciej Borzecki
2d51215322 data/selinux: allow snapd to remove/create the its socket
It has been observed that snapd may remove and create the socket when being
restarted by systemd right after the package update, what causes the following
SELinux denials:

time->Tue May 26 08:40:07 2020
type=AVC msg=audit(1590475207.721:397): avc:  denied  { write } for  pid=3490 comm="snapd" name="snapd.socket" dev="tmpfs" ino=21816 scontext=system_u:system_r:snappy_t:s0 tcontext=system_u:object_r:snappy_var_run_t:s0 tclass=sock_file permissive=1
----
time->Tue May 26 08:40:07 2020
type=AVC msg=audit(1590475207.721:398): avc:  denied  { write } for  pid=3490 comm="snapd" name="/" dev="tmpfs" ino=13932 scontext=system_u:system_r:snappy_t:s0 tcontext=system_u:object_r:var_run_t:s0 tclass=dir permissive=1
----
time->Tue May 26 08:40:07 2020
type=AVC msg=audit(1590475207.721:399): avc:  denied  { remove_name } for  pid=3490 comm="snapd" name="snapd.socket" dev="tmpfs" ino=21816 scontext=system_u:system_r:snappy_t:s0 tcontext=system_u:object_r:var_run_t:s0 tclass=dir permissive=1
----
time->Tue May 26 08:40:07 2020
type=AVC msg=audit(1590475207.721:400): avc:  denied  { unlink } for  pid=3490 comm="snapd" name="snapd.socket" dev="tmpfs" ino=21816 scontext=system_u:system_r:snappy_t:s0 tcontext=system_u:object_r:snappy_var_run_t:s0 tclass=sock_file permissive=1
----
time->Tue May 26 08:40:07 2020
type=AVC msg=audit(1590475207.721:401): avc:  denied  { add_name } for  pid=3490 comm="snapd" name="snapd.socket" scontext=system_u:system_r:snappy_t:s0 tcontext=system_u:object_r:var_run_t:s0 tclass=dir permissive=1
----
time->Tue May 26 08:40:07 2020
type=AVC msg=audit(1590475207.721:402): avc:  denied  { create } for  pid=3490 comm="snapd" name="snapd.socket" scontext=system_u:system_r:snappy_t:s0 tcontext=system_u:object_r:var_run_t:s0 tclass=sock_file permissive=1

Update the policy to allow that.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-05-26 09:11:59 +02:00
Vladimir Jelovac
26b1c82392 Merge remote-tracking branch 'upstream/master' 2020-05-06 19:08:25 +02:00
Maciej Borzecki
188cab443e data: move bash/zsh completion support to separate directories
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-05-05 09:45:46 +02:00