Failed to push image to registry with error: build error: Failed to push image: unauthorized: authentication required

Solution In Progress - Updated -

Environment

OCP 3.x

Issue

Unable to push an image to the docker registry getting: "Failed to push image to registry with error: build error: Failed to push image: unauthorized: authentication required"

Resolution

There is a workaround to even start a new build (oc start-build ) or reorder the resource definitions to make sure ImageStream appears before BuildConfig object.

Root Cause

During the generation of the build object, OCP tries to resolve the output IST so it can decide what secret it needs to use with it. The resolution fails so OCP doesn't setup any push secret, but that does not (and should not) fail the creation of the build object.

A build object gets created with no push secret.

Then the build controller sees it and tries to process the build object. Part of processing the build object requires resolving the output IST. Since OCP can't do this (no IST yet), the build hangs in a retry state until the IST gets created.

Finally the IST gets created and the build proceeds, but the push secret was never set up.

This was reported in a github issue: https://github.com/openshift/origin/issues/4518#issuecomment-140460107.
It is now being tracked in a bug report: https://bugzilla.redhat.com/show_bug.cgi?id=1443163

Diagnostic Steps

Pushing images to the docker-registry doesn't work at first time getting a message similar to:

Pushing image 172.30.220.103:5000/bfqc8526/workshop:latest ...
error: build error: Failed to push image: unauthorized: authentication required

But a second build works.

BuildConfig object appears before ImageStream one within the resources definition

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments