Commit Graph

5088 Commits

Author SHA1 Message Date
Matthew Leeds
d8853f424c doc: Improve docs for --arch options
It's not obvious what values are valid, so add a hint.

Closes: #2930
Approved by: matthiasclasen
2019-05-30 12:12:12 +00:00
Matthew Leeds
3af605dd39 app: Don't show arch column if it's not interesting
Flatpak already doesn't show the architecture column in the output of
"flatpak list" if every flatpak has the same architecture. This commit
does the same for the table printed for install/update/uninstall
operations, except if the user specifies an arch on the command line.

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

Closes: #2930
Approved by: matthiasclasen
2019-05-30 12:12:12 +00:00
Matthew Leeds
c29d9ebcf7 transaction: Minor docs improvements
Closes: #2930
Approved by: matthiasclasen
2019-05-30 12:12:12 +00:00
Alexander Larsson
57a6887352 Bump version to 1.5.0, 1.4.x is on flatpak-1.4.x branch 2019-05-28 15:47:12 +02:00
Alexander Larsson
170b0e2b8e Update pofiles 1.4.0 2019-05-28 15:07:09 +02:00
Alexander Larsson
3e8c42c823 Bump version to 1.4.0 2019-05-28 14:55:02 +02:00
Alexander Larsson
f8c13c8007 Update NEWS for 1.4.0 2019-05-28 14:54:44 +02:00
Valentin David
8d82a3e5f7 app/flatpak-builtins-build-commit-from.c: Recalculate download-size metadata
Download size of object depends on the compression used in the ostree
repository.  When a different source repository is specified, download
size might change.  So this metadata needs to be recalculated.

This issue happens with Freedesktop SDK which for build time
optimization reason run an intermediate build-export on a bare
repository.

See issue https://gitlab.com/freedesktop-sdk/freedesktop-sdk/issues/787

Closes: #2925
Approved by: alexlarsson
2019-05-28 12:46:13 +00:00
Debarshi Ray
bf96de941b session-helper: Relax directory permission for Toolbox containers
Toolbox [1] containers, like Flatpak containers, need to keep some
configuration files synchronized with the host. eg., /etc/localtime,
/etc/resolv.conf, etc.. The easiest way to keep them updated is to bind
mount the entire /etc from the host at some location inside the
container, and then replace the container's copy of the files with
symbolic links to the bind mounted copies.

However, this doesn't work when the host's copy of a configuration file
is itself a symbolic link to a location outside /etc. eg.,
/etc/localtime, which points somewhere inside /usr/share/zoneinfo. In
that case the host needs to be actively monitored via inotify(7) and
an updated copy of the file needs to maintained in a separate
directory, which can be bind mounted into the container.

This monitoring infrastructure is already present in Flatpak and it
makes sense to leverage it for Toolbox containers too.

However, Flatpak containers have only one user, the current one logged
into the host, whereas Toolbox containers have a longer list of users
like the host itself. Therefore, if the directory getting bind mounted
(ie., $XDG_RUNTIME_DIR/.flatpak-helper/monitor) isn't world readable,
then some users inside the container won't be able to read the
configuration file. eg., this will fail:
  $ sudo -u operator cat /run/host/monitor/localtime

Relaxing the directory permissions on the host shouldn't pose a
security risk. They are copies of originals that are world readable
anyway.

[1] https://github.com/debarshiray/toolbox

Closes: #2916
Approved by: alexlarsson
2019-05-28 07:37:13 +00:00
Matthew Leeds
3164c68e31 common: Fix double free of GError
Closes: #2919
Approved by: alexlarsson
2019-05-27 10:58:33 +00:00
Kukuh Syafaat
b0ad7003bc Update Indonesian translation
Closes: #2915
Approved by: matthiasclasen
2019-05-23 11:20:20 +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
584edb67d5 README: Add LGTM badge for Python
Hopefully we can get the one for C working too.

Closes: #2894
Approved by: matthiasclasen
2019-05-16 23:56:24 +00:00
Matthew Leeds
f9a4b44c64 flatpak-bisect: Remove unused variable
This fixes a warning pointed out by lgtm.com. I checked that the following
still works:
$ PAGER=more flatpak-bisect -b stable org.gnome.Builder log

