-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auth in extraheader makes it difficult to override #162
Comments
i believe you can override the extra header with a more specific url. Either |
@ericsciple Thanks for your reply. I didn't think of trying a more specific URL so I did some further testing. What I've discovered is that git and git-lfs clients have different ways of handling multiple First I tried setting a more specific URL as follows.
The git client still adds two I then read the git documentation a bit closer and it suggests you can reset the list of
https://git-scm.com/docs/git-config#Documentation/git-config.txt-httpextraHeader So I tried to reset the
As the documentation suggested, the In summary:
So in order to satisfy the way that both clients work, it seems I need to clear the list with an empty value for git, and then pass an This works as a method to override the local config for both git and git-lfs clients. Only one
Although it feels a bit awkward, I think this is a better solution than unsetting and restoring the local git config. cc: @bk2204 |
I think a custom credential helper is the right tool here. The extraheader code is designed to deal with things like cookies and Azure DevOps's insistence on using Bearer instead of Basic authentication for OAuth tokens. It's not designed to supplant Git's native authentication handling. Using a custom credential helper also makes it really easy to override: with the example I proposed, you simply change the value of I plan to patch Git to support Bearer tokens in the future, at which point there really won't be any reason to use extraheader for authentication in the future. |
Intentionally not using cred helper due to issues dealt with in the past, apple git caching and not calling the cred helper every time. The built-in token is generated per job. For self hosted runner, every job should use the new token sent down with that job. |
Hello, would you consider using GIT_ASKPASS, or the config equivalent? |
Description
Since
v2
auth is being persisted in git config, which is great, and makes it much easier to perform git commands. However, persisting the auth in a gitextraheader
config option makes it difficult to override. My particular use case is an action I maintain that creates pull requests for changes made during the workflow. The relevant part of which is that the action accepts a token passed to it and uses it to push to a branch. That token may, or may not, be the same token that was used to checkout the repository. Due to this, I must override whatever auth has been set byactions/checkout
and push using the token provided.Initially the action was setting the token in the URL like this:
However, the
Authorization
header set byextraheader
take precedence.Next, I decided to try overriding the
extraheader
in local git config like this:Initially, this seemed to work, but then I discovered that what was actually happening was instead of overriding the
extraheader
git adds twoAUTHORIZATION
headers. This actually makes sense and I was mistaken for thinking it would override the existingextraheader
config option. What is interesting about this is that the main Git service accepts these requests, but git-lfs does not. You can read the discussion I had about this at the git-lfs repository here: git-lfs/git-lfs#4031So the only option I was left with to override the auth was to unset the
extraheader
when the action starts, and restore theextraheader
in local config when the action completes. It feels kind of "hacky" and I don't like that I need to mess with config set byactions/checkout
.Possible solution
During the discussion at the git-lfs repository, @bk2204 suggested that this could be solved with a credential helper.
So I tested, assuming that
actions/checkout
set auth in a custom credential helper instead ofextraheader
.This then allows subsequent git calls to override the auth either by setting the token in the URL, or setting an extraheader with the
git -c
option. Both of these methods take precedence and it only falls back to the credential helper when auth hasn't been explicitly set.I'm sure changing the auth mechanism is the last thing you want to do, but I wondered what are your thoughts about this and whether you think it's worth considering switching to a credential helper for the next major version bump.
The text was updated successfully, but these errors were encountered: