Skip to content

Auth in extraheader makes it difficult to override #162

@peter-evans

Description

@peter-evans

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 git extraheader 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 by actions/checkout and push using the token provided.

Initially the action was setting the token in the URL like this:

git push https://x-access-token:<token>@github.com/owner/my-repo.git

However, the Authorization header set by extraheader take precedence.

Next, I decided to try overriding the extraheader in local git config like this:

git -c "http.https://github.com/.extraheader=AUTHORIZATION: basic <basic_credential>" push

Initially, this seemed to work, but then I discovered that what was actually happening was instead of overriding the extraheader git adds two AUTHORIZATION headers. This actually makes sense and I was mistaken for thinking it would override the existing extraheader 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#4031

So the only option I was left with to override the auth was to unset the extraheader when the action starts, and restore the extraheader 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 by actions/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 of extraheader.

git config credential.https://github.com/.helper "! f() { echo username=x-access-token; echo password=$GITHUB_TOKEN; };f"

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions