nektos / act

Run your GitHub Actions locally 🚀
https://nektosact.com
MIT License
53.89k stars 1.34k forks source link

Unable to clonem Error: authentication required on repository actions #1343

Closed Alegrowin closed 1 year ago

Alegrowin commented 2 years ago

Bug report info

act version:            0.2.31
GOOS:                   linux
GOARCH:                 amd64
NumCPU:                 16
Docker host:            DOCKER_HOST environment variable is unset/empty.
Sockets found:
        /var/run/docker.sock
Config files:           
        /home/vscode/.actrc:
                -P ubuntu-latest=catthehacker/ubuntu:act-latest
                -P ubuntu-22.04=catthehacker/ubuntu:act-22.04
                -P ubuntu-20.04=catthehacker/ubuntu:act-20.04
                -P ubuntu-18.04=catthehacker/ubuntu:act-18.04
Build info:
        Go version:            go1.18.5
        Module path:           github.com/nektos/act
        Main version:          (devel)
        Main path:             github.com/nektos/act
        Main checksum:         
        Build settings:
                -compiler:            gc
                -ldflags:             -s -w -X main.version=0.2.31 -X main.commit=a20b1d4669d8d032fe35347bd3cfdae58b4d1d97 -X main.date=2022-09-01T02:56:14Z -X main.builtBy=goreleaser
                CGO_ENABLED:          0
                GOARCH:               amd64
                GOOS:                 linux
                GOAMD64:              v1
                vcs:                  git
                vcs.revision:         a20b1d4669d8d032fe35347bd3cfdae58b4d1d97
                vcs.time:             2022-08-31T18:41:56Z
                vcs.modified:         false
Docker Engine:
        Engine version:        20.10.18
        Engine runtime:        runc
        Cgroup version:        2
        Cgroup driver:         systemd
        Storage driver:        overlay2
        Registry URI:          https://index.docker.io/v1/
        OS:                    Pop!_OS 22.04 LTS
        OS type:               linux
        OS version:            22.04
        OS arch:               x86_64
        OS kernel:             5.19.0-76051900-generic
        OS CPU:                16
        OS memory:             31805 MB
        Security options:
                name=apparmor
                name=seccomp,profile=default
                name=cgroupns

Command used with act

act pull_request
act pull_request -s GITHUB_TOKEN

Describe issue

I just updated my local act version with the latest version.

When I run the act cli with a clean state, I keep getting authentication required.

act -s GITHUB_TOKEN pull_request -j lint
[MegaLinter/MegaLinter] 🚀  Start image=catthehacker/ubuntu:act-latest
[MegaLinter/MegaLinter]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=false
[MegaLinter/MegaLinter]   🐳  docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[MegaLinter/MegaLinter]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[MegaLinter/MegaLinter]   ☁  git clone 'https://github.com/oxsecurity/megalinter' # ref=v6
[MegaLinter/MegaLinter] 🏁  Job succeeded
Error: authentication required

I tried all the version until v0.2.21 and it started to work again. curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash -s v0.2.21

P.S. I'm running act inside a container inside vscode devcontainer with a mounted docker.sock on my host.

Link to GitHub repository

No response

Workflow content

---
# MegaLinter GitHub Action configuration file
# More info at https://oxsecurity.github.io/megalinter
name: MegaLinter

on:
  # Trigger mega-linter at every push. Action will also be visible from Pull Requests to main
  push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions)
  pull_request:
    branches: [master, main]

env: # Comment env block if you do not want to apply fixes
  # Apply linter fixes configuration
  APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool)
  APPLY_FIXES_EVENT: pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all)
  APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)

concurrency:
  group: ${{ github.ref }}-${{ github.workflow }}
  cancel-in-progress: true

jobs:
  build:
    name: MegaLinter
    runs-on: ubuntu-latest
    steps:
      # Git Checkout
      - name: Checkout Code
        uses: actions/checkout@v3
        with:
          token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
          fetch-depth: 0 # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to improve performances

      # MegaLinter
      - name: MegaLinter
        id: ml
        # You can override MegaLinter flavor used to have faster performances
        # More info at https://oxsecurity.github.io/megalinter/flavors/
        uses: oxsecurity/megalinter@v6
        env:
          # All available variables are described in documentation
          # https://oxsecurity.github.io/megalinter/configuration/
          VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
          # DISABLE: COPYPASTE,SPELL # Uncomment to disable copy-paste and spell checks

      # Upload MegaLinter artifacts
      - name: Archive production artifacts
        if: ${{ success() }} || ${{ failure() }}
        uses: actions/upload-artifact@v2
        with:
          name: MegaLinter reports
          path: |
            megalinter-reports
            mega-linter.log

      # Create pull request if applicable (for now works only on PR from same repository, not from forks)
      - name: Create Pull Request with applied fixes
        id: cpr
        if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
        uses: peter-evans/create-pull-request@v4
        with:
          token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
          commit-message: "[MegaLinter] Apply linters automatic fixes"
          title: "[MegaLinter] Apply linters automatic fixes"
          labels: bot
      - name: Create PR output
        if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
        run: |
          echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
          echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"

      # Push new commit if applicable (for now works only on PR from same repository, not from forks)
      - name: Prepare commit
        if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
        run: sudo chown -Rc $UID .git/
      - name: Commit and push applied linter fixes
        if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
          commit_message: "[MegaLinter] Apply linters fixes"

