Commit Graph

1562 Commits

Author SHA1 Message Date
Alexander Larsson
e1f46ff43e OCI: Handle manifests without annotations in index.json
When we export a manifest to the index, always pass the ref we're
targeting instead of relying on the org.opencontainers.image.ref.name
annotation, because that may not be set if we're using labels instead.

This is no big deal, because we know what ref we're handling anyway.
2019-09-03 16:00:25 +02:00
Alexander Larsson
a9a0c37e5e OCI: Make use of labels or annotations configurable
If repo uri has ?index=label then query for labels, otherwise
keep querying for annotations like before.
2019-09-03 11:19:47 +02:00
Alexander Larsson
68e5d95aa2 OCI: Use labels as commit metadata source as well as annotations
We now pull the image config as well as the manifest and fall
back on the labels field if the keys we're looking for are not
in the annotations field.

This lets us support docker manifests too, which don't have
annotations (but do have labels).
2019-09-03 11:19:47 +02:00
Alexander Larsson
83c2bdf077 OCI: Don't crash if mediaType field missing in flatpak_oci_versioned_from_json 2019-09-03 11:19:47 +02:00
Alexander Larsson
94ed2946ab OCI: Add flatpak_oci_registry_load_image_config helper
We can't use load_versioned() for images because in the docker
case there is no mediatype field.
2019-09-03 11:19:47 +02:00
Alexander Larsson
09831d535a OCI: Accept docker v2 manifests as well as OCI manifests 2019-09-03 11:19:47 +02:00
Alexander Larsson
9436cf6e10 OCI: Add docker v2 media type defines 2019-09-03 11:19:47 +02:00
Alexander Larsson
f88bad8245 oci: Query for org.flatpak.ref label instead of annotation
This is not compatible with the old stuff, but works with registries
that only support the docker manifest format.
2019-09-03 11:19:47 +02:00
Alexander Larsson
4fde171055 oci: Allow reading metadata from labels too 2019-09-03 11:19:47 +02:00
Alexander Larsson
d820e333ed oci: Always generate a history, quay needs this 2019-09-03 11:19:47 +02:00
Alexander Larsson
6294ddb1ca oci: Add an easy api to set the labels in the image manifest 2019-09-03 11:19:47 +02:00
Philip Withnall
791f31898b flatpak-installation: Handle an unconfigured remote when listing remotes
This prevents a crash in flatpak_installation_list_remotes_by_type() if
the `FlatpakDir` can’t ensure it has a repo configured.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #3028
Approved by: alexlarsson
2019-08-16 09:33:18 +00:00
Debarshi Ray
e82efa8603 Trim unused shared library linkages from the session helper
The org.freedesktop.Flatpak user D-Bus service isn't just used by
flatpak(1) or applications running as Flatpaks. It's also used by
toolbox(1) for similar reasons:
 * To keep various configuration files inside the container
   synchronized with the host
 * To let the container request certain commands to be run on the host

The org.freedesktop.Flatpak D-Bus service itself doesn't need much in
the way of dependencies, but inherits a lot of unused shared library
linkages through the libflatpak-common.la convenience library. Removing
these unused shared libraries reduces the footprint of toolbox(1) for
those who care about such things. eg., Fedora CoreOS.

This commit brings down the number of shared libraries to 19 from 62.

Closes: #3052
Approved by: alexlarsson
2019-08-16 09:13:43 +00:00
Debarshi Ray
61d4316043 common, session-helper: Make the session helper more self-contained
... by moving the definition of FlatpakHostCommandFlags from the
'common' sub-directory to 'session-helper'. It hasn't been used by
anything else ever since flatpak-builder was moved to a separate
repository in commit 52bd146561.

Closes: #3052
Approved by: alexlarsson
2019-08-16 09:13:43 +00:00
Debarshi Ray
cde7934041 build: Link against libxml only when necessary
The libxml API is used in a relatively few places inside the 'common'
sub-directory. It's definitely not as widespread as GLib. A subsequent
commit will leverage this to prevent unused shared libraries from
being linked to the session helper.

Closes: #3052
Approved by: alexlarsson
2019-08-16 09:13:43 +00:00
Debarshi Ray
ebf5d08f47 build: Link against libarchive only when necessary
The libarchive API is used in a relatively few places inside the
'common' sub-directory. It's definitely not as widespread as GLib. A
subsequent commit will leverage this to prevent unused shared
libraries from being linked to the session helper.

