origin icon indicating copy to clipboard operation
origin copied to clipboard

accessing ImageStream from private repository with auth delegated to a different server requires creating two secrets instead of one

Open jperville opened this issue 10 years ago • 91 comments

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.yaml
apiVersion: v1
kind: ImageStream
metadata:
  name: myapp
spec:
  tags:
  - from:
      kind: DockerImage
      name: registry.internal.company.com/projects/myapp:latest
    name: latest
EOF
$ 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).

jperville avatar Jun 27 '16 14:06 jperville

@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.

soltysh avatar Jun 29 '16 11:06 soltysh

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?

jperville avatar Jun 29 '16 11:06 jperville

@jperville my bad, I wanted to point you to https://docs.openshift.org/latest/dev_guide/managing_images.html#private-registries apologies

soltysh avatar Jun 29 '16 11:06 soltysh

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.yaml
apiVersion: v1
kind: ImageStream
metadata:
  name: myapp
spec:
  tags:
  - from:
      kind: DockerImage
      name: registry.internal.example.com/myapp:latest
    name: latest
EOF
$ 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

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?

jperville avatar Jun 29 '16 13:06 jperville

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.

soltysh avatar Jun 29 '16 13:06 soltysh

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 myapp at level 8 below (with the real host and image names):

I0629 13:43:47.224945   29105 loader.go:242] Config loaded from file /root/.kube/config
I0629 13:43:47.227135   29105 round_trippers.go:264] GET https://192.168.56.220:8443/api
I0629 13:43:47.227148   29105 round_trippers.go:271] Request Headers:
I0629 13:43:47.227152   29105 round_trippers.go:274]     Accept: application/json, */*
I0629 13:43:47.227156   29105 round_trippers.go:274]     User-Agent: oc/v1.2.0 (linux/amd64) kubernetes/b12cbb6
I0629 13:43:47.227160   29105 round_trippers.go:274]     Authorization: Bearer 5x00cpdmr9mbsO1OuoZbyQJzc9BCN5Mi2SNzW86zQss
I0629 13:43:47.279596   29105 round_trippers.go:289] Response Status: 200 OK in 52 milliseconds
I0629 13:43:47.279620   29105 round_trippers.go:292] Response Headers:
I0629 13:43:47.279626   29105 round_trippers.go:295]     Cache-Control: no-store
I0629 13:43:47.279630   29105 round_trippers.go:295]     Content-Type: application/json
I0629 13:43:47.279634   29105 round_trippers.go:295]     Date: Wed, 29 Jun 2016 13:43:47 GMT
I0629 13:43:47.279638   29105 round_trippers.go:295]     Content-Length: 136
I0629 13:43:47.279681   29105 request.go:870] Response Body: {"kind":"APIVersions","versions":["v1"],"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"192.168.56.220:443"}]}
I0629 13:43:47.279909   29105 round_trippers.go:264] GET https://192.168.56.220:8443/apis
I0629 13:43:47.279918   29105 round_trippers.go:271] Request Headers:
I0629 13:43:47.279921   29105 round_trippers.go:274]     Accept: application/json, */*
I0629 13:43:47.279925   29105 round_trippers.go:274]     User-Agent: oc/v1.2.0 (linux/amd64) kubernetes/b12cbb6
I0629 13:43:47.279929   29105 round_trippers.go:274]     Authorization: Bearer 5x00cpdmr9mbsO1OuoZbyQJzc9BCN5Mi2SNzW86zQss
I0629 13:43:47.282089   29105 round_trippers.go:289] Response Status: 200 OK in 2 milliseconds
I0629 13:43:47.282111   29105 round_trippers.go:292] Response Headers:
I0629 13:43:47.282116   29105 round_trippers.go:295]     Content-Length: 778
I0629 13:43:47.282120   29105 round_trippers.go:295]     Cache-Control: no-store
I0629 13:43:47.282124   29105 round_trippers.go:295]     Content-Type: application/json
I0629 13:43:47.282128   29105 round_trippers.go:295]     Date: Wed, 29 Jun 2016 13:43:47 GMT
I0629 13:43:47.282162   29105 request.go:870] Response Body: {"kind":"APIGroupList","groups":[{"name":"autoscaling","versions":[{"groupVersion":"autoscaling/v1","version":"v1"}],"preferredVersion":{"groupVersion":"autoscaling/v1","version":"v1"},"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"192.168.56.220:443"}]},{"name":"batch","versions":[{"groupVersion":"batch/v1","version":"v1"}],"preferredVersion":{"groupVersion":"batch/v1","version":"v1"},"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"192.168.56.220:443"}]},{"name":"extensions","versions":[{"groupVersion":"extensions/v1beta1","version":"v1beta1"}],"preferredVersion":{"groupVersion":"extensions/v1beta1","version":"v1beta1"},"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"192.168.56.220:443"}]}]}
I0629 13:43:47.282985   29105 round_trippers.go:264] GET https://192.168.56.220:8443/oapi
I0629 13:43:47.282995   29105 round_trippers.go:271] Request Headers:
I0629 13:43:47.282999   29105 round_trippers.go:274]     User-Agent: oc/v1.2.0 (linux/amd64) openshift/2e62fab
I0629 13:43:47.283003   29105 round_trippers.go:274]     Authorization: Bearer 5x00cpdmr9mbsO1OuoZbyQJzc9BCN5Mi2SNzW86zQss
I0629 13:43:47.283007   29105 round_trippers.go:274]     Accept: application/json, */*
I0629 13:43:47.284778   29105 round_trippers.go:289] Response Status: 200 OK in 1 milliseconds
I0629 13:43:47.284801   29105 round_trippers.go:292] Response Headers:
I0629 13:43:47.284808   29105 round_trippers.go:295]     Cache-Control: no-store
I0629 13:43:47.284814   29105 round_trippers.go:295]     Content-Type: application/json
I0629 13:43:47.284820   29105 round_trippers.go:295]     Date: Wed, 29 Jun 2016 13:43:47 GMT
I0629 13:43:47.284826   29105 round_trippers.go:295]     Content-Length: 93
I0629 13:43:47.284856   29105 request.go:870] Response Body: {"kind":"APIVersions","apiVersion":"v1","versions":["v1"],"serverAddressByClientCIDRs":null}
I0629 13:43:47.285248   29105 round_trippers.go:264] GET https://192.168.56.220:8443/oapi/v1/namespaces/default/imagestreams/myapp
I0629 13:43:47.285263   29105 round_trippers.go:271] Request Headers:
I0629 13:43:47.285268   29105 round_trippers.go:274]     Accept: application/json, */*
I0629 13:43:47.285274   29105 round_trippers.go:274]     User-Agent: oc/v1.2.0 (linux/amd64) openshift/2e62fab
I0629 13:43:47.285279   29105 round_trippers.go:274]     Authorization: Bearer 5x00cpdmr9mbsO1OuoZbyQJzc9BCN5Mi2SNzW86zQss
I0629 13:43:47.288234   29105 round_trippers.go:289] Response Status: 200 OK in 2 milliseconds
I0629 13:43:47.288254   29105 round_trippers.go:292] Response Headers:
I0629 13:43:47.288259   29105 round_trippers.go:295]     Cache-Control: no-store
I0629 13:43:47.288263   29105 round_trippers.go:295]     Content-Type: application/json
I0629 13:43:47.288267   29105 round_trippers.go:295]     Date: Wed, 29 Jun 2016 13:43:47 GMT
I0629 13:43:47.288272   29105 round_trippers.go:295]     Content-Length: 1122
I0629 13:43:47.288302   29105 request.go:870] Response Body: {"kind":"ImageStream","apiVersion":"v1","metadata":{"name":"myapp","namespace":"default","selfLink":"/oapi/v1/namespaces/default/imagestreams/myapp","uid":"e75ff849-3df8-11e6-8434-080027c23ce5","resourceVersion":"639","generation":2,"creationTimestamp":"2016-06-29T12:56:32Z","annotations":{"openshift.io/image.dockerRepositoryCheck":"2016-06-29T12:56:33Z"}},"spec":{"tags":[{"name":"latest","annotations":null,"from":{"kind":"DockerImage","name":"registry.si.perfect-memory.com/core/exchange-manager:latest"},"generation":2,"importPolicy":{}}]},"status":{"dockerImageRepository":"10.10.87.191:5000/default/myapp","tags":[{"tag":"latest","items":null,"conditions":[{"type":"ImportSuccess","status":"False","lastTransitionTime":"2016-06-29T12:56:33Z","reason":"InternalError","message":"Internal error occurred: Get https://registry.si.perfect-memory.com/v2/core/exchange-manager/manifests/latest: token auth attempt for registry: https://gitlab.si.perfect-memory.com/jwt/auth?scope=repository%3Acore%2Fexchange-manager%3Apull\u0026service=container_registry request failed with status: 403 Forbidden","generation":2}]}]}}
I0629 13:43:47.289274   29105 request.go:555] Request Body: {"kind":"ImageStreamImport","apiVersion":"v1","metadata":{"name":"myapp","namespace":"default","resourceVersion":"639","creationTimestamp":null},"spec":{"import":true,"images":[{"from":{"kind":"DockerImage","name":"registry.si.perfect-memory.com/core/exchange-manager:latest"},"to":{"name":"latest"},"importPolicy":{}}]},"status":{}}
I0629 13:43:47.289321   29105 round_trippers.go:264] POST https://192.168.56.220:8443/oapi/v1/namespaces/default/imagestreamimports
I0629 13:43:47.289328   29105 round_trippers.go:271] Request Headers:
I0629 13:43:47.289331   29105 round_trippers.go:274]     Accept: application/json, */*
I0629 13:43:47.289335   29105 round_trippers.go:274]     User-Agent: oc/v1.2.0 (linux/amd64) openshift/2e62fab
I0629 13:43:47.289338   29105 round_trippers.go:274]     Authorization: Bearer 5x00cpdmr9mbsO1OuoZbyQJzc9BCN5Mi2SNzW86zQss
I0629 13:43:47.289342   29105 round_trippers.go:274]     Content-Type: application/json
I0629 13:43:47.698538   29105 round_trippers.go:289] Response Status: 201 Created in 409 milliseconds
I0629 13:43:47.698569   29105 round_trippers.go:292] Response Headers:
I0629 13:43:47.698577   29105 round_trippers.go:295]     Cache-Control: no-store
I0629 13:43:47.698584   29105 round_trippers.go:295]     Content-Type: application/json
I0629 13:43:47.698590   29105 round_trippers.go:295]     Date: Wed, 29 Jun 2016 13:43:47 GMT
I0629 13:43:47.698643   29105 request.go:870] Response Body: {"kind":"ImageStreamImport","apiVersion":"v1","metadata":{"name":"myapp","namespace":"default","selfLink":"/oapi/v1/namespaces/default/imagestreamimports/myapp","uid":"8113c15e-3dff-11e6-8434-080027c23ce5","resourceVersion":"639","creationTimestamp":"2016-06-29T13:43:47Z"},"spec":{"import":true,"images":[{"from":{"kind":"DockerImage","name":"registry.si.perfect-memory.com/core/exchange-manager:latest"},"to":{"name":"latest"},"importPolicy":{}}]},"status":{"import":{"metadata":{"name":"myapp","namespace":"default","uid":"e75ff849-3df8-11e6-8434-080027c23ce5","resourceVersion":"639","generation":2,"creationTimestamp":"2016-06-29T12:56:32Z","annotations":{"openshift.io/image.dockerRepositoryCheck":"2016-06-29T12:56:33Z"}},"spec":{"tags":[{"name":"latest","annotations":null,"from":{"kind":"DockerImage","name":"registry.si.perfect-memory.com/core/exchange-manager:latest"},"generation":2,"importPolicy":{}}]},"status":{"dockerImageRepository":"10.10.87.191:5000/default/myapp","tags":[{"tag":"latest","items":null,"conditions":[{"type":"ImportSuccess","status":"False","lastTransitionTime":"2016-06-29T12:56:33Z","reason":"InternalError","message":"Internal error occurred: Get https://registry.si.perfect-memory.com/v2/core/exchange-manager/manifests/latest: token auth attempt for registry: https://gitlab.si.perfect-memory.com/jwt/auth?scope=repository%3Acore%2Fexchange-manager%3Apull\u0026service=container_registry request failed with status: 403 Forbidden","generation":2}]}]}},"images":[{"status":{"metadata":{},"status":"Failure","message":"Internal error occurred: Get https://registry.si.perfect-memory.com/v2/core/exchange-manager/manifests/latest: token auth attempt for registry: https://gitlab.si.perfect-memory.com/jwt/auth?scope=repository%3Acore%2Fexchange-manager%3Apull\u0026service=container_registry request failed with status: 403 Forbidden","reason":"InternalError","details":{"causes":[{"message":"Get https://registry.si.perfect-memory.com/v2/core/exchange-manager/manifests/latest: token auth attempt for registry: https://gitlab.si.perfect-memory.com/jwt/auth?scope=repository%3Acore%2Fexchange-manager%3Apull\u0026service=container_registry request failed with status: 403 Forbidden"}]},"code":500}}]}}
The import completed successfully.

I0629 13:43:47.699732   29105 round_trippers.go:264] GET https://192.168.56.220:8443/oapi/v1/namespaces/default/imagestreams/myapp
I0629 13:43:47.699744   29105 round_trippers.go:271] Request Headers:
I0629 13:43:47.699750   29105 round_trippers.go:274]     Authorization: Bearer 5x00cpdmr9mbsO1OuoZbyQJzc9BCN5Mi2SNzW86zQss
I0629 13:43:47.699756   29105 round_trippers.go:274]     Accept: application/json, */*
I0629 13:43:47.699761   29105 round_trippers.go:274]     User-Agent: oc/v1.2.0 (linux/amd64) openshift/2e62fab
I0629 13:43:47.702488   29105 round_trippers.go:289] Response Status: 200 OK in 2 milliseconds
I0629 13:43:47.702509   29105 round_trippers.go:292] Response Headers:
I0629 13:43:47.702515   29105 round_trippers.go:295]     Cache-Control: no-store
I0629 13:43:47.702518   29105 round_trippers.go:295]     Content-Type: application/json
I0629 13:43:47.702522   29105 round_trippers.go:295]     Date: Wed, 29 Jun 2016 13:43:47 GMT
I0629 13:43:47.702526   29105 round_trippers.go:295]     Content-Length: 1122
I0629 13:43:47.702556   29105 request.go:870] Response Body: {"kind":"ImageStream","apiVersion":"v1","metadata":{"name":"myapp","namespace":"default","selfLink":"/oapi/v1/namespaces/default/imagestreams/myapp","uid":"e75ff849-3df8-11e6-8434-080027c23ce5","resourceVersion":"639","generation":2,"creationTimestamp":"2016-06-29T12:56:32Z","annotations":{"openshift.io/image.dockerRepositoryCheck":"2016-06-29T12:56:33Z"}},"spec":{"tags":[{"name":"latest","annotations":null,"from":{"kind":"DockerImage","name":"registry.si.perfect-memory.com/core/exchange-manager:latest"},"generation":2,"importPolicy":{}}]},"status":{"dockerImageRepository":"10.10.87.191:5000/default/myapp","tags":[{"tag":"latest","items":null,"conditions":[{"type":"ImportSuccess","status":"False","lastTransitionTime":"2016-06-29T12:56:33Z","reason":"InternalError","message":"Internal error occurred: Get https://registry.si.perfect-memory.com/v2/core/exchange-manager/manifests/latest: token auth attempt for registry: https://gitlab.si.perfect-memory.com/jwt/auth?scope=repository%3Acore%2Fexchange-manager%3Apull\u0026service=container_registry request failed with status: 403 Forbidden","generation":2}]}]}}
Name:           myapp
Created:        47 minutes 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 47 minutes ago          import failed: Internal error occurred: Get https://registry.si.per...

