Commit Graph

8205 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
Sebastian Wick
14bfb56ba3 tests: Make it possible to use mesontest --test-args
This makes it possible to pass arguments to g_test_init via mesons
--test-args. This can be useful when one wants to run a single test with
`meson test testlibrary --test-args='-p /context'.
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
lumingzh
cfb89ce026 update Chinese translation 2 2025-10-13 13:54:32 +00:00
lumingzh
750b5567ed update Chinese translation 2025-10-13 13:54:32 +00:00
Adian Kozlica
4f8b935567 feat: json support for table printer 2025-10-13 13:53:15 +00:00
Sebastian Wick
815301f341 doc: Build libflatpak-doc.html
Closes #4591
2025-10-10 10:04:37 +00:00
Sebastian Wick
a57f6bc372 portal: Clear the environment via flatpak arguments
Instead of clearing the environment that we spawn the flatpak executable
with, we use the new --clear-env. For environment variables that we
inherit from the calling instance, we append them as arguments after the
--clear-env so it starts from a clean slate.

Closes: https://github.com/flatpak/flatpak/issues/5271
2025-10-09 18:02:50 +00:00
Sebastian Wick
f760f1b539 run: Add --clear-env option for clearing the outside environment 2025-10-09 18:02:50 +00:00
Luca Boccassi
4c75a168e3 meson: switch default dbus_config_dir to /usr/share/dbus-1/
Upstream/vendor configuration files should be installed under /usr/,
so that local users/admins can install overrides in /etc/.
Distributions like Ubuntu are already manually configuring this,
so just make it the default.
2025-10-09 16:24:52 +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
Ryan Brue
02587b5676 flatpak-metadata: Note host-root symlink pitfalls
Following symlinks from /run/host/root naively (for example, with
realpath()) is wrong.

This commit warns about this problem, and provides examples of how to
avoid it when using the host-root permission, either by using
https://man7.org/linux/man-pages/man2/openat2.2.html for modern kernels,
or 65adfdd5fc/steam-runtime-tools/resolve-in-sysroot.c
for older kernels.

Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
2025-09-24 17:19:21 +00: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
Simon McVittie
2409de5105 Update NEWS
Signed-off-by: Simon McVittie <smcv@collabora.com>
2025-09-08 20:39:51 +01: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
AsciiWolf
5eea330414 Update Czech translation 2025-09-02 15:02:10 +00:00
lumingzh
adfa84ab09 update Chinese translation 2025-09-02 15:01:49 +00:00
Jordan Petridis
16aaa8e3b3 ci: Use a regex to define the stable branches
Avoid doing it manually for each stable branch, and
needing extra steps to create a stable branch.

https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#filter-pattern-cheat-sheet
2025-09-02 15:01:11 +00:00
Sijmen
5d1eaacb26 i18n: Improve dutch translation consistency, with small fixes 2025-09-01 11:01:40 +00:00
Sijmen
f8474ea788 i18n: Update dutch translations 2025-09-01 11:01: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
Georges Basile Stavracas Neto
76266177ab ci: Add flatpak-1.16.x to branch allowlist
This lets CI run for the flatpak-1.16.x branch. Needs backporting to
fully work.
2025-09-01 10:30:07 +00:00
Piotr Drąg
a832df659f Update Polish translation 2025-09-01 09:39:34 +00:00
Simon Chopin
7399dea960 testlib: add expected argument to fcntl(F_DUPFD)
The F_DUPFD and its relative F_DUPFD_CLOEXEC both expect an int argument
as extra argument, being the minimal value for the new FD. This argument
must be within the accepted range (see ulimit -H -n).

This was detected in Ubuntu during testing against the latest glibc,
stracing resulted in:

107244 fcntl(1, F_DUPFD_CLOEXEC, 1847846346272) = -1 EINVAL (Invalid argument)

On the system in question (ppc64el machine running Ubuntu Questing), the
relevant limit is 524288.

For the fix we use 3 as a reasonable floor value, as in the first one
after stderr. It also happens to be the one used in revokefs/main.c.

Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/2121039
2025-08-28 11:21:18 +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
Piotr Drąg
5d35f0deba Update POTFILES.in 2025-08-27 15:50:24 +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
555e9200d9 libtest.sh: Add have_working_bwrap to skip over parts of a test 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
eee21d5a27 builtins/install: Allow direct installation from OCI images
Similar to bundle installs, add:

 flatpak install [--image] docker://registry.example.com/image:latest
 flatpak install [--image] oci:/path/to/image

These is useful for testing purposes and in certain cases when installing
Flatpaks on disconnected systems.
2025-08-25 15:56:20 +00:00
Sebastian Wick
ee9d25dfe2 builtins/install: Create install transaction in common function 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