Commit Graph

2581 Commits

Author SHA1 Message Date
Sebastian Wick
c38e481fb4 context: Handle x11-fallback by converting to a conditional
This internally converts `x11-fallback` to `if:x11:!has-wayland` at
the earliest place possible, and converts back when serializing to a
file.
2025-10-13 18:31:33 +00:00
Sebastian Wick
a92c5f686e context: Support condtional permissions for socket and devices
This uses the new FlatpakPermissions API to support the new
commandline options --socket-if= and --device-if=.
2025-10-13 18:31:33 +00:00
Alexander Larsson
b93b58a44e context: Add new FlatpakPermission(s) type
This adds a new type that is meant to track more complex permissions
than a pure bitmask, including conditional dependencies. It is not yet
used, but it will be used for at least the socket and device
permissions.

For each possible permission we track whether the permission is
unconditionally allowed, unconditionally disallowed, or if it is
conditionally allowed (allowed if some conditions are met).

Additionally we track for each permission whether stacking the context
on top of another will reset permissions in the layer below. This is a
new feature, because previously merging layers *always* overrode the
value from below, whereas conditional permissions can either stack on
top of, or replace the underlying layer.

In terms of the keyfile, there are 4 possible types of layers:

1) Add a permission, removes all partial permissions below
socket=pipewire

2) Remove access, removes both partial and full permissions below
socket=!pipewire

3) Adds a partial permission, keeping whatever is already there:
socket=pipewire;pipewire:if:has-wayland
Note: This adds a plain `pipewire` for backwards compat.
Note: If parent has full pipewire access, this is a no-op.

4) Adds a partial permission, remove all previous access
socket=!pipewire;pipewire;pipewire:if:has-wayland
Note: This seems weird as it has both !pipewire and pipewire, but older versions
will read these in order and get the right result.

Additionally, partial permissions can have multiple conditions:
socket=pipewire;pipewire:if:has-something;pipewire:if:has-other;

In such a case the socket will be accessible if any condition matches.

Conditions can also be negated:
socket=pipewire;pipewire:if:!has-something;

Due to backwards compatibility we have to add the non-conditional
permission as well as the conditional, as older flatpak will ignore
the conditional. This is handle when serializing/deserializing the
permissions, and internally we don't have to care about this.
2025-10-13 18:31:33 +00:00
Sebastian Wick
5852e6f5e6 common: Pass the context to flatpak_context_*_to_args
Instead of pulling out data from the context and passing it to the
function. This allows to make further changes to the function which
require more data from the context.
2025-10-13 18:31:33 +00:00
Sebastian Wick
e74709b6ce common: Let flatpak_context_bitmask_to_string populate a GPtrArray
This moves the allocation of the GPtrArray to the caller which will
become useful in a future commit because another function can add more
elements to the same array.
2025-10-13 18:31:33 +00:00
Sebastian Wick
25e1a2a257 common: Split out parts of flatpak_context_load_metadata
Those functions will become a bit more complex in future commits and
this prevents flatpak_context_load_metadata from becoming increasingly
complex.
2025-10-13 18:31:33 +00:00
Alexander Larsson
5c12cd83a1 tests: Add support for adding internal tests
If the internal_tests option is enabled we build some internal tests
into the binary. These are added to the tests we run in testlibrary.

This is not intended to be enabled in production, as it adds size to
the real binary, but is useful for CI and development.
2025-10-13 18:31:33 +00:00
bbhtt
9dccb7a722 repo-utils: Drop stripping .desktop suffixes from appstream cids
This will pass the exact appstream component ID to copy_icon

This was introduced in 7dd92d8a9b to
handle appstream component IDs that ended in two `.desktop` suffixes.

Recent analysis of appstream data shows that at least on Flathub no such
appstream cid exist anymore and Telegram now has component ID
`com.telegram.desktop`.

With the switch to libappstream, appstreamcli-compose produces icons in
`share/app-info/flatpak` named by the appstream component ID instead of
the `$FLATPAK_ID` used by appstream-glib. This causes applications whose
`$FLATPAK_ID` does not end with `.desktop` but their appstream-component
ID ends in `.desktop` ie. `$FLATPAK_ID != appstream-cid` to loose icons
from the appstream ostree ref as `copy_icon` was being fed the id
without `.desktop` but icons were created by appstreamcli
with `.desktop` in them.

This will avoid adding anymore ID heuristics/workarounds on either side,
per the discussion in [1].

An application with the `$FLATPAK_ID` `com.telegram.desktop` and the
appstream ID `com.telegram.desktop.desktop` will be broken with this
change but such dual `.desktop` IDs are non existent and should be fixed
individually or be blocked on an app store level.

