Access the Red Hat Registry for Testing with cURL

Accessing a Docker registry can be performed using the curl command line tool by performing basic authentication.

For Red Hat’s registry.redhat.io, when attempting to access the registry we can see that there are

~|⇒ curl https://registry.redhat.io/v2/
{"errors":[{"code":"UNAUTHORIZED","message":"Access to the requested resource is not authorized"}]}%

When attempting to access this endpoint via basic CLI tools by querying the authentication endpoint found here: https://registry.redhat.io/auth/realms/rhcc/protocol/redhat-docker-v2/auth

An example of performing this authentication can be seen below:

# Set USER and password for the Red Hat Customer Portal
auth|⇒ USER=<USER>
auth|⇒ read -s PASSWORD
<Password>

auth|⇒ curl -X GET -Lv -u ${USER}:${PASSWORD} "https://registry.redhat.io/auth/realms/rhcc/protocol/redhat-docker-v2/auth?account=${USER}&service=docker-registry"

# Extract the token from the previous response
auth|⇒ TOKEN=`curl -X GET -u ${USER}:${PASSWORD} "https://registry.redhat.io/auth/realms/rhcc/protocol/redhat-docker-v2/auth?account=${USER}&service=docker-registry" | jq .token -r`

auth|⇒ curl -L -H "Authorization: Bearer ${TOKEN}"  https://registry.redhat.io/v2/openshift3/ose-node/tags/list
{"name": "openshift3/ose-node", "tags": ["v3.10.175-1", "v3.11.404-3", "v3.11.521-1.git.59aef03-source", "v3.11.570-1.g6e33ff0", "v3.11.69-3", "v3.11.487", "v3.11.374", "v3.10.66", "v3.11.161", "v3.11.272", "v3.11.380-1-source", "v3.10.45-2", "v3.11.318-2", "v3.11.404", "v3.10.127-6", "v3.11.521-1.git.59aef03", "v3.10.153-3", "v3.11.394-1", "v3.10.34", "v3.11.59", "v3.11.51", "v3.11.232", "v3.11.501-1.git.f8c4746", "v3.10.163", "v3.11.51-2", "v3.11.170", "v3.11.248-4", "v3.11.346", "v3.11.452-2.git.a782948-source", "v3.11.157-1", "v3.11.306-10", "v3.10.72", "v3.11.570", "v3.11.524-1.git.2dffce7-source", "v3.11.154-1", "v3.11.569", "v3.10.153", "v3.11.43", "v3.10.111-2", "v3.10.89-2", "v3.11.570-1.g6e33ff0-source", "v3.11.452-2.git.a782948", "v3.11.462-3.git.e7d0362-source", "v3.11.153-2", "v3.10.139", "v3.11.104", "v3.11.374-2", "v3.11.216", "v3.11.129-1", "v3.11.219", "v3.11.569-1.g9dc951a", "v3.11.465", "v3.11.462", "v3.11.501", "v3.11.161-1", "v3.11.188", "v3.10.89", "v3.11.420-1-source", "v3.11.439-1", "v3.11.188-2", "v3.10.83", "v3.10.149", "v3.11.117-2", "v3.10.127", "v3.10.101-4", "v3.11.117", "v3.11.141-3", "v3.11.16-2", "v3.11.219-1", "v3.11.501-1.git.f8c4746-source", "v3.10.119-2", "v3.11.200", "v3.10.127-4", "v3.11.104-14", "v3.10.14", "v3.10.72-3", "v3.11.465-1.git.be762e5", "v3.11.248", "v3.10.72-5", "v3.11.439-1-source", "v3.11.69", "v3.11.232-3", "v3.10.111", "v3.10.139-14", "v3.11.129", "v3.10.119", "v3.11.374-2-source", "v3.11.98", "v3.11.452", "v3.11.317-3", "v3.11.146-1", "v3.11.135-2", "v3.10.170-1", "v3.11.524", "v3.11.394-1-source", "v3.11.521", "v3.11.16", "v3.11.170-5", "v3.11.286", "v3.11.487-1.git.0b26065-source", "v3.11.286-1", "v3.11.135", "v3.10.14-13", "v3.11.98-6", "v3.11.380", "v3.11.272-1", "v3.11.487-1.git.0b26065", "v3.10.181", "v3.11.88", "v3.11.306", "v3.10.34-3", "v3.11.82", "v3.11.439", "v3.10.163-2", "v3.11.462-3.git.e7d0362", "v3.11.200-4", "v3.10.66-2", "v3.10.149-2", "v3.11.542-1.git.f2fd300-source", "v3.11.465-1.git.be762e5-source", "v3.11.317", "v3.11.43-2", "v3.11.141", "v3.11.98-3", "v3.10.181-1", "v3.11.146", "v3.11.318", "v3.10.45", "v3.11.542", "v3.11.420", "v3.11.380-1", "v3.10.45-7", "v3.11.82-3", "v3.11.420-1", "v3.10.101", "v3.11", "v3.10", "v3.11.524-1.git.2dffce7", "v3.11.216-3", "v3.10.14-8", "v3.11.404-3-source", "v3.11.157", "v3.11.154", "v3.11.346-2", "v3.10.14-6", "v3.11.153", "v3.10.83-2", "v3.11.88-2", "v3.11.59-2", "v3.11.569-1.g9dc951a-source", "v3.10.175", "v3.11.346-2-source", "v3.11.394", "v3.10.170", "v3.11.542-1.git.f2fd300", "latest"]}