Commit Graph

1686 Commits

Author SHA1 Message Date
Alexander Larsson
6e6c122cb2 Authenticators: Add BasicAuth operation and handle it in transaction
This adds a new way for authenticators to trigger interactive authentication
in the client for simple user/password dialogs. These are not recommended
to use as a webflow is often better. However, for OCI remotes that
use http basic auth this is useful and allows the CLI experience to work
with that.
2019-12-12 12:16:53 +01:00
Alexander Larsson
ba9d607a92 transaction: Rename active_webflow* to active_request*
We want to use this for other types of interactive requests too.
2019-12-12 12:16:53 +01:00
Alexander Larsson
2601b4cb1a utils: Add helpers for text prompts and password prompts 2019-12-12 12:16:53 +01:00
Alexander Larsson
d25f65e968 OCI: Add an authenticator for OCI remotes
Given a configuration like:

[remote "oci-remote"]
url=oci+http://some.server.com/api/v1/organization/foo?index=labels
xa.authenticator-name=org.flatpak.Authenticator.Oci
xa.default-token-type=1
xa.authenticator-options={"auth": <"a-token-here">}

I was able to install an app from an OCI remote that required a login
2019-12-12 12:16:53 +01:00
Alexander Larsson
461a592b8e OCI: Add flatpak_oci_registry_get_token() method
This tries to do a HEAD request to the repository and if that fails
with 401 uses the OCI mechanism to (given a basic auth token) generate
a token for the download.
2019-12-12 12:16:53 +01:00
Alexander Larsson
b1a8852895 authenticator: Pass xa.oci-registry-uri from summary to authenticator
OCI will need this.
2019-12-12 12:16:53 +01:00
Alexander Larsson
73ea55c638 authenticator: Add per-commit summary info
In the non-p2p case add the per-commit summary info into the autheticator
request. This rewrites the keys with a "summary." prefix.

In the p2p case this doesn't make sense, so nothing there.

This will be needed for the OCI case where we need the
xa.oci-repository key.
2019-12-12 12:16:53 +01:00
Alexander Larsson
4dba1c389b authenticator: Add more data to token request
This adds the remote uri, and the per-ref commit id, as well
as extensible per-ref and per-request dicts we can add stuff to
as needed.

These will be used for the OCI case.
2019-12-12 12:16:53 +01:00
Alexander Larsson
976c88cf56 oci: Pass down token into OCI http operations
This is needed for pull operations to actually use the token if one
is given by an authenticator.
2019-12-12 12:16:53 +01:00
Alexander Larsson
6563b83704 Add xa.default-token-type remote option
This allows us to specify on a remote that all refs need a token
2019-12-12 12:16:53 +01:00
Philip Chimento
3e0a8f296a utils: Fix crash with FlatpakRepoTransaction autoptr cleanup
The autoptr cleanup function for FlatpakRepoTransaction depends on the
OstreeRepo object that it was created with still being alive. If the
repo object is also an autoptr then it can depend on the order the
variables were declared in whether this works or crashes.

That is obviously an evil trap, so have FlatpakRepoTransaction take a
ref on the repo object and release it in the autoptr cleanup function,
in case the repo's autoptr cleanup function runs before that of
FlatpakRepoTransaction.
2019-12-06 13:26:49 -08:00
Philip Chimento
cbf1cc0e1d transaction: Fix transfer annotation on get_status()
flatpak_transaction_progress_get_status() returns a pointer created by
g_strdup() but was annotated transfer-none. A quick grep shows that
calling code in the tests does treat it as transfer-full, so change the
annotation to match the actual behaviour.
2019-12-06 13:26:49 -08:00
Philip Chimento
923beec024 Change "update-frequency" to "update-interval"
An event happens more often as its frequency gets higher, so these
values were confusing me.

Rename the constants to include their unit (ms) as well, to avoid
confusion.

Anything that affects public API (such as
flatpak_transaction_progress_set_update_frequency()) or libostree's
options passed to ostree_repo_pull_with_options(), is left as is.
2019-12-06 13:26:49 -08:00
Philip Chimento
0da49895ab Alphabetize and standardize some header includes
Cleanup commit, doesn't change functionality, but we'll be adding some
files to these lists in a subsequent commit.
2019-12-06 13:26:49 -08:00
Matthew Leeds
dded404c33 installation: Don't re-use a GError pointer
Here we're using the same GError pointer multiple times without clearing
it, which is an error. Use a local_error and print a debug message
instead, which matches the behavior in the loop above.
2019-12-05 17:00:59 -08:00
Matthias Clasen
44b6bc7f98 Merge pull request #3259 from uajain/uajain/cache-remote-state
installation: Cache remote states while querying installed refs
2019-12-04 11:48:47 -05:00
Umang Jain
4ab74d07c0 installation: Cache remote states while querying installed refs
Cache remote state so that each remote is only queried once
for getting its state.

