Commit Graph

1768 Commits

Author SHA1 Message Date
Alexander Larsson
ff317fd4fb Enforce little endian for token-type
When storing the token-type in the commit and the summary cache we
hardcode it to little-endian.

In theory this breaks the "ABI", but in practice this change is a
no-op on little-endian systems which is what most are. Additionally as most
servers are little-endian this also fixes using big-endian clients with
such servers.

This fixes:
https://github.com/flatpak/flatpak/issues/3434
2020-03-16 11:26:10 +01:00
Matthew Leeds
6aa3ff0d6f common: Don't shadow parameter variables 2020-03-16 09:29:31 +01:00
Matthew Leeds
2f49385379 dir: Add a comment to an empty block
This makes lgtm.com happy
2020-03-16 09:29:31 +01:00
Owen W. Taylor
f7616a8b3c flatpak-oci-registry.c: supply a default scope when getting a token
If no scope parameter is supplied in the WWW-Authenticate header,
docker and libpod will make up their own of the form
repository:<reponame>:pull when requesting a bearer token. Match that.

Signed-off-by: Owen W. Taylor <otaylor@fishsoup.net>
2020-03-16 09:15:00 +01:00
Owen W. Taylor
fe3f17a89a flatpak-oci-authenticator: try getting a token without credentials
Some registries require getting a token even to download an image
anonymously. So, if no auth has been configured, before prompting
the user for username/password, try without a BasicAuth header.

Signed-off-by: Owen W. Taylor <otaylor@fishsoup.net>
2020-03-16 09:13:41 +01:00
Simon McVittie
a36e0183b1 run: Cope with the primary gid not being in the nsswitch database
If it's an opaque integer on the host system, it might as well be an
opaque integer in the container too.

Fixes: #3416
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-03-11 14:27:59 +01:00
Erick555
b4c29df7bd Mount systemd sockets as read-only
This is continuation of ad9599d3e3 (diff-9efab2399c7c560b34de477b9aa0a465)
and should complete coverage of read-only bind-mounts of sockets.
2020-03-11 14:24:24 +01:00
Simon McVittie
189394653c build: Fix out-of-tree build with variant-schema-compiler
The variant-schema-compiler and its input are in the $(srcdir).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-02-27 12:46:01 +00:00
Alexander Larsson
f29830b4a4 Convert sparse cache API to generated variant APIs 2020-02-17 16:10:50 +01:00
Alexander Larsson
61da44a5e3 Convert flatpak_summary_lookup_ref from GVariants
Now it returns a VarRefInfoRef instead of a GVariant
2020-02-17 16:10:50 +01:00
Alexander Larsson
9f6c60405d utils: Convert summary ref lookup code to variant codegen
We can't use the built-in bsearch from the codegen because its an array
instead of a dict, so we have to keep that but its now not using
variant at least.
2020-02-17 16:10:50 +01:00
Alexander Larsson
7c4fd8891e Convert deploy data to use variant schemas 2020-02-17 16:10:50 +01:00
Alexander Larsson
0f028e5329 flatpak_remote_state_lookup_sparse_cache: Use variant schema 2020-02-17 16:10:50 +01:00
Alexander Larsson
8fe634d047 Remove unused flatpak_remote_state_lookup_repo_metadata() 2020-02-17 16:10:50 +01:00
Alexander Larsson
93d44413e6 flatpak_dir_list_all_remote_refs: Implement using variant schemas 2020-02-17 16:10:50 +01:00
Alexander Larsson
00283943f2 flatpak_remote_state_lookup_cache: Implement using variant schemas 2020-02-17 16:10:50 +01:00
Alexander Larsson
4f2c4a5b1c Add schema for some ostree/flatpak variant type and generate header 2020-02-17 16:10:50 +01:00
Alexander Larsson
ebca05ff10 utils: Add flatpak_bytes_save() 2020-02-17 16:10:50 +01:00
Alexander Larsson
2d2dd37741 flatpak-dir: Fix doc-comment for flatpak_deploy_data_get_subpaths 2020-02-17 16:10:50 +01:00
Simon McVittie
fe2536b844 exports: Add host-etc and host-os keywords
These are subsets of the host keyword, which provide access to operating
system files but not to users' personal files.

In particular, the experimental support for namespace-based sandboxes
in the Steam Runtime[1] uses the graphics stack from the host system,
which requires access to the host /usr/libQUAL, /libQUAL (even if the
host OS has undergone the /usr merge, the canonical paths of ELF
interpreters start with /lib), /etc/ld.so.cache, and for some libraries
on Debian-based systems, /etc/alternatives. It will not be possible to
do similar things in Flatpak without either allowing full host
filesystem access (which exposes personal files, and in any case cannot
be done by the Steam app because it is incompatible with --persist=.),
or adding the ability to expose /usr and related directories without
including the rest of the host filesystem.

To the best of my knowledge, host-etc is not necessary for anything;
I've mainly provided it for symmetry, since it's the other significant
thing that we mount in /run/host and cannot get via --filesystem=/path.

Some notes on the security/privacy implications of the new keywords:

- Neither new keyword allows anything that was not already allowed
  by "host".
- Neither new keyword can allow anything that was not already allowed
  to the user outside the sandbox.
- "host-os" allows enumeration of the installed packages on the host
  system, and often their version numbers too. A malicious app could
  use this to look for exploitable security vulnerabilities on the
  host system. An app could also use this for fingerprinting, although
  this is not a regression, because the systemd/D-Bus machine ID,
  MAC addresses, hostname, kernel boot UUID, DMI product ID and many
  other unique or relatively unique properties are already available
  inside the sandbox.
- "host-os" allows read access, and possibly write access (if the user
  has it outside the sandbox, for example members of group 'staff' in
  older Debian installations), to /usr/local.
- "host-etc" allows reading configuration files whose contents might
  be considered sensitive, such as /etc/passwd.

[1] https://steamcommunity.com/app/221410/discussions/0/1638675549018366706/

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-02-14 15:41:59 +01:00
Simon McVittie
949a3ec479 context: Generalize handling of special filesystems a bit
Currently there are only "home" and "host", but I'm going to add one
that represents /usr and friends (/usr, /lib, ...), and one for /etc.
These differ from ordinary filesystem mounts because they are redirected
into /run/host to avoid conflicting with the runtime.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-02-14 15:41:59 +01:00
Simon McVittie
08d65c5414 exports: If --filesystem=host, provide /run/host/lib etc.
In a host system where the /usr merge has not been implemented, these can
be necessary to load or inspect libraries or executables from the host
system. They are conceptually the same as /usr.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-02-14 15:41:59 +01:00
Simon McVittie
b34ccef1c0 common: Unify some lists of /usr-merged directories
In some places we want a list of basenames, and in others we want a list
of absolute paths. Use the absolute paths, because converting those into
basenames doesn't require memory allocation.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-02-14 15:41:59 +01:00
Simon McVittie
b2adbe2a74 exports: Only choose bwrap --bind/--ro-bind for host FS once
We can choose this once and use it repeatedly, which will be simpler
when we add more directories that work this way.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-02-14 15:41:59 +01:00
Alexander Larsson
b03916f5bd setup-extra-data: Avoid extra work for ostree-metadata and appstream branches
We never have extra data for non app/ or runtime/ refs, so lets not
do an unnecessary pull there.
2020-02-13 14:47:00 +01:00
Alexander Larsson
9aecad7f4f p2p: Don't mirror ostree-metadata refs when pulling into the child repo
This breaks Deploy which can't find the ref. It used to work due to
the extra non-mirroring pull in flatpak_dir_setup_extra_data, but
this is not needed here.
2020-02-13 14:47:00 +01:00
Alexander Larsson
b371ef9007 Actually use from-scratch deltas
As noticed in https://github.com/flatpak/flatpak/issues/3412 we
regressed at some point and are no longer using from-scratch deltas.
This is caused by an optimization in ostree where it decides to not
use a from-scratch deltas if theres is *some* version of the ref
locally available.

This conflicts with some code in flatpak that pulls *only* the commit
object in order to look for extra data size information so that we can
get the progress reporting right. Unfortunately the existance of
just the object triggers the above causing us to *never* use from-scratch
deltas.

We fix this by throwing away the partial pull in an aborted ostree
transaction.
2020-02-13 14:47:00 +01:00
Patrick Griffis
1a735f2f1a run: Prevent accidentally running with sudo
It is a common user error to prepend many flatpak commands with sudo
and doing so with run is quite unsafe and can cause issues.

This check simply handles the `sudo flatpak run foo` case and does
not prevent running as root or even running in a shell created by
sudo.