jperville avatar Jun 29 '16 13:06 jperville

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.

soltysh avatar Jun 29 '16 14:06 soltysh

Have no special logs appear on the master after I run the oc import-image command.

Here is how processes look on the master VM:

[root@master ~]# ps aux | grep origin
root      20908  0.3  2.4 578588 46580 ?        Ssl  12:37   0:25 /usr/bin/openshift start node --config=/etc/origin/node/node-config.yaml --loglevel=2
root      44545  3.4  9.3 834148 176644 ?       Ssl  14:48   0:13 /usr/bin/openshift start master --config=/etc/origin/master/master-config.yaml --loglevel=8

Notice the loglevel=8 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.

jperville avatar Jun 29 '16 14:06 jperville

You should see the logs like this one in the log. Without them I won't be able to dig what's going on.

soltysh avatar Jun 29 '16 15:06 soltysh

I'm sorry but I really don't see anything in the origin-master log after the booting messages (the last ones being about listing service account tokens). In neither the origin-master nor on the origin-node, both running at loglevel=8, anything shows when I try my oc import-image.

jperville avatar Jun 29 '16 15:06 jperville

@jperville Assuming those processes were started by systemd units the journalctl command used should be fine. @soltysh loglevel for systemd units is set via the OPTIONS variable in /etc/sysconfig/origin-master and restarting the service.

sdodson avatar Jun 29 '16 17:06 sdodson

@sdodson yes I have set the loglevel in /etc/sysconfig, as shown by the output of systemctl status origin-master.service below:

Redirecting to /bin/systemctl status  origin-master.service
● origin-master.service - Origin Master Service
   Loaded: loaded (/usr/lib/systemd/system/origin-master.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2016-06-29 15:50:12 UTC; 4h 8min ago
     Docs: https://github.com/openshift/origin
 Main PID: 55796 (openshift)
   CGroup: /system.slice/origin-master.service
           └─55796 /usr/bin/openshift start master --config=/etc/origin/master/master-config.yaml --loglevel=8

Still nothing interesting in the origin-master log when trying to oc import-image the image.

jperville avatar Jun 29 '16 20:06 jperville

@jperville thanks for confirming, @soltysh had asked me on irc how to properly configure loglevel for systemd units, sorry if that comment was a bit out of context.

However I have an idea, is the certificate for registry.si.perfect-memory.com trusted by the master host? If not you'll need to add the insecure annotation to the image stream, I think the error message for that condition is more clear than a 500 error, but I may be mistaken. See https://docs.openshift.org/latest/dev_guide/managing_images.html#insecure-registries

sdodson avatar Jun 29 '16 20:06 sdodson

I will try tomorrow the insecure annotation; for information the private registry is using a regular domain-validated certificate which poses no problem with docker pull.

jperville avatar Jun 29 '16 20:06 jperville

After trying all combinations of insecureRegistry and naming the secret after the registry URL and the registry authentication endpoint, I am proud to announce success with the following combination:

  • insecureRegistry annotation: NOT set
  • name of secret: hostname of registry authentication endpoint, which may NOT be the same as the hosthame of the public registry endpoint (that is: gitlab.internal.example.com instead of repository.internal.example.com).

Thank you very much for the help @soltysh and @sdodson.

Could you add a note in the documentation about the way secrets have to be named when working with authenticated image streams? This was not easy to figure out, I didn't even know about having to name the secret in a specific manner in the first place.

Sample working image stream definition:

apiVersion: v1
kind: ImageStream
metadata:
  name: myapp
spec:
  tags:
  - from:
      kind: DockerImage
      name: registry.internal.example.com/myapp:latest
    name: latest

Command-line to make a suitably named secret and add it to the default service accounts:

for name in gitlab.internal.example.com ; do
  oc secrets new-dockercfg ${name } --docker-server=${name } \
    --docker-username=someuser --docker-password=somepassword [email protected]
  oc secrets add serviceaccount/default secrets/${name } --for=pull
  oc secrets add serviceaccount/builder secrets/${name }
done

PS: found nothing relevant in the master log about image streams, even at loglevel8.

jperville avatar Jun 30 '16 07:06 jperville

After successfully importing my authenticated ImageStream, I finally can oc new-app --image-stream=myapp.

Surprisingly, after oc create-ing the application, the pod will refuse to start because ErrImagePull (can't find the credentials) so I added back the secret named after the public registry hostname (here: registry.internal.example.com).

In the end, I had to duplicate my secret and add it to the default and deployer service accounts twice to get my application working.

For now, this is OK, I have a workaround, but it would be nice to be able to have a single place to declare which secret to use to pull which docker image, which would work both for ImageStream and for instanciating pods.

jperville avatar Jun 30 '16 07:06 jperville

Could you add a note in the documentation about the way secrets have to be named when working with authenticated image streams? This was not easy to figure out, I didn't even know about having to name the secret in a specific manner in the first place.

Actually after re-testing and re-checking the code the key is created from the value passed to --docker-server, so the secret name does not matter. Apologies for the confusion, but I wonder why it didn't work for you, though :/

Secondly, I don't understand why you need to update both deployer and default serviceaccount. Since your image is used only for deployment, default should be sufficient. Again, I just verified that.

The only thing that comes to my mind and would be worth checking would be the fact that your auth is done against different server, but that shouldn't be a problem, imho.

The logs I was looking into for look like that:

I0630 13:32:16.941779    5048 credentials.go:169] Being asked for https://auth.docker.io/token, trying index.docker.io/v1 for legacy behavior
I0630 13:32:16.941800    5048 credentials.go:174] Being asked for //index.docker.io/v1, trying docker.io for legacy behavior
I0630 13:32:16.941809    5048 credentials.go:177] Unable to find a secret to match //docker.io (docker.io)

And these should be available at level 5, already. I'm not sure why you're not seeing those :(

Finally, I'd really appreciate if you could give it a try once again with above details.

soltysh avatar Jun 30 '16 14:06 soltysh

I have done more testing @soltysh and indeed the name of secret can be anything, as long as there is two secrets:

  • one with a --docker-server matching the authentication endpoint (gitlab.internal.example.com), used by the ImageStream
  • and one with a --docker-server matching the public registry endpoint (registry.internal.example.com), used when pulling pods images.

Yes, my authentication is done versus a different server (using the new integrated container registry from gitlab), hence the need for two secrets because of the two endpoints. I just wish there was a way to DRY that but for the moment duplicating the secrets is acceptable.

Also, I have tried adding the secrets only to the default service account (and not to the deployer), and it still works. Thanks for pointing that to me.

jperville avatar Jun 30 '16 14:06 jperville

@jperville thanks for the detailed info, I've changed the tile of the bug and recategorized this a bit, since it seems like a bug that we should address. I'll leave this open and will try to tackle that. Thanks a lot for your report and patience!

soltysh avatar Jul 01 '16 14:07 soltysh

what are the endpoints @jperville ? trying to use the saas version of registry without success

hernandev avatar Jul 29 '16 00:07 hernandev