Skip to content
subuilds.dev

← logbuild #23 passed178aa8f

Self-Host Harbor Image Registry on Debian: Internal PKI and GitLab CI

Install Harbor on Debian and build your own internal CA, so Harbor has real TLS. Then connect it to GitLab Runner, so every pipeline pulls base images from your LAN and not from Docker Hub.

· 17 min read

Every CI build that pulls from Docker Hub costs time and uses up your rate limit. Bigger runners do not fix this. A registry on your own LAN does. Harbor is a registry that you host yourself. It keeps copies of the images you pull and scans them with Trivy. It controls access with robot accounts and serves images at the full speed of your LAN.

This post covers the full path. You install Harbor. You see the TLS error that stops docker login. You build your own CA (certificate authority) to fix it. Then you connect Harbor to GitLab Runner, so .gitlab-ci.yml pulls from harbor.lan.

Environment:

Component Version
Server OS Debian 13 (Trixie)
Registry Harbor 2.13.0 (offline)
Runtime Docker Engine 27+
GitLab Runner 18.9
Workstation macOS (CA host)

In Simple Words#

The problem
Every CI job pulls its base image from Docker Hub. That is slow and uses up the rate limit. Your own registry with HTTP only does not help, because docker login fails.
The root cause
Docker talks to a registry over HTTPS and needs a certificate it trusts. Public Let’s Encrypt does not give certificates for .lan names. Each client also has its own list of trusted CAs.
The solution
Install Harbor on Debian. Build your own CA, sign a certificate for harbor.lan, and add the CA to every client. Then point GitLab Runner and .gitlab-ci.yml at Harbor.
Think of it like this
A company opens a small warehouse next door. Now it does not have to order from a far city. The workers only accept goods from a warehouse with a signed permit. The boss signs the permit once, and every worker learns the boss’s signature.

What We’ll Cover#

  1. Set up a Debian VM and install Docker Engine — prepare apt and add Docker’s official repo
  2. Install Harbor from the offline installer on HTTP — first run, no TLS
  3. Create a project and robot account in the UI — the login that CI will use
  4. See docker login fail on TLS — the point where HTTP only is not enough
  5. Build an internal CA on your Mac — OpenSSL and the basics of PKI (keys and certificates)
  6. Sign harbor.lan.crt with the right SANs — and serve a full chain
  7. Trust the CA on every client — Keychain, NSS, curl, Docker daemon, containerd
  8. Connect Harbor to GitLab Runner — DOCKER_AUTH_CONFIG and the containerd trap
  9. Replace the public base image in .gitlab-ci.yml — and watch pipelines pull from your LAN

VM Specs#

Harbor runs nine containers (core, portal, registry, db, redis, nginx, trivy, jobservice, chartmuseum). With 1 GB of RAM it crashes fast. A base that works:

Resource Suggested
CPU 2 vCPU
RAM 4 GB
Disk 40 GB

If you turn on Trivy scanning, raise RAM to 8 GB.

1. Prepare Debian#

bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl wget vim git ca-certificates gnupg lsb-release

2. Install Docker Engine#

Use Docker’s official repo. The Debian docker.io package is older and does not include docker compose.

Add the GPG key and repo:

bash
sudo install -m 0755 -d /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/debian/gpg \
  | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
  | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker:

bash
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io \
  docker-buildx-plugin docker-compose-plugin

Check the install and turn Docker on:

bash
docker version
docker compose version
sudo systemctl enable --now docker

3. Download the Harbor Offline Installer#

The offline installer contains every image that Harbor needs. You do not wait for slow Docker Hub pulls during the install. You can also do the first run while the machine’s network is closed off.

Download the latest release from github.com/goharbor/harbor/releases:

bash
cd /opt
sudo wget https://github.com/goharbor/harbor/releases/download/v2.13.0/harbor-offline-installer-v2.13.0.tgz
sudo tar xzf harbor-offline-installer-v2.13.0.tgz
cd /opt/harbor

You should now have /opt/harbor with the installer scripts and one archive file (tarball) that holds the images.

4. Configure harbor.yml for HTTP First#

Copy the template:

bash
sudo cp harbor.yml.tmpl harbor.yml
sudo vim harbor.yml

Make four changes:

yaml
hostname: harbor.lan

# Comment out the entire https block for the first run
# https:
#   port: 443
#   certificate: /your/certificate/path
#   private_key: /your/private/key/path

harbor_admin_password: StrongPassword123

data_volume: /data/harbor

Create the data directory:

bash
sudo mkdir -p /data/harbor

5. Install Harbor#

