checkout icon indicating copy to clipboard operation
checkout copied to clipboard

Error: fatal: could not read Username for 'https://github.com': terminal prompts disabled

Open jason-ausmus opened this issue 3 years ago • 45 comments

Hello,

I'm attempting a rollback flow using actions/checkout@v2. The problem is that I need to use a PAT in order to rollback commits that change Github Workflows and when I pass that PAT into actions/checkout, I get an error.

Error: fatal: could not read Username for 'https://github.com': terminal prompts disabled

My workflow:

name: "Dev Deploy"
on:
  workflow_run:
    workflows: ["Versioning"]
    types: [completed]
jobs:
  fail_job:
    runs-on: ubuntu-latest
    steps:
      - name: Fail
        run: |
          exit 1
  rollback-on-failure:
    runs-on: ubuntu-latest
    needs: [fail_job]
    if: always() && needs.fail_job.result == 'failure'
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          token: ${{ secrets.WORKFLOW_TOKEN }}
      - run: chmod +x environment/rollback.sh && ./environment/rollback.sh

The PAT used has the permissions to change workflows, as well as repository permissions. The issue seems to be that the action doesn't allow me to set a username before it tries to fetch the repository.

jason-ausmus avatar Dec 29 '21 22:12 jason-ausmus

I'm having similar issues. Did you ever find a fix @jason-ausmus?

My workflow:

name: Android Beta Prod Distribution

on:
  push:
    branches:
      - android-beta-prod-workflow

jobs:
  beta-distribution:
    runs-on: ubuntu-latest
    name: Beta Distribution
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - uses: actions/setup-node@master
    - uses: c-hive/gha-yarn-cache@v1

    - name: Clone repo
      uses: actions/checkout@v2
      with:
        repository: believrapp/api-env
        ref: main
        path: cloned-secrets
        token: $ {{ secrets.GH_TOKEN}}

adamevers avatar Jan 19 '22 11:01 adamevers

same issue here with a PAT

svc-instala avatar Jan 26 '22 09:01 svc-instala

@adamevers surprisingly it did start working for me when I added the repository to the with with statement. I can't really account for why that fixed it, but it's been running smoothly for me now since I did that.

jason-ausmus avatar Jan 26 '22 17:01 jason-ausmus

I'm also experiencing the same issue. I wanted to add a checkout of another private repo, that lives in the same organisation as the original private repo which the workflow is in.

My code:

     - name: Checkout the private repo in which the workflow lives
        uses: actions/checkout@v2
      - name: Checkout a public repo to see if it works
        uses: actions/[email protected]
        with:
          repository: actions/checkout
          ref: main
      - name: Checkout another private repo in the same organisation
      (and provide a PAT with repo, read:user and user:email permissions)
        uses: actions/[email protected]
        with:
          repository: org/private-repo
          ref: master
          token: $MY_PAT

Results: Checkout the private repo in which the workflow lives :heavy_check_mark: Checkout a public repo to see if it works :heavy_check_mark: Checkout another private repo in the same organisation :x:

The error: image

MikulasMascautanu avatar Feb 09 '22 13:02 MikulasMascautanu

@MikulasMascautanu Were you able to fix this issue ? If yes, please do share. thank you

ghost avatar Apr 13 '22 01:04 ghost

I stumbled into the same error message and found this issue. However in my case, the cause of the problem was that the token expired. :sweat_smile: Adding it here, in case it helps folks. The error message is very undescriptive.

dszakallas avatar Apr 30 '22 09:04 dszakallas

Another hint: The PAT must have an expiry date, otherwise the same error appears 😅.

MichaIng avatar Jun 10 '22 13:06 MichaIng

Has anyone found a solution to this issue? I have the same error and nothing seems to work

Ritalina avatar Jul 11 '22 17:07 Ritalina

Hi, sorry for my late response. I did NOT solve the issue, I used a different approach for my original task. Sorry:/

MikulasMascautanu avatar Jul 15 '22 13:07 MikulasMascautanu

You definitely use a PAT which has an expiry date and is not expired?

MichaIng avatar Jul 18 '22 06:07 MichaIng

Hi, sorry for my late response. I did NOT solve the issue, I used a different approach for my original task. Sorry:/

Thanks, I think the same, I will change my strategy. :)

Ritalina avatar Jul 18 '22 16:07 Ritalina

Another hint: The PAT must have an expiry date, otherwise the same error appears 😅.

@MichaIng Thanks for the tip! I wouldn't have figured that out on my own. :)

shrutiburman avatar Aug 01 '22 12:08 shrutiburman

@MichaIng Is the PAT something you generate yourself? Or is that the same access token we can reference with ${{secrets.GH_TOKEN}}

david-renner-dwg avatar Aug 02 '22 23:08 david-renner-dwg

@MichaIng Is the PAT something you generate yourself? Or is that the same access token we can reference with ${{secrets.GH_TOKEN}}

