Commit Graph

5385 Commits

Author SHA1 Message Date
Alexander Larsson
3d47dc02fa p2p: When updating/installing, resolve via ostree-metadata if possible
If the commit is available in the ostree-metadata and it matches what
the latest available commit in the p2p results then resolve it to that, so
we don't have to download the commit object.
2019-11-26 16:37:01 +01:00
Alexander Larsson
54415b79c7 p2p: Add flatpak_dir_resolve_maybe_resolve_from_metadata
This tries to resolve the p2p resolve operation from the info in
a ostree-metadata commit. This only works if the resolve ended up
on the same commit id as what was available in the ostree-metadata
which may not be correct if the two are not synchronized.
2019-11-26 16:37:01 +01:00
Alexander Larsson
7f5ed5020f p2p resolve: Resolve the token_type data from the commit 2019-11-26 16:37:01 +01:00
Alexander Larsson
f51cb45a4f tests: Add initial tests for token-needing installs 2019-11-26 16:37:01 +01:00
Alexander Larsson
c8e1ba41e1 Transaction: non-p2p support for tokens
We extract the need-token key from the summary and if set we
calculate a token to use for the operation, which we then pass
to install/update.

For now the actual token just comes from the FLATPAK_TEST_TOKEN
environment var. The details of this will be fleshed out later.

Additionally, this does not support the p2p case, because there
we need the token in order to request the commit during the resolve.
This will also be added later.
2019-11-26 16:37:01 +01:00
Alexander Larsson
077006ecc8 Add token-type per-commit metadata key and export it to summary
We store this in the sparse cache, because we don't expect it to be
set for everything.
2019-11-26 16:37:01 +01:00
Alexander Larsson
86ccfd9b99 Add support for bearer tokens to flatpak_dir_install/update
Anything passed in here will be added as a bearer token for all http
requests in the operation.
2019-11-26 16:37:01 +01:00
Alexander Larsson
99ce123215 transaction: Break out some shared code.
This moves some code into helper functions so it can be easily shared.
No behavioural change.
2019-11-26 16:37:01 +01:00
Alexander Larsson
e2379d20e2 Optionally return commit id in flatpak_remote_state_lookup_cache
This will only work if xa.commits is in the metadata, which is only
available in the p2p case and was only added recently.
2019-11-26 16:37:01 +01:00
Alexander Larsson
b1eaad3fa2 p2p: Generate xa.commits array in ostree-metadata
This is in the same order as the xa.cache array and contains the id of
the commit that the cached data is about. This is not necessary in the
non-p2p summary metadata, because in that we always have a matching
ref -> commit array.

However, in the p2p case this information can be useful.
2019-11-26 16:37:01 +01:00
Alexander Larsson
64f8a26e33 prepare_resolve_p2p() return last_remote_commit
We want this in the transaction code, to see what commit would
be pulled, and thus if the data in the ostree-metadata is good enough
2019-11-26 16:37:01 +01:00
Alexander Larsson
5a01ff44d6 dir: Split up the p2p resolve code into two phases
Historically the p2p resolve code always did a parallel call to find
all the available commits for the refs, and then it took the results
and pulled only the commits for all the refs so that it could resolve
against the exact commits that were available (which might not match
with whatever metadata we have in the local ostree-metadata copy.

This splits this into two phases, the first that uses the summary only,
and a second one that pulls the commit.

The reason for this is that we want to be able to do some stuff inbetween
these, such as resolving some refs via the ostree-metadata and maybe
requesting bearer tokens that we need for pulling the commit objects.
2019-11-26 16:37:01 +01:00
Alexander Larsson
3c74199549 Print errors on stderr in install/update
If we're not doing fancy ui, print errors on stderr. This was biting me
in some tests where I'd like to grep for some strings in the stderr
output.
2019-11-26 16:37:01 +01:00
Alexander Larsson
2db1c6e6c4 Add defines for existing summary sparse cache keys
These are explicitly made short to save space, so lets have defines
for them to make sure we don't mistype them, especially as we
will be adding new keys.
2019-11-26 16:37:01 +01:00
Alexander Larsson
ca5ba625a5 libtest.sh: Add gdb_bt helper
This is unused, but can be inserted in the tests if something is
segfaulting so that you can see the backtrace.
2019-11-26 16:37:01 +01:00
Alexander Larsson
0af4249c60 Don't pull dependencies for extension points unless strictly needed
These were added so that extra-data would work in #2954, however that
was a bit broad. We only need extension deps for extensions that:
1) Uses extra data (so we can run apply-extra)
2) Doesn't specify NoRuntime=true (because the apply-extra is static)

Fixes https://github.com/flatpak/flatpak/issues/3173
2019-11-26 10:19:55 +01:00
Alexander Larsson
c486cc461e run: Document the sandbox related swtiches 2019-11-26 09:52:07 +01:00
Alexander Larsson
834c23edc6 portal: Add sandbox-expose-fd[-ro] options that allow you to share any path
I you can open(O_PATH) any path in your sandbox you can now share that
with the sub-sandbox.
2019-11-26 09:52:07 +01:00
Alexander Larsson
7dad37f1b3 portal: Spawn clean up handling of file descriptors
We were using i instead of handle to index the file descriptors, which
is likely to be the same (due to ordering) but not really
correct. Also rename the variables to make this code easier to read.

Also, add some bounds check on the handles wrt the fd list.
2019-11-26 09:52:07 +01:00
Alexander Larsson
080a5c07a1 portal: Add sandbox flags for allowing ally/ and session bus access 2019-11-26 09:52:07 +01:00
Alexander Larsson
921d1c9b87 run: In sandboxed mode, if still allowing dbus, only allow $appid.Sandboxed.*
This means sandboxes with dbus access can use portals etc, but they can't
talk to the main app, or impersonate it, but you can still use dbus and
well-known names to talk to them if needed.

It does mean however that if you use this, different sandboxes can see each
other on the bus, so be careful.
2019-11-26 09:52:07 +01:00
Alexander Larsson
8cc737466f run: Allow overriding no-a11y/dbus for sandboxed runs 2019-11-26 09:52:07 +01:00
Alexander Larsson
66b2621297 run: Clean up code that sets flags
No changes, just make the code easier to read by using ifs
instead of a bunch of ?: ops.
2019-11-26 09:52:07 +01:00
Alexander Larsson
fa1bc8ca16 portal: Add flags for sharing display/sound/gpu when spawning sandboxed
This allows you to open up things (if the calling app has access) for
the sandboxed child.

Rather than duplicating all possible sandboxing technical details we
specify things at a higher level. We just assume you want the same
access as the caller (i.e. x11[-fallback] and/or wayland), as this is
easier to use for the caller and more flexible for us to later add new
technical details as needed.
2019-11-26 09:52:07 +01:00
Alexander Larsson
7071c38acf portal: Bump portal version to 3 (to signal new flag supported) 2019-11-26 09:52:07 +01:00
Matthias Clasen
d4b3694609 Document the flatpak-spawn --watch-bus option
This was missing from the man page.
2019-11-26 09:51:46 +01:00
Matthias Clasen
ad87b12264 Make per-user icon themes available in the sandbox
Mount ~/.local/share/icons at /run/host/user-share/icons in
the sandbox, so runtimes can add /run/host/user-share to
their XDG_DATA_DIRS and get access to locally-installed
icon themes.
2019-11-25 20:21:02 +01:00
Matthias Clasen
2561832c0a Merge pull request #3244 from piotrdrag/piotrdrag/update-potfiles-191124
Update POTFILES.in 191124
2019-11-24 11:56:19 -05:00
Piotr Drąg
61a4fa5308 Update POTFILES.in 2019-11-24 12:33:25 +01:00
Matthias Clasen
c503307ae0 Use DeletePermission when available
This avoids a racy client-side implementation.
2019-11-22 16:35:43 +01:00
Matthias Clasen
43a538e0a4 Update the permission store xml
Version 2 adds a new DeletePermission method.
2019-11-22 16:35:43 +01:00
Umang Jain
ceab716ab6 installation: Mark apps as updatable if their runtime is missing
Mark installed apps to be updatable if an installed in missing
its runtime for some reasons. In pre-FlatpakTransaction world,
an app migration from runtime X to runtime Y would have rendered
an app unusable because runtime Y would not be installed
automatically by clients like gnome-software.