See also #1357
2020-02-13 11:52:56 +01:00
Matthew Leeds
5d382f3211 dir: Avoid unnecessary _flatpak_dir_reload_config()
There's no point in reloading the config when it didn't change.
2020-02-12 16:41:06 +01:00
Matthew Leeds
5836de30e3 common: Properly reload config when it changes
In flatpak_dir_create_origin_remote() we reload the repo config after
adding an origin remote to it, but this only applies to the FlatpakDir
object used. In the case of flatpak_transaction_add_ref(), there is
another FlatpakDir object in the installation (priv->installation) which
needs to also be reloaded using flatpak_installation_drop_caches(). So
add a boolean out variable to flatpak_dir_create_origin_remote() and use
it to determine if it's necessary to call
flatpak_installation_drop_caches() (because if the origin remote already
exists we don't create another).

This commit also makes related changes at the other call sites of
create_origin_remote() (some indirectly via
flatpak_dir_ensure_bundle_remote()):
- in flatpak_dir_ensure_bundle_remote(), only set the out variable
  created_remote to TRUE if a new remote was actually created
- in flatpak_installation_install_bundle(), only drop the installation
  caches if a new remote was actually created
- in flatpak_transaction_resolve_bundles(), drop a redundant
  flatpak_dir_recreate_repo() call and only drop installation caches
  when necessary

Without these changes, this unit test failure occurs:
ERROR: testlibrary - Bail out!
flatpak:ERROR:tests/testlibrary.c:3311:test_transaction_install_local:
assertion failed (error == NULL): Remote "hello-origin" not found
(flatpak-error-quark, 7)
2020-02-12 16:41:06 +01:00
Matthew Leeds
04757e31d9 transaction: Fix a typo in a g_debug() 2020-02-12 16:41:06 +01:00
Matthew Leeds
3917ef8776 transaction: Fix use of uninitialized variable
This was reported by valgrind.
2020-02-12 16:41:06 +01:00
Patrick Griffis
b8d2271154 run: Fix TMPDIR env var not being passed through suid bwrap
Fixes #2641
Fixes flathub/org.electronjs.Electron2.BaseApp#4
2020-02-12 16:38:53 +01:00
Matthew Leeds
423a21271c Merge pull request #3374 from smcv/fix-home-host-confusion
exports: Fix a confusingly-named method
2020-02-07 16:47:44 -08:00
Umang Jain
fe8b3c4b33 nitpick: installation: Remove a blank line 2020-01-24 14:08:08 +05:30
Simon McVittie
1f9dc50e33 exports: Fix a confusingly-named method
It was called flatpak_exports_add_home_expose(), but it actually
exposed the entire host filesystem, to the extent possible.
Rename it to flatpak_exports_add_host_expose() to reflect that.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-01-23 18:33:57 +00:00
Alexander Larsson
b3bd501978 update-portal: Limit which filesystem access additions we allow
Don't allow adding access to things like ~/foo xdg-foo/bar or similar
things just because you used to have home access, because such files
may be outside the homedir (for instance, if they are symlinks or configured
via xdg-user-dirs).
2020-01-23 13:34:20 +01:00
Alexander Larsson
3c6c51f46b build-commit-from: Fix generation of download-size
In flatpak-builtins-build-commit-from.c we call flatpak_repo_collect_sizes()
without initializing the passed in download size to zero, which mean
we sum with sizes with some random value as the start.

This is fixed by having flatpak_repo_collect_sizes() always initialize
the counters to 0 at the start.

Fixes https://github.com/flatpak/flatpak/issues/3362
2020-01-23 09:04:29 +01:00
Alexander Larsson
39903eab40 Add --device=shm permission
This new permission exposes the host /dev, which is normally not visible
even with --device=all, as it is not really a device node but rather
a bunch of shared memory blocks available on the host.

This access is needed by jack, as explained at:
https://github.com/flatpak/flatpak/issues/1509

Long term I think a better solution for pro audio (like pipewire) is
a better solution, but for now we should at least allow jack apps to work.
2020-01-17 11:47:04 +01:00
Umang Jain
56787325ed dir: Return empty array instead of NULL while querying related-refs
Initialize the related-refs array with empty GPtrArray so that if
the remote has 'url= ' (for e.g., in case of flatpak bundle's remotes),
a empty array is returned instead of NULL.

(NULL mostly implies a operation has failed and error is set)

Also, this syncs the implementation of `if (*url == 0)` with
that of  flatak_dir_find_remote_related_for_metadata function.
2020-01-16 19:30:09 +05:30
Umang Jain
18626add02 dir: Return NULL instead of boolean when querying related refs
The related refs are returned as GPtrArray, hence return NULL
instead of FALSE on error paths.
2020-01-16 19:15:01 +05:30
Alexander Larsson
a98d655f4f Fix build on older glib
Don't use G_VARIANT_BUILDER_INIT() which is glib 2.50 only
2019-12-20 13:25:20 +01:00
Alexander Larsson
681ca88547 oci: Fix leak in index handling 2019-12-20 11:15:39 +01:00
Alexander Larsson
202b2508d5 filters: Fix some leaks 2019-12-20 11:15:39 +01:00
Alexander Larsson
aabcbfa586 flatpak_installation_list_unused_refs: Fix leak 2019-12-20 11:15:39 +01:00
Alexander Larsson
883f4bf177 oci: Fix leak 2019-12-19 17:42:32 +01:00
Alexander Larsson
0af22af913 transaction: Fix leak 2019-12-19 17:42:19 +01:00
Alexander Larsson
ca6c12d4dd authenticators: Fix leak 2019-12-19 17:42:04 +01:00
Alexander Larsson
7a8801da50 Fix leak in flatpak_repo_update() 2019-12-19 16:53:14 +01:00
Alexander Larsson
7c3e6f7214 appdata: Fix leak of id string. 2019-12-19 16:52:58 +01:00