Skip to content
Latchkey

Kaniko "error pushing image ... UNAUTHORIZED" (missing config.json) in CI

Kaniko built the image but the registry rejected the push with UNAUTHORIZED. Kaniko reads credentials from /kaniko/.docker/config.json; if that file is absent or has no auth entry for the destination registry, the push is anonymous and denied.

What this error means

Kaniko finishes building, then fails with "error pushing image: failed to push to destination registry.example.com/app:latest: UNAUTHORIZED: authentication required".

kaniko
error pushing image: failed to push to destination registry.example.com/app:latest:
UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:app Type:repository]]

Common causes

No /kaniko/.docker/config.json with the registry auth

Kaniko does not run a docker login; it reads a Docker config file. If that file is missing or lacks an auths entry for the destination host, the push has no credentials.

The credential is for a different registry host

The auths key must exactly match the destination registry hostname. A mismatch (for example docker.io versus registry.example.com) means no credential applies.

How to fix it

Write a config.json with a base64 auth entry

  1. Base64-encode user:token for the destination registry.
  2. Write it to /kaniko/.docker/config.json before running the executor.
  3. Confirm the auths key matches the destination hostname exactly.
Terminal
mkdir -p /kaniko/.docker
echo "{\"auths\":{\"registry.example.com\":{\"auth\":\"$(printf '%s' "$CI_USER:$CI_TOKEN" | base64 -w0)\"}}}" \
  > /kaniko/.docker/config.json

For GitLab, use the built-in CI credentials

GitLab CI exposes $CI_REGISTRY, $CI_REGISTRY_USER, and $CI_REGISTRY_PASSWORD; write them into the Kaniko config.

.gitlab-ci.yml
echo "{\"auths\":{\"${CI_REGISTRY}\":{\"auth\":\"$(printf '%s' "${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}" | base64 | tr -d '\n')\"}}}" \
  > /kaniko/.docker/config.json

How to prevent it

  • Provision /kaniko/.docker/config.json in every Kaniko job before the executor runs.
  • Match the auths hostname to the exact --destination registry.
  • Store the registry token as a masked CI variable, never in the image.

Frequently asked questions

What causes ""error pushing image ... UNAUTHORIZED""?
Kaniko does not run a docker login; it reads a Docker config file. If that file is missing or lacks an auths entry for the destination host, the push has no credentials.
How do I fix "error pushing image ... UNAUTHORIZED"?
Write a config.json with a base64 auth entry

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card