Commit Graph
135 Commits
Author SHA1 Message Date
Matthias Clasen 69d5692529 system-helper: Don't pass NULL for progress
When calling into FlatpakDir apis that take an
OstreeProgress, always pass a no-op instance,
never NULL.

Closes: #2468
Approved by: alexlarsson
2019-01-11 14:16:37 +00:00
Matthias Clasen 6abe5bef96 system-helper: Introduce a helper for errors
Be more systematic about returning FLATPAK_ERROR unmodified
and wrap everything else in a G_DBUS_ERROR_FAILED.

Closes: #2391

Closes: #2532
Approved by: alexlarsson
2019-01-11 12:50:56 +00:00
Matthias Clasen 9f06ec5775 Fix coverage for system helper and portal
These services were not generating coverage data
because they always get ended by GDBus raising
SIGTERM when the bus goes away. Prevent this by
telling GDBus not to do that, and let the services
exit regularly, on their own terms.

This makes the system helper code show up in the
coverage statistics.

Closes: #2530
Approved by: matthiasclasen
2019-01-08 02:10:35 +00:00
Alexander Larsson 9a37475e76 deploy-data: Prepare for versioning
This adds a version to the deply data format, assuming that if
there is no version then it is 0. Also extends all loaders so that
it can specify a required version, with the goal that most users
are fine with old versions, but if you need more recent we have
a (costly) conversion process to upgrade (will be added later).

The library and the flatpak list/info commands require the most
current version for full info, all other users can use any version.

Also, as part of this we now pass the ref to flatpak_load_deploy_data()
as this will be needed later for the backwards compat support.

Closes: #2409
Approved by: alexlarsson
2018-12-19 15:45:35 +00:00
Matthias Clasen ce8d976af2 system-helper: Plug a small memory leak
g_variant_loop only takes care of memory handling if
you don't jump out of the loop.

Closes: #2371
Approved by: alexlarsson
2018-12-18 14:50:26 +00:00
Matthew Leeds 6e42104020 system-helper: Fix an outdated comment 2018-12-10 22:04:37 -08:00
Matthew Leeds 3c43771d06 system-helper: Fix a seg fault on Deploy
The first element put in the variant created by
flatpak_dir_system_helper_call_deploy() is the repo path, but this is
being treated as the installation ID in
flatpak_authorize_method_handler(), which results in a seg fault when
dir_get_system() returns NULL and this NULL is passed to
dir_ref_is_installed(). Fix the seg fault by getting the correct element
from the variant.

Closes: #2411
Approved by: matthiasclasen
2018-12-09 07:09:49 +00:00
Matthias Clasen 9826622f6e Fix a policy mismatch
We added metadata-update to the PolicyKit policy,
but made the system-helper user update-metadata.
Oops

Closes: #2399
Approved by: mwleeds
2018-12-07 20:05:44 +00:00
Matthias Clasen 4fe9fbe2be system-helper: Strip polkit errors before sending them on
We shouldn't put the unsightly dbus error wrapping in the
UI. The cient already strips the wrapping from the system
helper call, but it can't strip the second level itself.

Closes: #2399
Approved by: mwleeds
2018-12-07 20:05:44 +00:00
Matthias Clasen 86c10e36df Fix a parameter type mismatch
GVariant doesn't take it lightly when you are trying to extract
an ay value with an s format. This was causing critical warnings.

Closes: #2393
Approved by: alexlarsson
2018-12-07 08:01:36 +00:00
Matthias Clasen e14af35207 system-helper: Centralize pid-setting
There was a bunch of handle methods which forgot to do
this manually, so call the flatpak_dir_set_source_pid()
method right when we create the FlatpakDir object.

Closes: #2384
Approved by: alexlarsson
2018-12-06 14:47:58 +00:00
Matthias Clasen 2089701206 system helper: Don't rely on the caller for updates
The Deploy method takes an 'update' flag from the caller
and picked the permission to check based on that, which
is not safe. Instead, we can check ourselves if the ref
we are given is already installed (in which case it is
an update, or a reinstall).

After this change, the update flag is ignored by the
system helper.

Closes: #2384
Approved by: alexlarsson
2018-12-06 14:47:58 +00:00
Matthias Clasen 21f845c1a7 Revise polkit messages again
I realized that these messages are a bit confusing, with
keep permissions and implications. We end up asking a
question about one ref, but then use the permission we optained
to operate on other refs. This will get a bit worse with
the new hints, so go back to more generic messages that
don't talk about the details. The ultimate goal here is
less messages, anyway.

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 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
Matthew Leeds feb7552a82 system-helper: Fix a copy paste error 2018-12-04 22:29:42 -08:00
Matthias Clasen 4c26a0d867 fix a few oversights in the recent system-helper change
1ba30f7ef1 introduced flags to system-helper methods
missing them, but some places were overlooked. This makes
the testsuite pass again.
2018-12-04 21:09:09 -05:00
Matthias Clasen f325d5f9fb Add a update-metadata action to the polkit policy
This action is used for UpdateSummary, GenerateOciSummary and
when updating the ostree-metadata branch.

Closes: #2383
Approved by: alexlarsson
2018-12-04 15:16:49 +00:00
Matthias Clasen 49ed514ac3 Add imply annotations to the polkit policy
Arrange things so that

app-install > app-update > runtime-install > runtime-update
app-uninstall > runtime-uninstall

Closes: #2383
Approved by: alexlarsson
2018-12-04 15:16:49 +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
Matthias Clasen a45029907e Bump the system helper interface version
We've added a new method, so bump the version.

Closes: #2369
Approved by: matthiasclasen
2018-12-02 00:36:26 +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
Matthew Leeds 701602c6ca system-helper: Use modify-repo action for metadata updates
Currently by an accident of history when the system-helper is asked to
deploy updates to the repo metadata (stored on the ref
"ostree-metadata") it uses the polkit action
org.freedesktop.Flatpak.runtime-install since the ref doesn't start with
"app/" and is therefore assumed to be a runtime. This of course doesn't
make much sense, so this commit redirects such invocations of the
"Deploy" method to the "modify-repo" action, which is a bit of a
catch-all of things the system-helper should be allowed to do. It
doesn't seem necessary to split this out into its own action, since
sysadmins probably don't need the ability to break Flatpak's expected
functionality by disabling it. See the PR for more discussion.

Fixes https://github.com/flatpak/flatpak/issues/2328

Closes: #2351
Approved by: matthiasclasen
2018-11-30 01:08:40 +00:00
Matthew Leeds b351b1ffd9 system-helper: Correct polkit message for modify-repo
Originally the modify-repo action was only used by the RemoveLocalRef
method, which has "remote" and "ref" parameters, but now other methods
use it which don't have such parameters. So this commit modifies
flatpak_authorize_method_handler() so that we're not trying to pass
information along to polkit that we might not have, and modifies the
message shown by polkit to be more accurate.

Closes: #2351
Approved by: matthiasclasen
2018-11-30 01:08:40 +00:00
Philip Withnall 0ffcd5e57f system-helper: Add default return at end of polkit rules
This is not a functional change: the default return value is equivalent
to polkit.Result.NOT_HANDLED. However, this makes the behaviour more
obvious.

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

Closes: #2354
Approved by: matthiasclasen
2018-11-29 23:12:16 +00: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
Matthias Clasen add199a1f9 Amend the policy comments further
As pointed out in #1269, we also install polkit rules
which affect this.

Closes: #2287
Approved by: matthiasclasen
2018-11-06 11:38:13 +00:00
Matthias Clasen 0a9a6abdf7 Update polkit policy descriptions
Update the user-visible messages to include some of
the details that are available. An informed user is
a happy user.

String change!

Closes: #2287
Approved by: matthiasclasen
2018-11-06 11:38:13 +00:00
Matthias Clasen cac9167558 Correct polkit policy comments
Make the security comments for our polkit rules match
the actual defaults.

Closes: #2287
Approved by: matthiasclasen
2018-11-06 11:38:13 +00:00
Umang Jain 34fd118bd9 system-helper: Rename variables for clarity
Closes: #2270
Approved by: matthiasclasen
2018-10-23 20:22:37 +00:00
Matthias Clasen 1134e28400 system helper: Set the source pid
We add the callers pid as OBJECT_PID to our journal
entries, which causes journald to add number of useful
fields, such as the user and binary on whose behalf we
are acting.
2018-10-11 14:51:51 +02:00
Robert McQueen 060322b50b system-helper: set IO class to idle
Our benchmarks show this significantly reduces the interactivity impact of
ongoing Flatpak operations while the user is continuing other tasks on the
system. The effect is very pronounced with the default CFQ scheduler, and in
combination with BFQ, using the idle class improves the worst case to nearly
the same as an unloaded system.

Closes: #2071
Approved by: alexlarsson
2018-09-04 10:56:35 +00:00
Alexander Larsson 0307afd5f2 Fix hang in system-herlpe::DeplayAppstream for OCI
When deploying the appstream for an OCI remote we actually pull the
http remote. This triggers some libsoup code that recurses the default
mainloop. As this happens of the main thread we can get the response
back on the wrong thread leading causing us to never send the reply
back, hanging the call.

Closes: #2010
Approved by: alexlarsson
2018-08-26 09:29:39 +00:00
Matthew Leeds fb989a62a1 common: Add and use FLATPAK_ERROR_DOWNGRADE
This will be useful in distinguishing downgrade errors from other
errors, which I'll need in the next commit.

Closes: #1965
Approved by: alexlarsson
2018-08-20 06:58:01 +00:00
Owen W. Taylor 8fe9bf4d86 Look at all refs when verifying a ref for flatpak-system-helper
The normal behavior where we only list already installed refs for
a noenumerate remote doesn't work for the case where flatpak-system-helper
verifies a ref on an OCI server during installation - in that case, the
ref being installed to does not *yet* exist locally.
2018-08-13 11:23:28 +02:00
Owen W. Taylor 65770d800f system-helpers: When deploying OCI's, verify refs against summary, not server
We previously made a separate request to the registry index to see if
the manifest hash of an image was the hash of the image in the registry.

