Commit Graph

1360 Commits

Author SHA1 Message Date
Matthias Clasen
43d4fb6a3e Fix oci pull progress reporting
Comparing the code in flatpak-utils.c:progress_cb,
we need to set bytes-transferred for the total amount
of data that has been transferred so far. The value
we were setting so far, fetched-delta-part-size, refers
to the size of the objects we already have locally, and
is subtracted from the total, which explains oci progress
running backwards.

Closes: #2392

Closes: #2400
Approved by: matthiasclasen
2018-12-07 19:51:11 +00:00
Matthias Clasen
b8cad064eb Add our own polkit listener implementation
This lets us respect the fancy output setting, and
it lets us do some other things that make it better
integrated.

Closes: #2379
Approved by: alexlarsson
2018-12-06 15:01:14 +00:00
Matthias Clasen
c685f05f8a trivial: Fix a gtk-doc warning
gtk-doc complains if parameter names don't match between
headers and doc comments, so make them match, for a quieter build.

Closes: #2384
Approved by: alexlarsson
2018-12-06 14:47:58 +00:00
Matthias Clasen
a2f57f64fd Add flags that allow to 'upgrade' permissions
This is to avoid multiple polkit dialogs, regardless
of transaction ordering.

FlatpakTransaction calculates the 'strongest' op it has,
and passes the hints accordingly. FlatpakInstallation
doesn't pass hints, since it does individual operations.

The system helper uses the hints to determine which PolicyKit
permission to request. Since the policy typically has 'keep'
set, this mean that the following operations in the same
transaction will be able to reuse the permission obtained
for the first one.

Closes: #2384
Approved by: alexlarsson
2018-12-06 14:47:57 +00:00
Matthias Clasen
c516a22e4d session-helper: Improve HostCommand life-cycle handling
Add flag that instructs the session-helper to kill
the spawned command when the caller drops off the bus.

Closes: #2326

Closes: #2365
Approved by: alexlarsson
2018-12-06 13:10:51 +00:00
Matthias Clasen
f3f7417b16 installation: Add a no-interaction property
Allow to mark a FlatpakInstallation as no-interaction, which
will get passed to the system helper to prevent it from presenting
polkit dialogs.

We make this a property on the object, since not all relevant
methods have flags that would let us pass this information.

Closes: #2367
Approved by: alexlarsson
2018-12-05 10:16:22 +00:00
Matthias Clasen
929da90a3e dir: Add a no-interaction property
Allow to mark a FlatpakDir as no-interaction, which will
get passed to the system helper to prevent it from presenting
polkit dialogs.

We make this a property on the object since the alternative
would require plumbing the flag through tons of API all over
the code.

Closes: #2367
Approved by: alexlarsson
2018-12-05 10:16:22 +00:00
Matthias Clasen
c148c7eeec system-helper: Allow non-interactive tasks
Add a new 'no-interaction' flag to all system-helper methods
that have flags, and don't allow polkit user interaction if
it is set. This will let tools like GNOME Software do automatic
updates in the background without interrupting the user with dialogs.

For methods that don't have flags, we always allow user interaction.

Closes: #2367
Approved by: alexlarsson
2018-12-05 10:16:22 +00:00
Matthias Clasen
1ba30f7ef1 system-helper: Add flags to all methods
Some methods were missing a flags argument. This
will be a problem in the future, when we want to
pass a no-interaction flag to all methods. Therefore,
add an empty flags enum for every method that is lacking
one now.

This is an api change for the system-helper interface.

Closes: #2370
Approved by: alexlarsson
2018-12-03 12:52:17 +00:00
TingPing
e5218a5623 Also add /dev/nvidia-uvm-tools
This may sometimes be needed also.
Closes: #2358
Approved by: matthiasclasen
2018-12-01 00:31:11 +00:00
Alexander Larsson
0b6a66013c OCI: Use system helper to generate summary for OCI remotes
The OCI support relies on downloading a json index and converting it
to a ostree-style summary, which we the use in all sorts of operations
in the client code. Currently this happens in the user code, which means
that it will fail (due to permissions) in the system installation case.

We could do the conversion as the user, but when eventually installing
something the system-helper will anyway do this download and
conversion, so that would only double the work and risk things going out
of sync. Also, the OCI index is not gpg signed, so we can't realy on
downloads done as the user.

So, the solution done here is to add a GenerateOciSummary
system-helper call which we use instead of directly generating the
oci summary.

This fixes https://github.com/flatpak/flatpak/issues/2350

Closes: #2363
Approved by: matthiasclasen
2018-12-01 00:16:08 +00:00
Owen W. Taylor
05cc3c0f66 flatpak_cache_http_uri: save downloaded files with permission 0644
Previously, downloaded files were being saved with 0600 permissions,
which prevented OCI icons downloaded by the system helper at appstream
creation time from being read by users.

Closes: #2362
Approved by: matthiasclasen
2018-11-30 23:53:10 +00:00
Patrick Griffis
9895014124 Grant access to /dev/nvidia-uvm for OpenCL/CUDA
Closes #2266

Closes: #2356
Approved by: alexlarsson
2018-11-30 07:36:41 +00:00
Kalev Lember
c915f73b41 remote: Add a way to get/set xa.main-ref
This is useful for gnome-software in order to figure out which app to
show from noenumerate remotes.

Closes: #2340
Approved by: matthiasclasen
2018-11-25 18:31:06 +00:00
Patrick Griffis
182b2674aa Add condition for XDG_CURRENT_DESKTOP checks
Firstly this changes the "download-if" and "enable-if" properties
to accept a `;` separated list of multiple conditions.

Secondly it adds `on-xdg-desktop-*` which will check against
the XDG_CURRENT_DESKTOP env var (case-insensitively).

This is done entirely for the Qt GNOME Platform so it can do this:

```
"org.kde.PlatformTheme.QGnomePlugin" : {
  "download-if": "on-xdg-desktop-GNOME;on-xdg-desktop-GNOME-classic"
}
```

Closes: #1436
Approved by: matthiasclasen
2018-11-17 23:42:49 +00:00
Matthew Leeds
5fe2a0aabe uninstall: Add support for fuzzy matching
This adds support for fuzzy matching ref names (AKA "typo helper") to
the uninstall command to mirror what the install command has. In short,
this means you can do "flatpak uninstall gedit" instead of "flatpak
uninstall org.gnome.gedit". Flatpak will prompt you to choose between
similarly named installed refs, and will only make the choice for you if
--assumeyes was used and there's only one match.

Note that this commit does have the side effect that if there are
multiple matching refs with the same ID (e.g. with different branches or
in different installations) you are prompted to choose between them.
Previously you were shown an error message.

Closes: #2330
Approved by: matthiasclasen
2018-11-17 13:00:33 +00:00
Matthew Leeds
7d35de18e4 app: Fix a couple memory leaks
Closes: #2330
Approved by: matthiasclasen
2018-11-17 13:00:33 +00:00
Erick555
ad9599d3e3 Mount common sockets as read-only
This is similar case as with x11_socket, 0af71792b4

Closes: #2333
Approved by: matthiasclasen
2018-11-16 21:18:12 +00:00
Matthew Leeds
3f13babb5a dir: Emit better errors for invalid flatpakrepo files
Closes: #2327
Approved by: matthiasclasen
2018-11-16 14:04:48 +00:00
Alexander Larsson
03732121db Make sure we dist flatpak-instance-private.h 2018-11-16 14:34:15 +01:00
Alexander Larsson
35598f46a5 extra-data: Don't allow creating files with non-canonical permissions in apply_extra
When installing a flatpak with extra-data we execute the apply_extra
script from the flatpak to extract the extra data files we
created. This script runs with very little filesystem acces, but it
does have write permissions to the location that will eventually be
/app/extra in the finished flatpak. This is especially problematic for
the systemwide install case, because the script is then run as root,
so it could potentially create a setuid file there.

Such a file would not be usable inside the sandbox (because setuid is
disabled in the sandbox), but it could potentially be a problem if the
user could be tricked into running the file directly on the host. This
is the same behaviour as e.g. rpm or deb which both can install setuid
files, but we want to guarantee that flatpak is better than that.

The fix is to run the script with all capabilities dropped (bwrap
--cap-drop ALL) which removes a bunch of possible attack vectors (for
instance setting file capabilities). However, even without
capabilities, it is possible for a user to make any file setuid to the
same user, so we also need to canonicalize the permissions of all
files generated by running the script.

Additionally, while running the script we set the toplevel directory
only be accessible to the user, meaning we will not temporarily leak
any potential setuid files to other users.