Relevant log output

[MegaLinter/MegaLinter ] Unable to clone https://github.com/oxsecurity/megalinter refs/heads/v6: authentication required
[MegaLinter/MegaLinter ] 🏁  Job succeeded
[Pulumi-Preview/Preview] Unable to clone https://github.com/actions/setup-python refs/heads/v2: authentication required
[Pulumi-Preview/Preview] 🏁  Job succeeded
Error: authentication required

Additional information

No response

emptyflask commented 1 year ago

Same here, using act v0.2.31 and a known good github token (which is also present in the current env, but figured I'd explicitly pass it into act as well):

act -v -j Test -s GITHUB_TOKEN=$(pass api.github.com | head -1) -W ./.github/workflows/rubyonrails.yml --env-file .env.test
...
Ruby on Rails CI/Test]   ☁  git clone 'https://github.com/ruby/setup-ruby' # ref=v1
[Ruby on Rails CI/Test] [DEBUG]   cloning https://github.com/ruby/setup-ruby to /home/jon/.cache/act/ruby-setup-ruby@v1
[Ruby on Rails CI/Test] Unable to clone https://github.com/ruby/setup-ruby refs/heads/v1: authentication required
[Ruby on Rails CI/Test] [DEBUG] skipping post step for 'Install Ruby and gems'; step was not executed
[Ruby on Rails CI/Test] [DEBUG] skipping post step for 'Checkout code'; step was not executed
ValeHaas commented 1 year ago

I just ran into this issue as well (on Windows) and I could solve it by logging out of Docker Desktop, as hinted on by https://github.com/nektos/act/issues/1166#issuecomment-1133637204

github-actions[bot] commented 1 year ago

Issue is stale and will be closed in 14 days unless there is new activity

elvinristi commented 1 year ago

I got this same error when I had incorrect GITHUB_TOKEN value. Generating new one which started with ghp_ and assigning this fixed Error: authentication required

melMass commented 1 year ago

I know it's an old issue, but it has high hits on google. I had this issue when using the scoop install with act -s GITHUB_TOKEN="$(gh auth token)" but just uninstalled the scoop package and used the gh extension gh extension install https://github.com/nektos/gh-act, auth is done properly without explicitly passing the token now

V0lantis commented 10 months ago

Didn't work for me 😢

gh act \
  --github-instance "github.mpi-internal.com" \
  -s GITHUB_TOKEN="$(gh auth token)"

resulted in

[build/publish_image]   ☁  git clone 'https://github.xxx.com/actions/setup-python' # ref=v4
[build/publish_image] Cleaning up container for job publish_image
[build/publish_image] 🏁  Job succeeded
Error: authentication required
soubhik-c commented 8 months ago

I'm getting the same error with v0.2.31 and new ghp_ GITHUB_TOKEN

bonzofenix commented 7 months ago

Same error here !

smagret commented 5 months ago

Same here with v0.2.60: gh act -j install_in_docker -s GITHUB_TOKEN="$(gh auth token)"

name: TEST!!

on:
  workflow_dispatch

jobs:
  install_in_docker:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '7.4'

Resulted in

[TEST!!/install_in_docker] 🚀  Start image=catthehacker/ubuntu:act-latest
time="2024-04-09T15:25:43+02:00" level=info msg="Parallel tasks (0) below minimum, setting to 1"
[TEST!!/install_in_docker]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=true
time="2024-04-09T15:25:44+02:00" level=info msg="Parallel tasks (0) below minimum, setting to 1"
[TEST!!/install_in_docker]   🐳  docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[TEST!!/install_in_docker]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[TEST!!/install_in_docker]   ☁  git clone 'https://github.com/shivammathur/setup-php' # ref=v2
[TEST!!/install_in_docker] Unable to clone https://github.com/shivammathur/setup-php refs/heads/v2: authentication required
[TEST!!/install_in_docker] Cleaning up container for job install_in_docker
[TEST!!/install_in_docker] 🏁  Job succeeded
Error: authentication required

Solved

Okay!! While writing this I found that the problem is the -s GITHUB_TOKEN="$(gh auth token)", I ran the same command without setting the token and worked (gh act -j install_in_docker)

jgf5013 commented 4 months ago

Okay!! While writing this I found that the problem is the -s GITHUB_TOKEN="$(gh auth token)", I ran the same command without setting the token and worked (gh act -j install_in_docker)

Well that's weird... I ran into the same issue and reran my command without the -s flag and now back to working

mrclrchtr commented 3 weeks ago

I can't get it work... neither with gh act nor with act and -s GITHUB_TOKEN="$(gh auth token)".

it's only working, when I put the token manually with -s GITHUB_TOKEN=mytoken.

Kixunil commented 3 days ago

Why would it even need the token? The repository is public anyway. I had a type and wrote action/checkout instead of actions/checkout.