본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

istio-csr 설치

원문 보기 위키 갱신

설치 단계

이 가이드에서는 istio-csr를 처음부터 설치하고 사용하는 과정을 자세히 다룰게요. 로컬 Docker에 새 클러스터를 만들기 위해 kind (https://kind.sigs.k8s.io/)를 사용하지만, 관련 Istio Platform Setup (https://istio.io/latest/docs/setup/platform-setup/)이 수행되어 있다면 모든 클러스터에서 이 가이드가 동작해야 해요.

OpenShift용 Platform Setup 가이드를 따르고 있다면 해당 가이드에 있는 istioctl install 명령은 실행하지 마세요. 우리는 나중에 자체 명령을 실행할 거예요.

0. 배경

지원되는 Istio 버전

istio-csr는 Istio 버전의 일부 하위 집합에 대해서만 테스트되며, 오래된 Istio 버전은 일반적으로 상위에서 지원 종료(EOL)에 도달하면 테스트에서 제외됩니다.

그렇긴 하지만 대부분의 Istio 버전은 대부분의 istio-csr 버전과 잘 동작하고, istio-csr는 지원되는 Istio 버전에 대해 호환성을 정기적으로 테스트하며 항상 최신 Istio 릴리스(Istio 사전 릴리스 포함)에 대해서도 테스트됩니다.

또한 다음 사항에 유의하세요:

  • Istio Ambient 지원에는 istio-csr v0.12.0 이상이 필요합니다

  • Istio 버전 1.24 이상에는 istio-csr v0.13.0 이상이 필요합니다

Issuer 구성

istio-csr는 cert-manager를 사용해 Istio 인증서를 발급하며, 이를 위해 issuer 리소스를 참조할 수 있어야 해요.

Helm 차트로 설치할 때 issuer를 구성하거나, 감시할 ConfigMap을 구성해 런타임에 issuer를 구성할 수 있습니다.

issuer 정보용 ConfigMap을 구성하는 것을 "런타임 구성(runtime configuration)"이라고 하며, Helm 차트에 issuer가 지정되지 않은 경우 필수입니다.

차트에서 issuer를 구성하면 istio-csr 포드가 온라인 상태가 되는 즉시 발급을 시작할 수 있지만, cert-manager를 이미 설치하고 issuer를 만들어 두어야 해요.

차트에 issuer를 설정하지 않으면 런타임 구성으로 issuer가 지정될 때까지 istio-csr은 ready 상태가 되지 않지만, cert-manager와 istio-csr을 동시에 설치할 수 있게 됩니다.

차트에는 기본 issuer 이름이 포함되어 있으므로 런타임 구성 사용에는 명시적 선택(opt-in)이 필요하다는 점에 유의하세요. 아래 가이드는 issuer를 구성한 후 런타임 구성 없이 istio-csr을 설치한다고 가정합니다. 런타임 구성에 대한 메모는 아래에 있습니다.

Istio Ambient

v0.12.0부터 istio-csr는 Istio Ambient 모드를 지원합니다. 이를 통해 사이드카 컨테이너 없이도 포드를 Istio 메시에 포함시킬 수 있어요.

Istio Ambient 모드 지원을 활성화하려면 app.server.caTrustedNodeAccounts Helm 값을 전달하세요. 이 값은 노드 인증을 사용할 수 있는 서비스 계정을 나타내는 namespace/service-accounts 값의 쉼표로 구분된 목록입니다.

예를 들면 --set app.server.caTrustedNodeAccounts=istio-system/ztunnel이죠.

1. 초기 설정

머신에 다음 도구가 설치되어 있어야 해요:

또한 클러스터에 Istio가 이미 설치되어 있으면 안 됩니다. Istio 설치 후에 istio-csr을 설치하는 것은 지원되지 않습니다.

2. 클러스터 생성 및 cert-manager 설치

Kind는 kubectl이 새로 생성된 클러스터를 가리키도록 자동으로 설정합니다.

여기서는 helm (https://cert-manager.io/docs/installation/helm/)으로 cert-manager를 설치하지만, 선호하는 방법이 있다면 어떤 방식으로든 설치할 수 있어요.

kind create cluster

# Helm setup
# install cert-manager; this might take a little time
helm install \
  cert-manager oci://quay.io/jetstack/charts/cert-manager \
  --namespace cert-manager \
  --create-namespace \
  --version v1.21.2 \
  --set crds.enabled=true

# We need this namespace to exist since our cert will be placed there
kubectl create namespace istio-system

3. cert-manager Issuer와 발급 Certificate 만들기

Issuer는 cert-manager에 인증서를 발급하는 방법을 알려줘요. 구성이 정말 간단하기 때문에 클러스터에 자체 서명 루트 CA를 만들겠습니다.

로컬에서 생성한 루트 인증서를 사용하는 방식은 프로덕션 배포에서도 동작하지만, cert-manager에는 사용할 수 있는 다른 여러 issuer (https://cert-manager.io/docs/configuration/)도 있습니다. ACME issuer는 발급된 인증서에 필요한 필드를 추가할 수 없어서 동작하지 않는다는 점에 유의하세요.

약간 더 자세한 내용을 제공하는 example-issuer (https://github.com/cert-manager/website/blob/7f5b2be9dd67831574b9bde2407bed4a920b691c/content/docs/tutorials/istio-csr/example/example-issuer.yaml)에도 몇 가지 주석이 있어요. 또한 이 가이드는 Issuer만 사용하고 ClusterIssuer는 사용하지 않는다는 점에 유의하세요 — ClusterIssuer를 사용하는 것은 그대로 대체(drop-in)할 수 없고, 어떤 경우든 프로덕션 배포에는 더 쉬운 접근 제어와 범위 지정을 위해 Issuers를 권장합니다.

kubectl apply -f https://raw.githubusercontent.com/cert-manager/website/7f5b2be9dd67831574b9bde2407bed4a920b691c/content/docs/tutorials/istio-csr/example/example-issuer.yaml

4. 루트 CA를 로컬 파일로 내보내기

Istio가 루트 CA를 자동으로 "발견"하도록 구성하는 것도 가능하지만, 이는 서명자 하이재킹 공격 (https://github.com/cert-manager/istio-csr/issues/103#issuecomment-923882792)을 가능하게 하는 다른 보안 취약점이 있는 특정 시나리오에서는 위험할 수 있어요.

따라서 루트 CA를 내보내고 나중에 그 정적 인증서를 사용해 Istio를 구성하겠습니다.

# Export our cert from the secret it's stored in, and base64 decode to get the PEM data.
kubectl get -n istio-system secret istio-ca -ogo-template='{{index .data "tls.crt"}}' | base64 -d > ca.pem

# Out of interest, we can check out what our CA looks like
openssl x509 -in ca.pem -noout -text

# Add our CA to a secret
kubectl create secret generic -n cert-manager istio-root-ca --from-file=ca.pem=ca.pem

5. istio-csr 설치

istio-csr는 Helm으로 설치하는 것이 가장 좋으며, 설치가 간단하고 빠를 거예요. helm 차트에는 여기 (/docs/usage/istio-csr/)에서 확인할 수 있는 여러 다른 구성 옵션이 있습니다.

# We set a few helm template values so we can point at our static root CA
helm upgrade cert-manager-istio-csr oci://quay.io/jetstack/charts/cert-manager-istio-csr \
  --install \
  --namespace cert-manager \
  --wait \
  --set "app.tls.rootCAFile=/var/run/secrets/istio-csr/ca.pem" \
  --set "volumeMounts[0].name=root-ca" \
  --set "volumeMounts[0].mountPath=/var/run/secrets/istio-csr" \
  --set "volumes[0].name=root-ca" \
  --set "volumes[0].secret.secretName=istio-root-ca"

# Check to see that the istio-csr pod is running and ready
kubectl get pods -n cert-manager
NAME                                       READY   STATUS    RESTARTS   AGE
cert-manager-aaaaaaaaaa-11111              1/1     Running   0          9m46s
cert-manager-cainjector-aaaaaaaaaa-22222   1/1     Running   0          9m46s
cert-manager-istio-csr-bbbbbbbbbb-00000    1/1     Running   0          63s
cert-manager-webhook-aaaaaaaaa-33333       1/1     Running   0          9m46s

6. Istio 설치

kind에서 실행하지 않는다면 Istio를 설치하기 전에 몇 가지 추가 설정 작업 (https://istio.io/latest/docs/setup/platform-setup/)이 필요할 수 있어요.

커스텀 IstioOperator 매니페스트로 구성된 istioctl CLI를 사용해 Istio를 설치합니다.

커스텀 매니페스트는 다음을 수행합니다:

  • istiod의 CA 서버를 비활성화하고,

  • Istio 워크로드가 istio-csr에 인증서를 요청하도록 보장하며,

  • istiod 인증서와 키가 istio-csr을 설치할 때 생성된 Certificate에서 마운트되도록 보장합니다.

먼저 데모 매니페스트를 다운로드한 다음 적용합니다.

curl -sSL https://raw.githubusercontent.com/cert-manager/website/7f5b2be9dd67831574b9bde2407bed4a920b691c/content/docs/tutorials/istio-csr/example/istio-config-getting-started.yaml > istio-install-config.yaml

잘 알고 있다면 istio-install-config.yaml을 검사하고 조정할 수 있지만, 이 매니페스트는 예제 목적상 그대로 동작해야 해요.

앞서 helm으로 istio-csr을 설치할 때 커스텀 app.tls.trustDomain을 설정했다면 그 값을 istio-install-config.yaml에도 반복해야 합니다.

이 마지막 명령이 Istio를 설치합니다. 정확한 명령은 플랫폼에 따라 다를 수 있으며 OpenShift에서는 확실히 다릅니다.

# This takes a little time to complete
istioctl install -f istio-install-config.yaml

# If you're on OpenShift, you need a different profile:
# istioctl install --set profile=openshift -f istio-install-config.yaml

Istio 프로필 선택을 확인하라는 입력 프롬프트가 표시될 거예요:

This will install the Istio 1.24.0 profile "demo" into the cluster. Proceed?

콘솔에 y를 입력해 선택을 확인하면 설치가 진행됩니다.

설치 검증

다음 단계는 선택 사항이지만 모든 것이 올바르게 연결되었는지 검증할 수 있어요:

  • 샘플 애플리케이션을 배포하고 certificaterequests.cert-manager.io 리소스를 확인

  • 새 certificaterequests와 응답에 대한 cert-manager 로그 확인

  • istio-proxy 사이드카 컨테이너에서 사용되는 CA Endpoint 확인

  • istioctl을 사용해 istio-proxy 컨테이너의 인증서 정보 가져오기

이 모든 것을 실제로 보려면 Istio 샘플 (https://github.com/istio/istio/tree/master/samples/httpbin)에서 아주 간단한 샘플 애플리케이션을 배포해 보겠습니다.

먼저 필요하면 값을 변경할 수 있는 몇 가지 환경 변수를 설정합니다:

# Set namespace for sample application
export NAMESPACE=default
# Set env var for the value of the app label in manifests
export APP=httpbin
# Grab the installed version of istio
export ISTIO_VERSION=$(istioctl version -o json | jq -r '.meshVersion[0].Info.version')

단순함을 위해 default 네임스페이스를 사용하므로 Istio 주입을 위해 네임스페이스에 레이블을 지정합니다:

kubectl label namespace $NAMESPACE istio-injection=enabled --overwrite

별도의 터미널에서 이제 cert-manager의 로그를 따라가세요:

kubectl logs -n cert-manager $(kubectl get pods -n cert-manager -o jsonpath='{.items..metadata.name}' --selector app=cert-manager) --since 2m -f

또 다른 별도 터미널에서 istio-system 네임스페이스의 certificaterequests를 살펴봅시다:

kubectl get certificaterequests.cert-manager.io -n istio-system -w

이제 레이블이 지정된 네임스페이스에 샘플 애플리케이션 httpbin을 배포하세요. 매니페스트 버전을 설치된 Istio 버전과 일치시키는 변수 사용에 유의하세요:

kubectl apply -n $NAMESPACE -f https://raw.githubusercontent.com/istio/istio/$ISTIO_VERSION/samples/httpbin/httpbin.yaml

certificaterequests에 대한 여기 출력과 비슷한 것을 볼 수 있을 거예요:

NAME             APPROVED   DENIED   READY   ISSUER       REQUESTOR                                         AGE
istio-ca-74bnl   True                True    selfsigned   system:serviceaccount:cert-manager:cert-manager   2d2h
istiod-w9zh6     True                True    istio-ca     system:serviceaccount:cert-manager:cert-manager   27m
istio-csr-8ddcs                               istio-ca     system:serviceaccount:cert-manager:cert-manager-istio-csr   0s
istio-csr-8ddcs   True                        istio-ca     system:serviceaccount:cert-manager:cert-manager-istio-csr   0s
istio-csr-8ddcs   True                True    istio-ca     system:serviceaccount:cert-manager:cert-manager-istio-csr   0s
istio-csr-8ddcs   True                True    istio-ca     system:serviceaccount:cert-manager:cert-manager-istio-csr   0s

예제 출력에서 핵심 요청은 istio-csr-8ddcs예요. cert-manager 로그 출력에서 이 요청이 "Approved"와 "Ready" 상태가 되는 두 개의 로그 줄을 확인해야 합니다:

I0113 16:51:59.186482       1 conditions.go:261] Setting lastTransitionTime for CertificateRequest "istio-csr-8ddcs" condition "Approved" to 2022-01-13 16:51:59.186455713 +0000 UTC m=+3507.098466775
I0113 16:51:59.258876       1 conditions.go:261] Setting lastTransitionTime for CertificateRequest "istio-csr-8ddcs" condition "Ready" to 2022-01-13 16:51:59.258837897 +0000 UTC m=+3507.170859959

이제 애플리케이션 컨테이너와 사이드카 둘 다와 함께 애플리케이션이 실행 중인 것을 볼 수 있어야 해요:

~ kubectl get pods -n $NAMESPACE
NAME                       READY   STATUS    RESTARTS   AGE
httpbin-74fb669cc6-559cg   2/2     Running   0           4m

istio-proxy 사이드카 컨테이너가 올바른 서비스에 인증서를 요청했는지 검증하려면 컨테이너 로그를 확인하세요:

kubectl logs $(kubectl get pod -n $NAMESPACE -o jsonpath="{.items...metadata.name}" --selector app=$APP) -c istio-proxy

이 예제와 비슷한 초기 로그를 볼 수 있을 거예요:

2022-01-13T16:51:58.495493Z	info	CA Endpoint cert-manager-istio-csr.cert-manager.svc:443, provider Citadel
2022-01-13T16:51:58.495817Z	info	Using CA cert-manager-istio-csr.cert-manager.svc:443 cert with certs: var/run/secrets/istio/root-cert.pem
2022-01-13T16:51:58.495941Z	info	citadelclient	Citadel client using custom root cert: var/run/secrets/istio/root-cert.pem

마지막으로 Envoy가 메모리에서 사용 중인 인증서를 검사할 수 있어요. 이 한 줄 명령이 사용 중인 인증서를 반환해야 합니다:

istioctl proxy-config secret $(kubectl get pods -n $NAMESPACE -o jsonpath='{.items..metadata.name}' --selector app=$APP) -o json | jq -r '.dynamicActiveSecrets[0].secret.tlsCertificate.certificateChain.inlineBytes' | base64 --decode | openssl x509 -text -noout

특히 다음 섹션을 찾으세요:

Signature Algorithm: ecdsa-with-SHA256
        Issuer: O=cert-manager, O=cluster.local, CN=istio-ca
        Validity
            Not Before: Jan 13 16:51:59 2022 GMT
            Not After : Jan 13 17:51:59 2022 GMT
...
            X509v3 Subject Alternative Name:
                URI:spiffe://cluster.local/ns/default/sa/httpbin

Issuer 안에서 관련 Trust Domain을 볼 수 있을 거예요. 기본 경우에는 위처럼 cluster.local이어야 합니다. 다른 네임스페이스나 애플리케이션을 사용했다면 SPIFFE URI는 다를 수 있다는 점에 유의하세요.

정리

kind에서 실행 중이라면 간단히 클러스터를 제거할 수 있어요:

kind delete cluster

런타임 구성으로 설치

런타임 구성으로 설치하는 옵션은 두 가지가 있어요:

  • cert-manager 다음에 설치하면서도 Helm 차트에 명시적 issuerRef를 계속 제공

  • Helm 차트에서 issuerRef를 비우고 순수 런타임 구성만 사용

두 옵션 모두 issuer를 가리키는 ConfigMap을 만들어야 합니다. 이 ConfigMap은 설치 전이나 후에 만들 수 있으며 istio-csr 포드와 같은 네임스페이스에 만들어야 해요.

ConfigMap 만들기

issuer 이름, kind, group을 지정하는 세 개의 키가 필요합니다. ConfigMap을 만드는 어떤 방법이든 작동해요. 예를 들어:

kubectl create configmap -n cert-manager istio-issuer \
  --from-literal=issuer-name=my-issuer-name \
  --from-literal=issuer-kind=ClusterIssuer \
  --from-literal=issuer-group=cert-manager.io

Helm 차트에는 원한다면 설치 시 런타임 구성 ConfigMap을 만들 수 있는 기능이 app.runtimeConfiguration.issuer 값으로 포함되어 있어요:

app:
  runtimeConfiguration:
    issuer:
      name: my-issuer-name
      kind: Issuer
      group: cert-manager.io

옵션 1: cert-manager 다음에 설치

cert-manager가 이미 설치되어 있다면 위와 같은 helm upgrade 명령을 사용하되 런타임 구성 ConfigMap의 이름도 지정할 수 있어요:

helm upgrade cert-manager-istio-csr oci://quay.io/jetstack/charts/cert-manager-istio-csr \
  --install \
  --namespace cert-manager \
  --wait \
  ...
  --set "app.runtimeConfiguration.name=istio-issuer"

이 시나리오에서 app.certmanager.issuer에 정의된 issuer는 시작 시와 istiod 인증서를 만드는 데 사용됩니다.

istio-csr이 런타임 ConfigMap을 감지하면 거기에 구성된 issuer를 사용해요. ConfigMap이 업데이트되면 istio-csr은 그 업데이트를 동적으로 존중합니다.

런타임 ConfigMap이 삭제되면 istio-csr은 app.certmanager.issuer의 값을 다시 사용하게 됩니다.

옵션 2: 순수 런타임 구성

순수 런타임 구성은 istio-csr v0.11.0 이상에서만 실용적입니다.

순수 런타임 구성에는 더 많은 값을 설정해야 해요:

  • app.certmanager.issuer 값은 비워야 합니다(차트에 기본값으로 설정되어 있으므로)

  • istiod 인증서는 istio-csr 리소스와 함께 프로비저닝되지 않아야 합니다. app.tls.istiodCertificateEnable=dynamic을 전달하면 istiod가 런타임 구성이 가능해질 때 동적으로 생성됩니다.

  • app.runtimeConfiguration.name이 설정되어야 합니다.

순수 런타임 구성용 values.yaml 파일 예시는 다음과 같아요:

app:
  runtimeIssuanceConfigMap: istio-issuer
  certmanager:
    issuer:
      enabled: false # Important: the default issuer is enabled by default
  tls:
    rootCAFile: "/var/run/secrets/istio-csr/ca.pem"
    istiodCertificateEnable: dynamic
volumeMounts:
- name: root-ca
  mountPath: /var/run/secrets/istio-csr
volumes:
- name: root-ca
  secret:
    secretName: istio-root-ca

이 파일은 다음 명령으로 사용할 수 있어요:

helm upgrade cert-manager-istio-csr oci://quay.io/jetstack/charts/cert-manager-istio-csr \
  --install \
  --namespace cert-manager \
  --wait \
  --values values.yaml

순수 런타임 설치 완료

istio-csr을 cert-manager 옆에 설치하기 더 쉽게 만들기 위해 순수 런타임 구성은 istio-csr의 상태 확인(health checks) 동작을 약간 수정합니다. Helm은 상태 확인이 통과될 때까지 설치는 완료하지 않기 때문이에요.

순수 런타임 구성일 때만, istio-csr의 상태 확인은 런타임 구성이 처음으로 사용 가능해질 때까지 healthy로 보고합니다.

런타임 구성이 처음으로 사용 가능해진 후에는 상태 확인이 정상 동작으로 되돌아갑니다.

사용법

📖 istio-csr 문서 (/docs/usage/istio-csr/)를 읽어 보세요.