Note, this commit actually goes furthen than that and completely
canonicalizes all the file permissions to be the same as those
otherwise used by flatpak. For example we fix up cases where the
script creates files writable or unreadable by non-root users.

Closes: #2323
Approved by: alexlarsson
2018-11-16 10:20:20 +00:00
Alexander Larsson
1ce0246b0d dir: Match pre-existing remotes better wrt collection-id
If you have a pre-existing remote configured its exact definition
might differ from the one specified in a flatpakrepo file and yet
be the same.

For example, i have:

$ flatpak --user remotes -d
Name      Title      URL                            Collection ID          Priority Options
flathub   Flathub    https://dl.flathub.org/repo/   org.flathub.Stable     1

Yet when i install a flatpakref:

$ flatpak --user install http://flathub.org/repo/appstream/org.gnome.gedit.flatpakref
The application org.gnome.gedit depends on runtimes from:
  https://dl.flathub.org/repo/
Configure this as new remote 'flathub-1' [y/n]:

Because the flathub flatpakrepo does not yet have the collection id specified.

So, we need to be more lenient when matching the pre-configured remotes.

Closes: #2324
Approved by: alexlarsson
2018-11-16 10:06:22 +00:00
Matthew Leeds
348fcc3f97 Add a DeployCollectionID key to replace CollectionID
This commit adds a key called DeployCollectionID to the flatpakref and
flatpakrepo file formats, which is intended to replace the CollectionID
key (which is still supported but deprecated). The reason for the change
is the same as for the metadata key change from xa.collection-id to
ostree.deploy-collection-id, which is that old versions of Flatpak
(roughly 0.9.8 through 1.0.1 depending on compile time options) hit
various bugs when collection IDs are in use. Flathub will soon enable
the metadata key to deploy collection IDs, and this change means Flathub
can also deploy the collection ID in flatpakref and flatpakrepo files
without affecting old clients.

Adding DeployCollectionID to the flatpakref and flatpakrepo files will
mean the flathub remote can be automatically configured with a
collection ID without depending on the metadata key to do that.

Closes: #2329
Approved by: alexlarsson
2018-11-16 09:17:07 +00:00
Erick555
0af71792b4 Mount x11_socket as read-only
Fixes https://github.com/flatpak/flatpak/issues/2315
Closes: #2316
Approved by: alexlarsson
2018-11-15 12:24:00 +00:00
Philip Withnall
9e9b8b75fc ref: Fix a typo in a documentation string
Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #2317
Approved by: matthiasclasen
2018-11-14 12:34:30 +00:00
Matthias Clasen
c4572c17f8 Merge pull request #2311 from matthiasclasen/name-validation
Name validation
2018-11-14 00:12:16 -05:00
Matthias Clasen
3a536f3878 Clarify FlatpakInstallation docs
Several doc comments were mistakenly talking
about a 'system installation'.

Closes: #2310
Approved by: matthiasclasen
2018-11-13 00:29:55 +00:00
Matthias Clasen
54f38284f6 Validate custom installation IDs
We want to avoid unnecessary confusion and complications,
so we rule out IDs that are problematic because they will
clash with the default installations.

At the same time, make the error messages for parsing
custom installations more informative.
2018-11-12 19:25:34 -05:00
Matthias Clasen
91f88dd204 Don't allow empty remote names
Prevent remotes from having empty names. This can only lead
to confusion and unnecessary complications.
2018-11-12 19:18:07 -05:00
Philip Withnall
4a1c11dba9 dir: Factor out code to load AppStream cache for a remote
This is currently only used in the ‘search’ built-in command, but will
need to be used in upcoming parental controls filtering changes in
Endless OS (which will go upstream eventually) too.

This introduces no functional changes.

The CFLAGS/LIBADD changes are necessary because of the new
AppStream #includes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #2296
Approved by: matthiasclasen
2018-11-12 13:13:09 +00:00
Alexander Larsson
7078a7f087 Make per-app generated files read-only
We generate various configuration files for each sandbox instance,
and expose them to the sandbox using flatpak_bwrap_add_args_data,
which in the end passed --bind-data to bwrap. These files are not
sensitive or shared, but it still doesn't really make sense for
the sandbox to allow them to be modified, so lets switch them
to --ro-bind-data.

