Commit Graph

1959 Commits

Author SHA1 Message Date
Bastien Nocera
6b46d9a0ed common: Allow skewering when converting in app-id for DConf migration
Allow a snake-case in the app-id to convert to a '-' or '_' in the
DConf path to be considered similar enough for DConf migration purposes.

This allows the org.gnome.SoundJuicer app-id to migrate its
/org/gnome/sound-juicer DConf path.

F: Ignoring D-Conf migrate-path setting /org/gnome/sound-juicer/
2020-09-15 08:59:53 +02:00
Bastien Nocera
c6802d2c0e common: Prepare DConf path parsing for changes
Separate the variables used to keep track of which character we were
checking in each of the paths.

No functional changes.
2020-09-15 08:59:53 +02:00
Phaedrus Leeds
92742d8387 dir: Remove superfluous flatpak_dir_ensure_repo()
This is no longer needed since a FlatpakRemoteState is passed in, which
ensures the repo exists. The similar call was already removed from
flatpak_dir_install().
2020-09-15 08:58:49 +02:00
Phaedrus Leeds
08f692962e Avoid shadowing local variables
Avoid shadowing variables that are already declared in a previous scope,
and make such occurrences compile-time errors. These are not functional
changes.

In a few places do related code cleanup.

A similar ostree PR is here:
https://github.com/ostreedev/ostree/pull/2195
2020-09-15 08:58:49 +02:00
Simon McVittie
5af5700af8 exports: Allow redirecting /etc, /usr from the host to an alternative
This is primarily for test coverage ("design for test"): it will let us
pretend a temporary directory is the host for the purposes of testing
--filesystem=host-etc, --filesystem=host-os, and the os-release handling
from #3733.

It can also be used to build a bwrap command-line that will be used on
the host, while already inside a container, which will be useful for
Steam's pressure-vessel tool (which copies some of the Flatpak code).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-09-14 11:12:25 +02:00
Phaedrus Leeds
238317d99b Avoid critical error in remote-info command
Without this patch, the remote-info command will sometimes emit a
critical error "g_utf8_strlen: assertion 'p != NULL || max == 0' failed"
and print (null) for the "Commit:" field, since the commit doesn't get
initialized properly.
2020-09-14 09:32:27 +02:00
Alexander Larsson
d8086141fb Don't loop authentincating if updating to the current version
In case we need to authenticate for updates (in my test case i was
doing an OCI downgrade) we might need to download a commit object (or
in the OCI case a manifest json), so it did a request_required_tokens(),
but that noticed during the flatpak_transaction_normalize_ops() call
that the partial resolve to a particular commit actually was the
same as the local installed commit and marked op->skip = TRUE.

However, when we got back to resolving the op again we didn't actually
look at the skip, so it kept looping wanting (but never doing) auth.

The fix is to just directly resolve ops marked as skipped.
2020-09-14 09:30:30 +02:00
Alexander Larsson
7622aab962 OCI: Fix progress reporting
Somewhere during the progress reporting cleanup we lost the progress
for OCI pulls, this puts it back.
2020-09-14 09:30:14 +02:00
Owen W. Taylor
25ff00994f OCI: extract appstream data for runtimes
Runtimes also have appstream data - with description, license information,
and so forth, so we should extract the appstream data from the index
for refs that start with runtime/ as well.
2020-09-11 09:35:05 +02:00
Phaedrus Leeds
a70b7a7628 installation: Clarify that SDKs aren't considered used
The docs claimed that SDK runtimes are considered used even if there is
no app using them or runtime for which they are the SDK, but the
implementation does not match that.

We could change the implementation to always consider SDK runtimes used,
but that would be problematic because some apps use an SDK as their
runtime, and in that case the runtime would persist forever after the
app is uninstalled, instead of eventually being garbage collected by the
subsequent commits to this one.
2020-08-31 16:29:03 +02:00
Phaedrus Leeds
097faa8411 uninstall: Note pinned runtimes in --unused output
When "flatpak uninstall --unused" is run, we don't remove unused
runtimes that are pinned. List them in the output so the user knows they
are being left installed.

This commit also adds new library API,
flatpak_installation_list_pinned_refs().
2020-08-31 16:29:03 +02:00
Phaedrus Leeds
7cd1990196 Automatically pin explicitly installed runtimes
If a runtime is installed explicitly rather than as a dependency, pin it
so it doesn't get automatically removed when unused runtimes are being
removed. We do this because the runtime might be installed for
development or other uses.

This commit also rearranges some code in the mask and pin commands, and
adds a unit test.
2020-08-31 16:29:03 +02:00
Matthew Leeds
d2d5397cc1 Add pin command to keep unused runtimes
As discussed here [1], we want a way to mark runtimes to be kept even
when they are unused by any apps and we are removing such runtimes.
Currently this is a command that can be run manually; a subsequent
commit will pin runtimes automatically if they are installed
independently of any app.

