두 개의 도메인을 지원하는 Harbor 인증서 설정 및 테스트

2–3분

폐쇄망 환경에서 Harbor를 사용하여 컨테이너 이미지를 저장하고 관리하는 과정에서 두 개의 도메인을 동시에 사용할 수 있도록 설정한 사례를 공유합니다. 이 글에서는 각각의 도메인에 대해 인증서를 적용하고, 두 도메인을 활용해 Harbor 서비스를 제공하는 방법과 테스트 결과를 다룹니다.


테스트 개요

요구사항

  1. 하나의 Harbor 인스턴스에서 두 개의 도메인을 사용:
    • example1.com: 이미지 저장과 관리 용도.
    • example2.com: 추가적인 접근성 확보 및 활용성 테스트.
  2. 인증서를 각각의 도메인에 적용하여 HTTPS 통신을 지원.

테스트 목표

  • 두 도메인 모두에서 Web UI와 Docker Pull/Push 기능이 정상 동작하는지 확인.
  • Harbor의 외부 URL 설정과 다른 도메인 사용이 가능한지 검증.

1. 인증서 발급

Cert-Manager를 이용하여 두 도메인(example1.com, example2.com)에 대한 인증서를 클러스터 내부에서 발급합니다.

인증서 발급 YAML 설정

아래 YAML은 두 도메인에 대해 각각의 인증서를 발급하는 과정입니다.

# ClusterIssuer 생성
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: selfsigned-issuer
spec:
  selfSigned: {}

# 인증서 생성 - example1.com
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: selfsigned-example1-cert
  namespace: istio-system
spec:
  commonName: 'example1.com'
  dnsNames:
  - 'example1.com'
  issuerRef:
    kind: ClusterIssuer
    name: selfsigned-issuer
  secretName: selfsigned-example1-cert
  duration: 87600h

# 인증서 생성 - example2.com
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: selfsigned-example2-cert
  namespace: istio-system
spec:
  commonName: 'example2.com'
  dnsNames:
  - 'example2.com'
  issuerRef:
    kind: ClusterIssuer
    name: selfsigned-issuer
  secretName: selfsigned-example2-cert
  duration: 87600h



2. Gateway 설정

두 도메인을 HTTPS로 지원하기 위해 Istio Gateway를 설정합니다. 이 Gateway는 두 인증서를 각각의 도메인에 매핑하여 HTTPS 트래픽을 처리합니다.

Gateway 설정 YAML

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: harbor
  namespace: harbor
spec:
  selector:
    istio: gateway
  servers:
  - hosts:
    - example1.com
    - example2.com
    port:
      name: http
      number: 80
      protocol: HTTP2
    tls:
      httpsRedirect: true
  - hosts:
    - example1.com
    port:
      name: https-example1
      number: 443
      protocol: HTTPS
    tls:
      credentialName: selfsigned-example1-cert
      mode: SIMPLE
  - hosts:
    - example2.com
    port:
      name: https-example2
      number: 443
      protocol: HTTPS
    tls:
      credentialName: selfsigned-example2-cert
      mode: SIMPLE



3. VirtualService 설정

Harbor의 기본 VirtualService와 추가 VirtualService를 생성하여 두 도메인의 트래픽을 Harbor 서비스로 라우팅합니다.

기본 VirtualService 수정

Helm 설치 시 생성되는 기본 VirtualService의 spec.http.match 설정을 수정합니다.

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: harbor
  namespace: harbor
spec:
  gateways:
  - harbor
  hosts:
  - example1.com
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        host: harbor.harbor.svc.cluster.local
        port:
          number: 80


추가 VirtualService 생성

example2.com에 대한 VirtualService를 새로 추가합니다.

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: example2
  namespace: harbor
spec:
  gateways:
  - harbor
  hosts:
  - example2.com
  http:
  - match:
    - uri:
        prefix: /
    route:
    - destination:
        host: harbor.harbor.svc.cluster.local
        port:
          number: 80



4. CoreDNS 및 호스트 파일 설정

테스트 환경에서는 example2.com에 대한 도메인과 IP를 CoreDNS에 등록하였으며, 노드에서 직접 테스트 시 /etc/hosts 파일에 등록하여 도메인을 해석할 수 있도록 설정했습니다.

CoreDNS 설정 예제

example2.com 10.1.2.3

/etc/hosts 설정 예제

10.1.2.3 example2.com


5. Harbor 배포 옵션

테스트 결과, externalURLhttps://example1.com으로 설정된 상태에서도 example2.com을 통해 Harbor에 정상적으로 접근할 수 있었습니다. 단, HTTPS 설정 없이 HTTP로 접근할 경우 로그인 기능에 문제가 발생했습니다.

Helm 명령어 예시

helm install harbor helm/harbor \\
-n harbor --create-namespace \\
--set expose.tls.enabled=false \\
--set expose.type=clusterIP \\
--set externalURL=https://example1.com \\
--set persistence.enabled=true \\
--set trivy.enabled=false \\
--set persistence.persistentVolumeClaim.registry.size=200Gi



테스트 결과

설정을 완료한 후 두 도메인(example1.com, example2.com)에서 다음 작업이 모두 정상적으로 동작함을 확인했습니다:

  1. Web UI 접근 및 로그인
  2. Docker Pull/Push

참고: HTTPS를 통한 안전한 통신을 위해 모든 도메인에 대해 올바른 인증서를 적용해야 합니다.


결론

Harbor에서 두 개의 도메인을 사용하는 환경은 다음과 같은 경우 유용합니다:

  • 여러 팀이나 프로젝트가 별도의 도메인을 활용해야 할 때.
  • 기존 도메인 외에 추가 도메인이 필요한 경우.

이 글에서 다룬 설정 과정을 따라하면 두 도메인 모두에서 인증서를 적용한 안전한 Harbor 서비스를 제공할 수 있습니다.