github-actions

Authentication fails after forking repository


I have a github action which performs a push to github packages

dotnet nuget push nuget\*.nupkg -k ${{secrets.GITHUB_TOKEN}} --source https://nuget.pkg.github.com/<organisation>/index.json --skip-duplicate

but is getting a 403

warn : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.
  Forbidden https://nuget.pkg.github.com/fire-testing-technology/ 171ms
error: Response status code does not indicate success: 403 (Forbidden).

The permissions are set at the beginning of the workflow

name: Build
on:
  push:
    branches: [ "*" ]
permissions: write-all
jobs:

This is occurring in a fork of a repo ( within the same organisation). I can't find any info on why the permissions for a fork would be different, nor how to change them. The original repo does not get the error.


Solution

  • A forked repository, by default, will always get a read-only token, even if you request a write token.

    You'll need to rely on a GitHub App Token or a Personal Access Token to work around this security feature.