Commit Graph

2612 Commits

Author SHA1 Message Date
Sebastian Wick
d4751443f5 dir, system-helper: Add support for installing extra-data from OCI
Extra-data usually is downloaded on the user side into an ostree repo.
For system installs, a temporary ostree repo is used on the user side
and then imported on the system side. This doesn't work for OCI images
because importing the image into an ostree repo makes it impossible for
the system side to verify the data.

So instead, the OCI image is first mirrored into a local OCI repo and
then gets imported on the system side, which can verify the image from
the index by the digest.

Closes: https://github.com/flatpak/flatpak/issues/3790
2025-11-20 23:14:18 +00:00
Sebastian Wick
ac0b61a0f1 dir: Refactor compute_extra_data_download_size to not depend on ostree
It took in a ostree commit before, but it really only needs the detached
metadata. The single caller now converts it correctly.

This will become useful when we want to know the size of the extra data
when the metadata is coming from an OCI image.
2025-11-20 23:14:18 +00:00
Sebastian Wick
5640e5bf59 dir: Refactor flatpak_dir_pull_extra_data to make it useful for OCI
This cleans up flatpak_dir_pull_extra_data in a way that it is only
responsible for downloading the extra-data. In has no dependencies on
ostree concepts any more.

The new flatpak_dir_pull_ostree_extra_data now takes care of extracing
the extra data sources and saving it in the detached metadata.
2025-11-20 23:14:18 +00:00
Sebastian Wick
d0fdac8854 dir: Pull out the downloading of extra-data into its own function 2025-11-20 23:14:18 +00:00
Sebastian Wick
f28d92da06 oci-registry: Return NULL instead of FALSE in function returning char* 2025-11-20 23:14:18 +00:00
Chris Williams
8bcba92042 dir: Remove unused parameter from flatpak_dir_setup_extra_data() 2025-11-20 23:14:18 +00:00
Kolja Lampe
4dca9efea0 utils-http: Replace g_assert_cmpint with g_assert for CURL error checks 2025-11-20 18:11:15 +00:00
Kolja Lampe
1434448f2d utils-http: Fix incorrect CURLM_OK comparison in curl_easy_setopt checks
CURLcode return values from curl_easy_setopt() were being compared
with CURLM_OK (a CURLMcode constant) instead of CURLE_OK. This is
incorrect as CURLM_OK is for multi interface functions, not easy
interface functions.
2025-11-20 18:11:15 +00:00
Sebastian Wick
e4edecdef5 utils-http: Drop libsoup2 support in favor of libcurl
A few years ago there was a very painful attempt at porting from
libsoup2 to libsoup3. Flatpak libsoup3 support never landed and it seems
like a large amount of distros have switched over to libcurl instead.

This commit removes libsoup2 support completely instead of growing
libsoup3 support.

Closes #5915
Closes #4582
2025-11-20 17:40:57 +00:00
Sebastian Wick
1c2c80b8c9 zstd-decompressor: Replace boilerplate with G_DECLARE_FINAL_TYPE macro 2025-11-20 17:30:07 +00:00
Owen W. Taylor
e6b584f85c flatpak-build-bundle: Add --oci-layer-compress=zstd
Add an option to build OCI bundles with zstd compressed layers.

gzip is kept as the default for maximum compatibility:

Ecosystem support:

 distribution/distribution: no explicit support, but works
 quay.io: sinc 2021
 Amazon ECR: supported
 pulp_container: since 2022
 flatpak: since first-OCI supporting version
 tardiff: since first version
2025-11-20 17:30:07 +00:00
Michael Catanzaro
8e038375ba run: Update note on seccomp filter code sharing
This comment needs to be modernized for 2025. It notably fails to
mention the two projects that are actually still using code that looks
like Flatpak's.
2025-11-10 14:01:09 +00:00
Sebastian Wick
c4af112df4 transaction: Handle --include-sdk if SDK is installed in other dir
If an SDK is already installed in a dir that is not targeted with a
flatpak transaction, and the transaction has auto_install_sdk set,
add_new_dep_op returns NULL in dep_op which is not correctly handled in
add_deps.

Fixes #5894
2025-10-31 12:58:39 +00:00
Sebastian Wick
842472d234 transaction: Preinstall from first remote with ref
We could previously just assume that the first enabled remote
(potentially matching the collection ID) contains the ref, but that
obviously is not always the case.

The change here looks up the remote state of the remotes to figure out
if they actually contain the ref, and adds the first matching remote to
the transaction.
2025-10-30 11:21:35 +00:00
Georgia Garcia
f61d931da8 common: Fix running_under_sudo check by checking euid
Sudo can be used in several ways other than calling a command with the
root user. For example, one can use -u to run the command as the
specified user, or -g to specify a primary group to run the command
as.

