Dependabot broke after switching to a public npm feed

We switched a repository to the public, secure package feed for npm. Builds were happy. Dependabot was not. Every run ended with the same error.

Dependabot broke after switching to a public npm feed

The problem

We switched a repository to the public, secure package feed for npm. Builds were happy. Dependabot was not. Every run ended with the same error:

GET https://<feed proxy>/npm/qs
* egress not allowlisted <feed proxy>
403 ...
private_source_authentication_failure

Dependabot runs in a locked-down proxy. It only talks to hosts it has been explicitly told about, and a registry configured in .npmrc is not enough. Anything else is blocked with a 403, even if the feed is public.

The solution

Declare the feed as a registry in .github/dependabot.yml and reference it from every npm update entry:

version: 2
registries:
  public-feed:
    type: npm-registry
    url: https://<feed proxy>/npm/
    token: ${{ secrets.NPM_FEED_TOKEN }}
    replaces-base: true
updates:
  - package-ecosystem: "npm"
    directory: "/"
    registries:
      - public-feed
    schedule:
      interval: "weekly"

Gotcha 1: a public feed still needs a credential

My first attempt, without a token, failed validation: "The property '#/registries/...' of type object did not match one or more of the required schemas". The npm-registry type requires a token, username/password or OIDC, even when the feed needs no authentication. A placeholder value satisfies the schema.

Gotcha 2: tokens belong in Dependabot secrets

The token should come from a secret, and it has to be a Dependabot secret, not an Actions secret. No permission to add one in the Settings UI?

Depending on your permissions the UI may not be showing the Dependabot Secrets and Variables section.

Given that Actions secrets can often be set using the API or CLI, even when the UI is missing, I hazarded a guess and asked Copilot to try and set the value for me, which succeeded:

As expected the API did allow me to set the value anyway.

For your convenience:

echo "placeholder" | gh secret set NPM_FEED_TOKEN --app dependabot --repo <owner>/<repo>

Take-aways

  • Switching package feeds means updating Dependabot too, not just .npmrc.
  • Dependabot's egress allowlist is driven by the registries block.
  • npm-registry entries require a credential, even for public feeds.
  • Use a Dependabot secret, not an Actions secret.