A unit test is included.

[1] https://github.com/flatpak/flatpak/issues/2639#issuecomment-662311756
2020-08-31 16:29:03 +02:00
Phaedrus Leeds
84a8c30e55 transaction: Remove an unused error parameter 2020-08-31 16:26:12 +02:00
Phaedrus Leeds
c6647c2b14 transaction: Fix ordering of runtime uninstallation
In case a transaction is uninstalling both an app and its runtime,
properly ensure the app is uninstalled first.
2020-08-31 16:26:12 +02:00
Phaedrus Leeds
ebcad3a402 dir: Fix a typo of .changed 2020-08-31 16:26:12 +02:00
Simon McVittie
5a83c73ed8 context: Implement MODE_NONE in unparse_filesystem_flags
flatpak doesn't yet use -Wswitch-enum, but perhaps it should at some
point. Now that FLATPAK_FILESYSTEM_MODE_NONE is a member of the enum,
it should be handled; and if we're doing that, we might as well make
the same function fully responsible for it.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-28 11:00:49 +02:00
Simon McVittie
09424423b9 context: Normalize home/path to ~/path, and ~ to home
Historically we didn't accept them, but there's no real reason why not.
They're normalized to the form in which earlier Flatpak releases would
want to see them.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 17:48:50 +02:00
Simon McVittie
02094b4f39 context: Forbid --filesystem=/
Making it an equivalent of --filesystem=host would be misleading,
because it wouldn't do what you'd think it does: host mounts some host
system directories in their usual places, but others below /run/host.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 17:48:50 +02:00
Simon McVittie
aafe1d36e0 context: Do some syntactic normalization on filesystems
Paths containing ".." are rejected: they're almost certainly a
terrible idea.

Paths containing "." or multiple slashes are syntactically normalized.

This assumes that nobody is going to use "--filesystem=/foo/bar/" to
mean "make /foo/bar available, unless it's a non-directory, in which
case fail".

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 17:48:50 +02:00
Simon McVittie
55b27b1393 context: Expose flatpak_context_parse_filesystem for testing
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 17:48:50 +02:00
Simon McVittie
115d82e6ff exports: Add assertions to distinguish between mode representations
When we're talking about a "mode", sometimes we mean a
FlatpakFilesystemMode, sometimes we mean a FlatpakFilesystemMode that
must be strictly greater than NONE, and sometimes we're willing to
accept the FAKE_MODE constants too.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 17:48:50 +02:00
Simon McVittie
517ad25b5f context: Only parse filesystem/mode strings in one place
This gives us the ability for the parse function (the former verify
function) to carry out a normalization step as well.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 17:48:50 +02:00
Simon McVittie
414671a666 run: Tell processes in container that the container manager is Flatpak
https://systemd.io/CONTAINER_INTERFACE/ describes a generic way to tell
programs and libraries that they are running in a container: set
pid 1's ${container} to the name of the container manager in lower case,
and populate /run/host/container-manager with the same string followed
by a newline. Let's be nice to application code by doing that, instead
of requiring it to look at /.flatpak-info.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-27 11:29:52 +02:00
Philip Withnall
78a2e45610 flatpak-dir: Pass cached summary{,.sig} to OSTree
This allows OSTree to avoid re-checking the `summary.sig` for freshness
once per pull in a transaction, since flatpak has already done that.
This avoids latency in a transaction (especially on high latency or
lossy network connections) and avoids the potential race condition of
the `summary` file changing on the server part-way through a
transaction.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-24 08:58:08 +02:00
Philip Withnall
95bef8e4a5 flatpak-dir: Cache the summary GBytes in FlatpakRemoteState
`FlatpakRemoteState` already caches the parsed `GVariant` form of the
summary, but it will be useful (in the following commits) to also have a
pointer to the `GBytes` which backs that variant. The `GBytes` will be
passed into OSTree in the following commits, to allow it to avoid
unnecessarily re-downloading the `summary` file.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-24 08:58:08 +02:00
Philip Withnall
d57db7074b flatpak-transaction: Don’t update metadata when uninstalling
When uninstalling a single app (an example of a transaction which is
entirely local-only), there’s no need to update the repository metadata
beforehand — but the code was doing that.