Follow up from https://github.com/flatpak/flatpak/pull/3204#discussion_r349642324
2019-12-04 18:22:23 +05:30
Matthew Leeds
17660cab57 common: Minor doc fixes 2019-12-02 18:16:44 -08:00
Matthias Clasen
91217ecb24 doc: Fix a duplicate section
In commit 88aaaab7b, I overlooked that there
was already a doc comment for the flatpak-version-macros
section at the bottom. To make things worse,
the duplicate I added was malformed.
Fix things up to work as intended.
2019-12-02 07:45:51 -05:00
Matthias Clasen
eb3eff11ae Merge pull request #3274 from matthiasclasen/nread-overflow
Fix a case of signed/unsigned confusion
2019-12-02 07:29:29 -05:00
Matthias Clasen
d580dd71cf Merge pull request #3268 from matthiasclasen/doc-updates
Doc updates
2019-12-02 07:29:12 -05:00
Matthias Clasen
e04263ca5c Fix a case of signed/unsigned confusion
G_input_stream_read_finish returns a gssize,
which we must not store in a gsize, since it
may be -1.

Closes: https://github.com/flatpak/flatpak/issues/2885
2019-12-01 23:01:10 -05:00
Matthew Leeds
d5909171bb context: Improve description of --persist
The --persist option makes a subpath in the user's home directory
available in the sandbox. Make the description more clear accordingly.
2019-12-01 15:50:29 -08:00
Matthias Clasen
7d78921488 doc: Improve docs around configuration
Various formatting and other tweaks for the
docs around setting and getting config keys.
2019-12-01 14:05:27 -05:00
Matthias Clasen
c313c98407 doc: Fix a copy-paste error
Correct the docs of FlatpakStorageType.
2019-12-01 14:05:22 -05:00
Matthias Clasen
eec8fcd2da doc: Add a few since tags
Lets keep annotating new apis with the version
they were introduced in.
2019-12-01 14:05:16 -05:00
Matthias Clasen
88aaaab7b2 doc: Add a long description for version macros
This makes the docs a little less incomplete.
2019-12-01 14:05:09 -05:00
Matthias Clasen
253188e4fc doc: Document FlatpakPortalError 2019-12-01 14:04:59 -05:00
Matthias Clasen
7a55291785 doc: Fix docs for flatpak_transaction_add_rebase
The subpaths argument was missing.
2019-12-01 14:04:53 -05:00
Matthias Clasen
1a1af89f1d doc: Document flatpak_installation_get_no_interaction 2019-12-01 14:04:46 -05:00
Alexander Larsson
2f628d11ff Make flatpak_instance_new_for_id non-static
We want to use this from the portal
2019-11-27 14:21:25 +01:00
Alexander Larsson
62797b4be9 flatpak run: Add --parent-pid=$pid --parent-expose-pids
Given the pid of an existing flatpak process, if --parent-expose-pids is
specified, the new sandbox is run such that its processes are visible in
the specified sandbox.

In all other senses the two are disjoint though. The new sandbox is
still isolated from the host and the existing sandbox.
2019-11-27 14:21:25 +01:00
Matthew Leeds
9f1c5a7033 dir: Improve comments about deleting mirror refs
Make it clear which refs we delete and why, per the discussion here:
https://github.com/endlessm/flatpak/pull/200#discussion_r350053918
2019-11-27 08:49:03 +01:00
Alexander Larsson
5a6b364ee5 transaction: Add xa-default-token-type support
This is from the summary and can be used as the default token type
if all/most refs need a token.
2019-11-26 16:37:01 +01:00
Alexander Larsson
a615113a83 Split out and document org.freedesktop.Flatpak.Authenticator API 2019-11-26 16:37:01 +01:00
Alexander Larsson
3f6245d41b authenticator: Add a parent_window handle to request_tokens
This allows the authenticator to directly do UI and parent it to the
relevant window. The actual parent string is specified just like
the xdg-desktop-portal one.

There is a new flatpak_transaction_set_parent_window() function that
clients can use to signal the what window they want to be parented to.
2019-11-26 16:37:01 +01:00
Alexander Larsson
90dc9ace2a authenticator: Pass token-type for each ref
This allows the authenticator to handle each token type differently.
For example, this allows a "purchase" type to run the donation
webflow, but not require login (and then store the fact that this was
run locally).
2019-11-26 16:37:01 +01:00
Alexander Larsson
e0cef17c0c tokens: Allow authenticators to send an error message 2019-11-26 16:37:01 +01:00
Alexander Larsson
b77f7c9383 authenticator: Pass remote name to RequestRefTokens
This makes it very easy to reuse a single authenticator for several
remotes. This is useful for the a default authenticator implementation
that we can ship with flatpak and use for e.g. flathub.
2019-11-26 16:37:01 +01:00
Alexander Larsson
0ca1a1624f FlatpakTransaction: Add webflow-start/done signals and abort_webflow()
These signals are emitted when the authenticator needs some kind of
web-based authentication. If the caller implements webflow-start and
returns TRUE, then it needs to show the user the URL and allow the user
to interact with it.

Typically this ends with the web-page being redirected to a url to
localhost or similar which tells the authenticator the result of the
operations. This will cause the webflow-done signal to be emitted and
the transaction operation to continue. If something goes wrong (or the
signal is not handled) it will also report webflow-done, but then the
transaction will fail in a normal way.

Generally all users of FlatpakTransaction need to do is:

 On webflow-start, show a browser window with the url and return TRUE.

 On webflow-done, close the browser window if its still visible.

 If the user closes the browser window early, call
 flatpak_transaction_abort_webflow().
2019-11-26 16:37:01 +01:00
Alexander Larsson
9a8bf2be31 auth: Add helpers dbus helpers for sending webflow signals 2019-11-26 16:37:01 +01:00
Alexander Larsson
ae13e31510 transaction: Request required tokens from configured authenticator
When we need a bearer token, look up the configured authenticator for
the remote and ask it for tokens. Also updates the test-auth test
with to use the new test authenticator instead of the previous
env var hack.
2019-11-26 16:37:01 +01:00
Alexander Larsson
e6465da03b Add some helper functions for working with authenticators
This will be used by later code in combination with the gdbus
generated code.
2019-11-26 16:37:01 +01:00
Alexander Larsson
ddc60ad179 Transaction: Support tokens for all p2p pulls
The p2p case is kinda weird wrt tokens. We can do most of the basics,
like which refs need updating using the partial summary from the p2p
mirrors, but we can't rely 100% on the ostree-metadata info for core
info like permissions or dependencies, since it may be out-of-sync.

So, if the information in the ostree-metadata doesn't match the
commit we're resolving, the p2p resolve code actually pulls the actual
commit objects as part of a resolve.

Now, the commit objects are protected by bearer tokens, so we need to
pass them while doing this pull. Unfortunately the information about
which refs requires tokens are part of the commit, which is a circular
dependency. We resolve this by relying on the (possibly stale, but
probably ok) copy of the need-token info in the ostree-repo metadata.

So, we do the first part of the p2p resolve, then for all the
not-yet-resolved ops (i.e. ones that actually need updates) we look
in the ostree-metadata for which refs need tokens, generate tokens
and then do the pulling with the tokens.

This is an iterative process, because resolving a ref can create more
update operations, which may need more tokens.
2019-11-26 16:37:01 +01:00
Alexander Larsson
59a2e9b704 p2p resolve: Support tokens in flatpak_dir_finish_resolve_p2p_refs
Also, since the lower level APIs don't allow you to pass different tokens
for different parts change this function to support passing a subset
of the resolves, so that we can pass all that need a specific token in
one go, and then call this multiple times. The way we handle this is
by saving all the original ref_to_checksum hashtables for all results
and then re-create them with the subset of refs needed when pulling.
2019-11-26 16:37:01 +01:00
Alexander Larsson
3d47dc02fa p2p: When updating/installing, resolve via ostree-metadata if possible
If the commit is available in the ostree-metadata and it matches what
the latest available commit in the p2p results then resolve it to that, so
we don't have to download the commit object.
2019-11-26 16:37:01 +01:00
Alexander Larsson
54415b79c7 p2p: Add flatpak_dir_resolve_maybe_resolve_from_metadata
This tries to resolve the p2p resolve operation from the info in
a ostree-metadata commit. This only works if the resolve ended up
on the same commit id as what was available in the ostree-metadata
which may not be correct if the two are not synchronized.
2019-11-26 16:37:01 +01:00
Alexander Larsson
7f5ed5020f p2p resolve: Resolve the token_type data from the commit 2019-11-26 16:37:01 +01:00
Alexander Larsson
c8e1ba41e1 Transaction: non-p2p support for tokens
We extract the need-token key from the summary and if set we
calculate a token to use for the operation, which we then pass
to install/update.

For now the actual token just comes from the FLATPAK_TEST_TOKEN
environment var. The details of this will be fleshed out later.

Additionally, this does not support the p2p case, because there
we need the token in order to request the commit during the resolve.
This will also be added later.
2019-11-26 16:37:01 +01:00
Alexander Larsson
077006ecc8 Add token-type per-commit metadata key and export it to summary
We store this in the sparse cache, because we don't expect it to be
set for everything.
2019-11-26 16:37:01 +01:00