From: Phillip Wood <phillip.wood123@gmail.com>
To: "Daniel Martí via GitGitGadget" <gitgitgadget@gmail.com>,
git@vger.kernel.org
Cc: "M Hickford" <mirth.hickford@gmail.com>,
"Mantas Mikulėnas" <grawity@gmail.com>,
"Patrick Steinhardt" <ps@pks.im>, "Daniel Martí" <mvdan@mvdan.cc>,
"Junio C Hamano" <gitster@pobox.com>
Subject: Re: [PATCH v2] credential/libsecret: load secrets explicitly
Date: Thu, 5 Nov 2026 14:37:11 +0000 [thread overview]
Message-ID: <c0a247f6-0dfa-4c10-8db5-203f2803ac8d@gmail.com> (raw)
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.
> 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
prev parent reply other threads:[~2026-11-05 14:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 22:40 [PATCH] credential/libsecret: load secrets explicitly Daniel Martí via GitGitGadget
2026-08-20 15:00 ` Daniel Martí
2026-08-20 19:05 ` Junio C Hamano
2026-08-22 20:47 ` Daniel Martí
2026-09-21 21:54 ` Daniel Martí
2026-09-21 22:52 ` Junio C Hamano
2026-09-24 7:00 ` M Hickford
2026-09-27 22:45 ` Daniel Martí
2026-09-27 22:46 ` [PATCH v2] " Daniel Martí via GitGitGadget
2026-09-28 7:37 ` Daniel Martí
2026-11-02 9:31 ` Junio C Hamano
2026-11-05 14:37 ` Phillip Wood [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c0a247f6-0dfa-4c10-8db5-203f2803ac8d@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=grawity@gmail.com \
--cc=mirth.hickford@gmail.com \
--cc=mvdan@mvdan.cc \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox