Commit Graph

2359 Commits

Author SHA1 Message Date
Patrick
e110bf7c7f Merge branch 'main' into appstreamcli-compose 2023-01-07 18:48:28 -06:00
Simon McVittie
7a99c82900 dir: Use consistent FlatpakRunFlags everywhere
In principle either of these functions might read any of the flags.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-19 19:15:23 +00:00
Simon McVittie
e69afb1986 portal: Factor out flatpak_bwrap_is_unprivileged()
We can use this for other features that rely on having a non-setuid
version of bubblewrap.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-19 19:15:23 +00:00
Simon McVittie
60e2cceb8c common: Replace all flatpak_debug2() with g_debug()
They are now equivalent.

Resolves: https://github.com/flatpak/flatpak/issues/5001
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
Simon McVittie
c2c034733e common: Make flatpak_debug2() use the same domain as g_debug()
Now that we are logging `flatpak -v` messages with log level INFO,
and printing INFO messages in the same way as DEBUG, we can reserve
log level DEBUG for `flatpak -v -v` messages. This means we no longer
need a weird secondary debug domain.

There is a very small behaviour change here: G_MESSAGES_DEBUG=flatpak
is now similar to `flatpak -v -v` (previously `flatpak -v`), and
G_MESSAGES_DEBUG=flatpak2 no longer has any effect. This seems more in
line with what would be expected from a GLib-based application.

In flatpak(1) and the system helper, this does not change behaviour
other than that: the same messages are logged by `-v` and by `-v -v`
as before.

In daemons that do not implement `-v -v` (the OCI authenticator, portal
and session helper), it continues to be necessary to use
G_MESSAGES_DEBUG to see flatpak_debug2() messages.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
Simon McVittie
07a6541f06 common: Use g_info() for messages that will be shown by flatpak -v
This brings us one step closer to being able to stop using the flatpak2
log domain for messages that are exclusive to `flatpak -v -v`.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
Simon McVittie
1eed25617c Replace calls to g_memdup() with g_memdup2()
g_memdup() is subject to an integer overflow on 64-bit machines if the
object being copied is larger than UINT_MAX bytes. I suspect none of
these objects can actually be that large in practice, but it's easier
to replace all the calls than it is to assess whether we need to
replace them.

A backport in libglnx is used on systems where GLib is older than 2.68.x.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-12 19:15:52 +00:00
Leorize
df0b9d98b5 flatpak-run: unset GIO_EXTRA_MODULES
This variable contains paths to load GIO modules from. For the most
part, they refer to paths outside of the sandbox or if they happen
to be in the sandbox, would contain modules that are incompatible with
the sandbox runtime (ie. different libc).

While I've not found programs that would crash outright, it may cause
unexpected behaviors (eg. Apostrophe not being able to render math in
preview panel).

This variable is set by NixOS for its dependency boxing.
2022-12-07 16:20:51 -06:00
Leorize
751ff11d3a flatpak-run: unset XKB_CONFIG_ROOT
This variable is typically used to configure the use of a custom
set of XKB definitions. In those cases, it's mostly meant for the
X11 server or Wayland compositor. NixOS is known to employ this
variable for their custom XKB layout implementation.

When the path it points to is unreachable (due to the sandbox),
most GTK+/Qt applications will crash on Wayland.

Unsetting this does not seem to negatively impact the use of custom
XKB layouts with Flatpak applications.
2022-12-01 20:01:14 -06:00
Philip Withnall
9ec783f029 flatpak-dir: Clean up old leaked deploy dirs at start of deploy
Following on from commit 85a83a06f9, add some code to clean up old
leaked deploy tmpdirs when we next try to deploy the same app
(successfully or not).

This should free up disk space leaked by failed deploys pre-85a83a06f95.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-16 18:46:01 +00:00
Philip Withnall
6c7eb34dd6 flatpak-dir: Add a debug message to remove_old_appstream_tmpdirs()
This should make it a bit clearer when `rm -rf` is being used in the
debug logs.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-16 18:46:01 +00:00
Erick555
d8695f3071 Clear more temporary file paths from env
This supplements clearing TMPDIR env variable which is only one among variables used for storing temporary files. Any of those leaking from host may confuse flatpak apps which try to save temporary files under non-existing directory in sandbox.

See https://github.com/flathub/com.logseq.Logseq/issues/29 for real world example.
2022-11-10 12:34:01 +00:00
Philip Withnall
ce1829a703 flatpak-dir: Use FD-relative operations in a few more places
These are the easy places to use the new `deploy_base_dfd` from to make
some more operations relative to an already-open dirfd in
`flatpak_dir_deploy()`.

