# Preserving credentials on authentication failures

2 messages from 2022-09-20 to 2022-09-21. Participants: Jan Tosovsky, brian m. carlson.
Thread: https://gitlist.dev/t/58471

## Jan Tosovsky, 2022-09-20 07:59

Subject: Preserving credentials on authentication failures
Message-ID: <007401d8ccc6$ef8ebe50$ceac3af0$@email.cz>
URL: https://gitlist.dev/e/007401d8ccc6%24ef8ebe50%24ceac3af0%24%40email.cz

```
On my local Windows machine I maintain a credential store in the form of a
text file. But from time to time one of the entries disappears. I run
regularly some background jobs, cloning some stuff, and I suspect this
happens when the external authentication service is down temporarily. When
it is later resumed, I can't clone the repo anymore because of that deleted
entry.

Is there any option to keep entries on authentication failures? Or is this
simply a bug? Or is there another reason why this happens?

Git 2.35.1.windows.2

Thanks, Jan


```

## brian m. carlson, 2022-09-21 21:13

Subject: Re: Preserving credentials on authentication failures
Message-ID: <Yyt+bAllVYJ9+SXa@tapette.crustytoothpaste.net>
URL: https://gitlist.dev/e/Yyt%2BbAllVYJ9%2BSXa%40tapette.crustytoothpaste.net
In-Reply-To: <007401d8ccc6$ef8ebe50$ceac3af0$@email.cz>

```
On 2022-09-20 at 07:59:38, Jan Tosovsky wrote:
> On my local Windows machine I maintain a credential store in the form of a
> text file. But from time to time one of the entries disappears. I run
> regularly some background jobs, cloning some stuff, and I suspect this
> happens when the external authentication service is down temporarily. When
> it is later resumed, I can't clone the repo anymore because of that deleted
> entry.
> 
> Is there any option to keep entries on authentication failures? Or is this
> simply a bug? Or is there another reason why this happens?

If you have a credential helper and the credentials retrieved from it
cause the server to send a 401, then Git will erase the credentials and
ask for new ones.  If your auth service is down, then the best thing for
your Git server to do is return a 503 if service cannot be maintained.
If it returns a 401 (which is not correct according to the RFC), then
Git will clear the credentials.

Git doesn't provide an option to preserve entries on authentication
failure, but you could write a simple shell script that wraps your
normal credential helper and ignores the "erase" command and use that
instead in `credential.helper`.
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA

```