Flatpak adds a check when --user is used to prevent an installation in
the root's directory, for example, but it does it by only checking if
sudo was used. As stated previously, it does not necessarily imply
root, so this patch explicitly checks if the command is being run with
the root user.

Fixes: https://github.com/flatpak/flatpak/issues/5979
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-10-28 13:17:13 +00:00
JakobDev
3544de6251 build-finish: Export AppStream external release metainfo
The appstream docs say:

  Release data may be present directly in a component metainfo file, but
  also optionally be split out into an external metadata file.

  The file must be installed as
  /usr/share/metainfo/releases/%{cid}.releases.xml, where cid is the
  component ID of the component the release information belongs to.

This change allows flatpak build-finish to export those external release
files.

Closes #6057
2025-10-28 10:22:45 +00:00
Kolja Lampe
b6775dc221 http: Add cancellation support for curl downloads and error handling 2025-10-28 00:21:01 +00:00
Sebastian Wick
1372e16d05 dir: Check parental control authorization via system bus name
PIDs are pretty much always a bad idea because they can be racy. The
authorization did use the PID though. We can replace it by a check via
the system bus name.

Closes: https://github.com/flatpak/flatpak/issues/6212
2025-10-27 13:37:26 +00:00
Sebastian Wick
621790e797 transaction: Support sideloading from OCI repos/archives
This allows adding FlatpakImageCollection sideload repositories to a
transaction.
2025-10-24 16:27:33 +00:00
Sebastian Wick
f7671ebbc9 dir: Support sideloading from OCI repos/archives
This is implemented in a straightforward way by adding GFile
*sideload_path, FlatpakImageSource *image_source.
2025-10-24 16:27:33 +00:00
Sebastian Wick
51bf27c0d9 dir: Add sideload image collections and is_oci helper
They will be used in the next commit to better deal with sideloading OCI
images.
2025-10-24 16:27:33 +00:00
Sebastian Wick
b486437c8e image-source: Add a method to get the summary metadata 2025-10-24 16:27:33 +00:00
Sebastian Wick
feb2220a46 image-collection: Add the new FlatpakImageCollection class
The new FlatpakImageCollection class represents a set of
FlatpakImageSource loaded from the image sideload repository.
2025-10-24 16:27:33 +00:00
Sebastian Wick
9551f7d402 image-source: Make flatpak_image_source_new public
And check that the digest is a sha256 hash.

Will be used in the next commits.
2025-10-24 16:27:33 +00:00
Owen W. Taylor
86b000c34b dir: Don't return a VarRefInfoRef from flatpak_remote_state_lookup_ref()
The memory management of returning a VarRefInfoRef is tricky - it
points to data owned by the summary or the sideload repo. External
consumers were always retrieving a copy of the summary metadata,
so make the public function do that.
2025-10-24 16:27:33 +00:00
Sebastian Wick
bc5c8e65be dir: Handle NULL sideload state in flatpak_remote_state_lookup_ref
Even on success, flatpak_remote_state_resolve_sideloaded_ref might
return a NULL FlatpakSideloadState. Handle it properly.
2025-10-24 16:27:33 +00:00
Kolja Lampe
e069452d7c utils-http: remove duplicate pointer clearing for hdr_last_modified 2025-10-22 00:29:54 +00:00
Sebastian Wick
0a3c2452c0 flatpak-build: Drop host permissions by default
For some reason, flatpak build always had host permissions set by
default. There really isn't a good reason for this. The build should be
isolated from the host as much as possible by default.
2025-10-13 19:24:50 +00:00
Chris Williams
a7ac4206c6 dir: Also reload repo configuration after setting via system helper
Without doing so, flatpak_dir_get_config() won't reflect changes made
with flatpak_dir_set_config().

This fixes passing multiple patterns to `flatpak mask` for the system
installation.

Closes #5464
2025-10-13 19:14:44 +00:00
d34db3ff
65f5c98e11 session-helper: track the destinations of broken symlinks
Fixes #4268

Make sure that session-helper always tracks the destinations of symlinks.
This fixes a race condition on systems where '/etc/resolv.conf' is a symlink.
2025-10-13 19:02:44 +00:00
bbhtt
0bf531f44a dir: Add basic OS info to Flatpak-Os-Info header when pulling objects
Fixes https://github.com/flatpak/flatpak/issues/5549
2025-10-13 18:52:55 +00:00
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