[1]: https://github.com/flathub/flathub/issues/4222
2025-10-13 14:07:33 +00:00
Sebastian Wick
f760f1b539 run: Add --clear-env option for clearing the outside environment 2025-10-09 18:02:50 +00:00
bbhtt
cd0212aa40 utils-http: Fix an uninitialised variable warning
Fixes c75ba1c7e1

```
In file included from /usr/lib/aarch64-linux-gnu/glib-2.0/include/glibconfig.h:9,
 from /usr/include/glib-2.0/glib/gtypes.h:34,
 from /usr/include/glib-2.0/glib/galloca.h:34,
 from /usr/include/glib-2.0/glib.h:32,
 from /usr/include/glib-2.0/gobject/gbinding.h:30,
 from /usr/include/glib-2.0/glib-object.h:24,
 from /usr/include/glib-2.0/gio/gioenums.h:30,
 from /usr/include/glib-2.0/gio/giotypes.h:30,
 from /usr/include/glib-2.0/gio/gio.h:28,
 from ../common/flatpak-utils-http.c:23:
In function ‘glib_autoptr_clear_GFileEnumerator’,
 inlined from ‘glib_autoptr_cleanup_GFileEnumerator’ at /usr/include/glib-2.0/gio/gio-autocleanups.h:69:1,
 inlined from ‘flatpak_get_certificates_for_uri’ at ../common/flatpak-utils-http.c:284:34:
/usr/include/glib-2.0/glib/gmacros.h:1361:10: warning: ‘enumerator’ may be used uninitialized [-Wmaybe-uninitialized]
 1361 | { if (_ptr) (cleanup) ((ParentName *) _ptr); } \
 | ^
/usr/include/glib-2.0/glib/gmacros.h:1379:3: note: in expansion of macro ‘_GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS’
 1379 | _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(TypeName, TypeName, func)
 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/gio/gio-autocleanups.h:69:1: note: in expansion of macro ‘G_DEFINE_AUTOPTR_CLEANUP_FUNC’
 69 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileEnumerator, g_object_unref)
 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../common/flatpak-utils-http.c: In function ‘flatpak_get_certificates_for_uri’:
../common/flatpak-utils-http.c:284:34: note: ‘enumerator’ was declared here
 284 | g_autoptr(GFileEnumerator) enumerator;
```
2025-10-08 14:14:50 +00:00
Ryan Brue
446afd82b0 formatting(flatpak-context): Fix a few wrong indentations
Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
2025-09-25 11:03:29 -05:00
Harald Sitter
0493219ca5 exports: add host-root
Adapted from: https://github.com/flatpak/flatpak/pull/6125

In systemd v259, /run/host/root will be a documented location
for bind mounting the host's root filesystem into a
container. Ref: https://github.com/systemd/systemd/pull/38384

host-root is the sledgehammer permission for file browsers
and similar apps that the user might want to give full access
to.

This works same as the existing host keywords by mounting into
/run/host/root. applications will need adjustments to essentially
treat that path as "root".

Since this opens the door to all sorts of malicious software, the
permission should be put under tight review in flatpak
repositories.

Resolves: #5723

Co-authored-by: Ryan Brue <ryanbrue.dev@gmail.com>
2025-09-24 17:19:21 +00:00
joj
f53cef0041 Enable VA-API extension for Intel GPUs if either i915 or xe is loaded
Xe module supports the discrete and new integrated GPUs (the Arc series) and
the i915 supports the older Intel integrated GPUs (Intel HD).

Closes: https://github.com/flatpak/flatpak/issues/5248
2025-09-10 22:44:52 +00:00
Mary Strodl
919d2922bf common: support reinstall option on bundle installations
Fixes #2489

Adds and wires up a `reinstall` option to
`flatpak_dir_install_bundle`. Previously, bundle install
transactions would silently drop the reinstall flag.
2025-09-08 12:57:40 +00:00
Sebastian Wick
3773617f30 oci: Actually only return the only manifest in get_only_manifest
Instead of using flatpak_oci_manifest_descriptor_get_ref which requires
the `org.opencontainers.image.ref.name` annotation, get any valid
manifest, and make sure to return NULL if there are multiple valid
manifests.

