git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] credential/libsecret: load secrets explicitly

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Nov 5, 2026, 14:37 UTC
Message-ID
<c0a247f6-0dfa-4c10-8db5-203f2803ac8d@gmail.com>
In-Reply-To
<pull.2372.v2.git.git.1790549181518.gitgitgadget@gmail.com>
Hi Daniel
Here are some comments from someone who uses the libsecret credential helper and has just spent some time reading the api docs (i.e. I don't have any experience writing code that uses libsecret).
On 27/09/2026 23:46, Daniel Martí via GitGitGadget wrote:
> From: =?UTF-8?q?Daniel=20Mart=C3=AD?= <mvdan@mvdan.cc>
> > keyring_get() searches with SECRET_SEARCH_LOAD_SECRETS, then passes
> secret_item_get_secret() of the first match unchecked to
> secret_value_get_text() and secret_value_unref().
This sentence is incredibly dense - I had to go and read the code to understand what it was saying.
> As libsecret
> documents, that secret can be NULL: the search does not load secrets
> of locked items, such as when SECRET_SEARCH_UNLOCK fails to unlock
> them, and it ignores errors from loading secrets. The GNOME keyring> daemon also silently leaves out of its reply any item which is locked
Is that true? My reading of the documentation is that it includes the SecretItem in the list we get back from the search, but we cannot load the secret because it is locked.
Show 9 quoted lines
> or which was deleted after the search matched it, e.g. by a concurrent
> "credential erase" from another git process. We then print
> >      secret_value_get_text: assertion 'value' failed
>      secret_value_unref: assertion 'value != NULL' failed
> > before git falls back to prompting for the password.
> > We could keep the flag and load the secret explicitly only when it is
> NULL, but SECRET_SEARCH_LOAD_SECRETS is not part of the search call:
> libsecret implements it as a separate GetSecrets D-Bus call after
> SearchItems.
I don't see how this implementation detail is relevant. Surely what matters is the lack of error information, not how SECRET_SEARCH_LOAD_SECRETS is implemented.
> Drop the flag and instead always load the one secret we
> use with secret_item_load_secret_sync(), which reports errors.
If SECRET_SEARCH_UNLOCK fails and so we cannot load a secret because it is still locked, calling secret_item_load_secret_sync() does not tell us why the unlock failed. If we want to provide a better error message in that case I think we need to unlock the secret ourselves.
> This takes as many D-Bus calls as before,
Are we really that worried about the number of D-Bus calls? If we are then we should remove SECRET_SEARCH_UNLOCK and call secret_item_get_locked() to see whether we need to unlock it or not.
> and leaves a single code path
> that runs every time, rather than a fallback that only runs in a rare
> race. libsecret's own secret-tool also loads each secret explicitly
> after searching.
secret-tool appears to use a completely different api to the code here
> An inaccessible item now produces a useful error message The error message is printed with g_critical() which is intended for logging failed assertions[1], not printing runtime error messages. We should use
    g_printerr("error: could not load secret: %s", error->message);
instead. If we cannot load a secret because it has been erased by another process should we consider that an error as this patch does, or should we treat it like a missing credential behave as if the initial lookup had failed?
> instead of
> the assertion failures, and git still falls back to prompting. The
> race needs a concurrent process or a locked keyring to trigger, so
> there is no test.
I don't understand why needing a locked keyring means we cannot have a test. "secret-tool lock" will lock the keyring. There maybe other reasons that make it hard to test but it would be helpful to give a bit more detail.
> +		if (!secret_item_load_secret_sync(item, NULL, &error)) {
> +			g_critical("could not load secret: %s", error->message);
While this matches the existing code, we should be using g_printerr().
> +			g_error_free(error);
> +			g_list_free_full(items, g_object_unref);
It is a bit of a pain to have to free this in two paths. We could avoid that by doing
	loaded = secret_item_load_secret_sync(item, NULL, &error);
	g_list_free_full(items, g_object_unref);
	if (!loaded) {
		/* report error and return */
	}
and removing the call to g_list_free_full() at the end of the function. That would match how we handle freeing the hash table of attributes after the call to secret_service_search_sync().
> +			return EXIT_FAILURE;
> +		}
>   		secret = secret_item_get_secret(item);
Are we sure this can never fail now, or should we check secret is non-NULL to avoid future problems?
Thanks
Phillip
[1] https://docs.gtk.org/glib/func.critical.html
>   		attributes = secret_item_get_attributes(item);
>   > > base-commit: 34f06850c16c7f7ac822b1adc71354f11b0f2ca3
Previous: Junio C Hamano
Message 12 of 12 in “credential/libsecret: load secrets explicitly”
  1. credential/libsecret: load secrets explicitlyDaniel Martí via GitGitGadget, Aug 4, 2026
  2. Daniel MartíAug 20, 2026
  3. Junio C HamanoAug 20, 2026
  4. Daniel MartíAug 22, 2026
  5. Daniel MartíSep 21, 2026
  6. Junio C HamanoSep 21, 2026
  7. M HickfordSep 24, 2026
  8. Daniel MartíSep 27, 2026
  9. credential/libsecret: load secrets explicitlyDaniel Martí via GitGitGadget, Sep 27, 2026
  10. Daniel MartíSep 28, 2026
  11. Junio C HamanoNov 2, 2026
  12. Phillip WoodNov 5, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.