Commit Graph

1423 Commits

Author SHA1 Message Date
Phaedrus Leeds
b912053c6c Fix several memory leaks
(cherry picked from commit 404d7c6941)
2021-06-16 10:13:37 +01:00
Phaedrus Leeds
a539691dca create-usb: Skip copying extra-data flatpaks
Currently the create-usb command copies extra-data flatpaks such as the
org.freedesktop.Platform.openh264 runtime extension along with normal
non-extra-data content. This is an issue because on the computer
installing from the USB it will attempt to get the extra-data content
from the URI specified in the commit metadata, which will fail if the
URI is a resource on the Internet and the computer is offline.

Instead, have create-usb omit such refs. If it was specified explicitly
this is treated as a hard error and if it's a dependency it's treated as
a warning, so that e.g. org.freedesktop.Platform can still be copied to
a USB and installed/updated offline. On the receiving end the absence of
org.freedesktop.Platform.openh264 will correctly not be treated as fatal
to the installation of org.freedesktop.Platform.

This issue was affecting offline updates of Endless OS, since such OS
updates include flatpaks along with the OS content.

For the (legally questionable) topic of properly supporting extra-data
distribution offline, see https://github.com/flatpak/flatpak/issues/969

(cherry picked from commit 0bf8cf9a08)
2021-04-06 10:10:32 +02:00
Simon McVittie
9a61d2c44f build: Convert environment into a sequence of bwrap arguments
This means we can systematically pass the environment variables
through bwrap(1), even if it is setuid and thus is filtering out
security-sensitive environment variables. bwrap itself ends up being
run with an empty environment instead.

This fixes a regression when CVE-2021-21261 was fixed: before the
CVE fixes, LD_LIBRARY_PATH would have been passed through like this
and appeared in the `flatpak build` shell, but during the CVE fixes,
the special case that protected LD_LIBRARY_PATH was removed in favour
of the more general flatpak_bwrap_envp_to_args(). That reasoning only
works if we use flatpak_bwrap_envp_to_args(), consistently, everywhere
that we run the potentially-setuid bwrap.

Fixes: 6d1773d2 "run: Convert all environment variables into bwrap arguments"
Resolves: https://github.com/flatpak/flatpak/issues/4080
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=980323
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-21 14:16:44 +01:00
Simon McVittie
bbf6debec2 Add an option to share the pid namespace with the parent flatpak
As with flatpak run --parent-expose-pids, this will only work if we have
a working, non-setuid bwrap. Systems where user namespace creation is
restricted and bwrap needs to be setuid (Debian 10, RHEL/CentOS 7,
Arch Linux linux-hardened kernel) will have degraded functionality.

This option is similar to --expose-pids, except that instead of making
the subsandbox use a nested pid namespace inside the parent's, it makes
the subsandbox share the parent's pid namespace as-is, so that process
IDs in the parent and the subsandbox are interchangeable. This will
be useful if the parent and the subsandbox communicate via protocols
that assume a global view of the process ID namespace, for example
passing process IDs across an AF_UNIX socket or in shared memory.

In particular, this will be useful for Steam's pressure-vessel container
tool: the IPC between the Steam client and the "game overlay" loaded into
Steam games uses process IDs, and becomes confused if they don't match up.

