Commit Graph

1248 Commits

Author SHA1 Message Date
Matthew Leeds
8ba74182bc installation: Fix a mistake in the docs 2018-08-31 10:34:54 -07:00
Matthias Clasen
b3c07c5397 Add private api to remove an override file
This uses the same logic as the other override
functions to determine where the file is.

Closes: #2041
Approved by: alexlarsson
2018-08-29 14:58:15 +00:00
Matthias Clasen
c3e0471133 Tell bubblewrap to write info
Create a bwrapinfo.json file and tell bubblewrap
to write its 'info' there. For now, this just contains
the child-pid. More may appear over time.

Closes: #2039
Approved by: alexlarsson
2018-08-29 14:46:47 +00:00
Alexander Larsson
e2a79a275d Fix build with glib < 2.50
G_PID_FORMAT was added in glib 2.50, but pids are always %d on linux,
so we can avoid using it.

Closes: #2042
Approved by: alexlarsson
2018-08-29 07:21:26 +00:00
Matthew Leeds
e9d9f54ab8 common/installation: Search dynamic remotes for appstream2 also
Flatpak has API called flatpak_installation_list_remotes_by_type() which
can list dynamic (LAN/USB) remotes that mirror configured remotes in an
installation. It does this by searching them for the appstream/<arch>
ref, such as appstream/x86_64. But Flatpak now supports
appstream2/<arch> as a way to provide the appstream data as uncompressed
XML, and it's possible that a USB created with `flatpak create-usb` (or
a LAN peer) only has the appstream2 ref available for a certain
collection ID. So this commit changes
list_remotes_for_configured_remote() so that it looks for both
appstream/<arch> and appstream2/<arch>, which makes
flatpak_installation_list_remotes_by_type() robust to that scenario.
2018-08-28 10:05:18 +02:00
Matthias Clasen
2d26cc07c2 Export flatpak_run_gc_ids()
Currently, we only remove stale instance directories
when a new instance ID is allocated. A future 'flatpak ps'
command will want to remove stale instances before
enumerating them, so make this function available.

Closes: #2023
Approved by: alexlarsson
2018-08-27 14:25:15 +00:00
Matthias Clasen
95e5b394c2 Save a pid for running sandboxes
Store the pid of the bwrap process which gets spawned or exec'ed
by flatpak inside the instance directory. This can be useful
for others, such as gnome-software, or a future 'flatpak ps'
command.

We write the pid to a file named 'pid'. It will get cleaned
up together with the instance directory.

Closes: #2023
Approved by: alexlarsson
2018-08-27 14:25:15 +00:00
Matthias Clasen
06e8830377 Keep the .flatpak-info file accessible
The information in this file is of interest to other
users outside the sandbox, like gnome-software, or
a possible future 'flatpak ps' command.

We use the already existing instance directory, and
put the file at /run/user/$UID/.flatpak/$INSTANCE/info

The existing logic for cleaning up instance directories
will clean up the file.

Closes: #2023
Approved by: alexlarsson
2018-08-27 14:25:15 +00:00
Alexander Larsson
b8d594e390 OCI summary generation: Fix generation of summary on 32bit
The "t" variant type is guint64, so we must cast "0" to it when using
it in a varargs.

Closes: #2024
Approved by: alexlarsson
2018-08-27 14:07:55 +00:00
Patrick Griffis
738c11324a Add /proc to blacklist
This doesn't make sense to ever be in the sandbox

Closes: #2008
Approved by: alexlarsson
2018-08-27 11:06:56 +00:00
Will Thompson
b0f8736467 installation: document nullability of some arch/branch params
I've inferred this by walking through the code, which ultimately calls
one of flatpak_build_[app|runtime]_ref() which both implement these
defaults.

Closes: #1995
Approved by: alexlarsson
2018-08-27 10:57:16 +00:00
Will Thompson
9cc72ed08f transaction: improve cross-refs for signal parameter docs
Closes: #1995
Approved by: alexlarsson
2018-08-27 10:57:16 +00:00
Will Thompson
04846e24b2 transaction: fix signal parameter documentation
I guess these predate the creation of FlatpakTransactionOperation.