Closes: #3052
Approved by: alexlarsson
2019-08-16 09:13:43 +00:00
Owen W. Taylor
a794c07e18 OCI: correctly handle locally present icons
If the download URL for an icon was already cached locally, the HTTP
code returned FLATPAK_OCI_ERROR_NOT_CHANGED - this was treated as a real
error, and after downloading missing icons, all present icons were
deleted!

See https://bugzilla.redhat.com/show_bug.cgi?id=1683375

Closes: #3048
Approved by: alexlarsson
2019-08-15 20:04:18 +00:00
Matthew Leeds
b44c1a5799 dir: Don't overzealously rewrite an error
It's an error to call g_set_error() on an error that's already set, and
flatpak_dir_get_deploy_data() already sets FLATPAK_ERROR_NOT_INSTALLED
for us when necessary, so just pass on any errors to the caller of
flatpak_dir_get_origin(). In the case that the error is something else,
that should be treated as an error, because we never expect the deploy
directory to exist but not have a deploy file (see the implementations
of flatpak_dir_deploy() and flatpak_dir_undeploy()).

Closes: #3032
Approved by: alexlarsson
2019-08-15 19:42:45 +00:00
Matthew Leeds
9a258e8a0c common: Use correct flag for ostree_repo_resolve_rev_ext()
Use the correct NONE flag, although both are 0 so this change won't make
any functional difference.

Closes: #3032
Approved by: alexlarsson
2019-08-15 19:42:45 +00:00
Matthew Leeds
f09049b7aa common: Fix branch validation docs
The docs for flatpak_is_valid_branch() say branch names can't start with
a digit but the implementation doesn't enforce this, and we have lots of
branches out in the wild that start with a digit (e.g. "3.32" and
"5.12"). So make the docs imply that branches can start with a digit.

The implementation also disallows "." as the leading character for a
branch, so add that to the docs. I'm just guessing that "." was intended
to be disallowed but it makes sense; otherwise the file we create named
with the branch would be hidden.

Closes: #3023
Approved by: alexlarsson
2019-08-15 09:07:14 +00:00
Philip Withnall
f80cce6b8d installation: Fix a small leak of a FlatpakCollectionRef
Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #3031
Approved by: mwleeds
2019-08-03 05:03:23 +00:00
Andre Moreira Magalhaes
37a7b6edfd transaction: Append bundle to correct list on flatpak_transaction_add_install_bundle()
Signed-off-by: Andre Moreira Magalhaes <andre@endlessm.com>

Closes: #3025
Approved by: matthiasclasen
2019-07-23 14:54:59 +00:00
Matthew Leeds
f1b8a4275f transaction: Fix "Can't load dependent file" error
Make the error message translatable, and add ": " between the URL and
the rest of the error.

Closes: #3003
Approved by: mwleeds
2019-07-05 15:41:56 +00:00
Matthew Leeds
1ce250b5bd common/flatpak-dir-private.h: Fix order of arguments
This issue was introduced by commit 5da7a0411.

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

Closes: #2968
Approved by: matthiasclasen
2019-06-20 19:06:51 +00:00
Kalev Lember
18a1622755 ref: Fix a memory leak
Closes: #2964
Approved by: mwleeds
2019-06-14 22:44:27 +00:00
Richard Hughes
4f327649fd Do not break ABI and cause gnome-software to crash
This restores the ABI to the pre-1.4.0 version. This moves the new signal to
the *end* of the struct and also correctly decrements the padding.

Fixes https://github.com/flatpak/flatpak/issues/2957, although we probably need
a 1.4.1 release with this included pretty quickly to avoid chaos.

Closes: #2958
Approved by: alexlarsson
2019-06-13 06:59:41 +00:00
Alexander Larsson
1029f2b1d0 transaction: Add back support for file: uris in RuntimeRepo keys
This used to work, and the gnome-software test suite relies on it,
so add it back. I believe it regressed in
 https://github.com/flatpak/flatpak/pull/2740

This fixes https://github.com/flatpak/flatpak/issues/2955

Closes: #2956
Approved by: alexlarsson
2019-06-12 07:21:26 +00:00
朝歌
0bb64e9a88 Update flatpak-run.c
Closes: #2936
Approved by: alexlarsson
2019-06-12 06:37:23 +00:00
Ryan Gonzalez
9cd682b057 dir: Use ExtensionOf.runtime for apply_extra
Closes: #2954
Approved by: alexlarsson
2019-06-12 06:23:07 +00:00
Ryan Gonzalez
c87c480a18 transaction: Install an extension's required runtime
Closes: #2954
Approved by: alexlarsson
2019-06-12 06:23:07 +00:00
Will Thompson
dbc90df513 dir: include NULL url in flatpak_dir_log() call
I spotted this line in the output from `flatpak history`:

    Jun  4 16:17:20	deploy install	com.discordapp.Discord	x86_64	stable	system	flathub	8a0fc700c701		Installed %s from %s	root (test)	flatpak-system-helper (gnome-software)	1.3.3

This is because the format string is passed as the 'url' parameter, the
first format parameter (the ref) is passed as the 'format' parameter,
and 'origin' is ignored because (fortunately) as far as I know, no
character significant to printf (like '%') is permitted in ref names.

Fix this by passing a NULL 'url', like the neighbouring call in
flatpak_dir_deploy_update().
2019-06-05 10:58:14 +01:00
Matthew Leeds
c29d9ebcf7 transaction: Minor docs improvements
Closes: #2930
Approved by: matthiasclasen
2019-05-30 12:12:12 +00:00
Matthew Leeds
3164c68e31 common: Fix double free of GError
Closes: #2919
Approved by: alexlarsson
2019-05-27 10:58:33 +00:00
Matthew Leeds
c028e0dc1b installation: Use FLATPAK_ERROR_REF_NOT_FOUND in one more place
I missed this when adding FLATPAK_ERROR_REF_NOT_FOUND.

Closes: #2914
Approved by: matthiasclasen
2019-05-21 02:06:00 +00:00
Matthew Leeds
c0d5f1bfc8 Add FLATPAK_ERROR_REF_NOT_FOUND
This adds a new error to FlatpakError and uses it everywhere a ref is not
found, either locally or in a remote. This should hopefully be more useful than
the status quo of either returning FLATPAK_ERROR_INVALID_DATA or
G_IO_ERROR_NOT_FOUND or something else. Technically this is an API break but it
seems worth the risk. I checked gnome-software which does not seem affected by
this, and I checked eos-updater which does check for G_IO_ERROR_NOT_FOUND in
one place that will be affected by this but we can patch that.

Closes: #2895
Approved by: matthiasclasen
2019-05-13 10:57:11 +00:00
Matthew Leeds
9a09001317 common/flatpak-error: Fix a typo
Closes: #2895
Approved by: matthiasclasen
2019-05-13 10:57:11 +00:00
Alexander Larsson
c01fdee171 lib Add flatpak_remote_new_from_file() to add remotes from flatpakrefs
Closes: #2888
Approved by: alexlarsson
2019-05-09 12:39:36 +00:00
Alexander Larsson
8d674234aa lib: Add flatpak_installation_add_remote
This is basically modify_remote, but it fails if the remote is
already configured instead of modifying it. Although it also
has a if_needed option, and if that is set it will silently complete
as a no-op (exept resetting filters).

Closes: #2888
Approved by: alexlarsson
2019-05-09 12:39:36 +00:00
Alexander Larsson
4c4c80b85d update: Fix OCI updates in the system repo
We need to check whether the remote is gpg verified after handling
the oci case, because OCI is fine to update systemwide without gpg
verification (in fact it doesn't support verification).

This just reorders the code, matching what is done in the install
case already.

Closes: #2891
Approved by: alexlarsson
2019-05-09 12:22:44 +00:00
Alexander Larsson
d7bc26031c filters: Make a backup copy of the filter when it is set and use when needed
We still look at the regular file to pick up changes, but to avoid
issues if the file disappears (for example if it was in a package
that was uninstalled) then we still have something to show so we don't
start accidentally showing unfiltered stuff.

Closes: #2890
Approved by: alexlarsson
2019-05-09 09:46:17 +00:00
Matthew Leeds
f67a7ad5bd dir: Do some minor refactoring
Rearrange a few things for the purposes of readability and adherence to
conventions around using GError. This introduces no functional changes.

Closes: #2705
Approved by: alexlarsson
2019-05-09 09:12:26 +00:00
Matthew Leeds
b8a3075d84 common: Properly handle empty arrays of P2P results
ostree_repo_find_remotes_finish() can return an empty array of
OstreeRepoFinderResults without setting @error and expects the caller to
check for this before doing a pull. Currently in a few different places
Flatpak does not check if the array is empty after calling
ostree_repo_find_remotes_finish() which leads to a critical warning in
ostree_repo_pull_from_remotes_async() which expects a non-empty results
array. This is causing one of the unit tests to fail.

So properly handle the case of an empty results array in each place it
can occur. In most places it's an error condition so the error pointer
is set appropriately. In list_remotes_for_configured_remote() it's not
an error because there may legitimately be no LAN/USB remotes available,
so in that case just properly handle the case of (results == NULL).

Also, add a debug statement in flatpak_dir_do_resolve_p2p_refs() since
we're now building a string of the refs being resolved.

Closes: #2705
Approved by: alexlarsson
2019-05-09 09:12:26 +00:00
Matthew Leeds
915ad583a7 dir: Check commit signatures before resolving a ref
Currently flatpak_dir_pull() has a phase where it tries to resolve a ref
to a commit before doing the pull, which is good because it means we're
pulling the same commit even if we do multiple subpath pulls, and it
allows us to get set up for accurate progress reporting. On the P2P code
path, this resolution is accomplished with an
ostree_repo_find_remotes_async() call, and then checking the results
from that. Normally that works fine, but in case a remote tries to
maliciously serve an update to refs which didn't originate from it (by
setting the same collection ID as the victim remote) things break. The
find_remotes_async() will use the malicious remote's keyring for
verification and return that commit as the most recent. This causes
errors later during the pull phase.