Closes: #2894
Approved by: matthiasclasen
2019-05-16 23:56:24 +00:00
Alexander Larsson
b53f937d7e Fix installable tests when running on a tty
This sets FLATPAK_FANCY_OUTPUT=0 in most tests and then special cases
the test_fancy_output() test in case the installable tests are running
on an actual tty. This was causing failures because the added bold escapes
caused some test cases to not generate the expected output.

Closes: #2907
Approved by: alexlarsson
2019-05-16 15:24:47 +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
Serdar Sağlam
165234041e Update tr.po
Hi
Missing and incorrect translation arrangement. Incomplete
Closes: #2896
Approved by: matthiasclasen
2019-05-13 10:41:58 +00:00
Alexander Larsson
4abc170f9b Update po/ for release 1.3.4 2019-05-10 09:19:25 +02:00
Alexander Larsson
4947fa6e44 fix distcheck: Pass -f to rm to avoid interactive prompt 2019-05-10 09:07:41 +02:00
Alexander Larsson
1b2207c64e tests: Fix distcheck (test.filter is in srcdir, not builddir) 2019-05-10 08:59:41 +02:00
Alexander Larsson
c369699122 Update NEWS for release 2019-05-09 15:49:51 +02:00
Alexander Larsson
ef470d54b4 Bump version to 1.3.4 2019-05-09 15:49:39 +02: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
1313506449 tests: Add test for updating from oci remote (currently broken)
This is currently failing with:
  Can't pull from untrusted non-gpg verified remote

Closes: #2891
Approved by: alexlarsson
2019-05-09 12:22:44 +00:00
Alexander Larsson
08c544a3f0 tests/oci-registry-server.py: Delete old images for the tag when creating
Closes: #2891
Approved by: alexlarsson
2019-05-09 12:22:44 +00:00
Alexander Larsson
436d738a16 tests: In the oci test, install both app and runtime dependencies
This tests dependencies and stuff too. Also we run it to make sure it works.

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
Kukuh Syafaat
02bf8e32e1 Update Indonesian translation
Closes: #2892
Approved by: alexlarsson
2019-05-09 09:31:32 +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
6cfad442c5 tests: Add test-p2p-security.sh
This test is meant to test the issue described in the message for the
commit "dir: Use the right keyring to verify P2P pulls".

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
803fa15b06 tests: Consistently use a bash shebang
There's not much point in using /bin/bash for all but three scripts and
using /bin/sh for those, so use bash for everything.

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
4ef72ab991 remote-add: Don't fail if metadata updates fail, just warn
This typically happens when the network is offline or in some weird
state.

Closes: #2884
Approved by: alexlarsson
2019-05-08 08:13:52 +00:00
Alexander Larsson
b519b69e38 Add tests for adding remotes from flatpakrefs
Closes: #2884
Approved by: alexlarsson
2019-05-08 08:13:52 +00:00
Alexander Larsson
11c439cee2 Port flatpak remote-add to use flatpak_parse_repofile
We shouldn't be parsing this in two places in the code.

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
Alexander Larsson
e31023c32f Move flatpak_dir_parse_repofile to utils (and drop the unused dir)
Closes: #2884
Approved by: alexlarsson
2019-05-08 08:13:52 +00:00
Alexander Larsson
e1ffc0e730 flatpak_dir_parse_repofile: Handle version and comment/desc/etc keys
These were supported by remote-add, so should be supported here too.

Closes: #2884
Approved by: alexlarsson
2019-05-08 08:13:52 +00:00
Alexander Larsson
1d49053e62 remote-add: Don't set xxx-is-set if the option comes from a flatpakrepo file
This is meant to mean that the user explicitly overrided it, and
that is not right for a flatpakrepo file.

Closes: #2884
Approved by: alexlarsson
2019-05-08 08:13:52 +00:00
Alexander Larsson
6ee61a29fd Remove support for /etc/flatpak/remotes.d config files
This kind of remotes don't work very well, because they are not modifiable
or removable and can cause conflicts with pre-existing remotes.

We instead want to switch to a way to define default remotes that
is applied to the regular ostree repo config, allowing later changes.

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