Commit Graph

1717 Commits

Author SHA1 Message Date
Alexander Larsson
1291663a5a transaction: Automatically install authenticator if needed
If the local config for the remote specifies an authenticator name
and that is should in installed, automatically add it to updates
in a transaction.

The local config can either be manually configured, or automatically
from a flatpakrepo file or the summary metadata.
2019-12-19 10:33:21 +01:00
Alexander Larsson
4bb2f0684a Support updating authenticator keys via remote config updates 2019-12-19 10:33:21 +01:00
Alexander Larsson
04162f3286 repo support for setting authenticator options
flatpak build-update-repo now lets you modify the
autenticator-name/install/options keys, and these are migrated to
the summary/metadata during update.
2019-12-19 10:33:21 +01:00
Alexander Larsson
798d90ef0c flatpakrepo files: Support Authenticator keys
This parses AuthenticatorName and AuthenticatorInstall
2019-12-19 10:33:21 +01:00
Alexander Larsson
af2ecb7335 transaction: Make metadata updates more efficient
When we call flatpak_dir_update_remote_configuration we pass it
the pre-existing FlatpakRemoteState (if known) and also take into
account if it actually changed anything before blowing away the
cached remote state.

We also ensure we have metadata in
flatpak_dir_update_remote_configuration_for_state to ensure the passed
in optional state has metadata in it.
2019-12-19 10:33:21 +01:00
Umang Jain
142a7fd855 dir: Immediately return if getting remote state is cancelled
Immediately return the error instead of saving the error and
continuing on an optional codepath if _flatpak_dir_get_remote_state
is cancelled.
2019-12-18 10:36:05 +01:00
Alexander Larsson
4c3e59cd12 utils: Fix chaining of progress
With the latest ostree that enables the chaining of progress the
testsuite broke because we were not getting changed events. Looking
into this the reason seems to be that when we run the
ostree_async_progress_finish() on the chained progress it is marked
as dead, which causes ostree_async_progress_copy_state() to not copy
any data when called from handle_chained_progress().

The fix is to copy the content manually before calling the finish().

Also, the entire callback chaining system seems wildly
overcomplicated, so I simplified it by relying on the existing change
notification of OstreeAsyncProgress.
2019-12-18 09:46:39 +01:00
Alexander Larsson
a9888574ec authenticator: Empty authenticator name means none 2019-12-17 15:25:42 +01:00
Alexander Larsson
4106fc4677 authenticators: For no-interaction dirs, send no-interaction flag
For apps that run in the backgroun without interaction, pass this info
to the authenticator.

This can be used to avoid sending unnecessary webflow or basic auth
request, but those were already silenced by FlatpakTransaction. However
this also allows the authenticator to avoid doing direct, native user
interaction which was otherwise not avoidable.
2019-12-17 14:59:43 +01:00
Simon McVittie
10ee004d77 dir: Don't leak result of flatpak_get_current_locale_langs()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-12-17 14:59:24 +01:00
Alexander Larsson
0b732ba111 dir: Fix leak in flatpak_remote_state_lookup_cache()
For some reason we're assigning refdata the same thing twice, leaking
the first copy.
2019-12-17 14:55:13 +01:00
Alexander Larsson
24558eec47 dir: Fix leak in flatpak_dir_p2p_state_free
We forgot to free the results_refs member
2019-12-17 14:55:13 +01:00
Alexander Larsson
f983ed616b dir: Actually free the main memory chunk in flatpak_dir_p2p_state_free 2019-12-17 14:55:13 +01:00
Alexander Larsson
d7474daaf2 dir: Fix leak
When recreating self->repo, also clear self->cache_dir, otherwise it was
leaking when we replaced it.
2019-12-17 14:55:13 +01:00
Alexander Larsson
510fbce093 Remove extraneous ostree_async_progress_finish()
These should only be called at the leaf level, because the first
time its called no more change events will ever be sent on that
progress, which is not right possibly in the middle of an operation.
2019-12-17 14:55:13 +01:00
Alexander Larsson
c322cbdbb6 Add and use OstreeAsyncProgressFinish helper
This is a g_autoptr version of OstreeAsyncProgress that also
calls ostree_async_progress_finish() before being freed.

This should be used in all "leaf" functions that creates an asyncprogress
to avoid leaking any idle change idle sources. Using a auto* means
some code can be cleaned up to avoid goto out style handling for this.