This should introduce no functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-01 14:29:28 +00:00
Philip Withnall
85a83a06f9 flatpak-dir: Clean up temp deploy dir on failure of flatpak_dir_deploy()
This already happens for installs due to the cleanup path in
`flatpak_dir_deploy_install()`, but it doesn’t happen for other calls to
`flatpak_dir_deploy()`. Notably, during updates of already installed
apps.

Specifically, this means that if an app update is cancelled due to being
blocked by a parental controls policy, the temp deploy dir for that app
(such as
`~/.local/share/flatpak/app/com.corp.App/x86_64/stable/.somehex-XXXXXX`)
will be leaked. It will never be automatically cleaned up, as it’s not
in `/var/tmp` either.

Fix that by using `glnx_mkdtempat()` to create a scoped temporary
directory.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-01 14:29:28 +00:00
Gaël Donval
397c97de9f Add /efi in the hidding list when (fs=host)
When filesystem=host access is provided, some root folders are hidden, including /boot.

The bootloader specification now recommends mounting the system EFI filesystem in /efi
(currently visible) instead of /boot/efi (currently hidden). This hides /efi for the same 
reasons /boot is already hidden.
2022-11-01 10:06:05 +00:00
Simon McVittie
9eb824f863 Add a Meson build system
Resolves: https://github.com/flatpak/flatpak/issues/2241
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-24 16:12:14 +01:00
Michael Catanzaro
1c32317841 Block KRB5CCNAME from inheriting into sandbox
If this environment variable is set on the host, it's going to mess up
authentication in the sandbox. For example, if the host has:

KRB5CCNAME=KCM:

then the sandboxed process will try to use the host KCM socket, which is
not available in the sandboxed environment, rather than the gssproxy
socket that we want it to use. We need to unset it to ensure that
whatever configuration we ship in the runtime gets used instead. We have
switched the GNOME runtime to use an empty krb5.conf and it works as
long as we don't break it with this environment variable meant for the
host.
2022-09-19 09:03:48 +02:00
Michael Catanzaro
0184e542c5 Bind gssproxy socket into sandbox environment
We're using a directory rather than binding a socket directly for
increased robustness. In theory, if gssproxy crashes on the host, a new
socket that a new gssproxy process creates should be immediately visible
inside the sandbox. Nifty.

Previously, applications that wanted to use Kerberos authentication
would have to punch a sandbox hole for the host's KCM socket. In
contrast, this gssproxy socket is designed for use by sandboxed apps.

See also: https://github.com/gssapi/gssproxy/issues/45
2022-09-19 09:03:48 +02:00
Simon McVittie
3a93ef4842 enum-types: Make generated files more reproducible
`@filename@` expands to the relative or absolute path to the source
file, which varies between build systems and build directories.
`@basename@` expands to the basename of the file, which stays constant
across more build configurations.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-07 09:21:58 +02:00
Simon McVittie
3591ba08f6 uri: Don't rely on g_time_zone_new_offset()
g_time_zone_new_offset() was new in GLib 2.58, but Ubuntu 18.04 'bionic'
only has GLib 2.56, and in theory we still claim to support versions
all the way back to GLib 2.46. If that function isn't available,
reimplement it in terms of the deprecated g_time_zone_new().

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-07 09:21:19 +02:00
Simon McVittie
8c51650662 uri: Don't do scheme-based normalization with GLib 2.66.x
GLib 2.66.x is present in Debian 11, and didn't support scheme-based
normalization. This has two effects:

1. URIs containing an explicit port, like https://example.com:443/,
   don't get normalized to https://example.com/
2. URIs with an empty path, like https://example.com, don't get
   normalized to https://example.com/

Neither of these normalizations seems particularly critical for Flatpak.

Resolves: https://github.com/flatpak/flatpak/issues/5062
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-06 13:20:05 +02:00
git-bruh
83b881cdc2 flatpak-utils-http: check for HTTP2 support before trying to use it 2022-09-06 12:47:16 +02:00
Joaquim Monteiro
bd53d40962 Allow the modify_ldt syscall when using multiarch
Some patches for Wine, as well as old 16-bit programs,
require this syscall to work.

As the only programs that need it are using --allow=multiarch,
this commit keeps it disabled when it isn't used,
as a security hardening measure.

For more information, see issue #4297.
2022-09-06 12:34:17 +02:00
Phaedrus Leeds
600e18567c Add a vim modeline and .editorconfig
To make indentation work with less effort. The modeline was copied from
libostree with minor modification and the .editorconfig from GLib.

The advantage of having both a modeline and an editorconfig is we can
work out of the box on more editor setups, and the modeline allows us to
specify the style with a lot more fine grained control.
2022-08-22 19:48:10 -07:00
Milan Crha
dc82a19dc5 common: Add thread safety on libcurl usage
There can happen a race condition between internal libcurl structure
content when two threads set the `data` structure for the callbacks
from two threads, which can cause access of already freed stack-allocated
`data`, resulting in a memory corruption.

Closes https://github.com/flatpak/flatpak/issues/3701
2022-08-22 10:36:30 +02:00
Nick Reiley
764e5a4d0c Add --socket=gpg-agent 2022-08-16 13:29:06 +02:00
Simon McVittie
092d30c777 exports: Add logging at a finer granularity
This helps to figure out what is going on if the expected paths are not
being exported.

The general design principle here is that I've used flatpak_debug2()
(which appears in `flatpak -v -v` but not `flatpak -v`) for situations
which occur under normal circumstances, and g_debug() (which appears
in `flatpak -v` or higher) for situations which are expected to be
uncommon.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-16 10:52:37 +02:00
Patrick Griffis
6540f85511 Allow sub-sandboxes to own MPRIS names
We already allow normal apps to own MPRIS names but subsandboxes could not.

This allows them with the same dbus restrictions that they must be
prefixed by $app_id.Sandboxed.

This will be used by WebKitGTK.
2022-08-16 10:48:00 +02:00
Simon McVittie
ca992c7862 run: Preserve X11 display number instead of redirecting it to :99
Suppose the user's "real" X11 display on the host is Xorg or Xwayland
listening on :42, but they also have an Xvfb server listening on :99.

If we change the X11 display number to the arbitrary value :99, and
the Flatpak sandbox shares its network namespace with the host, then
clients inside the Flatpak sandbox will prefer to connect to the
abstract socket @/tmp/.X11-unix/X99 (which is Xvfb), rather than the
filesystem-backed socket /tmp/.X11-unix/X99 in the sandbox (which is
really /tmp/.X11-unix/X42 on the host, i.e. Xorg or Xwayland).

If they're relying on Xauthority (MIT-MAGIC-COOKIE-1) for access
control (as many display managers do), then this will fail, because
we gave the sandboxed app access to the cookies for Xorg/Xwayland
(rewriting their display number from 42 to 99 as we did so), but
Xvfb does not accept those cookies.

If we're relying on `xhost +"si:localuser:$(id -nu)"` for access control
(as gdm does), then the Flatpak app will successfully (!) connect to
whatever is on :99, for example Xvfb or Xephyr, which is rarely what
anyone wants either.

Resolves: https://github.com/flatpak/flatpak/issues/3357
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-16 10:45:08 +02:00
Phaedrus Leeds
53a0b528bf Add DeploySideloadCollectionID flatpakref/flatpakrepo key
When Flatpak's P2P updates support was replaced with the "sideloading"
implementation in 1.7.1, a new server side repo config key
"deploy-sideload-collection-id" was added which gets set when you pass
"--deploy-sideload-collection-id" to "flatpak build-update-repo", and
has the effect of setting "xa.deploy-collection-id" in the repo metadata
that is pulled by clients, which itself causes a collection id to be set
on the remote for clients using Flatpak >= 1.7.1.

This commit adds an analogous key in flatpakref and flatpakrepo files,
so the collection id can be set when the remote is configured, rather
than later on when the repo metadata is pulled and acted upon. As before
with DeployCollectionID, it has no difference in function compared to
DeployCollectionID or CollectionID and the only difference is which
Flatpak versions are affected.

It would've been better if this were added in 1.7.1 when the sideload
support was added, but alas here we are.

(Also update the docs and unit tests)
2022-08-16 10:37:36 +02:00
Phaedrus Leeds
bf37034663 common: Add missing error codes to GDBusErrorEntry array
These were mistakenly only added to flatpak-error.h
2022-07-25 16:58:32 -04:00
Phaedrus Leeds
e739773056 app: List apps that use a runtime extension when it's EOL
Currently if a runtime extension, e.g.
org.freedesktop.Platform.html5-codecs//18.08 is used by a runtime
org.kde.Platform//5.12 which itself is used by one or more apps, when we
print a message to the user about html5-codecs being EOL, we don't find
any apps using it and don't print any. Fix this by including apps that
indirectly use a runtime extension in the "Applications using this
runtime:" list.

