Skip to content

Polkit hints - #2384

Closed
matthiasclasen wants to merge 5 commits into
flatpak:masterfrom
matthiasclasen:polkit-hints
Closed

matthiasclasen wants to merge 5 commits into
flatpak:masterfrom
matthiasclasen:polkit-hints

Conversation

@matthiasclasen

Copy link
Copy Markdown
Collaborator

Adding hints that let transactions get away with just a single polkit dialog even when they update a runtime first, then install an app.

@alexlarsson

Copy link
Copy Markdown
Member

Seems we lost the protecion against downgrades:

[####################] 7 metadata, 2 content objects fetched; 1 KiB transferred 
++ assert_not_reached 'Should not be able to update to older commit'
++ echo Should not be able to update to older commit
Should not be able to update to older commit

@rh-atomic-bot

Copy link
Copy Markdown

☔ The latest upstream changes (presumably f3f7417) made this pull request unmergeable. Please resolve the merge conflicts.

@matthiasclasen

Copy link
Copy Markdown
Collaborator Author

This is very frustrating to debug

  • test-suite.log is some kind of nightmare to dig through when something fails
  • the system-helper output is nowhere to be found
  • hard to run individual tests
  • I don't know where this downgrade protection is happening
  • Trying to reproduce it locally ends with a different 'must be root to do this' error

Any hints ?

@matthiasclasen
matthiasclasen force-pushed the polkit-hints branch 2 times, most recently from 0649bb1 to bd64f93 Compare December 6, 2018 01:12
@matthiasclasen

Copy link
Copy Markdown
Collaborator Author

This took all afternoon to figure out: two boolean parameters were swapped.

Booleans - just say no :(

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.
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.
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.
gtk-doc complains if parameter names don't match between
headers and doc comments, so make them match, for a quieter build.
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.
/* Can't install already installed app */
g_dbus_method_invocation_return_error (invocation, FLATPAK_ERROR, FLATPAK_ERROR_ALREADY_INSTALLED,
"%s is already installed", arg_ref);
return TRUE;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API kinda relies on flatpak_dir_install() returning these errors, so this is a behaviour change. I think we need to move the checks to the flatpak_dir_use_system_helper() part of flatpak_dir_install/update.

@matthiasclasen matthiasclasen Dec 6, 2018 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flow just changed a bit here, due to us no longer paying attention to what the caller said about this being an update or an install, with the UPDATE flag. Instead, we now look at the ref we got, and check whether it has a deploy and then we go:

has-deploy && !reinstall -> this is an update
else -> this is an install

previously, we had a case like

has-deploy && update flag not set -> report 'already installed' error

this just doesn't happen anymore, since we don't look at the flag, so no chance for the caller to get us into this inconsistent situation

The api change here is that we took a bit of redundancy (and potential for error cases) out of the api, by removing the update flag.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, my issue is rather with callers of for instance flatpak_dir_install() where, if he app was already installed it would return a FLATPAK_ERROR_ALREADY_INSTALLED error, whereas it now returns G_DBUS_ERROR_INVALID_ARGS. Similarly flatpak_dir_update() with no previous update used to return NOT_INSTALLED, and now succeeds with deploying the pulled app.

However, I looked at the higher level callers of these (libflatpak and flatpak-transaction) and they all do early checks for these error cases anyway, so its not really a problem.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I guess that is true. both flatpak_dir_install and flatpak_dir_update call the same Deploy underneath, so having it fail for the one but not the other seems a bit odd - now the system-helper just does what its asked to do: deploy the ref.

{
/* Can't update not installed app */
g_dbus_method_invocation_return_error (invocation, FLATPAK_ERROR, FLATPAK_ERROR_NOT_INSTALLED,
"%s is not installed", arg_ref);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly, this case here just doesn't happen anymore, where we had the caller claim that this is an update, but there is in fact no deploy

@alexlarsson

Copy link
Copy Markdown
Member

@rh-atomic-bot r+

@rh-atomic-bot

Copy link
Copy Markdown

📌 Commit 794042f has been approved by alexlarsson

@rh-atomic-bot

Copy link
Copy Markdown

⌛ Testing commit 794042f with merge e14af35...

rh-atomic-bot pushed a commit that referenced this pull request Dec 6, 2018
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
rh-atomic-bot pushed a commit that referenced this pull request Dec 6, 2018
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
rh-atomic-bot pushed a commit that referenced this pull request Dec 6, 2018
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
rh-atomic-bot pushed a commit that referenced this pull request Dec 6, 2018
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
@rh-atomic-bot

Copy link
Copy Markdown

☀️ Test successful - status-papr
Approved by: alexlarsson
Pushing e14af35 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants