You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
accessing ImageStream from private repository with auth delegated to a different server requires creating two secrets instead of one #9584
I want to declare an ImageStream that tracks an external docker image located on an authenticated docker registry.
My use-case is:
build docker images for our internal applications as part of our CI pipeline
have the CI pipeline push the docker image to external registry (eg. gitlab) on success
track the docker images from many OpenShift environments (using ImageStreams)
redeploy all relevant applications in OpenShift when their docker image has been updated (using image change triggers)
So far, I have found no way to declare an ImageStream which uses a secret to pull the image.
I have found 2 workarounds:
either use S2I source builds (then what we deploy wont be the docker image build in CI)
either use an inline dockerfile (eg. FROM registry.internal.mycompany.com/myapp) but then how do I trigger a new build since ImageStream still cannot follow the source image).
I have also tried without success to run docker login on the Openshift hosts, in the hope that the image puller would run as same user and implicitly use my dockercfg but no success.
Version
$ oc version
oc v1.2.0
kubernetes v1.2.0-36-g4a3f9c5
Steps To Reproduce
Run the following commands (after adjusting docker image source to point to an authenticated docker registry).
$ cat <<EOF | tee is.yamlapiVersion: v1kind: ImageStreammetadata: name: myappspec: tags: - from: kind: DockerImage name: registry.internal.company.com/projects/myapp:latest name: latestEOF
$ oc create -f is.yaml
imagestream "myapp" created
$ oc get is
NAME DOCKER REPO TAGS UPDATED
myapp 10.10.166.188:5000/gio/myapp latest
$ oc import-image myapp
The import completed successfully.
Name: myapp
Created: 14 seconds ago
Labels: <none>
Annotations: openshift.io/image.dockerRepositoryCheck=2016-06-27T14:15:06Z
Docker Pull Spec: 10.10.166.188:5000/project/myapp
Tag Spec Created PullSpec Image
latest registry.internal.company.com/projects/myapp:latest 13 seconds ago import failed: Internal error occurred: Get https://registry.intern....
Current Result
Image fails to import because the image puller does not use any secret.
Expected Result
ImageStream should provide a way to specify a secret to use when pulling the image (with a mechanism similar to pullSecret in BuildConfig dockerStrategy).
Yes @soltysh , I know how to reference docker images on other registries in my pod definitions, however I would really like my pods to be automatically redeployed if their docker images are updated; to me this is the point of the ImageStream feature.
If there is another method, how to use use it with oc new-app --docker-image=some-external-registry/image?
Thanks @soltysh . I have created the secret, however I see no way with ImageStream object or with the oc import-image command to tell explicitly "use this secret when pulling the image".
Assuming I am in the 'project' project, here are my secrets:
$ oc secrets new-dockercfg registry-login --docker-server=registry.example.com \
--docker-username=someuser --docker-password=somepassword [email protected]
$ oc secrets add serviceaccount/default secrets/registry-login --for=pull
$ oc secrets add serviceaccount/builder secrets/registry-login
$ oc get secrets/registry-login
NAME TYPE DATA AGE
registry-login kubernetes.io/dockercfg 1 26s
I want to create the following image Stream:
$ cat <<EOF | tee is.yamlapiVersion: v1kind: ImageStreammetadata: name: myappspec: tags: - from: kind: DockerImage name: registry.internal.example.com/myapp:latest name: latestEOF
$ oc create -f is.yaml
$ oc get is
NAME DOCKER REPO TAGS UPDATED
myapp 10.10.87.191:5000/default/myapp latest
If I oc import-image the image, here is the error I get:
$ oc import-image myapp
oc describe is myapp
Name: myapp
Created: About a minute ago
Labels: <none>
Annotations: openshift.io/image.dockerRepositoryCheck=2016-06-29T12:56:33Z
Docker Pull Spec: 10.10.87.191:5000/default/myapp
Tag Spec Created PullSpec Image
latest registry.si.perfect-memory.com/core/exchange-manager:latest About a minute ago import failed: Internal error occurred: Get https://registry.si.per...
$ oc get is/myapp -o yaml
apiVersion: v1
kind: ImageStream
metadata:
annotations:
openshift.io/image.dockerRepositoryCheck: 2016-06-29T12:56:33Z
creationTimestamp: 2016-06-29T12:56:32Z
generation: 2
name: myapp
namespace: default
resourceVersion: "639"
selfLink: /oapi/v1/namespaces/default/imagestreams/myapp
uid: e75ff849-3df8-11e6-8434-080027c23ce5
spec:
tags:
- annotations: null
from:
kind: DockerImage
name: registry.internal.example.com/myapp:latest
generation: 2
importPolicy: {}
name: latest
status:
dockerImageRepository: 10.10.87.191:5000/default/myapp
tags:
- conditions:
- generation: 2
lastTransitionTime: 2016-06-29T12:56:33Z
message: 'Internal error occurred: Get https://registry.internal.example.com/myapp/manifests/latest: token auth attempt for registry: https://gitlab.example.com/jwt/auth?scope=repository%3Amyapp%3Apull&service=container_registry request failed with status: 403 Forbidden'
reason: InternalError
status: "False"
type: ImportSuccess
items: null
tag: latest
If the secret is to be associated with a specific serviceaccount so that all image stream pulls use that secret automatically, can it be documented somewhere?
Your use-case is different from what I've been testing/working on so far. Generally all this works like this: during importing image the importer will match against all secrets, in the same project the ImageStream is defined in, based on the hostname (see here). Having said that you start with changing the secret name so that it matches the registry uri, or rather auth endpoint uri in your case. If either won't help attach me log from import operation at level 8, I'll have a look, it might be that your use-case requires more work.
Sorry for not being clear, I need logs from openshift master, since the oc import-image just invokes the import on the server and the actual importing is being done on the master.
I get some verbose messages in journalctl -f -u origin-master when the master restarts, but no mew logs are visible when running the oc import-image command.
@miminar Mmmmh ok, where are these logs located ? I'm having quite a hard time to figure it out, looks like everything gets spread in daemon.log, is that possible ? And there is nothing in daemon.log related to import-image
@zonArt do you run the cluster containerized? If yes, you need to docker logs <name-your-master-container>. If you run the openshift-master as a service (using e.g. systemd), you will need:
oct 19 15:28:09 openshift origin-master[49915]: I1019 15:28:09.111972 49915 panics.go:76] PUT /api/v1/nodes/openshift.example.com/status: (8.546383ms) 200 [[openshift/v1.5.2+43a9be4 (linux/amd64) kubernetes/43a9be4] xxx.xx.xxx.xxx:37192]
oct 19 15:28:09 openshift origin-master[49915]: I1019 15:28:09.126211 49915 panics.go:76] GET /api/v1/nodes?resourceVersion=0: (1.260212ms) 200 [[openshift/v1.5.2+43a9be4 (linux/amd64) kubernetes/43a9be4] xxx.xx.xxx.xxx:37172]
oct 19 15:28:09 openshift origin-master[49915]: I1019 15:28:09.372724 49915 panics.go:76] GET /api: (2.46666ms) 200 [[oc/v1.3.0+52492b4 (linux/amd64) kubernetes/52492b4] xx.xx.xxx.xx:52931]
oct 19 15:28:09 openshift origin-master[49915]: I1019 15:28:09.378061 49915 panics.go:76] GET /apis: (2.888212ms) 200 [[oc/v1.3.0+52492b4 (linux/amd64) kubernetes/52492b4] xx.xx.xxx.xx:52931]
oct 19 15:28:09 openshift origin-master[49915]: I1019 15:28:09.392347 49915 panics.go:76] GET /oapi: (2.966155ms) 200 [[oc/v1.3.0 (linux/amd64) openshift/3ab7af3] xx.xx.xxx.xx:52931]
oct 19 15:28:09 openshift origin-master[49915]: I1019 15:28:09.400887 49915 panics.go:76] GET /api/v1/namespaces/default/services/docker-registry: (1.231769ms) 404 [[openshift/v1.5.2+43a9be4 (linux/amd64) kubernetes/43a9be4] xxx.xx.xxx.xxx:37172]
oct 19 15:28:09 openshift origin-master[49915]: I1019 15:28:09.402395 49915 panics.go:76] GET /api/v1/namespaces/default/services/docker-registry: (936.554µs) 404 [[openshift/v1.5.2+43a9be4 (linux/amd64) kubernetes/43a9be4] xxx.xx.xxx.xxx:37172]
oct 19 15:28:09 openshift origin-master[49915]: I1019 15:28:09.402904 49915 panics.go:76] GET /oapi/v1/namespaces/projectname/imagestreams/imagename: (8.08406ms) 200 [[oc/v1.3.0 (linux/amd64) openshift/3ab7af3] xx.xx.xxx.xx:52931]
oct 19 15:28:09 openshift origin-master[49915]: I1019 15:28:09.458501 49915 panics.go:76] GET /api/v1/namespaces/projectname/resourcequotas: (1.685423ms) 200 [[openshift/v1.5.2+43a9be4 (linux/amd64) kubernetes/43a9be4] xxx.xx.xxx.xxx:37172]
oct 19 15:28:09 openshift origin-master[49915]: I1019 15:28:09.482718 49915 panics.go:76] GET /api/v1/namespaces/projectname/secrets: (7.610672ms) 200 [[openshift/v1.5.2+43a9be4 (linux/amd64) kubernetes/43a9be4] xxx.xx.xxx.xxx:37172]
oct 19 15:28:09 openshift origin-master[49915]: I1019 15:28:09.483875 49915 panics.go:76] GET /oapi/v1/namespaces/projectname/imagestreams/imagename/secrets: (9.783863ms) 200 [[openshift/v1.5.1 (linux/amd64) openshift/7b451fc] xxx.xx.xxx.xxx:37172]
oct 19 15:28:10 openshift origin-master[49915]: I1019 15:28:10.519661 49915 panics.go:76] GET /api/v1/namespaces/default/services/docker-registry: (1.552176ms) 404 [[openshift/v1.5.2+43a9be4 (linux/amd64) kubernetes/43a9be4] xxx.xx.xxx.xxx:37172]
oct 19 15:28:10 openshift origin-master[49915]: I1019 15:28:10.522288 49915 panics.go:76] GET /api/v1/namespaces/default/services/docker-registry: (1.832307ms) 404 [[openshift/v1.5.2+43a9be4 (linux/amd64) kubernetes/43a9be4] xxx.xx.xxx.xxx:37172]
oct 19 15:28:10 openshift origin-master[49915]: I1019 15:28:10.523486 49915 trace.go:61] Trace "Create /oapi/v1/namespaces/projectname/imagestreamimports" (started 2017-10-19 15:28:09.417974961 +0200 CEST):
oct 19 15:28:10 openshift origin-master[49915]: [37.877215ms] [37.877215ms] About to convert to expected version
oct 19 15:28:10 openshift origin-master[49915]: [38.019256ms] [142.041µs] Conversion done
oct 19 15:28:10 openshift origin-master[49915]: [41.246518ms] [3.227262ms] About to store object in database
oct 19 15:28:10 openshift origin-master[49915]: [1.105178634s] [1.063932116s] Object stored in database
oct 19 15:28:10 openshift origin-master[49915]: [1.105189942s] [11.308µs] Self-link added
oct 19 15:28:10 openshift origin-master[49915]: "Create /oapi/v1/namespaces/projectname/imagestreamimports" [1.105465153s] [275.211µs] END
oct 19 15:28:10 openshift origin-master[49915]: I1019 15:28:10.523543 49915 panics.go:76] POST /oapi/v1/namespaces/projectname/imagestreamimports: (1.108359098s) 201 [[oc/v1.3.0 (linux/amd64) openshift/3ab7af3] xx.xx.xxx.xx:52931]
oct 19 15:28:10 openshift origin-master[49915]: I1019 15:28:10.538851 49915 panics.go:76] GET /api/v1/namespaces/default/services/docker-registry: (1.943446ms) 404 [[openshift/v1.5.2+43a9be4 (linux/amd64) kubernetes/43a9be4] xxx.xx.xxx.xxx:37172]
oct 19 15:28:10 openshift origin-master[49915]: I1019 15:28:10.541654 49915 panics.go:76] GET /api/v1/namespaces/default/services/docker-registry: (1.886461ms) 404 [[openshift/v1.5.2+43a9be4 (linux/amd64) kubernetes/43a9be4] xxx.xx.xxx.xxx:37172]
oct 19 15:28:10 openshift origin-master[49915]: I1019 15:28:10.542445 49915 panics.go:76] GET /oapi/v1/namespaces/projectname/imagestreams/imagename: (10.077725ms) 200 [[oc/v1.3.0 (linux/amd64) openshift/3ab7af3] xx.xx.xxx.xx:52931]
Still not sure to find any interesting info, except on the fact it tries to reach the inexistent internal registry (which doesn't really help by the way)
For the convenience of people finding this through a search engine, here is a condensed answer. Thank you to everyone above for the excellent guidance.
Suppose you want an ImageStream that references a secured external registry such as GitLab, and the auth for said registry is done through a different hostname e.g. gitlab.com rather than registry.gitlab.com. The following has been tested in OpenShift Online 4.2.
First we find out the exact URI of the auth server with:
Activity
soltysh commentedon Jun 29, 2016
@jperville have you checked our docs at https://docs.openshift.org/latest/dev_guide/managing_images.html#allowing-pods-to-reference-images-from-other-secured-registries I think that topic fits your use case. If not lemme know where you're having problems, I'll help.
jperville commentedon Jun 29, 2016
Yes @soltysh , I know how to reference docker images on other registries in my pod definitions, however I would really like my pods to be automatically redeployed if their docker images are updated; to me this is the point of the ImageStream feature.
If there is another method, how to use use it with
oc new-app --docker-image=some-external-registry/image?soltysh commentedon Jun 29, 2016
@jperville my bad, I wanted to point you to https://docs.openshift.org/latest/dev_guide/managing_images.html#private-registries apologies
jperville commentedon Jun 29, 2016
Thanks @soltysh . I have created the secret, however I see no way with ImageStream object or with the
oc import-imagecommand to tell explicitly "use this secret when pulling the image".Assuming I am in the 'project' project, here are my secrets:
I want to create the following image Stream:
If I
oc import-imagethe image, here is the error I get:Note that in the error above, the registry public endpoint is https://registry.internal.example.com which delegates authentication by redirecting to https://gitlab.example.com (a different domain name but still part of the same environment); that authentication fails with 403 .
From reading https://docs.openshift.org/latest/dev_guide/managing_images.html#private-registries I was expecting the secret to be automatically used to authenticate to the external registry, but it seems it is not used.
If the secret is to be associated with a specific serviceaccount so that all image stream pulls use that secret automatically, can it be documented somewhere?
soltysh commentedon Jun 29, 2016
Your use-case is different from what I've been testing/working on so far. Generally all this works like this: during importing image the importer will match against all secrets, in the same project the ImageStream is defined in, based on the hostname (see here). Having said that you start with changing the secret name so that it matches the registry uri, or rather auth endpoint uri in your case. If either won't help attach me log from import operation at level 8, I'll have a look, it might be that your use-case requires more work.
jperville commentedon Jun 29, 2016
I have tried again naming the secret after the registry name (eg. `oc get secrets/registry.internal.example.com) without success.
You will find below a trace of
oc import-image myappat level 8 below (with the real host and image names):soltysh commentedon Jun 29, 2016
Sorry for not being clear, I need logs from openshift master, since the
oc import-imagejust invokes the import on the server and the actual importing is being done on the master.jperville commentedon Jun 29, 2016
Have no special logs appear on the master after I run the
oc import-imagecommand.Here is how processes look on the master VM:
Notice the loglevel=8 on the master.
I get some verbose messages in
journalctl -f -u origin-masterwhen the master restarts, but no mew logs are visible when running theoc import-imagecommand.soltysh commentedon Jun 29, 2016
You should see the logs like this one in the log. Without them I won't be able to dig what's going on.
78 remaining items
bparees commentedon Oct 18, 2017
@miminar does image import do any useful logging that would show us if the secret is being used when we try to do the import?
@zonArt the buildconfig that successfully did the push is in the same project as the imagestream that can't import?
zonArt commentedon Oct 18, 2017
@bparees yes it is, having this BC:
makes the build success without any issue (thanks to the
pushSecretsection)miminar commentedon Oct 19, 2017
@zonArt you can try to run the import cmd with
--loglevel=5which may reveal some more info.zonArt commentedon Oct 19, 2017
Here is the info: (I see nothing really relevant though)
Even with loglevel 8:
miminar commentedon Oct 19, 2017
@zonArt I'm sorry, the log from the master service needs to be captured from the time of import with
--loglevel=5.zonArt commentedon Oct 19, 2017
@miminar Mmmmh ok, where are these logs located ? I'm having quite a hard time to figure it out, looks like everything gets spread in daemon.log, is that possible ? And there is nothing in daemon.log related to import-image
miminar commentedon Oct 19, 2017
@zonArt do you run the cluster containerized? If yes, you need to
docker logs <name-your-master-container>. If you run theopenshift-masteras a service (using e.g.systemd), you will need:zonArt commentedon Oct 19, 2017
@miminar thanks, here is the linked log output:
Still not sure to find any interesting info, except on the fact it tries to reach the inexistent internal registry (which doesn't really help by the way)
zonArt commentedon Nov 8, 2017
It case it may interest anybody: I found the solution in RedHat KB:
https://access.redhat.com/solutions/3019071
I never thought you needed to also specify the port in case it runs on 443. I therefore added a comment on the above mentioned article.
Thanks again for your support
zonArt commentedon Jan 31, 2018
@miminar
This is actually working, thanks
andutt commentedon May 28, 2019
@jperville jperville thanks for posting the solution! This works for me also (y)
nqbao commentedon Aug 1, 2019
Thanks @zonArt , this is the only solution that works for me!
3dbrows commentedon Jan 23, 2020
For the convenience of people finding this through a search engine, here is a condensed answer. Thank you to everyone above for the excellent guidance.
Suppose you want an ImageStream that references a secured external registry such as GitLab, and the auth for said registry is done through a different hostname e.g. gitlab.com rather than registry.gitlab.com. The following has been tested in OpenShift Online 4.2.
First we find out the exact URI of the auth server with:
We will therefore use
https://gitlab.com/jwt/authbelow.Create secret
Have a dockerconfig.json file with contents like:
Then do:
Important: It seems necessary to name it
regsecret. I haven't had success if the secret has any other name. If anyone can think why, please say.Set default service account to use this secret:
Verify:
Create the image stream
You should now have a working ImageStream.
gwagner commentedon May 25, 2021
confirmed that the solution from @3dbrows works for registry.digitalocean.com as well:
docker login -u API_KEY -p API_KEY registry.digitalocean.comgets you the value of XXX in ~/.docker/config.jsonThen modify ~/.docker/config.json to look like this:
Then run:
Setup your image stream as shown above, and it should work