Closes: https://github.com/flatpak/flatpak/issues/6081
2025-09-01 10:59:29 +00:00
Sebastian Wick
d944d9afb6 dir: Propagate errors from flatpak_remote_state_fetch_image_source 2025-09-01 10:59:29 +00:00
Owen W. Taylor
2c7b9342cc image-source: Pass token to flatpak_image_source_new_remote()
Since flatpak_image_source_new_remote() already tries to load files
from the registry, having a separate flatpak_image_source_set_token()
doesn't work - when the token is set, it's already too late to
be passed along with the initial requests.
2025-09-01 10:59:29 +00:00
Sebastian Wick
37d6fbe033 oci-registry: Fix leak in unpack_archive by freeing the archive path 2025-08-28 11:20:01 +00:00
Sebastian Wick
5a80ac679d oci-registry: Fix leak by freeing certificates in finalize 2025-08-28 11:20:01 +00:00
Kalev Lember
d10e11482d Add initial support for preinstalling flatpaks
This adds new FlatpakTransaction API, and a new top level CLI command to
preinstall flatpaks, that is to install flatpaks that are considered
part of the operating system.

A new drop-in directory /etc/flatpak/preinstall.d/ allows configuring
what apps should be preinstalled, and a new flatpak preinstall command
installs and removes apps based on the current configuration.

A drop-in loupe.preinstall file can look something like this:

[Flatpak Preinstall org.gnome.Loupe]
Branch=stable
IsRuntime=false

The corresponding API is flatpak_transaction_add_sync_preinstalled()
which can be implemented by GUI clients to drive the actual installs
on system startup.

Resolves: https://github.com/flatpak/flatpak/issues/5579
Co-authored-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-08-26 11:51:07 +00:00
Sebastian Wick
667ad4c57b glib-backports: Add g_set_str from 2.84.1 2025-08-26 11:51:07 +00:00
Owen W. Taylor
555d676cc0 Enable collection IDs for OCI remotes
We want to use collection IDs to specify what remote to install from
when processing /etc/flatpak/preinstall.d; in order for this to work
for OCI remotes, we need to permit collection IDs.

 - In flatpakrepo files, don't require a GPGKey for a OCI remote
   with a collection - we don't have signature verification for GPG remotes.
 - Don't validate that the collection ID appears in the summary -
   the image index doesn't currently contain an image ID
2025-08-25 18:49:34 +00:00
Owen W. Taylor
609f0ce0a1 common: Move delta_url into the FlatpakImageSource
Instead of passing the delta URL along with the image source, when
we create an image source for a remote registry, if we find a delta
URL in the metadata, set it on the FlatpakImageSource for later use.

Centralize duplicated code for creating an image source for a remote
repository based on a summary lookup into one place.
2025-08-25 15:56:20 +00:00
Owen W. Taylor
a460dd5069 image-source: Support oci-archive: image sources
Add support for `oci-archive:` image sources by temporarily
unpacking the archive using libarchive.

Co-authored-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-08-25 15:56:20 +00:00
Sebastian Wick
74e4c2a601 oci-registry: Allow passing a NULL URI 2025-08-25 15:56:20 +00:00
Sebastian Wick
3824aba911 oci-registry: Remove a bunch of double newlines 2025-08-25 15:56:20 +00:00
Owen W. Taylor
806fc83cd6 common: Add OCI image installation support 2025-08-25 15:56:20 +00:00
Owen W. Taylor
dc56bda820 image-source: Add flatpak_image_source_new_for_location
Which allows one to create an image source from a container location.

It also adds a new FlatpakDockerReference to access different parts of a
docker reference and changes to FlatpakOciIndex to get a manifest for a
specific architecture.

This will become useful in the next commit when we're going to add
support for installing OCI images.
2025-08-25 15:56:20 +00:00
Sebastian Wick
0bfc82a8a3 transaction: Use g_clear_pointer/object functions for op finalize 2025-08-25 15:56:20 +00:00
Sebastian Wick
15560e87e0 transaction: Typedef structs directly 2025-08-25 15:56:20 +00:00
Owen W. Taylor
5950438ca7 image-source: Replace flatpak_oci_parse_commit_labels with getters
Instead of having one function with a pile of out arguments in
arbitrary order, add getters to FlatpakImageSource.
2025-08-25 15:56:20 +00:00
Owen W. Taylor
59ad08e78c image-source: Refactor - add FlatpakImageSource type
To avoid passing around combinations of a FlaptakOciRegistry with
repository and digest, add a FlatpakImageSource type.

This also reduces duplicated code where every place that did
this independently retrieved the repository and image config.
2025-08-25 15:56:20 +00:00
taoky
dd2a04f978 utils: Don't pass NULL remote to ostree_repo_get_remote_option
Fixes: #4662
2025-08-20 18:27:33 +00:00
taoky
b5f9d6e18a run: Add directory forwarding support
Use document portal's AddFull interface to forward dirs to sandboxed
apps. Requires version 4 of AddFull.

