Skip to content

Backstage API: 401 AuthenticationError “Missing credentials”

Kubernetestested on Backstage 1.55.0 (create-app 0.9.2)

Since the new backend system, Backstage protects every backend API. Anyone accessing the catalog with curl or a script needs a token – otherwise you get 401 with Missing credentials, and with an unknown token Illegal token.

Symptom

curl -s -o /dev/null -w '%{http_code}\n' "$BACKSTAGE/api/catalog/entities"
curl -s "$BACKSTAGE/api/catalog/entities" | jq -c '.error | {name, message}'
curl -s -H 'Authorization: Bearer falsch' "$BACKSTAGE/api/catalog/entities" \
  | jq -r .error.message
401
{"name":"AuthenticationError","message":"Missing credentials"}
Illegal token

Without a token 401, with a wrong token Illegal token.

Diagnosis

In the course the configuration allows a fixed lab token with the subject lab-cli.

externalAccess:
      - type: static
        options:
          token: ${BACKSTAGE_TOKEN}
          subject: lab-cli

Causes

kein TokenThe backend API always requires a token

The backend only accepts user tokens from sign-in, service tokens of other plugins and the configured externalAccess tokens. Without an Authorization header you get 401 Missing credentials.

Illegal tokenWrong or unconfigured token

A token that none of these sources knows is rejected by the backend with Illegal token.

Fix

Configure a static token with its own subject under backend.auth.externalAccess and send it as Authorization: Bearer (in the course via the shell function bs).
source ~/backstage-lab/setup/env.sh
bs catalog/entities | jq -r '.[] | "\(.kind)\t\(.metadata.name)"' | sort

Don't: Turning off backend authentication so scripts work. Then anyone on the network can read and change the catalog.

▶
Break it yourself and find it – free
Backstage hands-on, day 0: the lab with create-app, Forgejo, configuration and a first look at the catalog API.
Go to day 0 →

FAQ

Which tokens does the backend accept?

User tokens from sign-in, service tokens of other plugins and the configured externalAccess tokens.

Why a dedicated subject?

So audit logs and permission rules recognise the caller, in the course lab-cli.

Related error patterns

More