The "Personal Access Token" is what you need to create yourself in your account's developer settings. In my case, AFAIK, it was required for a workflow to checkout and push to a branch/PR created by dependabot, which didn't work with the default GitHub actions token.

MichaIng avatar Aug 06 '22 16:08 MichaIng

I needed to auto-create a release for my private golang repository, and came across this page in my investigations. Being new to github actions and workflows, I needed to resolve how to inject https://[email protected] instead of https://github.com gitconfig statement into my workflow setup. Found this blog post which exactly solved my issue. Posting here in case someone else needs a pointer

pcbuildpluscoding avatar Aug 18 '22 04:08 pcbuildpluscoding

Using a token that doesn't expire fixed this issue for me.

Could someone explain if there is some underlying reason why these tokens are rejected though?

If GitHub is going to reject tokens that don't expire then they shouldn't let you generate them in the first place.

ScottG489 avatar Sep 23 '22 19:09 ScottG489

@ScottG489 - have a look at this blog post. Seems there are 3 requirements for a valid token applied in actions.

  1. It belongs to the right user or organization account
  2. It has repository scope
  3. It is not expired

pcbuildpluscoding avatar Sep 23 '22 23:09 pcbuildpluscoding

I had somewhat the same issue.

I just removed the token.

 - name: Clone repo
      uses: actions/checkout@v2
      with:
        repository: believrapp/api-env
        ref: main
        path: cloned-secrets
        token: $ {{ secrets.GH_TOKEN}} <-- removed this line.

Hope it helps someone :)

ola-adolfsson-ipex avatar Oct 10 '22 14:10 ola-adolfsson-ipex

For a simple checkout indeed no PAT is required.

MichaIng avatar Oct 10 '22 15:10 MichaIng

my 2 cents: it would be great that github checkout action automatically detect this kind of error return to provide a tips on this: (example: please verify your token and expiration date.

I think in many case this is just "private" + "expired" or "wrong" PAT configuration?

boly38 avatar Jan 06 '23 20:01 boly38

@boly38 good idea. I was also very confused by the message, but ultimately I juts had the token not configured

papanito avatar Feb 20 '23 18:02 papanito

Should the requirement to have an expiration date in the PAT be documented here? https://github.com/marketplace/actions/checkout#usage

ghost avatar Mar 27 '23 13:03 ghost

I'm having the same problem as MikulasMascautanu, but I don't think there's anything wrong with my PAT. I'm only getting this error on one private repo in the entire organization. Every other repo in the same organization is completing its actions just fine, and they all use an identical CI yaml (the only difference being that this one specifies a working directory).

Is there some repo setting in Github that I might need to change?

pidgezero-one avatar Apr 13 '23 20:04 pidgezero-one

Personally I didn't have a PAT in my GitHub workflow and it worked fine till 2 weeks ago for simple checkout, so not sure what happened on GitHub side here.

ocervell avatar Apr 29 '23 12:04 ocervell

Looks like I found the root cause of this behavior. When the first actions/checkout@v2 performs without any options for current repository it caches github token in local git store and further the same token is used. I added flag "persist-credentials: false" to the first checkout step and further steps with github communications started work (ad-m/github-push-action or simple git push https://user:token@github/org/repo). Looks like git cli ignores incoming token if it is already stored in local storage.. At lest it helped me.. :-) p.s. username does not matter when token is used..

alexey-berdyugin avatar May 11 '23 05:05 alexey-berdyugin

@alexey-berdyugin Interesting! Could I please see an example of how you configured this? I saw this post which is making me scared to try it !

pidgezero-one avatar May 11 '23 14:05 pidgezero-one

In my case:

      - name: Checkout Application Repo
        uses: actions/checkout@v3
        with:
          path: app_repo
          persist-credentials: false
  # other steps
      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ steps.get_github_token.outputs.git_app_token }}
          directory: app_repo
          branch: ${{ github.ref }}
  # Or simple
      - name: Manual push
        run: |
          cd app_repo
          git config --local user.email "[email protected]"
          git config --local user.name "github-actions"
          git diff-index --quiet HEAD || git commit -a -m "Test"
          gut push https://<any-user_or_app-id>:<token>@github.com/user_or_org/repo.git

alexey-berdyugin avatar May 11 '23 18:05 alexey-berdyugin

It started working again for me after some time. Probably a misconfig and the cache got erased after a while.

ocervell avatar May 13 '23 08:05 ocervell

Works for me with actions/checkout@v2, but with actions/checkout@v3 shows error from the topic

willinDrive avatar Jul 10 '23 10:07 willinDrive

I had the same error on multiple repositories. Tried checkout@v3 and v4, but result was the same. For me, replacing the Action secret in each repository with a new Personal Access Token (with expiration) solved it.

ddsharpe avatar Sep 12 '23 15:09 ddsharpe