Also, this adds a missing finish() in
_flatpak_dir_fetch_remote_state_metadata_branch().
2019-12-17 14:55:13 +01:00
Alexander Larsson
b3ab31e18a FlatpakAsyncProgressChained: Don't leak chained progress
If we're using a chained progress, it will be unchained
in the destroy notifier. However, it was newly constructed so we
need to also unref it or we'll leak it.

This also makes some minor cleanups:

1) Centralize version checks to one place and replace users
   with #ifdef FLATPAK_DO_CHAIN_PROGRESS which makes it
   easier to read and to test the fallback.

2) Make flatpak_progress_chain return a FlatpakAsyncProgressChained
   to make it clear the two needs to be paired.
2019-12-17 14:55:13 +01:00
Alexander Larsson
dd6df7589e utils: Don't leak GMainContextPopDefault contextes
We're creating a new one, making it the default, and on destroy
we pop it, but since we're not also destroying it we're leaking the
entire context!
2019-12-17 14:55:13 +01:00
Alexander Larsson
93a7718678 test: Fix leak of OstreeRepo cachedir fd
It turns out ostree_repo_open() overwrites custom cachedir_fd we've
set for the system using installation in case the object dir is
writable. Normally this is not a problem, because it is not writable,
but in the testsuite is *is*, which means the initial cachedir fd is
leaked, as well as using the wrong dir for summary caches during the
tests.

We work around this by setting the cache_dir after a successful
ostree_repo_open().

This fixes #3303
2019-12-17 14:55:13 +01:00
Alexander Larsson
7fedf3578f OCI: Only use labels, never annotations
This is a slightly incompatible change, as we now only support
oci images generated with (what was before) build-export --oci-use-labels.
However, there are not a lot of OCI implementations in the wild, and
we can modify the ones in use to ensure there are labels (and
annotations if needed for older flatpak clients).

This also removes the --oci-use-label option from build-bundle --oci as
this is now the default.
2019-12-16 09:23:49 +01:00
Thiago Jung Bauermann
c3bd7bc855 Fix typo in /etc/timezone filename
flatpak_get_timezone () tries to access /etc/timezone if /etc/localtime
isn't a valid symlink, but gets the name wrong. Fix it.

Found by code inspection.
2019-12-16 09:07:23 +01:00
Matthew Leeds
f4337b9a4e Merge pull request #3298 from alexlarsson/authenticator-collection-id
Pass collection-id (if any) to authenticator when requesting tokens
2019-12-13 14:16:09 -08:00
Jan Grulich
a61f61870e Add support for CUPS socket 2019-12-13 17:56:22 +01:00
Alexander Larsson
9f1582b09b Authenticator: Pass collection-id with the request 2019-12-13 15:07:58 +01:00
Alexander Larsson
9a4f5084ad run: (re-)allow forwarding fds into flatpak run
It turns out d91660fe2a accidentally
broke the inheritance of non-stdin/out file descriptor into children
of "flatpak run" which broke the fd passing in the flatpak spawn portal.

This reverts that, allowing all fds not specifically marked as CLOEXEC
by other means to be inherited into the child.

Fortunately the regression was not in any stable release.
2019-12-12 17:02:02 +01:00
Alexander Larsson
4902acbebf authenticator: Change how authenticator options are stored
We used to store all options as a gvariant format string like so:

 xa.authenticator-options={"key1": <"a string value">, "key2": <"foo">}

But nobody really knows how to write these things, so now we
have instead multiple options with a common prefix that
get collected like so:

 xa.authenticator-options.key1="a string value"
 xa.authenticator-options.key2="foo"

This means all options are strings, but most options are, and
if not you can just parse them.
2019-12-12 14:27:59 +01:00
Alexander Larsson
bdf734edb2 utils: flatpak_dir_list_remote_config_keys() helper
Lists all the config key for a specified remote (if any)
2019-12-12 14:27:59 +01:00
Alexander Larsson
c6aa7f56a1 password prompt: Emit newline (as we stole it during input) 2019-12-12 14:27:59 +01:00
Alexander Larsson
38c86bdf0f Authenticator: Add extra a{sv} args for future use
These are not used atm, but make the APIs future proof.
2019-12-12 14:27:59 +01:00
Alexander Larsson
134e01f606 OCI: Extract token-type and eol metadata into generated summary 2019-12-12 12:16:53 +01:00
Alexander Larsson
5b58f7f7c2 Auth: Add flatpak_auth_request_emit_basic_auth() helper 2019-12-12 12:16:53 +01:00
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