For example, if we're trying to update example-ref from good-remote,
and good-remote is offering commit v1 and malicious-remote is offering
commit v2, we resolve example-ref to commit v2. Then pulling that commit
from malicious-remote using good-remote's keyring fails, and pulling
commit v2 from good-remote fails because it doesn't exist there.

So this commit changes flatpak_dir_pull() so that it pulls commit
metadata before deciding on a commit. Since the pull code uses the
"ref-keyring-map" option, the bad signatures will be found and the
latest good commit will be returned. This requires a few changes:
1) Move the ostree_repo_prepare_transaction() call up to before the new
pull, which also means using "goto out;" in a few more places.
2) Use OSTREE_REPO_PULL_FLAGS_MIRROR for the pull and
flatpak_repo_resolve_rev() after the pull. That is more correct but we
need the patch in this PR[1] for it to work so the commit signature
check is conditional on a check for ostree v2019.2.
3) Change repo_pull() so that it will accept results_to_fetch != NULL &&
rev_to_fetch == NULL. This means making a g_autofree version of
rev_to_fetch and resolving it after the pull if necessary.

This is all working toward the goal of getting the unit test in the
following commit, test-p2p-security.sh, to succeed.

[1] https://github.com/ostreedev/ostree/pull/1821

Closes: #2705
Approved by: alexlarsson
2019-05-09 09:12:26 +00:00
Matthew Leeds
caedda5b2a dir: Use the right keyring to verify P2P pulls
With Flatpak you should only have to trust each remote to provide good
updates for the apps provided by it. However the P2P support in OSTree
considers each remote to be equally trustworthy, which opens a possible
attack vector. For example if I have a flathub remote configured and
apps installed from it and I also have a remote "sketchy-remote"
configured which I have one app installed from, I expect the Flathub
apps to update from Flathub (or to update from LAN/USB sources with
Flathub GPG signatures) and not from the sketchy-remote.

The way this attack would play out is that the sketchy-remote would
deploy the same collection ID as the victim remote (in this case
org.flathub.Stable) in order to serve updates for it. So this commit
mitigates the issue by using the new "ref-keyring-map" option
added to libostree[1], which means that pulls of updates to Flathub apps
will always be verified using the Flathub GPG keyring, even if they're
coming from another source like another configured remote or a LAN/USB
source signed with the malicious remote's keyring. In the latter case
the pull from the malicious source will fail, and flatpak should then do
a successful pull from a legitimate source.

We use the "ref-keyring-map" option in both
flatpak_dir_do_resolve_p2p_refs() and repo_pull() because if we only use
it in the latter place the ref could be resolved to the malicious commit
(which would be checked with the malicious keyring), and then in
repo_pull() we would try unsuccessfully to pull the malicious commit
from the legitimate remote.

Since pulls into the system installation already use the correct
remote's keyring (see the use of ostree_repo_verify_commit_for_remote()
in flatpak_dir_pull_untrusted_local()) this mitigation is only needed
for per-user installations (or other scenarios that circumvent the
system helper). It's also only needed since the commit "dir: Fix an edge
case of resolving collection-refs" because before that commit this
attack vector wasn't exploitable.

Unfortunately this implementation is not perfect, because there's not
always a one-to-one mapping between configured remotes and GPG keyrings.
On Endless OS some remotes have keyrings in /usr/share/keyrings/ rather
than /var/lib/flatpak/repo/remote_name.trustedkeys.gpg as do remotes
added by Flatpak. However presumably you would only add a keyring to a
global directory if you trust it to the same extent as the others.

A subsequent commit will add a unit test for this.

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

[1] https://github.com/ostreedev/ostree/pull/1810