This affects these files in the sandbox:

 $HOME/.var/app/$APPID/config/user-dirs.dirs
 /etc/group
 /etc/ld.so.conf
 /etc/passwd
 /etc/pkcs11/modules/p11-kit-trust.module
 /etc/pkcs11/pkcs11.conf
 /etc/timezone
 /run/flatpak/ld.so.conf.d/*.conf
 /run/user/$UID/pulse/config
 /run/user/$UID/Xauthority
2018-11-12 14:13:05 +01:00
Alexander Larsson
6711d7ae99 Don't allow writes to runtime files in /etc
We mistakenly bind-mounted the runtime /usr/etc files read-write in
/etc, which means that application could modify some parts of the
runtimes (at least when using a per-user installed runtime). Fix
this by using a --ro-bind.
2018-11-12 14:13:05 +01:00
Matthias Clasen
40854e00df Fix misleading error message
The error messages here make it appear that values can
be prepended with a '!', but a few lines down we throw
an error if thats the case.

Closes: #2298
Approved by: matthiasclasen
2018-11-10 16:09:47 +00:00
Umang Jain
94969d5057 Installation: Add flatpak_installation_get_min_free_space_bytes
A convenience wrapper around ostree_repo_get_min_free_space_bytes().
Clients programs like gnome-software can get the value of minimum free
space as defined in the OSTree repo. This can be useful in various
disk-space checks these client program can implement.

At Endless, we have downstream heuristics in gnome-software which
determine the success/failure likelihood of an install/update
operation to some extend. Depending upon the likelihood of the
success/failure we dispatch install/update/auto-update operations.

With client programs gaining features such as auto-updates, it makes
sense to have a min-free-space API so that these programs can check
free-space availablity vs minimum free space defined by user inside
OSTree's repo before auto-updating. Although, OSTree will certainly
fail operations over-stepping min-free-space's value; It's just a
matter of convenience to provide a way to query the value to client
programs as well.

Closes: #2274
Approved by: matthiasclasen
2018-11-07 12:02:14 +00:00
Matthew Leeds
a22dfbd7c1 Default to only choice in multiple choice prompts
This commit implements a feature in the multiple choice prompt that
mirrors the behavior in the yes/no prompt where it can default to "yes"
when the user only presses Enter. In the case of the multiple choice
prompt, it only defaults to the first choice on Enter if there's only
one option (e.g. you're asked if you want to install from the "flathub"
remote as opposed to being asked to choose between the "flathub" and
"eos-apps" remotes).

This feature can be turned off on a per-prompt basis if we want explicit
user input for something but I didn't find that necessary for any of the
existing prompts.

Also note that as with the yes/no prompt defaulting to yes on Enter,
this only applies for interactive terminals. If Flatpak is being run by
a script no choice will be made automatically.

This should save users unnecessary keystrokes, such as when they use
"flatpak install devhelp" and are asked to confirm that the Flathub
remote is the one to use (now they can just press Enter).

Closes: #2288
Approved by: matthiasclasen
2018-11-06 02:48:06 +00:00
Matthew Leeds
5ddca0fc36 common: Document that get_latest_commit() can return NULL
It's possible for the "latest_commit" field of a FlatpakInstalledRef to
be NULL, which I think happens if the ref is no longer in the
remote.[1][2][3] So this commit documents the possibility of
flatpak_installed_ref_get_latest_commit() returning NULL.

[1] https://github.com/flatpak/flatpak/issues/309
[2] https://github.com/flatpak/flatpak/commit/6b4402b60
[3] https://github.com/flatpak/flatpak/commit/230e18db7

Closes: #2289
Approved by: matthiasclasen
2018-11-03 01:04:34 +00:00
Matthew Leeds
7b1a5c4fb9 Allow yes/no prompt to default to yes
Currently when the Flatpak command line prompts the user with a yes or
no question, the user must type "y" or "n" to respond. This commit
changes it so that the prompt can assume "yes" if the user just presses
Enter. In that case the prompt ends in "[Y/n]" rather than "[y/n]". If
there are some operations that are considered dangerous, we can still
require explicit user input on those, but as far as I can tell those
criteria don't apply to any existing prompts.

This behavior of allowing the user to just press Enter is consistent
with how apt works for example.

Note that this is distinct from the "--assume-yes" option we have, since
that won't prompt the user at all when a decision needs to be made.

Closes: #2113
Approved by: matthiasclasen
2018-10-31 22:48:56 +00:00
Matthew Leeds
7fb57f7221 install: Implement a typo helper
This commit implements a "typo helper" for the install command, so that
if you don't get the app ID exactly correct you're prompted with
similarly named apps available in the remote that you can choose from.
Essentially this allows you to do "flatpak install flathub devhelp"
instead of "flatpak install flathub org.gnome.Devhelp".

The choice is only made for you in two cases: 1. If it's an exact match
and there's only one match, it is used as before this commit.  2. If the
-y/--assume-yes option was used and there's only one match, it is used.
Presumably scripts would always specify the full app ID, so this should
only affect users on the command line who choose to use that option.

In the future we may want to use the groundwork laid in this commit to
add similar functionality to other commands, like perhaps remote-info
and run.

This is a partial fix for https://github.com/flatpak/flatpak/issues/1258

Closes: #2113
Approved by: matthiasclasen
2018-10-31 22:48:56 +00:00
Matthew Leeds
7c86f12262 Move Levenshtein distance implementation
This moves the implementation of the Levenshtein "edit distance"
algorithm from app/ to common/ so it can be used in an upcoming commit.

Closes: #2113
Approved by: matthiasclasen
2018-10-31 22:48:56 +00:00
Matthew Leeds
c7772f3504 dir: Remove outdated comments
flatpak_dir_find_remote_refs() and flatpak_dir_find_remote_ref() have
support for finding remote refs via P2P means because
flatpak_dir_list_all_remote_refs() uses the list of refs in the xa.cache
in that case. So remove the outdated comments.

Closes: #2113
Approved by: matthiasclasen
2018-10-31 22:48:56 +00:00
Matthias Clasen
f024e95362 Check that wayland-0 is a socket
This is a little better than just checking that the file
exists. Still does not protect against a stale socket.

Closes: #2258

Closes: #2271
Approved by: matthiasclasen
2018-10-27 13:49:51 +00:00
Matthew Leeds
a4683a4328 installation: Respect configured set of repo finders
OSTree now has a repo config option to set which repo finders (that is,
sources for refs) will be used, and API which exposes the default set
(which was either configured by the user or decided by libostree). So
this commit changes flatpak_installation_list_remotes_by_type() to
respect that configuration, since that's the only place flatpak passes a
set of OstreeRepoFinder instances to libostree.

See also https://github.com/ostreedev/ostree/pull/1758/

Closes: #2264
Approved by: pwithnall
2018-10-24 16:38:16 +00:00
Matthias Clasen
70fdad9a89 Remove some unused FlatpakDir functions
Closes: #2252
Approved by: matthiasclasen
2018-10-23 20:10:37 +00:00
Matthias Clasen
9da443f26f Remove another unused function
flatpak_context_load_for_app was not used.

Closes: #2252
Approved by: matthiasclasen
2018-10-23 20:10:37 +00:00
Matthias Clasen
2bbdd7712a Remove unused functions
Neither flatpak_variant_builder_init_from_variant nor
flatpak_gvariant_new_empty_string_dict are used anywhere.

Closes: #2252
Approved by: matthiasclasen
2018-10-23 20:10:37 +00:00
Matthias Clasen
6daf195e42 Instance: mitigate races, add new launch api
Avoid the 3-second 'afterlife' of instances by using
kill (pid, 0) instead of checking the file lock. We
trade pid for lock races, but this seems more reliable.

Also add flatpak_installation_launch_full that returns
a FlatpakInstance for the launched app, and lets us
avoid races around killing the app, by using a child
watch.

Closes: #2221
Approved by: matthiasclasen
2018-10-23 07:15:39 +00:00
Matthew Leeds
80c4da4374 Remove old OSTree version checks
Flatpak depends on OSTree 2018.7 now, so we don't need these.
2018-10-19 17:54:02 -07:00
Matthias Clasen
4b85aa7859 Merge pull request #2254 from mwleeds/instance-element-type-annotation
instance: Fix gtk-doc warning
2018-10-17 14:56:01 -07:00
Matthew Leeds
d5b8266a09 instance: Fix gtk-doc warning 2018-10-17 14:23:20 -07:00
Will Thompson
0d6b979212 dir: use G_KEY_FILE_DESKTOP_GROUP constant
This and all the other standard Desktop Entry Specification keys are
defined in gkeyfile.h. Who knew?
2018-10-16 14:40:55 -07:00