Configure HTTPS Access to Harbor
Important: Using Existing Third-Party Certificates
If you already have a TLS certificate and key from a trusted authority (e.g., Let’s Encrypt, DigiCert, GoDaddy), you can skip the self-signed certificate generation steps on this page. Simply place your certificate and key files on the Harbor host and provide their paths in the harbor.yml file, as described in ./configure-yml-file.md. This is the recommended approach for all production environments.
By default, Harbor does not ship with certificates. It is possible to deploy Harbor without security, so that you can connect to it over HTTP. However, using HTTP is acceptable only in air-gapped test or development environments that do not have a connection to the external internet. Using HTTP in environments that are not air-gapped exposes you to man-in-the-middle attacks. In production environments, always use HTTPS.
To configure HTTPS, you must create SSL certificates. You can use certificates that are signed by a trusted third-party CA, or you can use self-signed certificates. This section describes how to use OpenSSL to create a CA, and how to use your CA to sign a server certificate and a client certificate. You can use other CA providers, for example Let’s Encrypt.
The procedures below assume that your Harbor registry’s hostname is yourdomain.com, and that its DNS record points to the host on which you are running Harbor.
Generate a Certificate Authority Certificate
In a production environment, you should obtain a certificate from a CA. In a test or development environment, you can generate your own CA. To generate a CA certficate, run the following commands.
- 
Generate a CA certificate private key. openssl genrsa -out ca.key 4096
- 
Generate the CA certificate. Adapt the values in the -subjoption to reflect your organization. If you use an FQDN to connect your Harbor host, you must specify it as the common name (CN) attribute.openssl req -x509 -new -nodes -sha512 -days 3650 \ -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=MyPersonal Root CA" \ -key ca.key \ -out ca.crt
Generate a Server Certificate
The certificate usually contains a .crt file and a .key file, for example, yourdomain.com.crt and yourdomain.com.key.
- 
Generate a private key. openssl genrsa -out yourdomain.com.key 4096
- 
Generate a certificate signing request (CSR). Adapt the values in the -subjoption to reflect your organization. If you use an FQDN to connect your Harbor host, you must specify it as the common name (CN) attribute and use it in the key and CSR filenames.openssl req -sha512 -new \ -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=yourdomain.com" \ -key yourdomain.com.key \ -out yourdomain.com.csr
- 
Generate an x509 v3 extension file. Regardless of whether you’re using either an FQDN or an IP address to connect to your Harbor host, you must create this file so that you can generate a certificate for your Harbor host that complies with the Subject Alternative Name (SAN) and x509 v3 extension requirements. Replace the DNSentries to reflect your domain.cat > v3.ext <<-EOF authorityKeyIdentifier=keyid,issuer basicConstraints=CA:FALSE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment extendedKeyUsage = serverAuth subjectAltName = @alt_names [alt_names] DNS.1=yourdomain.com DNS.2=yourdomain DNS.3=hostname EOF
- 
Use the v3.extfile to generate a certificate for your Harbor host.Replace the yourdomain.comin the CSR and CRT file names with the Harbor host name.openssl x509 -req -sha512 -days 3650 \ -extfile v3.ext \ -CA ca.crt -CAkey ca.key -CAcreateserial \ -in yourdomain.com.csr \ -out yourdomain.com.crt
Provide the Certificates to Harbor and Docker
After generating the ca.crt, yourdomain.com.crt, and yourdomain.com.key files for your self-signed certificate, you must provide them to Harbor and to the Docker daemon.
- 
Create the Certificate Directory for Harbor. The /data/cert/directory is the default location where Harbor looks for its certificates, but this directory does not exist by default. You must create it first.sudo mkdir -p /data/cert/
- 
Copy the Server Certificate and Key to the Harbor Directory cp yourdomain.com.crt /data/cert/ sudo cp yourdomain.com.key /data/cert/
- 
Configure the Docker Daemon to Trust the Certificate To allow the Docker client to push and pull images, the Docker daemon must also trust the certificate so ,convert your server certificate from .crt to .cert, as the Docker daemon requires this extension. openssl x509 -inform PEM -in yourdomain.com.crt -out yourdomain.com.cerNext, create a dedicated directory for your Harbor domain and copy all three certificate files into it. mkdir -p /etc/docker/certs.d/yourdomain.com/ cp yourdomain.com.cert /etc/docker/certs.d/yourdomain.com/ cp yourdomain.com.key /etc/docker/certs.d/yourdomain.com/ cp ca.crt /etc/docker/certs.d/yourdomain.com/
- 
Restart Docker Engine. systemctl restart docker
You might also need to trust the certificate at the OS level. See Troubleshooting Harbor Installation for more information.
The following example illustrates the final directory structure for Docker, which uses your custom certificates.
/etc/docker/certs.d/
    └── yourdomain.com:port
       ├── yourdomain.com.cert
       ├── yourdomain.com.key
       └── ca.crt             
Deploy or Reconfigure Harbor
If you have not yet deployed Harbor, see 
Configure the Harbor YML File for information about how to configure Harbor to use the certificates by specifying the hostname and https attributes in harbor.yml.
If you already deployed Harbor with HTTP and want to reconfigure it to use HTTPS, perform the following steps.
- 
Run the preparescript to enable HTTPS.Harbor uses an nginxinstance as a reverse proxy for all services. You use thepreparescript to configurenginxto use HTTPS. Theprepareis in the Harbor installer bundle, at the same level as theinstall.shscript../prepare
- 
If Harbor is running, stop and remove the existing instance. Your image data remains in the file system, so no data is lost. docker compose down -v
- 
Restart Harbor: docker compose up -d
Verify the HTTPS Connection
After setting up HTTPS for Harbor, you can verify the HTTPS connection by performing the following steps.
- 
Open a browser and enter https://yourdomain.com. It should display the Harbor interface. Some browsers might show a warning stating that the Certificate Authority (CA) is unknown. This happens when using a self-signed CA that is not from a trusted third-party CA. You can import the CA to the browser to remove the warning. 
- 
On a machine that runs the Docker daemon, check the /etc/docker/daemon.jsonfile to make sure that the-insecure-registryoption is not set for https://yourdomain.com.
- 
Log into Harbor from the Docker client. docker login yourdomain.comIf you’ve mapped nginx443 port to a different port,add the port in thelogincommand.docker login yourdomain.com:port
What to Do Next
- If the verification succeeds, see Harbor Administration for information about using Harbor.
- If installation fails, see Troubleshooting Harbor Installation.
On this page
Contributing