The goal here is that clients like gnome-software can show
those installed apps as updatable again, if such a situation
arises. The FlatpakTransaction API can automatically resolve one of
its ops to install the new runtime, provided we can mark the app
as updatable again at the first place.
2019-11-22 16:08:32 +01:00
Umang Jain
61f9d19eae installation: Return refs as updatable if related extensions are missing
While updating, if the related extension is missing on
the installation of an installed ref (could be an app or
runtime), FlatpakTransaction tends to "repair" the ref by
automatically downloading the related extension again and
restoring the overall functionality of the ref.

The related extension concerned that are the ones associated with
`should-download` to TRUE only.

Hence, teach the libflatpak API to do that same, so that clients
like gnome-software can mark those refs as updatable, if their
related extensions is missing.
2019-11-22 16:08:32 +01:00
Umang Jain
c76dca8550 test-list-updates: Update to use FlatpakTransaction
FlatpakTransaction will automatically download the related ref
(.Locale ref in this case). In case of mentioning previous-ids
in the deploy file, the related ref(.Locale) should be also
be requiring an update.
Hence, flatpak_installation_list_installed_refs_for_update now
will return 2 refs (app and related .Locale extension) to be
updated, instead of 1.
2019-11-22 16:08:32 +01:00
Philip Chimento
91f1280e73 utils: Check outstanding-extra-data in progress callback early return
The previous code checked whether the progress object had
"outstanding-fetches" set in order to decide whether it had been
initialized enough to show progress information. However, if the
callback saw a progress object on which flatpak_dir_setup_extra_data()
had not yet been called, then it would crash.

Therefore it seems that we should additionally be checking for the
presence of "outstanding-extra-data" which is set in
flatpak_dir_setup_extra_data().

It's likely that this wasn't previously a problem because the callback
would never get called due to the progress object's associated main
context not being iterated. It crashes now because that problem was
fixed in a previous commit.
2019-11-22 16:03:26 +01:00
Philip Chimento
529783e56b dir: Fix varargs argument width mismatch
Previously, in flatpak_dir_setup_extra_data(), n_extra_data (a gsize
which is 8 bytes wide on x86_64) was passed in a varargs list where an
unsigned int (4 bytes wide) was expected due to the "u" variant type
specifier.

This doesn't seem to have directly caused any crashes for me, but it's
undefined behaviour.

Therefore, this changes the affected keys "outstanding-extra-data" and
"total-extra-data" to be guint64 types instead of unsigned ints. The
gsize returned from g_variant_n_children() is cast to guint64 by virtue
of being assigned to a guint64-typed variable, but should not lose any
bits on supported platforms.
2019-11-22 16:03:26 +01:00
Philip Chimento
6b2c47a334 utils: Allow chaining OstreeAsyncProgress when pushing GMainContext
It's a common idiom in this codebase to push a temporary GMainContext as
the thread default context in order to run an async operation as if it
were sync. If we are not expecting progress callbacks this isn't a
problem, but it becomes a problem if we pass in an OstreeAsyncProgress
object that was created under a different GMainContext. The reason for
this is that OstreeAsyncProgress creates an idle source and attaches it
to the thread default context, so if we are iterating a temporary
context then the OstreeAsyncProgress's context never gets iterated, and
so no progress signals are fired.

