GitHub Actions with hub results in Unauthorized (HTTP 401) Bad credentials

finefoot

The following exemplary workflow runs without issues:

on: [push]

jobs:
  create_release:
    runs-on: ubuntu-latest
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Create release
        run: hub release create -m "$(date)" "v$(date +%s)"

However, some of my CI/CD code needs to run in a container:

on: [push]

jobs:
  create_release:
    runs-on: ubuntu-latest
    container:
      image: ubuntu:latest
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - name: Install dependencies
        run: apt update && apt install -y git hub
      - name: Checkout
        uses: actions/checkout@v2
      - name: Create release
        run: hub release create -m "$(date)" "v$(date +%s)"

Now, hub suddenly doesn't work anymore:

Run hub release create -m "$(date)" "v$(date +%s)"
  hub release create -m "$(date)" "v$(date +%s)"
  shell: sh -e {0}
  env:
    GITHUB_TOKEN: ***
Error creating release: Unauthorized (HTTP 401)
Bad credentials
Error: Process completed with exit code 1.
finefoot

The issue was actually with mismatching versions: hub on native ubuntu-latest GitHub Actions was the (as of now) most recent version 2.14.2 while apt install on the ubuntu:latest container installed only version 2.7.0 (from Dec 28, 2018!).

The solution is to install the latest hub binary directly from their GitHub releases page instead of using apt:

on: [push]
 
jobs:
  create_release:
    runs-on: ubuntu-latest
    container:
      image: ubuntu:latest
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - name: Install dependencies
        run: |
          apt update && apt install -y git wget
          url="$(wget -qO- https://api.github.com/repos/github/hub/releases/latest | tr '"' '\n' | grep '.*/download/.*/hub-linux-amd64-.*.tgz')"
          wget -qO- "$url" | tar -xzvf- -C /usr/bin --strip-components=2 --wildcards "*/bin/hub"
      - name: Checkout
        uses: actions/checkout@v2
      - name: Create release
        run: hub release create -m "$(date)" "v$(date +%s)"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Http failure response for http url: 401 Unauthorized

SpringSecurity gives error 401 Bad Credentials

403 Forbidden vs 401 Unauthorized HTTP responses

Github actions, 401 unauthorized when installing a Github Package with npm or yarn

Sending Push Through Parse API Results in 401 Unauthorized

Android NTLM getting HTTP/1.1 401 Unauthorized

Installation failed: Bad credentials (401) travis ci with R

Django Rest Framework: HTTP 401 Unauthorized error

401 unauthorized github api

HTTP response '401: Unauthorized' using NTLM with Wildfly

WatsonApiException: Error: Unauthorized: Access is denied due to invalid credentials , Code: 401

Calling customer service results in 401 Unauthorized

How AWS Credentials works at GitHub Actions?

Laravel Socialite Github OAuth Response 401 Bad Credentials

Personal Access Token returns 401 with ‘bad credentials’

401 Unauthorized access for Github API using HttpBuilder (Groovy)

Solr HTTP error: Unauthorized (401)

Bad Credentials for Github API

Apache HttpClient DigestAuth - 401, Unauthorized. But Credentials are okay

401 - Unauthorized: Access is denied due to invalid credentials. For windows authentication

Removing "issuer" from JWT results in 401 Unauthorized

Laravel API Authentication using Passport results in 401 (Unauthorized)

Unauthorized (HTTP 401) R omdbapi

GitHub API 401 Bad Credentials in Node but not curl

Rails & Github Actions - Credentials

GitHub Actions: CodeQL Analysis results

GitHub Actions: Error 401 Unauthorized in JIB maven plugin

Getting 401 Unauthorized error while requasting GitHub API

Unauthorized 401 (Missing credentials) using Passport JWT in NestJS