Since the summary is now downloaded by the system helper and trusted, just
check if the hash matches the hash in the summary data. This is as good,
and in is a lot more efficient if the index is statically generated,
and we can't get the index data for just one image.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:36 +00:00
Owen W. Taylor 4dfa7721bb Remove unused etag functionality
Checking the registry against a previous etag is now handled inside
flatpak_cache_http_uri(), so remove the etag parameters that were
previously passed around in various places for simplicity.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Owen W. Taylor baa7d35ca1 Extract the appstream data from the OCI registry index
Previously the code assumed that appstream data was stored in a separate
OCI image in the registry. Replace that with storing the appstream data
and icons as image annotations. When we download a new version of the
image index, the appstream data is combined, and icons are downloaded
as necessary.

Since there is no longer a content hash for the appstream data, it's
not practical for the user to download the appstream data and pass it
to the system helper, instead the system helper just downloads the
appstream data directly.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Matthew Leeds 8292732e65 Add a system-helper UpdateSummary method
This system-helper method will allow flatpak to update the ostree repo
summary while running as a non-root user that's in the "sudo" group.
This will allow the `flatpak create-usb` command to work without
requiring the user to first run `sudo ostree summary -u`, and without
requiring the system to have `core.auto-update-summary` set to true in
the ostree repo config. This is also much more efficient than
`core.auto-update-summary` because it allows us to only update the
summary when we need it rather than after every transaction.

Generating the summary basically just involves traversing the repo to
enumerate all the refs and putting this information into a file, so I
don't think there are security concerns with allowing it to happen
without authentication.

Closes: #1945
Approved by: alexlarsson
2018-08-08 14:42:16 +00:00
Matthew Leeds 486eb76f75 system-helper: Update outdated vendor_url
Closes: #1943
Approved by: alexlarsson
2018-08-07 09:31:17 +00:00
Will Thompson 96854b902a system-helper: fix error when updating not-installed app
Closes: #1919
Approved by: mwleeds
2018-07-24 20:30:52 +00:00
Alexander Larsson 3f4518b15c Run uncrustify
Closes: #1870
Approved by: alexlarsson
2018-07-08 10:05:37 +00:00
Simon McVittie 7179c12e22 Fix error handling while deploying AppStream
Setting an error with second_error->message is going to work poorly
when second_error has never been set non-NULL.

Related to #1845, although not necessarily the full solution.

Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #1867
Approved by: alexlarsson
2018-07-07 16:17:46 +00:00
Alexander Larsson 0d19e60ce3 system-helper: Add EnsureRepo operation
This is used to create the /var/lib/flatpak repo if
needed so that other later operations work. We have
some partial support for it not working in various
operations (using the allow_empty argument) but
this is in no way complete. For example, this
can easily happen if you have a per-user installation
but no system one and then you run flatpak install
with no --user, then it will try to figure out
which one to use and die.
2018-07-07 16:37:44 +02:00
Philip Withnall 441fe25255 all: Use GMainContextPopDefault when handling thread defaults
Simplify some of the return logic when handling pushing/popping the
thread default main context by using g_autoptr(GMainContextPopDefault).

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

Closes: #1736
Approved by: alexlarsson
2018-06-04 12:22:30 +00:00
Alexander Larsson 3e47247425 Batch running triggers
This moves the triggers from out of flatpak_install/update/uninstall
and instead calls them manually at all the sites that call this.

This allows FlatpakTransaction to only run the triggers once for the
entire operation.

Closes: #1743
Approved by: alexlarsson
2018-06-01 11:41:56 +00:00
Alexander Larsson 2642b55e91 libflatpak: Guard public headers for individual includes 2018-05-29 16:37:21 +02:00
Alexander Larsson efb92704fe Merge lib/* into common
This moves all the files from lib into common, and it also adds all the libflatpak
sources into libflatpak-common, making libflatpak just a wrapper around the common
helper library.

This move allows the CLI to use all the code from libflatpak. We were already doing
this with a few things like flatpak-error*.[ch], and we want to do it even more
when sharing FlatpakTransaction. This also allows use to slowly move
the CLI to using the libflatpak apis for some things.

Closes: #1706
Approved by: alexlarsson
2018-05-24 11:59:52 +00:00
Alexander Larsson c570e09ac9 common: Rename all generated files to *-dbus-generated.[ch]
Easier to spot them this way

Closes: #1706
Approved by: alexlarsson
2018-05-24 11:59:52 +00:00
Alexander Larsson 960d20448c common: Rename all private headers to *-private.h
This is the start of the merging of lib/* into common/*

Closes: #1706
Approved by: alexlarsson
2018-05-24 11:59:52 +00:00