To fix this, we introduce flatpak_progress_chain() and a RAII helper
FlatpakAsyncProgressChained which creates a new OstreeAsyncProgress
under the temporary GMainContext, but forwards all its state and updates
to the previous OstreeAsyncProgress's callbacks.

This is documented in a comment in the code as well.

All known instances of this problem in the existing code are fixed in
this commit.

This uses new API in libostree which is proposed in
ostreedev/ostree#1968. In anticipation of it being included in libostree
version 2019.6, the bug fix is predicated on that version being present.
If compiling against an older version, the old buggy behaviour will be
the fallback.

This problem was solved conceptually by Philip Withnall, I only wrote
the code.
2019-11-22 16:03:26 +01:00
Matthias Clasen
bb5b2de3f1 install: Always show the op column
Otherwise, it is not clear what changes the question below
the table refers to.

Fixes: https://github.com/flatpak/flatpak/issues/3075
2019-11-21 13:49:30 +01:00
Matthias Clasen
c917257a1c permission-remove: Allow removing a single row
Allow specifying an app-id to remove from a given
id in a given table.
2019-11-21 13:48:31 +01:00
Matthias Clasen
5a8489cefe Add a permission-set command
This command adds permissions for an app to one of the permission
store database(s).
2019-11-21 13:48:31 +01:00
Alexander Larsson
4718bcccfd enter: Make sure sudo -E works when using setuid brwap
This also updates the manpage so it is correct wrt permissions and
sudo.
2019-11-20 13:17:43 +01:00
Alexander Larsson
6d68094879 enter: Better error values if enter is not supported on your kernel 2019-11-20 13:17:43 +01:00
Alexander Larsson
a094aa0040 enter: Add comment about why NS_GET_USERNS ioctl is not used 2019-11-20 13:17:43 +01:00
Alexander Larsson
47e2718833 enter: Clean up namespace equality checks
There is no need to read the links, just look at the inode nr
which is the same info, and that also works on the bind-mounted
.userns thing where readlink fails.

Also, don't fail for non-existing namespaces.
2019-11-20 13:17:43 +01:00
Alexander Larsson
a0cb7f6964 enter: No need to fail if a pid is specified that it is not the primary pid.
We can enter from any pid in the sandbox.
2019-11-20 13:17:43 +01:00
Alexander Larsson
f568a068c6 enter: Support non-root flatpak enter
Assuming unprivileged namespaces works we can now user the .userns
bindmount to access the intermediate bubblewrap user namespace.

This also drops the warning about root, and make sure we drop all caps
at the end.
2019-11-20 13:17:43 +01:00
Alexander Larsson
e16b40dfec enter: Use the correct pid (child pid) as the target for entering
This is the one in a namespace, the other one is just the wrapper.
2019-11-20 13:17:43 +01:00
Alexander Larsson
180494ca41 run: Don't install polkit agent for enter/run/build
Neither of these ever need a polkit agent, and run/build are somewhat
performance sensitive and we don't want to connect to dbus unnecessarily.
For enter this is critical though, as the dbus connection starts a thread
which is not compatible with the setns syscall.
2019-11-20 13:17:43 +01:00
Alexander Larsson
7079c6c722 run: Keep around base user namespace reference in /run/.userns
There is a kernel issue which has been fixed in linux 4.9:
 e98d413703
Which makes it impossible (on older kernels) to mount devpts unless
uid 0 is mapped in the user namespace. Bubblewrap works around this
by using two namespaces, the base one which sets up everything (and
thus owns all the other namespaces), and then at the end a child of that
that remaps uid 0 to the real uid.

Unfortunately, this makes it impossible to enter the bubblewrap user
namespace, because there are no references to the intermediate
user namespace we can use. To work around this we make a bind mount
of the intermediate namespace during setup using --ro-bind-try which
we can use for nsenter.
2019-11-20 13:17:43 +01:00
Alexander Larsson
6df104837c Require bubblewrap 0.3.1 for --bind-try support
We want to use this to work around some stuff for flatpak enter to work.
2019-11-20 13:17:43 +01:00