Closes: #4799
2025-08-06 18:16:03 +00:00
Owen W. Taylor
c75ba1c7e1 common: Implement /etc/containers/certs.d for OCI registries
Docker and podman can be configured to use mutual TLS authentication
to the registry by dropping files into system-wide and user
directories. Implement this in a largely compatible way.

(Because of the limitations of our underlying libraries, we
can't support multiple certificates within the same host config,
but I don't expect anybody actually needs that.)

The certs.d handling is extended so that certificates are separately
looked up when downloading the look-aside index. This is mostly
to simplify our tests, so we can use one web server for both -
in actual operation, we expect the indexes to be unauthenticated.

Also for testing purposes, FLATPAK_CONTAINER_CERTS_D is supported
to override the standard search path.

Co-authored-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-05-08 16:08:21 +00:00
Sebastian Wick
d0a5125d38 run: Use the instance id in the cgroup name
The systemd Desktop Environments conventions for cgroup names is

  app[-<launcher>]-<ApplicationID>-<RANDOM>.scope

where RANDOM should ensure that multiple instances of the application
can be launched. Currently flatpak uses the PID of itself but the
instance fullfills this convention and is a bit more useful for matching
the cgroup to a flatpak instance.

There are cases where flatpak is doing some internal work (apply extra
data) where there is no instance id, and more philosophically also no
app instance. In those cases we simply do not move the process to the
cgroup with the XDG convention.
2025-04-30 14:16:11 +00:00
Bartłomiej Piotrowski
b6836ee865 prune: Move locking operations to execute only outside dry run
The original idea behind this code was that the initial lockless scan
of reachable objects will make the locking one fast enough that
it won't matter to software managing flatpak repos like flat-manager.
Few years later I can say this is not true, and the locking variant
of scan does take too long and affects Flathub's publishing process.

By keeping only the lockless variant in dry run, we can run it on a
weekly schedule without affecting operations, and issue actual pruning
with flat-manager which will hold a lock in external system and avoid
executing any actions requiring locking to avoid errors/timeouts.
2025-04-30 14:00:20 +00:00
Philip Withnall
2ae9cfd950 dir: Allow app updates without consulting parental controls
Currently, app installs and updates are treated the same from the point
of view of the parental controls permissions checks. This was intended so
that parents have to re-check each app update to make sure it’s still
appropriate for their children.

In practice, though, parents are not that hands-on, and there are a lot of
regular app updates. The tradeoff between app updates (which bring
security fixes and features) and not changing so much in apps that a
parent’s initial assessment of their suitability for their child is
probably skewed the wrong way. We should be preferring updates (in
particular, so we get security updates), and assuming that if an app is
OK to begin with, it’s probably not going to change so radically as to
become unsuitable for a child with an update.

As a data point, Google Play’s parental controls will allow apps to be
automatically updated even if a child account can’t install new apps.

So, implement this by splitting the existing
`org.freedesktop.Flatpak.override-parental-controls` polkit action in
two: the existing action for _installs_, and a new
`org.freedesktop.Flatpak.override-parental-controls-update` action for
_updates_. `FlatpakDir` is changed to use the appropriate action
depending on whether an app is being installed from scratch or updated.
The default policies for the two actions differ.

Users/Distros who disagree with the new default policy can provide their
own polkit rules to change the behaviour of
`override-parental-controls-update` so that it matches
`override-parental-controls`, to bring back the old behaviour.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: https://github.com/flatpak/flatpak/issues/5552
2025-03-31 13:47:28 +00:00
Sebastian Wick
bc8b40613c run: Add udmabuf to --device=dri
udmabuf allows clients to allocate virtual memory as dmabufs,
which then potentially can be imported by other dma subsystems -
most importantly GPU drivers and KMS. This can avoid copies and
thus increase performance.

Unlike other dmabuf allocators like e.g. dma heaps this doesn't
have known issues relevant for sandboxing. Notably memory accounting
works as expected, so apps can't use udmabuf to escape resource
limitations. For this reason systemd, since version 257[1], grants
"uaccess" access to udmabuf by default, considering it as "safe".

With udmabuf increasingly being availably by default, various apps
and libraries start making use of it - examples include libcamera,
mesa llvmpipe and Gstreamer. Thus let's grant access to it in Flatpak
as well.

For now limit it to "dri" access as sharing buffers with GPUs is
the most common use-case. There is no strong reason to not lift
restrictions further if the need arises, though.

1: https://github.com/systemd/systemd/pull/33738

Signed-off-by: Sebastian Wick <sebastian@sebastianwick.net>
Signed-off-by: Robert Mader <robert.mader@collabora.com>
2025-03-31 13:46:20 +00:00
Simon McVittie
2acbddd95a run-dbus: Don't call GetAddress() if AT_SPI_BUS_ADDRESS is set
In the real at-spi2-core client library, AT_SPI_BUS_ADDRESS is treated
as higher-precedence than the AT_SPI_BUS X11 atom or the GetAddress()
D-Bus method. Mimic this.

We don't currently implement querying the X11 atom because that would
require a libX11 dependency, so leave a comment indicating where it
would appear in precedence order.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-03-31 12:41:32 +00:00
Sebastian Wick
53150218c7 wayland: Unset WAYLAND_DISPLAY, WAYLAND_SOCKET when socket is disabled
To handle those details at the right place (flatpak-run-wayland.c), we
pass if the wayland socket is allowed to flatpak_run_add_wayland_args
and handle it there instead of in the caller.

Closes #3948
2025-03-27 20:04:13 +00:00
Chris Williams
fa252b865a dir: Avoid overwriting error in apply_extra_data()
Fixes 9cd682b057
Helps #5170
2025-02-22 09:59:12 -06:00
Alyssa Ross
114c22e814 build: fix build with -Ddefault_library=static
Static libraries do not carry information about their dependencies.
Thus, libflatpak_dep must include all of the dependencies for
libraries to link against libflatpak.  To do this, I've repurposed the
libflatpak_common_deps variable, which previously was either empty or
contained only wayland_client, and was then included into the list of
dependencies for libflatpak-common, to be a list of all dependencies
required to both build libflatpak-common, and link against it (or
libflatpak).

This fixes building Flatpak with -Ddefault_library=static.  gtkdoc
must currently be disabled due to a Meson bug I'm working on[1].

[1]: https://github.com/mesonbuild/meson/pull/14257
2025-02-15 12:33:28 +01:00
Hubert Figuière
99143ad94b flatpak-dir: Fix a memory leak installing extra-data
Return a borrowed extra_data_name from g_variant_get_child

Signed-off-by: Hubert Figuière <hub@figuiere.net>
2025-02-12 08:34:45 -05:00
David Auer
9f822ff145 run: Unset PYTHONPYCACHEPREFIX from envrionment
This repeatedly lead to errors when users had it set to a directory
accessible from the flatpak when importing pillow/PIL.
2025-02-11 11:36:37 -06:00
Bartłomiej Piotrowski
050f6e35fe prune: Skip calculating potential freed space in the dry run 2025-02-11 13:00:24 +01:00
Chris Williams
23583b7791 utils-http: Simplify unclear expression discovered by clang
Closes #5013
2025-02-04 18:42:15 -06:00
Will Thompson
2eb4819240 Fix "end of line" typo in internal #defines
The ostree and Flatpak APIs both refer to "end of life", but
this internal #define (though not the data stored in the cache)
refer to "end of line".

Fix this.
2025-01-09 17:00:07 +01:00
Hubert Figuière
6b1bb87a29 gir: Fix closure annotations
This is a new warning. Reproducible on F41
Fixes:

../common/flatpak-installation.c:1963: Warning: Flatpak: invalid closure annotation: only valid on callback parameters
../common/flatpak-installation.c:1858: Warning: Flatpak: invalid closure annotation: only valid on callback parameters
../common/flatpak-installation.c:2129: Warning: Flatpak: invalid closure annotation: only valid on callback parameters
../common/flatpak-installation.c:2014: Warning: Flatpak: invalid closure annotation: only valid on callback parameters
../common/flatpak-installation.c:1732: Warning: Flatpak: invalid closure annotation: only valid on callback parameters
../common/flatpak-installation.c:2177: Warning: Flatpak: invalid closure annotation: only valid on callback parameters
../common/flatpak-installation.c:2220: Warning: Flatpak: invalid closure annotation: only valid on callback parameters
../common/flatpak-installation.c:2608: Warning: Flatpak: invalid closure annotation: only valid on callback parameters

Signed-off-by: Hubert Figuière <hub@figuiere.net>
2025-01-09 16:59:40 +01:00
Owen W. Taylor
35995290f5 Add a FLATPAK_DOWNLOAD_TMPDIR variable
Instead of hardcoding /var/tmp when temporarily downloading layer
tarballs, support overriding with a FLATPAK_DOWNLOAD_TMPDIR
environment variable.

We don't use TMPDIR because the layer tarballs can be very big
(in extreme cases like an SDK > 1GB), and TMPDIR is more
likely to point to a in-memory tmpfs.
2024-12-18 16:35:46 +00:00