$ oc policy add-role-to-user \
system:image-puller system:serviceaccount:project-a:default \
--namespace=project-b
If you are using the OpenShift image registry and are pulling from image streams located in the same project, then your pod service account should already have the correct permissions and no additional action should be required.
However, for other scenarios, such as referencing images across Red Hat OpenShift Service on AWS projects or from secured registries, additional configuration steps are required.
You can obtain the image pull secret from Red Hat OpenShift Cluster Manager. This pull secret is called pullsecret
.
You use this pull secret to authenticate with the services that are provided by the included authorities, Quay.io and registry.redhat.io, which serve the container images for Red Hat OpenShift Service on AWS components.
When using the OpenShift image registry, to allow pods in project-a
to reference images in project-b
, a service account in project-a
must be bound to the system:image-puller
role in project-b
.
When you create a pod service account or a namespace, wait until the service account is provisioned with a docker pull secret; if you create a pod before its service account is fully provisioned, the pod fails to access the OpenShift image registry. |
To allow pods in project-a
to reference images in project-b
, bind a service account in project-a
to the system:image-puller
role in project-b
:
$ oc policy add-role-to-user \
system:image-puller system:serviceaccount:project-a:default \
--namespace=project-b
After adding that role, the pods in project-a
that reference the default service account are able to pull images from project-b
.
To allow access for any service account in project-a
, use the group:
$ oc policy add-role-to-group \
system:image-puller system:serviceaccounts:project-a \
--namespace=project-b
To pull a secured container from other private or secured registries, you must create a pull secret from your container client credentials, such as Docker or Podman, and add it to your service account.
Both Docker and Podman use a configuration file to store authentication details to log in to secured or insecure registry:
Docker: By default, Docker uses $HOME/.docker/config.json
.
Podman: By default, Podman uses $HOME/.config/containers/auth.json
.
These files store your authentication information if you have previously logged in to a secured or insecure registry.
Both Docker and Podman credential files and the associated pull secret can contain multiple references to the same registry if they have unique paths, for example, |
config.json
file{
"auths":{
"cloud.openshift.com":{
"auth":"b3Blb=",
"email":"you@example.com"
},
"quay.io":{
"auth":"b3Blb=",
"email":"you@example.com"
},
"quay.io/repository-main":{
"auth":"b3Blb=",
"email":"you@example.com"
}
}
}
apiVersion: v1
data:
.dockerconfigjson: ewogICAiYXV0aHMiOnsKICAgICAgIm0iOnsKICAgICAgIsKICAgICAgICAgImF1dGgiOiJiM0JsYj0iLAogICAgICAgICAiZW1haWwiOiJ5b3VAZXhhbXBsZS5jb20iCiAgICAgIH0KICAgfQp9Cg==
kind: secret
metadata:
creationTimestamp: "2021-09-09T19:10:11Z"
name: pull-secret
namespace: default
resourceVersion: "37676"
uid: e2851531-01bc-48ba-878c-de96cfe31020
type: Opaque
Create a secret from an existing authentication file:
For Docker clients using .docker/config.json
, enter the following command:
$ oc create secret generic <pull_secret_name> \
--from-file=.dockerconfigjson=<path/to/.docker/config.json> \
--type=kubernetes.io/dockerconfigjson
For Podman clients using .config/containers/auth.json
, enter the following command:
$ oc create secret generic <pull_secret_name> \
--from-file=<path/to/.config/containers/auth.json> \
--type=kubernetes.io/podmanconfigjson
If you do not already have a Docker credentials file for the secured registry, you can create a secret by running:
$ oc create secret docker-registry <pull_secret_name> \
--docker-server=<registry_server> \
--docker-username=<user_name> \
--docker-password=<password> \
--docker-email=<email>
To use a secret for pulling images for pods, you must add the secret to your service account. The name of the service account in this example should match the name of the service account the pod uses. The default service account is default
:
$ oc secrets link default <pull_secret_name> --for=pull
A private registry can delegate authentication to a separate service. In these cases, image pull secrets must be defined for both the authentication and registry endpoints.
Create a secret for the delegated authentication server:
$ oc create secret docker-registry \
--docker-server=sso.redhat.com \
--docker-username=developer@example.com \
--docker-password=******** \
--docker-email=unused \
redhat-connect-sso
secret/redhat-connect-sso
Create a secret for the private registry:
$ oc create secret docker-registry \
--docker-server=privateregistry.example.com \
--docker-username=developer@example.com \
--docker-password=******** \
--docker-email=unused \
private-registry
secret/private-registry