bash
sudo ./install.sh

install.sh loads the images, builds the compose files from harbor.yml, and starts the services. This takes 2–5 minutes on most disks.

When it finishes, check:

bash
docker ps

You should see nine harbor-* containers plus nginx, registry, registryctl, redis, trivy-adapter.

6. First Login and Create a Project#

Open http://harbor.lan and log in as admin with the password from harbor.yml.

Create a project. I use base-images for the base images that CI jobs share.

A robot account is a login for machines, not for people. Create one that can only use that project: Project → Robot Accounts → New Robot Account. Give it pull and push. Save the token. Harbor shows it only once.

7. The Docker Login TLS Wall#

Up to now you only used Harbor in the browser. Now try it with Docker. On your workstation:

bash
docker login harbor.lan
text
Username: robot$bot-01
Password:
Error response from daemon: Get "https://harbor.lan/v2/":
  dialing harbor.lan:443 container via direct connection
  because Docker Desktop has no HTTPS proxy:
  connecting to harbor.lan:443:
  dial tcp 10.10.1.23:443: connect: connection refused

For internal systems, build your own CA. A CA signs certificates, and a client accepts a certificate when it trusts the CA that signed it. Public Let’s Encrypt does not give certificates for .lan names. A certificate that Harbor signs for itself, with no CA behind it, makes every client show an error. So build the CA once, and add it to every client once. After that, every certificate you sign with it works.

8. Build an Internal CA on Your Mac#

Create a working directory:

bash
mkdir -p ~/Projects/labA1-pki/{root,harbor}
cd ~/Projects/labA1-pki/root

Create the CA key and the root certificate. The CA signs this root certificate itself. 10 years is fine for a homelab. For production, use 1–2 years and replace it on a schedule.

bash
openssl genrsa -out a1-root-ca.key 4096

openssl req -x509 -new -nodes \
  -sha512 \
  -days 3650 \
  -key a1-root-ca.key \
  -out a1-root-ca.crt

OpenSSL asks for a Distinguished Name (the identity fields of the certificate). Only the Common Name matters. Pick a name that you will know when you see it in a browser’s certificate viewer:

text
Country Name (2 letter code): VN
State or Province Name: HCM
Locality Name: HCM
Organization Name: SuBuilds
Organizational Unit Name: DevOps
Common Name: A1-Lab Root CA
Email Address: [email protected]

You now have two files. a1-root-ca.key is the private key. Keep it secret, because anyone who has it can make certificates that your network trusts. a1-root-ca.crt is the public certificate. You can give it to anyone.

9. Generate Harbor’s Key and CSR on the Harbor Server#

The private key never leaves the Harbor server. The server makes a CSR (Certificate Signing Request), a file that asks the CA for a signed certificate. Only the CSR goes to the CA host.

bash
sudo mkdir -p /opt/harbor/certs
cd /opt/harbor/certs

sudo openssl genrsa -out harbor.lan.key 4096

sudo openssl req -sha512 -new \
  -key harbor.lan.key \
  -out harbor.lan.csr

In the DN prompts, set Common Name to harbor.lan. This is the hostname that clients will ask for.

The flow:

  1. Harbor makes a key and a CSR (a signing request). No client trusts Harbor yet, so docker login fails.
  2. Copy only the CSR to the Mac, the CA host. The private key harbor.lan.key stays on the Harbor server.
  3. The CA key signs the CSR, with the SANs from v3.ext. The result is the certificate harbor.lan.crt.
  4. Copy harbor.lan.crt back to Harbor and turn on HTTPS. The clients still do not know your CA.
  5. Install a1-root-ca.crt on every client: browser, Docker and the runner host. Now they trust Harbor, and docker login works.
5 / 5

Copy the CSR to the Mac:

bash
scp harbor:/opt/harbor/certs/harbor.lan.csr ~/Projects/labA1-pki/harbor/

10. Sign the CSR with SANs#

Modern TLS checks the Subject Alternative Name (SAN), not the Common Name. Clients do not trust a certificate that has no SAN. This is true in Chrome (since 58), Go (since 1.15), and OpenSSL 3+. You need a v3 extensions file.

text
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage=digitalSignature,keyEncipherment
extendedKeyUsage=serverAuth
subjectAltName=@alt_names

[alt_names]
DNS.1=harbor.lan
IP.1=10.10.1.23

Sign:

bash
openssl x509 -req \
  -sha512 \
  -days 3650 \
  -extfile v3.ext \
  -CA ../root/a1-root-ca.crt \
  -CAkey ../root/a1-root-ca.key \
  -CAcreateserial \
  -in harbor.lan.csr \
  -out harbor.lan.crt

