threads / discuss / 58912

Git credential store conflicting configuration leads to unexpected behavior

Subject: Git credential store conflicting configuration leads to unexpected behavior

## tl;dr

6 messages between Dec 6, 2022 and Dec 7, 2022.

replies: 5people: 3as markdown or json

Gennady Uraltsev· Dec 6, 2022, 22:05 UTC · lore
Hello everyone,

I have an issue with git credential-store. In my global configuration dir (.config/git/config) I had the line

[credential] helper = store

while ini a repository's .git/config while I have

[credential] helper = "store --file=./.git/git-credentials"

to store credentials "locally".

I thought the latter would overrule the former However what happens is the following:

1) On first run the file repo-local file ./.git/git-credentials gets
created and the credentials are saved there after the user is queried
for a password
2) On subsequent runs the credentials get recovered from
./.git/git-credentials and the user is NOT asked for credentials
2b) **Here is the weird behavior** git ALSO creates the
.git-credentials file in the home directory and saves a copy of
credentials there.

The behavior 2b leads to exfiltration of passwords to a location a user might not expect.

Workaround: Remove the line

[credential] helper = store

in the global config.
It seems that the global config somehow does not get shadowed by the local one!
I think this is a bug with mild security implications.
Let me  know.
Best,
Gennady

-- Gennady Uraltsev <gennady.uraltsev@gmail.com> (https://guraltsev.github.io)

brian m. carlson· Dec 6, 2022, 22:16 UTC · re: Gennady Uraltsev · lore

Re: Git credential store conflicting configuration leads to unexpected behavior

On 2022-12-06 at 22:05:22, Gennady Uraltsev wrote:
Show 38 quoted lines
> Hello everyone,
> 
> I have an issue with git credential-store. In my global configuration
> dir  (.config/git/config) I had the line
> 
> [credential]
> helper = store
> 
> while ini a repository's .git/config while I have
> 
> [credential]
> helper = "store --file=./.git/git-credentials"
> 
> to store credentials "locally".
> 
> I thought the latter would overrule the former However what happens is
> the following:
> 
> 1) On first run the file repo-local file ./.git/git-credentials gets
> created and the credentials are saved there after the user is queried
> for a password
> 2) On subsequent runs the credentials get recovered from
> ./.git/git-credentials and the user is NOT asked for credentials
> 2b) **Here is the weird behavior** git ALSO creates the
> .git-credentials file in the home directory and saves a copy of
> credentials there.
> 
> The behavior 2b leads to exfiltration of passwords to a location a
> user might not expect.
> 
> Workaround: Remove the line
> 
> [credential]
> helper = store
> 
> in the global config.
> 
> It seems that the global config somehow does not get shadowed by the local one!

This behaviour is by design. The reason is that sometimes the user may have two sets of credential helpers, one for one set of domains, and another for another. For example, I believe AWS has its own custom credential helper. Git calls credential helpers until it finds a credential, and then it sends store commands to all of them. A credential helper which has no credentials for a domain will generally respond with no credentials.

If you want to override the credential helpers in the `.git/config` file, you can do so by first writing an empty value, like so:

[credential] helper = helper = "store --file=./.git/git-credentials"

-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA
Gennady Uraltsev· Dec 6, 2022, 23:53 UTC · re: brian m. carlson · lore

Re: Git credential store conflicting configuration leads to unexpected behavior

Thank you!

This makes sense and the solution is simple. Is this somewhere in the documentation (honest question, I am not being a jerk)? I tried my best to figure this out before bugging people on the mailinglist.

Best,
Gennady

-- Gennady Uraltsev <gennady.uraltsev@gmail.com> (https://guraltsev.github.io)

On Tue, Dec 6, 2022 at 5:16 PM brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 58 quoted lines
>
> On 2022-12-06 at 22:05:22, Gennady Uraltsev wrote:
> > Hello everyone,
> >
> > I have an issue with git credential-store. In my global configuration
> > dir  (.config/git/config) I had the line
> >
> > [credential]
> > helper = store
> >
> > while ini a repository's .git/config while I have
> >
> > [credential]
> > helper = "store --file=./.git/git-credentials"
> >
> > to store credentials "locally".
> >
> > I thought the latter would overrule the former However what happens is
> > the following:
> >
> > 1) On first run the file repo-local file ./.git/git-credentials gets
> > created and the credentials are saved there after the user is queried
> > for a password
> > 2) On subsequent runs the credentials get recovered from
> > ./.git/git-credentials and the user is NOT asked for credentials
> > 2b) **Here is the weird behavior** git ALSO creates the
> > .git-credentials file in the home directory and saves a copy of
> > credentials there.
> >
> > The behavior 2b leads to exfiltration of passwords to a location a
> > user might not expect.
> >
> > Workaround: Remove the line
> >
> > [credential]
> > helper = store
> >
> > in the global config.
> >
> > It seems that the global config somehow does not get shadowed by the local one!
>
> This behaviour is by design.  The reason is that sometimes the user may
> have two sets of credential helpers, one for one set of domains, and
> another for another.  For example, I believe AWS has its own custom
> credential helper.  Git calls credential helpers until it finds a
> credential, and then it sends store commands to all of them.  A
> credential helper which has no credentials for a domain will generally
> respond with no credentials.
>
> If you want to override the credential helpers in the `.git/config`
> file, you can do so by first writing an empty value, like so:
>
> [credential]
> helper =
> helper = "store --file=./.git/git-credentials"
> --
> brian m. carlson (he/him or they/them)
> Toronto, Ontario, CA
brian m. carlson· Dec 7, 2022, 01:15 UTC · re: Gennady Uraltsev · lore