This weakens the security boundary between a subsandbox and the parent,
but that's OK in some cases, especially if the subsandbox is being used
as a way to get a different runtime /usr (flatpak-spawn --latest-version
or #4018) rather than as a security boundary.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-12 09:55:23 +01:00
Philip Withnall
9411fe2bca flatpak: Add --print-updated-env option to print environment
This is the environment needed to use flatpaks; a following commit will
hook this up to the systemd environment generator.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-22 14:21:54 +01:00
Phaedrus Leeds
91223477d4 app: Handle NULL flatpak_instance_get_app()
Gracefully handle flatpak_instance_get_app() returning NULL, which
happens for example when there is a shell in a runtime, e.g. flatpak run
--command=sh org.gnome.Platform
2020-12-21 09:11:08 +01:00
Haochen Tong
b0b42e70ff app: fix crash when killing a process without a name 2020-12-21 09:11:08 +01:00
Alexander Larsson
b3321e9179 extra-data: Resolve runtime from the target installation
When installing to an installation we need to find the runtime to use
for the apply-extra-data script from the installation we're targeting,
because that is the one that FlatpakTransaction guaranteed has the
required dependencies (although its possible they came from the
default dependency source too, i.e. the system repos).

In particular, we run into this issue if nothing is installed
anywhere, and then we install an extra-data app into a custom
directory. The transaction will download the runtime, and it
will not be anywhere else. Without this change flatpak only
looked for the dependency in the systam an regular user dirs
where it isn't.
2020-12-09 16:12:25 +01:00
Phaedrus Leeds
2a8602ed88 app: Swap order of rebase/uninstall calls
In case the second of these two fails, the first will still have been
added to the transaction. And since it's better to install the renamed
app but not uninstall the old one, than to uninstall the old one but not
install the new one, swap the order.

See also https://github.com/flatpak/flatpak/issues/3991
2020-12-09 09:03:31 +01:00
Alexander Larsson
c4d2d6f0a9 cli: Show branch in eol messages 2020-11-16 11:23:10 +01:00
Alexander Larsson
7eb5f4ddc8 cli-transaction: Better handling of EOL refs
We remember what action we took for EOLs, and for sub-refs (ie .Locale)
we reuse that.

Also, we show if eol:ed refs are pinned (as that makes them not be
auto-uninstalled), and we list the apps that use the eol:ed runtime
ref.

Example run:
```
Looking for updates…
Info: (pinned) org.gnome.Sdk.Compat.i386 is end-of-life, with reason:
   The GNOME 3.34 runtime is no longer supported as of 14th August 2020. Please ask your application developer to migrate to a supported platform.
Info: org.gnome.Platform is end-of-life, with reason:
   The GNOME 3.32 runtime is no longer supported as of 11th March 2020. Please ask your application developer to migrate to a supported platform.
Applications using this runtime:
   org.gnome.HexGL
```
2020-11-16 11:23:10 +01:00
Alexander Larsson
866d471d37 build-repo: Switch order of subset and options columns
The subset column is typically short, while for eol options the
options column can be very long. So, it makes more sense to have the
options at the end.
2020-11-14 11:12:28 +01:00
Alexander Larsson
60caa765de remote-list: Support showing the subset 2020-11-13 10:32:19 +01:00
Alexander Larsson
754e1fb5d4 Allow configuring the subset
This adds support to remote-add, remote-modify and the flatpakrepo file
parser.
2020-11-13 10:32:19 +01:00
Alexander Larsson
a679fd5787 remote-repo: Properly list subset info
We don't user subsummary names, but the highlevel summary names.
2020-11-13 10:32:19 +01:00
Alexander Larsson
bf5329aa69 table-printer: Add append_with_comma_unique
This means we can ensure a flag is only added once
2020-11-13 10:32:19 +01:00
Alexander Larsson
cbe8e8ca36 build-export: Support --subset to add subsets 2020-11-13 10:32:19 +01:00
Alexander Larsson
e4c52df63f build-commit-from: Remove leftover spew 2020-11-13 10:32:19 +01:00
Alexander Larsson
4f793a45c2 Remove some spammy debug spew
as_store_find_app() was constantly spewing things you don't really
need to see.
2020-11-10 14:32:13 +01:00
Alexander Larsson
b111965640 decomposed: Convert flatpak_dir_read/set_active() 2020-11-10 14:32:13 +01:00
Alexander Larsson
adb3b61f0a decomposed: Return FlatpakDecomposed from flatpak_dir_find_remote_ref() 2020-11-10 14:32:13 +01:00
Alexander Larsson
e633fe0d81 Remove last uses of flatpak_decompose_ref() 2020-11-10 14:32:13 +01:00
Alexander Larsson
1159004dc8 Add len argument to flatpak_decomposed_is_arches()
This allows this to be used both with strv (len=-1) and other arrays.
2020-11-10 14:32:13 +01:00
Alexander Larsson
c5b2c60609 decompose: Convert more FlatpakDir functions to use FlatpakDecomposed 2020-11-10 14:32:13 +01:00
Alexander Larsson
409fa1eafc decomposed: Use FlatpakDecomposed in flatpak_run_* 2020-11-10 14:32:13 +01:00
Alexander Larsson
3d8c04db50 CliTransaction: Use the FlatpakDecomposed from the transaction
There is no need to re-split the ref.
2020-11-10 14:32:13 +01:00
Alexander Larsson
8dc9318346 CliTransaction: Only print "partial" in the actual partial case
We used to match the ref id with .Locale and print "partial" in the
transaction status, but that is not right. Sometimes we do other refs
partially and sometimes locales are not partial. We now use the status
of the subpaths to do the right thing here.
2020-11-10 14:32:13 +01:00
Alexander Larsson
b6a1eb8d48 Delete some unused variables 2020-11-10 14:32:13 +01:00
Alexander Larsson
a988ee19d8 decompose: Use FlatpakDecomposed for bundles 2020-11-10 14:32:13 +01:00
Alexander Larsson
a3a2dcb2c5 decomposed: Remove _decomposed prefix on functions
We now converted most of these and removed the non-prefixed functions,
so rename them back.
2020-11-10 14:32:13 +01:00
Alexander Larsson
38a0706e76 decomposed: Return decomposed from find_installed_pref/ref 2020-11-10 14:32:13 +01:00
Alexander Larsson
d8ad979378 repair: Convert to decomposed 2020-11-10 14:32:13 +01:00
Alexander Larsson
6897b8e2ff decomposed: Take decomposed arg in flatpak_dir_load_deployed()
Then convert all callers
2020-11-10 14:32:13 +01:00
Alexander Larsson
48641c05f6 app utils: Add print_aligned_take()
This makes it easy to print a string that came from a strdup() like
return value.
2020-11-10 14:32:13 +01:00
Alexander Larsson
1fc8d540d5 uninstall: Use FlatpakDecomposed 2020-11-10 14:32:13 +01:00
Alexander Larsson
b77c337790 update: Convert to user FlatpakDecomposed 2020-11-10 14:32:13 +01:00
Alexander Larsson
eadf6147ae list: Use decomposed 2020-11-10 14:32:13 +01:00
Alexander Larsson
ee9507a81d remote-ls: Fix regression with -a
During the previous coversion we accidentally dropped
flatpak_make_valid_id_prefix() when getting the "parent"
id of a subid (like `foo.Locale`).
2020-11-10 14:32:13 +01:00
Alexander Larsson
fa1a494566 decomposed: Convert various "current ref" functions to use FlatpakDecomposed 2020-11-10 14:32:13 +01:00
Alexander Larsson
ed192e1044 remote-ls: Add a smarter fallback for names if appstream is missing
Rather than just taking the last element of the name we also
look at known extensions like .Platform, .Sdk, .Debug, .Locale, etc.
2020-11-05 10:43:10 +01:00
Alexander Larsson
e1da8d9455 remote-ls: Use list_decomposed() 2020-11-05 10:43:10 +01:00
Alexander Larsson
a60e2cbe2d Remove some unused variables 2020-10-29 15:30:35 +01:00
Alexander Larsson
7483a98769 utils: Allow passing sizes to more utils
These now take (optional) string length args:
  flatpak_id_has_subref_suffix()
  flatpak_levenshtein_distance()
  flatpak_is_valid_name()
  flatpak_is_valid_branch()
2020-10-29 15:30:35 +01:00
Alexander Larsson
f147df908a repo: Support indexed summaries in existing code and add new support
If indexes are available we now use those. Also we now allow listing
subsummaries and filtering by subset prefix.
2020-10-29 15:30:35 +01:00
Alexander Larsson
caa1c8c839 table printer: Add some helpers
Allow looking up pre-existing rows (by key) and appending to existing
cells.
2020-10-29 15:30:35 +01:00
Alexander Larsson
0221f5a1fa summaries: Ensure we can support non-default arches W/ indexed summaries
We need to load the ensure the right arch whenever we need it.

Also this restructures the RemoteState handling a bit in general so that
we avoid loading the same remote state multiple times when converting
partial refs to full refs.
2020-10-29 15:30:35 +01:00
Alexander Larsson
0d2cf085af Add option to disable generating summary index
This is mainly useful for the tests
2020-10-29 15:30:35 +01:00
Alexander Larsson
096daf91f2 summary: Implement a new, more efficient, summary format
This drops the deltas from the summary and uses the per-commit
metadata field to add the cache data to avoid the need for the separate
xa.cache and xa.sparse-cache indexes. This way we avoid repeating the
refs in multiple places.

Nothing uses this format yet, but we still pass make check if we enable
it.
2020-10-29 15:30:35 +01:00
Alexander Larsson
97fa217072 build-commit-from: Add --subset option
This sets the xa.subsets property on the commit, which we will later
use to create subsets of the repo.
2020-10-29 15:30:35 +01:00
Alexander Larsson
aec1f62f8f CLI: Ask for transaction confirmation before authentication
If possible, ask for confirmation of the entire transaction before
starting to do the per-ref authentication. We do this by splitting
the current "ready" callback into two parts, one in ready-pre-auth
and the rest in ready.

There is some complexity added because if we do any authentication
between the two signals we can't back-patch the transaction list we
already printed. To handle this we detect this case and re-print the
table if this happens.
2020-10-09 16:57:57 +02:00