Look at the result:

bash
openssl x509 -in harbor.lan.crt -text -noout

Check these fields:

Field Expected value
Issuer CN=A1-Lab Root CA, O=SuBuilds, OU=DevOps, …
Subject CN=harbor.lan, O=SuBuilds, OU=DevOps, …
X509v3 SAN DNS:harbor.lan, IP Address:10.10.1.23
Basic Constraints CA:FALSE (this is a server cert, not a CA)
Key Usage Digital Signature, Key Encipherment
Extended Key Usage TLS Web Server Authentication

11. Enable HTTPS in Harbor#

Copy the signed certificate into Harbor’s certificate directory:

bash
scp harbor.lan.crt harbor:/tmp/
ssh harbor "sudo mv /tmp/harbor.lan.crt /opt/harbor/certs/"

Remove the comment marks from the HTTPS block in harbor.yml:

yaml
https:
  port: 443
  certificate: /opt/harbor/certs/harbor.lan.crt
  private_key: /opt/harbor/certs/harbor.lan.key

Build the compose files again and restart:

bash
cd /opt/harbor
sudo ./prepare
sudo docker compose down
sudo docker compose up -d

Open https://harbor.lan. It will still say “not secure”. This is expected. Harbor serves a certificate signed by a CA that the browser does not know. Next, make every client trust the CA.

12. Trust the CA Everywhere It Matters#

This step took me the most time. Every client has its own trust store, the list of CAs that it trusts. When you add the CA to Keychain, you only cover about a third of them.

Client Trust store How to trust the CA
Chrome, Safari macOS Keychain (System) Import a1-root-ca.crt, expand Trust, set Always Trust
Firefox, Zen NSS (browser-private) Settings → Privacy → View Certificates → Authorities → Import
curl on macOS LibreSSL CA bundle (not Keychain!) curl --cacert a1-root-ca.crt …, or install Homebrew curl which reads Keychain
Docker daemon /etc/docker/certs.d/<host>/ca.crt Drop ca.crt in that folder
containerd (23+) OS trust store /usr/local/share/ca-certificates/ + update-ca-certificates + restart Docker

macOS Keychain (Chrome and Safari)#

Open Keychain Access. Select the System keychain. File → Import Items → pick a1-root-ca.crt. Double-click the imported certificate, open Trust, set When using this certificate → Always Trust.

Chrome and Safari use it at once. Reload https://harbor.lan. The browser now shows it as secure.

Firefox / Zen — NSS, not Keychain#

Firefox (and browsers built from it, like Zen) has its own CA store, called NSS. Trust that you set in Keychain does not apply to it.

  1. Settings → Privacy & Security → Certificates → View Certificates
  2. Authorities tab → Import
  3. Select a1-root-ca.crt
  4. Check ✅ Trust this CA to identify websites
  5. Restart the browser

curl#

The curl that comes with macOS uses Apple’s LibreSSL bundle. It ignores certificates that you add to Keychain. So this fails even when Keychain trust works:

bash
curl https://harbor.lan
text
curl: (60) SSL certificate problem:
unable to get local issuer certificate

Three fixes:

bash
curl --cacert ~/Projects/labA1-pki/root/a1-root-ca.crt https://harbor.lan
bash
brew install curl
/opt/homebrew/opt/curl/bin/curl https://harbor.lan

Option C is to check the chain at the protocol level:

bash
openssl s_client \
  -connect harbor.lan:443 \
  -CAfile ~/Projects/labA1-pki/root/a1-root-ca.crt \
  </dev/null 2>&1 | grep -E "Verify return code"

Verify return code: 0 (ok) means the chain is correct. Any other problem is then a trust-store problem, not a certificate problem. Use this check each time a client says “untrusted”.

Aside: the “fullchain” detour#

While I debugged the same TLS error, I saw a different symptom. openssl s_client -showcerts showed:

text
--- Certificate chain
 0 s:CN=harbor.lan
   i:CN=A1-Lab Root CA
---

Harbor serves only depth 0 (the server certificate). The CA certificate is not in the chain. Most clients expect the server certificate plus the chain of its issuer. Then they do not have to find the CA themselves. The fix: join the server certificate and the root certificate into one file, and serve that file.

bash
cat harbor.lan.crt ../root/a1-root-ca.crt > harbor-fullchain.crt
bash
cat harbor-fullchain.crt
# -----BEGIN CERTIFICATE-----   (harbor.lan)
# ...
# -----END CERTIFICATE-----
# -----BEGIN CERTIFICATE-----   (A1-Lab Root CA)
# ...
# -----END CERTIFICATE-----