Closes: #2705
Approved by: alexlarsson
2019-05-09 09:12:26 +00:00
Matthew Leeds
253fcc6e35 Made wider use of flatpak_repo_resolve_rev()
As described in the last commit message, it makes sense to move toward
using flatpak_repo_resolve_rev() rather than ostree_repo_resolve_rev()
for a few reasons:
1) It means we can use OSTREE_REPO_PULL_FLAGS_MIRROR which causes refs
to be pulled into repo/refs/mirrors/ rather than repo/refs/remotes/
which fixes a few edge cases of using collection IDs[1]
2) It falls back to using ostree_repo_resolve_rev() if
ostree_repo_resolve_collection_ref() fails so we can maintain backwards
compatibility for repo/refs/remotes/
3) It distinguishes between remote and local refs, and in the local case
uses OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY and
ostree_repo_resolve_rev_ext() to make sure we don't for example
accidentally use a remote's repo metadata rather than the local repo's
metadata for the "flatpak repo" command.

So this commit changes every instance of ostree_repo_resolve_rev() in
the codebase to flatpak_repo_resolve_rev().

[1] https://github.com/flatpak/flatpak/issues/1832

Closes: #2705
Approved by: alexlarsson
2019-05-09 09:12:26 +00:00
Matthew Leeds
8cea78db1f dir: Fix an edge case of resolving collection-refs
In flatpak_dir_do_resolve_p2p_refs() after pulling a ref we use
ostree_repo_resolve_rev() and pass a refspec with the remote from which
the ref originated. This has a couple side effects, one good and one
bad:
1) The good side effect is that the attack I speculated about in this
comment[1] is not exploitable. Because if the ref in question is pulled
from any remote other than its origin (or a LAN/USB source using another
remote's keyring) it will not be found by ostree_repo_resolve_rev() and
the malicious commit will not be used.
2) The bad side effect is that there are some legitimate reasons a ref
could be pulled from another remote (say, a configured mirror), and in
those cases the pulled ref will not be found. So if I have remote A and
remote B both configured with the same collection ID, a ref installed
from one could be pulled from the other. See this issue[2] for a
concrete example.

The solution is to use OSTREE_REPO_PULL_FLAGS_MIRROR for the pull and
use ostree_repo_resolve_collection_ref() to resolve the ref. This is
done in the caller as well for consistency
(flatpak_dir_resolve_p2p_refs()). This fixes the bad side effect
described above and brings us a step closer to fixing issue #1832. This
also means the attack from #1447 is exploitable, but that is addressed
in a subsequent commit.

This change is conditional on a version check for OSTree 2019.2 because
we need this bug fix[3].

Also, add a helper function flatpak_repo_resolve_rev() which falls back
to using ostree_repo_resolve_rev() when
ostree_repo_resolve_collection_ref() fails, so we start to move toward
using /refs/mirrors/ but maintain backwards compatibility for
/refs/remotes/. A subsequent commit will make wider use of
flatpak_repo_resolve_rev() across the codebase; for now just use it for
the case described above.

[1] https://github.com/flatpak/flatpak/issues/1447#issuecomment-445347590
[2] https://github.com/flatpak/flatpak/issues/1832
[3] https://github.com/ostreedev/ostree/pull/1821

Closes: #2705
Approved by: alexlarsson
2019-05-09 09:12:26 +00:00
Matthew Leeds
d18dd69fe4 dir: Move find and pull options to innermost scope
There's no point building up the options GVariant for a find or a pull
that doesn't happen, so move that work to the innermost scope.

As an aside, it's much more pleasant to look at the diff for this commit
using git's --patience option than the default diff algorithm.

Closes: #2705
Approved by: alexlarsson
2019-05-09 09:12:25 +00:00
Alexander Larsson
39946c3959 Support .flatpakrepo files in /etc/flatpak/remotes.d
A *.flatpakrepo file in this directory will be automatically
added as a system remote with the basename (sans extension) as the
name unless that name already exist. Also, once this is done we
record the name in the repo config so that it is not applied again if
the remote is removed.

Closes: #2884
Approved by: alexlarsson
2019-05-08 08:13:52 +00:00
Alexander Larsson
7dedbbb56b FlatpakDir: Break out the remote-config copy code into a helper
Closes: #2884
Approved by: alexlarsson
2019-05-08 08:13:52 +00:00
Alexander Larsson
6278420ba8 dir: Add flatpak_dir_compare_remote_filter and handle canonicalization
In general xa.filter being "" means don't filter, so that it can be
used to override-unset a previous filter. However, We canonicalize
to unset/NULL when comparing, returing, or setting the ostree config.

Closes: #2884
Approved by: alexlarsson
2019-05-08 08:13:52 +00:00