Closes: #1995
Approved by: alexlarsson
2018-08-27 10:57:15 +00:00
Will Thompson
a710f36e31 transaction: validate refs
Without this, it's not safe to use 'pref': if there are no slashes in
'ref', 'pref == 0x1', and any attempt to dereference it later in the
function will crash.

Closes: #1995
Approved by: alexlarsson
2018-08-27 10:57:15 +00:00
Will Thompson
6e270190c8 transaction: add docs & introspection annotations
Without explicit annotation, all optional parameters are assumed to be
mandatory, and 'const gchar **locales' is assumed to be a scalar string
input parameter (rather than an array or an in/out) for some reason.

Closes: #1995
Approved by: alexlarsson
2018-08-27 10:57:15 +00:00
Will Thompson
ae269ba390 transaction: add NULL guards in API entry points
Closes: #1995
Approved by: alexlarsson
2018-08-27 10:57:15 +00:00
Will Thompson
61107c56ce transaction: don't critical in finalize if initable_init() failed
If no installation path is specified at construct time, or if it doesn't
exist, priv->dir will be NULL even after initable_init() has been
called.

Closes: #1995
Approved by: alexlarsson
2018-08-27 10:57:15 +00:00
Alexander Larsson
a7c88682d3 Don't use G_NUMBER_PARSER_ERROR as it requires a newer glib
Closes: #1987
Approved by: alexlarsson
2018-08-20 10:42:21 +00:00
Matthew Leeds
37ad100cfe dir: Quietly refuse to downgrade ostree-metadata
This reverts commit ed1d7eacf4 and fixes
the issue in a different way.

With the introduction of peer (LAN/USB) sources of refs comes a problem:
they may have outdated repository metadata (which is stored as
contentless commits on the branch "ostree-metadata"). Currently Flatpak
allows the older metadata to be pulled into the local repo, but this is
undesirable for a few reasons: it hurts the security properties of the
system because for example the GPG keys might have been rotated and you
don't want to go back to using the old ones, and it's undesirable
because the old metadata might have missing or wrong information about
the apps installed on the system.

So this commit makes Flatpak ignore the downgrade and use the newer
metadata for the offline operation. This is not a perfect solution,
because the newer metadata might have information (such as the download
size or needed runtime) that's not accurate for the old versions of the
refs that are available offline. This issue is significantly mitigated
by the fact that FlatpakTransaction operations use commit metadata to
make decisions, rather than depending on the xa.cache.

Another possible solution would be to read the outdated metadata into
the FlatpakRemoteState object without pulling it into the local repo or
using it to update the remote config, but that's not perfect either
because there's no guarantee you'll pull the metadata from the same
source as the refs (perhaps one comes from a USB drive and the other
from a LAN peer). Longer term, we should figure out how to rely less on
the xa.cache (which is stored in ostree-metadata) or otherwise make
architectural changes to solve those issues. For now, I think this fix
will be enough to make USB updates usable and secure.

Fixes https://github.com/flatpak/flatpak/issues/1473

Closes: #1965
Approved by: alexlarsson
2018-08-20 06:58:01 +00:00
Matthew Leeds
fb989a62a1 common: Add and use FLATPAK_ERROR_DOWNGRADE
This will be useful in distinguishing downgrade errors from other
errors, which I'll need in the next commit.

Closes: #1965
Approved by: alexlarsson
2018-08-20 06:58:01 +00:00
Matthew Leeds
1ff0cf8c16 common: Register all FlatpakError codes as D-Bus errors
This will allow us to return anything in the FlatpakError domain using
g_dbus_method_invocation_return_gerror().

Closes: #1965
Approved by: alexlarsson
2018-08-20 06:58:01 +00:00
Matthew Leeds
5cff4500a2 transaction: Fix error handling for related refs
This commit fixes the handling of errors from installing/updating
related refs during a transaction, so that they're treated as non-fatal,
and so that the operation is skipped if the primary operation fails. The
current behavior is that a failure to install/update a related ref
causes the whole transaction to fail, and even after a failure to
install/update the primary ref the related ref install/update is
attempted.

I hit this error when doing an offline USB app install, when the USB
repo has an older version of the runtime and the runtime's locale
extension than what's in the local repo. Without this commit, the
failure to update the runtime (due to it being a downgrade) is treated
as a warning, but the failure to update the runtime locale is treated as
an error. With this commit, the runtime update failure is still treated
as a warning, and the locale update is not attempted. This is better
behavior because the locale extension update (or even install) is not
critical to the app install.

Closes: #1979
Approved by: alexlarsson
2018-08-17 09:34:34 +00:00
Alexander Larsson
ef9297a0f1 dbus-proxy: Fix handling of broadcasts
In https://github.com/flatpak/flatpak/pull/1689 we were meant to
have limited the receiving of broadcasts on portals, but die to a
bug in the proxy we accidentally allowed all broadcasts anyway.

The change which ignores all applied filters < POLICY_TALK fixes that.

However, it also turns out that the desktop portal actually *does*
rely on signals. For example the network portal uses property change
notification.

So, to make sure this works we allow all signal from the portal
names, but only if they are on a object path starting under
/org/freedesktop/portal (which incidentally all portal object are).
This means there is no real change in anything that is currently
deployed, but it does allow portals to opt out of this global signal
visiblity if they want by using a different object path, which we
want to use in dconf.

Closes: #1976
Approved by: alexlarsson
2018-08-17 09:24:13 +00:00
Matthew Leeds
cbc0046554 transaction: Fix a regression in installing bundles
This commit fixes a regression that causes installing from a bundle to
fail if the bundled app's runtime was itself installed from a bundle, or
otherwise has a non-working remote (such as when the user is offline).

The fix is to treat a failure of flatpak_dir_find_latest_rev() as
non-fatal in resolve_ops() if the ref in question is already installed.
In other words, if we don't need to fetch a ref for the transaction to
succeed, errors in fetching remote info about the ref shouldn't be
fatal.

Closes: #1973
Approved by: alexlarsson
2018-08-17 09:14:26 +00:00
Matthew Leeds
9616737c0b dir: Fix a subpath checkout error message
In this loop we're checking out a subpath under /files, not /metadata,
so fix the error message.

Closes: #1970
Approved by: alexlarsson
2018-08-17 08:45:36 +00:00
Matthew Leeds
4c5fc20d60 common: Improve "No xa.metadata" error messages
When I run `flatpak update` I get messages saying "Warning: No
xa.metadata in commit" which isn't very helpful without knowing what
commit is being referred to. So this commit adds the checksum and ref to
such error messages.

Closes: #1978
Approved by: alexlarsson
2018-08-17 08:35:07 +00:00
Alexander Larsson
341ad02193 flatpak_dir_remote_make_oci_summary: Actually use cache
We need to return early on cache hits.

Closes: #1966
Approved by: alexlarsson
2018-08-17 08:13:15 +00:00
Alexander Larsson
9cc0f0d404 Fix leak in flatpak_cache_http_uri
Need to free the return value of soup_header_parse_param_list

Closes: #1966
Approved by: alexlarsson
2018-08-17 08:13:15 +00:00
Alexander Larsson
3d9a616632 flatpakref: Fix leak of gpg key string
Closes: #1966
Approved by: alexlarsson
2018-08-17 08:13:15 +00:00
Matthew Leeds
c3a0617557 NULL initialize g_auto variables
It's a good idea to NULL initialize g_autoptr/g_autofree variables, so
we can be sure uninitialized memory isn't passed to g_free or similar.

Closes: #1968
Approved by: alexlarsson
2018-08-17 08:06:51 +00:00
Matthew Leeds
745287e48f dir: Fix another GVariant leak
g_variant_builder_end() returns a floating reference, so sink it.

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:10 +00:00
Alexander Larsson
75adff05f4 flatpak-json: Don't leak empty optional nodes.
Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
4b8624e705 flatpak_yes_no_prompt: Fix leak of formated string
Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
a6bec60d24 flatpak_dir_find_remote_related_for_metadata: Fix leak
Move extension_ref into the loop so its freed every iteration.

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
335f69675e Fix leak in flatpak_transaction_ensure_remote_state
We return a ref now, and free it in all callers, otherwise
the non-caching codepath of this leaks the state.

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
cbbc98b50d Make FlatpakRemoteState refcounted
This is needed to fix a memory leak

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
c70078b7eb flatpak_dir_read_latest: Fix leak
Make sure we free res if we exit early

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
ebb3ff532d Fix GVariant leak
ostree_async_progress_get_variant returns a ref, so free it.

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
7df3f9f1ba appstream: Fix leak
Move some autoptr to the inner scope of the loop over each
appstream branch to avoid leaking.

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
ed1d7eacf4 Fix regression from #1961 which broke the tests
Sometimes (for example in some test-repo-collections.sh test that broke) we
update from a remote with an older ostree-metadata branch, and the
check for downgrades broke in this case.

Its unclear exactly what it the best solution here, maybe to silently
disallow the update. However, this change instead just re-allows the
downgrade for this particular case so we get the old behaviour.
2018-08-13 12:10:22 +02:00
Owen W. Taylor
09d0e83c43 Handle switching a remote type between OCI and non-OCI
When we switch the remote type, we need to clean up cached files
(appstream, OCI index/summary) because they are stored differently
for the two types of remote.
2018-08-13 11:23:28 +02:00
Owen W. Taylor
df431fe4b0 Remove unused calls to ostree_repo_remote_get_url 2018-08-13 11:23:28 +02:00
Owen W. Taylor
d7d05a8619 Use oci+http[s]:// as an URL to identify OCI registries
The old pattern of using a separate 'OCI' flag was very ugly
internally in the code once it was extended to flatpak bundles and
flatpakrefs - using a different URI scheme means that the nature
of the remote can't be accidentally lost in some part of the code.

Probing would be possible as well, but would make it difficult to
add a remote when offline, and also doesn't deal well with the
fact that our data layout is different for the two types of remotes -
the type of remote could change at any point!

As a side effect this change enables flatpakrefs and flatpak bundles for OCI
registries.
2018-08-13 11:23:28 +02:00
Owen W. Taylor
b283084826 Improvements to index URI generation for OCI registries
* Restrict the queried images to the desired architecture
* Sort query parameters as the spec requests
* Allow a fragment on the remote URI to mean "tag to query for
  in the registry"
* Tweak flatpak_oci_index_ensure_cached() not to return the
  index URL in the normal error case.
2018-08-13 11:23:28 +02:00
Owen W. Taylor
d64c1c1b95 flatpak_dir_remove_oci_file(): be tolerant of missing files
If a remote is removed before we ever fetched content, the OCI
index and summary files won't exist.
2018-08-13 11:23:28 +02:00
Owen W. Taylor
8fe9bf4d86 Look at all refs when verifying a ref for flatpak-system-helper
The normal behavior where we only list already installed refs for
a noenumerate remote doesn't work for the case where flatpak-system-helper
verifies a ref on an OCI server during installation - in that case, the
ref being installed to does not *yet* exist locally.
2018-08-13 11:23:28 +02:00
Owen W. Taylor
70776b0eaf Fix args to flatpak_bundle_load 2018-08-13 11:23:28 +02:00
Owen W. Taylor
00b5f568ec Clean up properly when pruning an origin remote
Using flatpak_dir_remove_remote() rather than ostree_repo_remove_remote()
means that appstream and OCI index/summary files will be properly
removed.
2018-08-13 11:23:28 +02:00
Matthew Leeds
5b21a5b7fc dir: Fix detection of downgrades for P2P operations
In general Flatpak tries to prevent downgrades of anything: apps,
runtimes, repo metadata, etc. with some exceptions such as when the user
specifies a commit they want. However at the moment the detection of a
downgrade is broken if both of the following are true: (1) a collection
ID is enabled on the relevant remote, and (2) a per-user installation
is being used instead of the system-wide one (or the system-helper is
otherwise being circumvented, such as by running flatpak as root).

This bug is a security vulnerability, but it's one with limited impact
because very few people have collection IDs enabled yet, and the
downgrade attack would require either a MITM on the network connection
(which HTTPS should prevent) or a malicious USB drive or local network
peer.
2018-08-13 11:21:46 +02:00
Alexander Larsson
3fa34ebd8a Work around libsoup recursive type hang in tests
Closes: #1952
Approved by: alexlarsson
2018-08-09 15:45:08 +00:00