harbor/docs/1.10/install-config/customize-token-service.md

62 lines
2.9 KiB
Markdown
Raw Normal View History

---
title: Customize the Harbor Token Service
2020-02-11 16:24:43 +01:00
weight: 60
---
2019-12-18 15:38:10 +01:00
By default, Harbor uses its own private key and certificate to authenticate with Docker clients. This topic describes how to optionally customize your configuration to use your own key and certificate.
2020-01-13 12:25:55 +01:00
Harbor requires the Docker client to access the Harbor registry with a token. The procedure to generate a token is like [Docker Registry v2 authentication](https://github.com/docker/distribution/blob/master/docs/spec/auth/token.md). Firstly, you make a request to the token service for a token. The token is signed by the private key. After that, you make a new request with the token to the Harbor registry, Harbor registry verifies the token with the public key in the root cert bundle. Then Harbor registry authorizes the Docker client to push and pull images.
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
- If you do not already have a certificate, follow the instructions in [Generate a Root Certificate](#gen-cert) to generate a root certificate by using openSSL.
- If you already have a certificate, go to [Provide the Certificate to Harbor](#provide-cert).
## Generate a Root Certificate {#gen-cert}
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
1. Generate a private key.
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
```sh
openssl genrsa -out private_key.pem 4096
2020-01-13 12:25:55 +01:00
```
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
1. Generate a certificate.
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
```sh
openssl req -new -x509 -key private_key.pem -out root.crt -days 3650
2020-01-13 12:25:55 +01:00
```
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
1. Enter information to include in your certificate request.
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some of them blank. For some fields there is a default value. If you enter `.`, the field is left blank.
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
- Country Name (2 letter code) [AU]:
- State or Province Name (full name) [Some-State]:
- Locality Name (eg, city) []:
- Organization Name (eg, company) [Internet Widgits Pty Ltd]:
- Organizational Unit Name (eg, section) []:
- Common Name (eg, server FQDN or YOUR name) []:
- Email Address []:
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
After you run these commands, the files `private_key.pem` and `root.crt` are created in the current directory.
2019-12-18 15:38:10 +01:00
## Provide the Certificate to Harbor {#provide-cert}
2019-12-18 15:38:10 +01:00
2020-02-20 13:02:41 +01:00
See [Run the Installer Script](run-installer-script.md) or [Reconfigure Harbor and Manage the Harbor Lifecycle](reconfigure-manage-lifecycle.md) to install or reconfigure Harbor. After you run `./install` or `./prepare`, Harbor generates several configuration files. You need to replace the original private key and certificate with your own key and certificate.
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
1. Replace the default key and certificate.
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
Assuming that the key and certificate are in `/root/cert`, run the following commands:
2019-12-18 15:38:10 +01:00
```sh
cd config/ui
cp /root/cert/private_key.pem private_key.pem
cp /root/cert/root.crt ../registry/root.crt
2020-01-13 12:25:55 +01:00
```
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
1. Go back to the `make` directory, and start Harbor by using following command:
2019-12-18 15:38:10 +01:00
```sh
docker-compose up -d
2020-01-13 12:25:55 +01:00
```
2019-12-18 15:38:10 +01:00
2020-01-13 12:25:55 +01:00
1. Push and pull images to and from Harbor to check that your own certificate works.