This avoids an unnecessary download of the `summary.sig` file (or other
repository metadata, depending on what’s out of date) when uninstalling.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-24 08:58:08 +02:00
Philip Withnall
254a885879 dir: Clarify a comment about caching
`flatpak-dir.c` supports two caches for `summary{,.sig}` files: one in
memory (per `FlatpakDir` instance) and one on disk (shared between all
users of the repository). Clarify in this comment which one is being
referred to.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-24 08:58:08 +02:00
Philip Withnall
98e372e85e dir: Tidy up definition of cache timeout
Adding brackets makes it a little more obvious that it’s 5 minutes, and
less likely that operator precedence where the macro is used will result
in the wrong value being calculated.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-24 08:58:08 +02:00
Philip Withnall
63b4f3a5c1 dir: Fix caching of summary files
Cache hits didn’t result in the cache entry’s timeout being extended,
and timeouts didn’t result in the entry being removed from the cache to
free up resources (even though it would never be returned as a cache hit
again).

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-24 08:58:08 +02:00
Philip Withnall
9bec865995 dir: Fix potential overflow when comparing cache timeouts
Also use a constant to clarify the code a little, although it’s
functionally equivalent.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-24 08:58:08 +02:00
Phaedrus Leeds
332f75494b Properly validate configured collection IDs
This commit is a follow-up for the commit "dir: Validate locally
configured collection IDs". Whereas in that commit we validate the
collection ID in flatpak_remote_state_fetch_commit_object(), here we do
it in _flatpak_dir_get_remote_state(), since fetch_commit_object() is
not called on the code path normally taken for a transaction (only if
try_resolve_op_from_metadata() fails and in other niche scenarios).

This should ensure that if someone erroneously sets a collection ID on a
remote, the error will be caught quickly. It also helps the eos-updater
unit tests pass.
2020-08-21 09:35:49 +02:00
Alexander Larsson
83f11317e6 Allow multiarch in the apply_extra for extra-data
Some things could need to run e.g. i386 code in apply_extra (for
example #3742).  In this very limited context (almost everything is
read-only) this seems pretty secure.

We could require the app to specify a multiarch pemission to allow
this, but such permissions only really make sense for an app, and
extra data is often used for other things like runtimes and
extensions, that seems a bit weird.  Lets just enable it always.
2020-08-20 16:44:39 +02:00
Alexander Larsson
8c23c90c1e run: Fix double free in the cups config file parser
We were returning a g_autofree:d string and it was then also freed
by the parent.
2020-08-18 11:55:43 +02:00
Ryan Gonzalez
c95cb1973d run: Avoid hanging if xdg-dbus-proxy startup fails 2020-08-17 15:52:30 +02:00
Alexander Larsson
87a44588d6 dir: Cache responses from localed and account service
These are system dbus calls that could potentially be somewhat slow
and its unlikely that the local config changes during runtime of the
session (because the desktop really needs a restart to pick up a new
locale). Also, if there are any issues with these (such as #3755) each
call will be the 25sec dbus timeout, which is not great.

Fixes https://github.com/flatpak/flatpak/issues/3792
2020-08-17 14:27:02 +02:00
Matthew Leeds
845a877ce1 Prioritize an app's origin for its runtime
Currently when searching for a remote to provide the runtime for an app,
we search remotes in priority order. This commit makes it so we search
the remote providing the app before others with the same priority, and
otherwise still search in priority order.  This means for the common
case where every remote has the default priority of 1, the app's origin
will have the first chance to provide the runtime. This behavior seems
logical, but the impetus for this change was also to keep a unit test
passing in eos-updater[1] after a port to FlatpakTransaction.

Originally the eos-updater unit test was written to prioritize the
origin remote regardless of the priorities on any other remote, but
during code review it was decided to let higher priority remotes stay
above the app's origin.

In practice it's usually true that only one remote provides a runtime
and priorities aren't set at all, so this is an edge case that probably
doesn't come up much.

A unit test and documentation updates are included.

[1] eede0a8b9c/tests/test-update-install-flatpaks.c (L1919)
2020-08-17 09:21:30 +02:00
Simon McVittie
12e3dc051f exports: Try harder to export usrmerge symlinks as symlinks
In applications with --filesystem=host or --filesystem=host-os, the
library directories in /run/host/usr and /run/host/lib* can be used
like a sysroot to inspect the host's library stack, regardless of
whether the host system has undergone the "/usr merge" or not. This is
particularly relevant for Steam's pressure-vessel container tool,
which imports graphics drivers from the host system, or for potential
future work on using host graphics drivers via libcapsule in Flatpak
apps.

The original implementation of this feature assumed that the /usr merge
always creates symbolic links /foo -> /usr/foo or /foo -> usr/foo, for
some value of foo. However, Arch Linux uses a variation of multilib
in which /usr/lib contains 64-bit libraries, and has a non-matching
symbolic link /lib64 -> usr/lib (instead of a chain of symlinks
/lib64 -> usr/lib64 -> lib). Similarly, Arch uses /sbin -> usr/bin
and /usr/sbin -> bin, instead of a chain of symlinks
/sbin -> usr/sbin -> bin.

This led to Flatpak ignoring the symlink and treating it like a directory,
so the host /usr/lib would be bind-mounted on both /run/host/usr/lib and
/run/host/lib64. This is *mostly* equivalent, but whether a directory
is a symlink or a real directory sometimes matters, for example when
evaluating relative symlinks that contain ".."  components; so try harder
to preserve symlinks as symlinks.

Fixes: 08d65c54 "exports: If --filesystem=host, provide /run/host/lib etc."
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-11 15:48:05 +02:00
Philip Withnall
af6842b237 http-utils: Stop exporting an internal error quark
This made its way into the Debian symbols file, but looks like it was
never supposed to be exported.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-10 15:20:59 +02:00
Julian Andres Klode
8ba141c38f Fix argument order of clone() for s390x in seccomp filter
clone() is a mad syscall with about 4 different argument orders. While
most of them agree that argument 0 is flags, s390 and s390x have the
flags argument second - A0 is the child stack pointer there.

[smcv: Add an explanatory comment; also test __CRIS__ for completeness]

Bug-Debian: https://bugs.debian.org/964541
Bug-Ubuntu: https://launchpad.net/bugs/1886814
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-10 15:08:32 +02:00
Jacob Weisz
161ad85ff6 Fix libseccomp Google Groups link
Otherwise it just bounces you to the Google Groups home page.
2020-08-06 11:54:15 -05:00
Luca Boccassi
7872935e12 run: implement sandbox host os-release interface
If available, always read-only bind-mount /etc/os-release as
/run/host/os-release (or /usr/lib/os-release as fallback)
as suggested by the os-release specification:

https://www.freedesktop.org/software/systemd/man/os-release.html
2020-07-24 10:28:30 +02:00
Matthew Leeds
1bf5f2ed9e dir: Validate locally configured collection IDs
Currently if the user configures a collection ID on a remote which is
incorrect, either because it doesn't match the one configured server
side or because the server doesn't have one configured at all, Flatpak
will not notice the issue and happily still pull from the remote. This
is new since 1.7.1; before that such a problem would be caught because
the server wouldn't provide the ostree-metadata ref for the configured
collection ID.

This commit catches such errors by checking commit metadata, as we
already do for the ref binding metadata. Otherwise such a mismatch would
prevent successful offline distribution of the apps/runtimes provided by
the remote.

The impetus for this is to keep an eos-updater unit test passing with
Flatpak 1.8.x:
"/updater/install-flatpaks-pull-to-repo-error-if-collection-id-invalid"
2020-07-23 11:29:13 +02:00
Matthew Leeds
1841803ef3 Fix typos in a comment 2020-07-21 09:02:18 +02:00
Matthew Leeds
b17bf86dee More fully reset remote in unit tests
Don't leave options set on the remote in one of the unit tests. If
something should be set for every test it should be done in
global_setup(). This commit also changes the FlatpakRemote
implementation to allow unsetting title and default branch.
2020-07-21 08:59:22 +02:00
Matthew Leeds
2b9c6616ff transaction: Update get_operations() docs
Document that operations are executed in the same order they are
returned because gnome-software is depending on that:
cf5656031f/plugins/flatpak/gs-flatpak-transaction.c (L279)
2020-07-06 15:29:30 -07:00
Ryan Gonzalez
9833b90019 run: Don't use userns2 if same as userns
When --device=all is *not* passed to Flatpak, --dev is passed to bwrap,
which causes it to use an intermediate user namespace to mount devpts
because it can only be mounted as UID 0. Therefore, when expose-pids
is used, Flatpak will pass both --userns *and* --userns2 to handle
the presence of the intermediate namespace.

However, when --device=all *is* passed, there is no intermediate
namespace. Thus, setns(userns2) will fail with EINVAL. In order to
handle this, --userns2 is no longer passed if the namespace is
identical to that passed via --userns.

Fixes #3722.
2020-07-03 09:36:06 +02:00
Alexander Larsson
b283abe491 transaction: Don't fail if install returns ALREADY_INSTALLED
We already verify that the ref is not installed on add_ref(), so we
did check for "user error". If the transaction either raced with some
other process, or the install from the install-authentitcator signal
that should not be treated as an error.
2020-06-30 16:13:51 +02:00
Alexander Larsson
012f6de1f8 transaction: No need to authenticate when an op just is a redeploy 2020-06-30 16:13:51 +02:00
Alexander Larsson
4f139467c2 transaction: Avoid authentication for no-op updates
Ensure we normalize ops before requesting authentication so we
can trust the op->skip value to be set for no-op updates (which
don't need authentication).
2020-06-30 16:13:51 +02:00