Re: Git credential store conflicting configuration leads to unexpected behavior

On 2022-12-06 at 23:53:05, Gennady Uraltsev wrote:
Show 5 quoted lines
> Thank you!
> 
> This makes sense and the solution is simple. Is this somewhere in the
> documentation (honest question, I am not being a jerk)? I tried my
> best to figure this out before bugging people on the mailinglist.

Yes, but maybe not where you'd expect. In gitcredentials(7), there's this text:

  If there are multiple instances of the `credential.helper` configuration
  variable, each helper will be tried in turn, and may provide a username,
  password, or nothing. Once Git has acquired both a username and a
  password, no more helpers will be tried.
  If `credential.helper` is configured to the empty string, this resets
  the helper list to empty (so you may override a helper set by a
  lower-priority config file by configuring the empty-string helper,
  followed by whatever set of helpers you would like).
The `credential.helper` option mentions that manual page.
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA
Gennady Uraltsev· Dec 7, 2022, 01:19 UTC · re: brian m. carlson · lore

Re: Git credential store conflicting configuration leads to unexpected behavior

Thank you! I did miss it. I appreciate your time.

-- Gennady Uraltsev <gennady.uraltsev@gmail.com> (https://guraltsev.github.io)

On Tue, Dec 6, 2022 at 8:15 PM brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 25 quoted lines
>
> On 2022-12-06 at 23:53:05, Gennady Uraltsev wrote:
> > Thank you!
> >
> > This makes sense and the solution is simple. Is this somewhere in the
> > documentation (honest question, I am not being a jerk)? I tried my
> > best to figure this out before bugging people on the mailinglist.
>
> Yes, but maybe not where you'd expect.  In gitcredentials(7), there's
> this text:
>
>   If there are multiple instances of the `credential.helper` configuration
>   variable, each helper will be tried in turn, and may provide a username,
>   password, or nothing. Once Git has acquired both a username and a
>   password, no more helpers will be tried.
>
>   If `credential.helper` is configured to the empty string, this resets
>   the helper list to empty (so you may override a helper set by a
>   lower-priority config file by configuring the empty-string helper,
>   followed by whatever set of helpers you would like).
>
> The `credential.helper` option mentions that manual page.
> --
> brian m. carlson (he/him or they/them)
> Toronto, Ontario, CA
Philip Oakley· Dec 7, 2022, 12:01 UTC · re: Gennady Uraltsev · lore

Re: Git credential store conflicting configuration leads to unexpected behavior

On 06/12/2022 23:53, Gennady Uraltsev wrote:
Show 5 quoted lines
> Thank you!
>
> This makes sense and the solution is simple. Is this somewhere in the
> documentation (honest question, I am not being a jerk)? I tried my
> best to figure this out before bugging people on the mailinglist.
I think it's all hidden in the docs, but isn't easy to tease out.

The 'override a multi-value config with a leading empty value" technique, I think, is covered in the general discussions about how config values are entered and parsed.

A useful question would be to ask, where did, or would, you look to hope to find this information? If we put the info in the right place, sufficient folks will read it.

Philip PS in-line posting preferred.  

Show 69 quoted lines
>
> Best,
>
> Gennady
>
> --
> Gennady Uraltsev
> <gennady.uraltsev@gmail.com>
> (https://guraltsev.github.io)
>
>
> On Tue, Dec 6, 2022 at 5:16 PM brian m. carlson
> <sandals@crustytoothpaste.net> wrote:
>> On 2022-12-06 at 22:05:22, Gennady Uraltsev wrote:
>>> Hello everyone,
>>>
>>> I have an issue with git credential-store. In my global configuration
>>> dir  (.config/git/config) I had the line
>>>
>>> [credential]
>>> helper = store
>>>
>>> while ini a repository's .git/config while I have
>>>
>>> [credential]
>>> helper = "store --file=./.git/git-credentials"
>>>
>>> to store credentials "locally".
>>>
>>> I thought the latter would overrule the former However what happens is
>>> the following:
>>>
>>> 1) On first run the file repo-local file ./.git/git-credentials gets
>>> created and the credentials are saved there after the user is queried
>>> for a password
>>> 2) On subsequent runs the credentials get recovered from
>>> ./.git/git-credentials and the user is NOT asked for credentials
>>> 2b) **Here is the weird behavior** git ALSO creates the
>>> .git-credentials file in the home directory and saves a copy of
>>> credentials there.
>>>
>>> The behavior 2b leads to exfiltration of passwords to a location a
>>> user might not expect.
>>>
>>> Workaround: Remove the line
>>>
>>> [credential]
>>> helper = store
>>>
>>> in the global config.
>>>
>>> It seems that the global config somehow does not get shadowed by the local one!
>> This behaviour is by design.  The reason is that sometimes the user may
>> have two sets of credential helpers, one for one set of domains, and
>> another for another.  For example, I believe AWS has its own custom
>> credential helper.  Git calls credential helpers until it finds a
>> credential, and then it sends store commands to all of them.  A
>> credential helper which has no credentials for a domain will generally
>> respond with no credentials.
>>
>> If you want to override the credential helpers in the `.git/config`
>> file, you can do so by first writing an empty value, like so:
>>
>> [credential]
>> helper =
>> helper = "store --file=./.git/git-credentials"
>> --
>> brian m. carlson (he/him or they/them)
>> Toronto, Ontario, CA

← back to recent threads