Copy harbor-fullchain.crt to the Harbor server. In harbor.yml, use it in place of the server certificate:

yaml
https:
  certificate: /opt/harbor/certs/harbor-fullchain.crt
  private_key: /opt/harbor/certs/harbor.lan.key

Run ./prepare && docker compose down && docker compose up -d and test again.

13. Verify Docker Login#

Docker Desktop now trusts the CA, because it reads macOS Keychain when it restarts. Try the login again:

bash
docker login harbor.lan
text
Username: robot$bot-01
Password:
Login Succeeded

This is a big step. Harbor now works like any other registry. docker pull harbor.lan/base-images/<image> works, and you have a place to push images.

14. Wire Harbor into GitLab Runner#

The goal: every .gitlab-ci.yml job pulls its base image from Harbor, not from Docker Hub. This is the real gain for production. There are no more Docker Hub rate limits, and pulls run at LAN speed.

There are three traps on the way. All three happened to me.

Trap 1: containerd uses a different trust path than the Docker daemon#

On the GitLab Runner host, install the CA the “Docker way”:

bash
sudo mkdir -p /etc/docker/certs.d/harbor.lan
sudo cp a1-root-ca.crt /etc/docker/certs.d/harbor.lan/ca.crt

Now login works:

bash
docker login harbor.lan
# Login Succeeded

But the pull fails:

bash
docker pull harbor.lan/base-images/node:24.12.0-trixie-slim
text
Error response from daemon: failed to resolve reference
"harbor.lan/base-images/node:24.12.0-trixie-slim":
failed to authorize: failed to fetch oauth token:
Post "https://harbor.lan/service/token":
tls: failed to verify certificate:
x509: certificate signed by unknown authority

Install the CA into the OS trust store:

bash
sudo cp /etc/docker/certs.d/harbor.lan/ca.crt \
  /usr/local/share/ca-certificates/a1-root-ca.crt
sudo update-ca-certificates
sudo systemctl restart docker

Test the pull again. It should work now.

Trap 2: The job container doesn’t inherit the host’s Docker auth#

GitLab Runner in docker executor mode starts a new container for each job. The host’s ~/.docker/config.json is not available inside it. If you do not give the job its own login data, the base-image pull fails: unauthorized: unauthorized to access repository.

Make a base64 auth string from the robot account’s name and password:

bash
echo -n 'robot$bot-01:<password>' | base64

Put it into config.toml as a DOCKER_AUTH_CONFIG environment variable:

toml
[[runners]]
  name = "docker-runner-01"
  url = "http://gitlab.lan"
  executor = "docker"
  environment = ["DOCKER_AUTH_CONFIG={\"auths\":{\"harbor.lan\":{\"auth\":\"<base64-from-above>\"}}}"]
  [runners.docker]
    image = "harbor.lan/base-images/alpine:latest"
    pull_policy = ["if-not-present"]

Restart the runner. In my setup the runner itself runs as a Docker container (gitlab/gitlab-runner:v18.9.0) inside a VM. So it is not a systemd service on the host. When I restart the Docker daemon, the container restarts and loads config.toml again:

bash
sudo systemctl restart docker

If your runner is installed as a systemd service, use sudo systemctl restart gitlab-runner.

Trap 3: Point .gitlab-ci.yml at Harbor#

Change one line:

yaml
# Before
image: node:24.12.0-trixie-slim

# After
image: harbor.lan/base-images/node:24.12.0-trixie-slim

Before you commit, push the image into Harbor once:

bash
docker pull node:24.12.0-trixie-slim
docker tag node:24.12.0-trixie-slim harbor.lan/base-images/node:24.12.0-trixie-slim
docker push harbor.lan/base-images/node:24.12.0-trixie-slim

Commit, push, and watch the pipeline. The job logs show that the runner pulls from harbor.lan and not from registry-1.docker.io.

The registry is only one thing that slows a pipeline. For more ways to save pipeline time, see GitLab Runner Performance Optimization.

What You Have Now#

Layer Outcome
Registry Harbor 2.13 on Debian, serving HTTPS via your internal CA
Trust a1-root-ca.crt installed on workstations (Keychain + NSS + Docker) and every runner host (Docker + containerd)
CI .gitlab-ci.yml pulls base images from harbor.lan/base-images/* — no more Docker Hub rate limits

You also have the base for Harbor’s strongest features: Trivy scanning, vulnerability policies that block pulls, replication to a DR (disaster recovery) registry, OIDC for human users, and webhooks for image events.

Next Steps#