192 Commits

Author SHA1 Message Date
Ian Johnson
7ae57afc07 snap/validate.go: disallow snap layouts with new top-level directories
We previously wouldn't fail on verification for snaps that used new top-level
directories, and would fail at runtime, which produces a very unhelpful message.

Also adjust some test yamls in interfaces/mount tests, which are not valid as
they are for new top-level directories in /.

Finally, add an additional unit test for the test case with LP #1831010 that is
already covered by spread tests, but not yet by unit tests.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-07-06 22:36:47 -05:00
Samuele Pedroni
d3dd6e3afa cmd,many: move Version and bits related to snapd tools to snapdtool 2020-06-12 17:24:35 +02:00
Pawel Stolowski
befb1a6e74 Pass unnamed interfaces.SecurityBackendOptions argument to Initialize for backends that don't use it. 2020-02-19 09:33:24 +01:00
Pawel Stolowski
b87345b8bb Introduce interfaces.SecurityBackendOptions for passing Preseed mode flag to backends via Initialize(). Change maybeRestart to a method of snap manager. 2020-02-18 10:43:41 +01:00
Maciej Borzecki
2007905025 interfaces/mount: account for cgroup version when reporting supported features
Take into account the host's cgroup version when reporting mount backend
features.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2019-10-07 13:49:02 +02:00
Zygmunt Krynicki
ac1589cf7f osutil: rename MemoryBlob -> MemoryFileState
Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>
2019-09-27 18:32:36 +02:00
Zygmunt Krynicki
7876ce6f1e osutil: generalize SyncDir with FileState interface
The directory synchronization code grew out of the desire to have a set
of files described by a glob and short, in-memory contents be reflected
to the disk in an efficient and predictable way.

Recently this code has started to be used to install icon themes shipped
by snaps. This means it may be used to coerce snapd to read arbitrary
amount of data into memory.

This address this issue by generalizing the directory sync APIs to take
an interface instead of a concrete representation of the desired file.

There are now three concrete implementations, one that keeps the content
in memory, just like before, called MemoryBlob and two new ones:
FileReference and FileContentReference. Those both refer to an existing
file for content, opening up the possibility to refer to large files.
They only differ in the treatment of file mode, either mirroring the
mode of the file being referred or using a fixed mode, respectively.

Behind the scenes the EnsureFileState function will no longer read all
of the file into memory. Instead if will use FileReference to stream it,
chunk by chunk, in an attempt to see if the file is identical to what we
expected.

On top of that, if the file is not the same and the caller has provided
a FileReference or FileContentReference, the logic that writes a new
file and replaces the original is also using streaming, again saving a
in-memory copy.

This way we can now process files of arbitrary size using fixed amount
of memory. This involves the new icon wrapper which has been switched to
use FileContentReference.

The patch contains some verbose automatic changes around the code using
maps of FileState structure to replace them with maps of FileState
interface instead.

Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>
2019-09-27 13:46:33 +02:00
Zygmunt Krynicki
caa57b96a1 interfaces/mount: discard mount ns on backend Remove
When a snap is removed each security backend is asked to remove the
security profiles associated with the snap in question. For the mount
backend that would just remove the desired mount namespace profile.

While this part worked correctly there was more to be done. The system
may still have the preserved mount namespace as well as the actual
applied (current) mount profiles that exist therein.

In a case where a snap was installed but the installation failed because
of a hook issue, the system would be left in a state where an existing
mount namespace would be left behind.

Related-To: https://bugs.launchpad.net/snapd/+bug/1808821
Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>
2019-08-14 15:17:29 +02:00
Zygmunt Krynicki
c06fd4ea43 Merge pull request #6502 from zyga/feature/refresh-app-awareness-5
dirs,overlord/snapstate: add Soft and Hard refresh checks
2019-04-03 07:46:12 +02:00
Maciej Borzecki
42f175cb09 Merge remote-tracking branch 'origin/master' into bboozzoo/simplify-internal-tool-lookup 2019-03-28 14:58:09 +01:00
Zygmunt Krynicki
bb7a7b7141 snap/snaplock: move locking routines
The per-snap lock routines were defined in the mount interface package
long ago, when they were still used there. They are only referenced from
snap-update-ns now so it's sensible to move them.

I will need the same routine in overlord/snapstate so I picked
snap/snaplock (due to the dependency on osutil) as the appropriate
location.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2019-03-19 10:04:29 +01:00
Maciej Borzecki
08c0fad19b interfaces: replace custom internal-tool helpers with cmd.InternalToolPath()
Use a common helper for finding local tools.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2019-03-14 16:14:10 +01:00
Pawel Stolowski
3d42db9d0c Measurement -> Measurer 2019-03-13 17:19:35 +01:00
Pawel Stolowski
721196b56a Introduce an interface for Span/Timings. 2019-03-13 16:41:12 +01:00
Pawel Stolowski
a5bf6c84e4 Renaming. 2019-03-11 18:03:37 +01:00
Pawel Stolowski
79f3d87b42 Basic timings in interface manager. 2019-03-11 14:16:40 +01:00
Zygmunt Krynicki
86f737136d interfaces/mount: take layouts out of beta
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2018-09-27 09:10:56 +02:00
Maciej Borzecki
2ac586c47d many: mount namespace mapping for parallel installs of snaps (#5713)
Establish the necessary mappings for parallel installed snaps by updating the
mount profile of the snap. The change adds the following bind
mounts:

- /snap/foo_bar      -> /snap/foo
- /var/snap/foo_bar  -> /var/snap/foo

The mounts have `x-snapd.origin=overname` in the mount profile. 'Overname' mounts are applied before any other mounts.
2018-09-18 08:45:34 +02:00
Pawel Stolowski
53f11209fd NewConnectedPlug/NewConnectedSlot: take extra argument for static attributes. 2018-09-10 17:18:54 +02:00
Maciej Borzecki
0d78818222 interfaces: take instance name in ifacetest.InstallSnap (#5749) 2018-09-03 21:45:47 +01:00
Maciej Borzecki
57f6466755 interfaces/mount: tweak naming of things
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2018-08-31 10:50:21 +02:00
Maciej Borzecki
ff216577f3 many: rename snap.Info.Name() to snap.Info.InstanceName(), leave parallel-install TODOs
In preparation for parallel installation of snaps, introduce the necessary
rename of snap.Info.Name() to snap.Info.InstanceName(). The change is benign and
will make subsequent parallel installs reviews easier and smaller.

Leave TODO notes about possible issues with parallel installation where
possible.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2018-06-13 12:23:44 +02:00
Zygmunt Krynicki
49720ad446 interfaces/mount: add an extra test for clashing
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2018-06-11 13:34:52 +02:00
Zygmunt Krynicki
7d95441dd4 many: add "snap debug sandbox-features" and needed bits (#5142)
* many: add "snap debug sandbox" and needed bits

This patch adds a way to inspect the features of the sandbox from a new
hidden, debugging command. The command shows a set of tags for each of
the security backends that are in use.

Having access to this command helps in two ways:

First of all, this is far more comprehensive and informative than the
very dry "partial" vs "full" output of "snap debug confinement". Snapd
offers a wide range of confinement technologies when used on a mainline
kernel and this should be celebrated.

Second of all having this allows us to write more precise tests. If a
test needs to be skipped because a specific thing is absent can now be
codified directly. This will allow both Debian and openSUSE to run far
more confinement-specific tests than we currently do simply because
"partial" apparmor is reported. Mainline kernel is very close to full
apparmor patch used by Ubuntu and the remaining differences don't apply
to many existing tests.

Technically this patch adds the key "sandbox", defined as a map of lists
of strings, to the sysinfo API and uses it in the new hidden command.
Each of the security backends can now optionally offer sandbox tags that
are associated with the backend name in the said map.

* interfaces: namespace kernel features with "kernel:"

This arrangement will allow the seccomp and apparmor backends to report
additional sandbox feature tags without risking any clash with kernel
reported things.

* interfaces/seccomp: return at least one sandbox tag from seccomp

In case the kernel doesn't advertise seccomp kernel features we don't
want to make the seccomp backend appear as missing or unused. Add an
explicitly managed tag to achieve that.

* interfaces/apparmor: dbus mediates more than just bus names

* many: rename sandbox tags to sandbox features

* cmd/snap: add support for "sandbox-features --required=..."

This patch allows using the sandbox-features command for simple
scripting, especially in spread tests, where we could check if a given
sandbox feature is present before checking confinement is effective.

* tests: fix and expand sandbox-features tests

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2018-05-14 20:08:27 +02:00
Zygmunt Krynicki
63f939135d osutil,interfaces,cmd: use less hardcoded strings (#5086)
This patch changes various mount related code to use functions that
access or create various x-snapd.foo mount options. This should lessen
the chance of any typo sneaking past code reviews.

The test suite is also improved to be more consistent and complete with
regards to code coverage.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2018-04-26 08:20:06 +02:00