In a later commit we can re-use the helper function added here to add a
confirmation dialog if the user tries to remove a runtime extension
that's being used; currently we just let them remove it.

This is limited to only looking in the current flatpak installation, so
a per-user app using a system-wide runtime extension would not be found.

This is implemented using in-memory caches because otherwise it is
horribly slow; see
https://github.com/flatpak/flatpak/pull/4835#discussion_r876425289

Helps: #3531
2022-07-21 14:32:45 -05:00
Phaedrus Leeds
07ef6a41fa transaction: Fix typos and wrap lines 2022-07-20 21:37:03 -05:00
Phaedrus Leeds
dffa10dd61 transaction: Tweak docs on get_related_to_ops() API 2022-07-20 21:37:03 -05:00
Phaedrus Leeds
43768b2510 common: Remove erroneous Since: annotations
I think these were accidentally copied from GLib.
2022-07-18 18:51:07 -05:00
Philip Withnall
ab028e0d71 flatpak-remote: Fix some minor leaks of some property values
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-06-20 13:17:45 +02:00
Alexander Larsson
aea92f3909 http: Support curl
If build with curl (--with-curl, which is default) then we use libcurl
instead of libsoup as the http backend.
2022-06-16 13:49:45 +02:00
Alexander Larsson
0c6bb85cb6 flatpak-http: Restructure the soup http implementation
This miniminzes the soup implementation by moving it out of the
highlevel multiple-retry entry points and simplifying the
lower level part to use only one shared helper.

This will also make it easier to replace the soup specific
parts.
2022-06-16 13:49:45 +02:00
Alexander Larsson
69f4543bc0 uri utils: Add some helpers for HTTP timestamps 2022-06-16 13:49:45 +02:00
Alexander Larsson
1c9e65d5e4 Move all use of soup APIs into flatpak-utils-http
This will allow us to make the soup dependency optional.
2022-06-16 13:49:45 +02:00
Alexander Larsson
676c018113 oci-registry: Use the new http methods to replace last soup use 2022-06-16 13:49:45 +02:00
Alexander Larsson
6f15c147c5 flatpak-uri: Add some uri query and http header utils
This copies and simplifies some helpers from soup:
 * Encoding url queries
 * Parsing simple http header parameter lists

The goal is to use mostly GUri and a few extra helpers for the flatpak
internals, and then pass raw string uris to the http functions which
could then be backed by any kind of http implementation.
2022-06-16 13:49:45 +02:00
Alexander Larsson
98651d33b6 oci-registry: Use the new utils to encode url queries 2022-06-16 13:49:45 +02:00
Alexander Larsson
62f33a4d6d oci-registry: Use the new http header parser 2022-06-16 13:49:45 +02:00
Alexander Larsson
618d0c8fae http: Add flatpak_load_uri_full with some more complete features
This allows:
 * getting http status
 * getting www-authenticate header
 * Doing HEAD instead of get

This is needed by the OCI registry code for authentication
2022-06-16 13:49:45 +02:00
Alexander Larsson
b1083a4c41 http utils: Make a generic FlatpakHttpSession instead of SoupSession
Its still just a SoupSession, but now the implementation is more
centralized and can be something else down the line.
2022-06-16 13:49:45 +02:00
Alexander Larsson
d4508905a5 Use GUri (possibly with backport) instead of SoupURI
As discussed in https://github.com/flatpak/flatpak/pull/4582 we
want ot use GUri for soup3, and if we want to use libcurl we might
as well also use it to avoid complex ifdefs, as we're linking to it
already via glib.

This imports a subset of GUri for older versions of glib.
2022-06-16 13:49:45 +02:00
Alexander Larsson
f800c79e6f oci-registry: Be better at finding error message in registry reponses
This now finds the correct error message in the redhat oci repo for rhel.
2022-06-16 13:49:45 +02:00
Phaedrus Leeds
d764202ce7 transaction: Add new API for getting an op by ref
This will be useful in gnome-software's flatpak plugin, which currently
iterates over the operations a few times, and it will be useful
internally as well.
2022-06-15 16:44:17 -07:00
Phaedrus Leeds
476b277e5a dir: Don't waste time reading metadata for the wrong ref
We don't support extensions of extensions, as evidenced by add_related()
only being called once in flatpak_transaction_real_run(), so there's no
need to read the metadata file of an extension in
flatpak_dir_find_local_related(), only to find that it doesn't have any
extensions of its own.
2022-06-15 16:44:17 -07:00