Skip to content

Harbor

Interactive Diagram

새 탭 ↗

What is harbor? (Source: https://goharbor.io/)

Harbor is an open-source registry that secures artifacts with policy and role-based access control, ensures images are scanned and free from vulnerabilities, and signs images as trusted. As a CNCF (Cloud Native Computing Foundation) Graduated project, Harbor delivers compliance, performance, and interoperability to help you consistently and securely manage artifacts across cloud-native computing platforms such as Kubernetes and Docker.

CNCF project maturity levels (CNCF project maturity levels, Source: https://www.cncf.io/projects/)

Container registry landscape

(Source: https://landscape.cncf.io/?category=container-registry&grouping=category)

Harbor Architecture (Source: https://github.com/goharbor/harbor/wiki/Arch%E3%85%81itecture-Overview-of-Harbor)

Harbor Mainfeature (Source: https://goharbor.io/)

  • Security and vulnerability analysis
    • Harbor regularly scans images to check for vulnerabilities and performs policy checks to prevent vulnerable images from being deployed.
  • Content signing and validation
  • Multi-tenant
  • Extensible API and web UI
  • Image replication across multiple Harbor instances
    • You can replicate (synchronize) images and charts between multiple registry instances based on policies that use filters (repository, tag, label). Harbor automatically retries replication when an error occurs. This can be used to support load balancing, achieve high availability, and facilitate multi-datacenter deployments in hybrid and multi-cloud scenarios.
  • Identity integration and role-based access control(RBAC) : You can grant user permissions separately per project, and actions are restricted according to those permissions.

Harbor RBAC (Source: https://github.com/goharbor/harbor/blob/master/docs/user_guide.md#role-based-access-controlrbac)

There are two types of container registries: public and private.

- A public registry is basic in terms of abilities/offerings and easy to use, making it suitable for individuals or small teams who want to get a registry up and running as quickly as possible. However, as the scale grows, security issues such as patching, privacy, and access control may arise.

- A private registry provides a way to integrate security and privacy into enterprise container image storage that is hosted remotely or on-premises. A company can choose to build and deploy its own container registry or choose a commercial private registry service. Such private registries often come with advanced security features and technical support.

 nexusharbor
docker An integrated repository concept where Docker Registry is not the primary featureIn addition to a Docker Registry, it provides extra features such as Garbage Collection and Docker image vulnerability scanning
Active/Active HAHA-C supported only for Nexus Repository Pro
(Starts at 3,000$/year)
Supports image synchronization between registries via Replication

Nexus (Source: https://help.sonatype.com/repomanager3/high-availability)

proscons
identity management

hard to setup on k8s cluster

API and graphical UI
Vulnerability scanning
image replication
online or offline installation
(Source: https://www.slant.co/topics/2436/~best-docker-image-private-registries)

DP3 Harbor Archi.

Harbor optionally supports HTTP connections, but the Docker Client always tries to connect to the registry using HTTPS first.

HTTPS (Source: https://goharbor.io/docs/1.10/working-with-projects/working-with-images/pulling-pushing-images/)

An ingress controller is software that provides a reverse proxy, configurable traffic routing, and TLS termination for Kubernetes services. Kubernetes ingress resources are used to configure ingress rules and routing for individual Kubernetes services. Using an ingress controller and ingress rules, you can route traffic to multiple services in a Kubernetes cluster using a single IP address.

# create namespace
kubectl create ns dp3-ingress-basic
# Helm repo add
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
# install Nginx Ingress Controller with Helm
helm install dp3-nginx-ingress ingress-nginx/ingress-nginx \
--namespace dp3-ingress-basic \
--set controller.replicaCount=2 \
--set controller.nodeSelector."beta\.kubernetes\.io/os"=linux \
--set defaultBackend.nodeSelector."beta\.kubernetes\.io/os"=linux \
--set controller.admissionWebhooks.patch.nodeSelector."beta\.kubernetes\.io/os"=linux

Route53

Cert-manager is open source that automatically provisions and manages TLS (formerly SSL) certificates within a k8s cluster.

Cert-manager can issue certificates using things like let’s encrypt and Vault. It also automatically renews certificates before they expire, even after issuance.

cert-manager (Source: https://cert-manager.io/docs/)

# Label the ingress-basic namespace to disable resource validation
kubectl label ns dp3-ingress-basic cert-manager.io/disable-validation=true
# Add the Jetstack Helm repository
helm repo add jetstack https://charts.jetstack.io
# Update your local Helm chart repository cache
helm repo update
# Install the cert-manager Helm chart
helm install dp3-cert-manager jetstack/cert-manager \
--namespace dp3-ingress-basic \
--set installCRDs=true \
--set nodeSelector."kubernetes\.io/os"=linux \
--set webhook.nodeSelector."kubernetes\.io/os"=linux \
--set cainjector.nodeSelector."kubernetes\.io/os"=linux

Let’s Encrypt is a certificate authority that provides free X.509 certificates for Transport Layer Security encryption through an automated process that eliminates the previously complex steps of manually creating, validating, digitally signing, installing, and renewing certificates for secure websites.

= Automatic creation of free SSL certificates

Create the ClusterIssuer used by cert-manager so that certificates can be issued from Let’s Encrypt.

apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: MY_EMAIL_ADDRESS
privateKeySecretRef:
name: letsencrypt
solvers:
- http01:
ingress:
class: nginx
podTemplate:
spec:
nodeSelector:
"kubernetes.io/os": linux

After applying the Cluster Issuer, when you create an ingress resource, content like the following appears under spec.

tls:
- hosts:
- [YOUR_DOMAIN]
secretName: tls-secret

If you configure this part appropriately, the following processing proceeds.

  • It validates the domain configured in spec.tls.hosts. It runs the web server needed for validation and updates the routing configuration.
  • When the certificate is issued, it is stored in the secret specified in spec.tls.secretName. If the secret does not exist, it creates and stores a new one.

When the certificate issuance completes normally, you can query the certificate with the Ready = True state as shown below.

certificate

This completes the preparation to automatically create an SSL certificate each time an Ingress is created.

  1. kubed

What if you want to use a certificate you created earlier in a different namespace?

kubed synchronizes configmaps/secrets between clusters or namespaces.

kubed (Source: https://cert-manager.io/docs/)

Install kubed with Helm

helm repo add appscode https://charts.appscode.com/stable/
helm install dp3-kubed appscode/kubed --namespace dp3-ingress-basic \
--set config.clusterName=demo-cluster-001 \
--set apiserver.enabled=false

helm

And to share the secret with the ns where harbor will be installed, label the current ns. (I applied the label “app=dp3”.)

kubectl label ns dp3-ingress-basic app=dp3

harbor label

Annotate the secret to be shared with other namespaces.

kubectl annotate secret tls-secret -n dp3-ingress-basic kubed.appscode.com/sync="app=dp3"

secret


Install harbor with Helm

helm repo add harbor https://helm.goharbor.io
helm install dp3-harbor -n dp3-harbor harbor/harbor \
--set expose.ingress.hosts.core=harbor.example.com \
--set persistence.enabled=true \
--set externalURL=https://harbor.example.com

Verify the created resources

helm resource

3rd-party components such as chartmuseum, notary, and trivy were also installed. The function of each component is as follows.

- notary : a tool for managing Docker image signatures - redis : data caching, job metadata cache - postgresql : stores backend storage data - Clair : container vulnerability analysis - trivy : container vulnerability analysis - jobservice : used for image replication based on work that can queue and process background jobs - chartmuseum: helm chart repository

Modify the host in the ingress and access harbor.example.com in the browser.

harbor main


Create a Client in the demo Realm.

realm

Enter the domain to integrate with Keycloak in the Root URL and Save.

Next, enter Settings

keycloak setting

setting detail

In Client Setting, set Access Type = confidential and then go to the Credentials tab,

credentials

You can see that a Secret uuid was generated as shown above!

We will proceed with the integration using this Client Id and Secret

After connecting with the Harbor administrator account, select Configuration from the left menu.

Here, enter auth mode=OIDC, provider=keycloak, endpoint= the keycloak domain

and enter the client id and secret you verified earlier in keycloak.

configuration

oidc verified

harbor main oidc

A LOGIN VIA OIDC PROVIDER button was created. Now you can access Harbor through your Keycloak account.

Now, for per-user (or per-group) access control via Keycloak accounts,

we will verify whether the user created in keycloak can be controlled through the Harbor UI, and also test CLI login and docker events.

First, enter the Realm of the keycloak integrated with harbor, select the Users menu, and press the Add user button.

keycloack user

Create one appropriately. After creating the user by pressing the Save button, enter the Credentials tab.

keycloak user credential

Enter password / confirmation and press the “Set Password” button. Next, enter the Role Mappings tab.

role mappings

In the Client Roles combo box, select the client connected to harbor, and map the Role.

Now that a User has been appropriately created, press the “Login via OIDC Provider” button in the Harbor Web UI to log in.

harbor login

After changing the password, a window appears to enter the OIDC username

set username

Once you enter this as well, you are logged in to harbor. Afterward, if you go in with the admin account, you can see that the account you just created appears in users.

harbor users

Now we will send a CLI command as that user.

Connect again as the user you created earlier and click the OIDC username in the top right to enter the User profile.

user profile

user profile detail

Copy the CLI secret and attempt docker login [YOUR_DOMAIN].

docker login harbor2.example.com

Log in with the OIDC username and CLI secret configured in harbor.

docker login


Among the features officially supported by Harbor, there is “Configuring Replication”.

This synchronizes resources (images, charts, etc.) between multiple registries.

When a Harbor system administrator configures a Replication Rule, all resources matching the defined filter pattern are replicated to the target registry when the trigger condition is met.

cf) However, in actual production environments, you often need to mirror to release tens or hundreds of cluster nodes. In this case, a single download registry cannot meet the demands of many nodes, so you configure multiple instance registries to perform load balancing.

harbor ha

As shown above, Harbor supports replication of various registries.

I configured one more harbor Registry in advance (harbor2), and registered the existing harbor’s endpoint in harbor2

harbor endpoint

Once you’ve registered the endpoint, enter the Replications menu and try creating a Rule.

harbor endpoint rule

You can see that the endpoint you just registered appears in the Destination registry (the registry to synchronize data to).

push-based and pull-based determine whether to replicate from another registry or replicate to another registry when replicating an artifact. (Official Harbor docs: Select Push-based or Pull-based replication, depending on whether you want to replicate artifacts to or from the remote registry.)

Once you’ve registered it this way, the data is synchronized with the existing harbor each time an image is pushed to harbor2 as shown below.

docker push

Image push to harbor2

sync

kmchoi-test was also pushed to the existing harbor.

However, registering the existing harbor Registry in harbor2 only means one-way synchronization from harbor2->harbor,

so if you want two-way synchronization, you must also create a Rule with the harbor2 Registry in harbor.


Enter Projects > Repo

In the Artifacts tab, select the desired image and click the SCAN button

harbor scanning

Once the scan is complete and you click the artifact, you can check the scan results as follows.

vulnerabilities

If you hover over Vulnerabilities, you can also check the vulnerability statistics.

vul severity