InfoGrab Docs

IaC로 Kubernetes OIDC 조인 구성하기

요약

이 가이드에서는 Kubernetes 에이전트가 시크릿 토큰 없이 Teleport에 조인할 수 있도록 Teleport를 구성하는 방법을 알아봅니다. 이 가이드는 Kubernetes 조인 방법의 OIDC 변형을 사용합니다.

이 가이드에서는 Kubernetes 에이전트가 시크릿 토큰 없이 Teleport에 조인할 수 있도록 Teleport를 구성하는 방법을 알아봅니다. Teleport는 코드에서 리소스를 동적으로 생성하는 세 가지 방법을 지원합니다:

  • Kubernetes에서 Teleport 리소스를 관리할 수 있는 Teleport Kubernetes Operator
  • Terraform을 통해 Teleport 리소스를 관리할 수 있는 Teleport Terraform 프로바이더
  • 로컬 컴퓨터나 CI 환경에서 Teleport 리소스를 관리할 수 있는 tctl CLI

작동 방식#

이 가이드는 Kubernetes 조인 방법의 OIDC 변형을 사용합니다. 대부분의 Kubernetes 클러스터는 OpenID Connect(OIDC) 프로바이더를 사용하여 서비스 어카운트 토큰에 서명합니다.

이 가이드에서는 Kubernetes 클러스터에서 실행 중인 에이전트가 Kubernetes 발급 토큰을 사용하여 Teleport 클러스터에 조인할 수 있도록 Teleport를 구성합니다.

사전 요구 사항#

이 가이드를 따르려면 다음이 필요합니다:

  • v18.1.5 이상을 실행 중인 Teleport 클러스터
  • 등록하려는 Kubernetes 클러스터로, 서비스 어카운트 토큰이 공개적으로 접근 가능한 OIDC 프로바이더에 의해 서명되어야 합니다.
Note

클라우드 관리형 Kubernetes 클러스터는 기본적으로 공개 OIDC 프로바이더를 사용하거나, 클러스터 생성 시 구성할 수 있습니다:

클러스터 자체는 공개일 필요가 없으며, OIDC 프로바이더만 공개이면 됩니다.

  • A running Teleport cluster. If you want to get started with Teleport, sign up for a free trial or set up a demo environment.

  • The tctl and tsh clients.

    Installing `tctl` and `tsh` clients
    1. Determine the version of your Teleport cluster. The tctl and tsh clients must be at most one major version behind your Teleport cluster version. Send a GET request to the Proxy Service at /v1/webapi/find and use a JSON query tool to obtain your cluster version. Replace with the web address of your Teleport Proxy Service:

      $ TELEPORT_DOMAIN=
      $ TELEPORT_VERSION="$(curl -s https://$TELEPORT_DOMAIN/v1/webapi/find | jq -r '.server_version')"
      
    2. Follow the instructions for your platform to install tctl and tsh clients:

다음 중 하나를 따라 실행 중인 오퍼레이터:

오퍼레이터를 배포한 네임스페이스도 설정해야 합니다. 이 네임스페이스가 CustomResources를 배포하는 곳입니다:

# `teleport-cluster` Helm 차트로 배포된 오퍼레이터의 경우
$ export OPERATOR_NAMESPACE="teleport-cluster"

# 독립 실행형 오퍼레이터의 경우
$ export OPERATOR_NAMESPACE="teleport-iac"

Terraform 프로바이더 가이드를 따라 Teleport Terraform 프로바이더를 작동 중인 상태로 준비합니다.

1/4단계. OIDC 프로바이더 URL 감지#

이 단계에서는 클러스터에 연결하고 OIDC 프로바이더 URL을 복구합니다. 이미 클러스터의 OIDC 프로바이더 URL이 있는 경우(예: 클러스터 프로비저닝의 출력으로) 2단계로 건너뛸 수 있습니다.

접근 권한이 있는지 확인합니다:

$ kubectl cluster-info

Kubernetes control plane is running at https://kube.example.com:443
CoreDNS is running at https://kube.example.com:443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://kube.example.com:443/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

OIDC 구성 엔드포인트의 issuer 필드에서 OIDC 발급자 URL을 가져옵니다:

$ kubectl get --raw=/.well-known/openid-configuration

{"issuer":"",
"jwks_uri":"https://kube.example.com:443/openid/v1/jwks","response_types_supported":["id_token"],
"subject_types_supported":["public"],"id_token_signing_alg_values_supported":["RS256"]}

위의 예에서는 입니다.

Warning

발급자 URL은 URL 끝의 / 유무를 포함하여 정확하게 복사해야 합니다.

다음 명령을 실행하여 OIDC 프로바이더가 공개적으로 접근 가능한지 확인하고 JSON이 반환되는지 확인합니다:

$ curl .well-known/openid-configuration

{
  "issuer": "",
  "jwks_uri": "openid/v1/jwks",
  "response_types_supported": [
    "id_token"
  ],
  "subject_types_supported": [
    "public"
  ],
  "id_token_signing_alg_values_supported": [
    "RS256"
  ]
}

2/4단계. 조인 토큰 생성#

이 단계에서는 Kubernetes OIDC 프로바이더가 서명한 토큰을 신뢰하도록 Teleport를 구성합니다. 이를 통해 이 Kubernetes 클러스터에서 실행 중인 에이전트가 Teleport 클러스터에 조인할 수 있습니다.

Note

토큰 이름은 신뢰하는 Kubernetes 클러스터의 이름을 따르는 것을 권장합니다. 이를 통해 토큰 이름 충돌 없이 다른 클러스터를 등록할 수 있습니다.

매니페스트 작성#

토큰을 생성할 때 미래 에이전트 네임스페이스()와 에이전트 릴리즈 이름()을 지정해야 합니다. 이를 통해 Teleport는 에이전트가 조인할 수 있는지 확인합니다.

다음 내용으로 token.yaml 파일을 생성합니다:

kind: token
version: v2
metadata:
  name:  name="kube-cluster-name"/>-oidc
spec:
  roles: ['Kube']
  join_method: "kubernetes"
  kubernetes:
    type: oidc
    oidc:
      issuer: "https://oidc.example.com/path/to/issuer/"/>"
    allow:
      - service_account: "teleport"/>: name="teleport-agent"/>"

다음 내용으로 token.yaml 파일을 생성합니다:

apiVersion: resources.teleport.dev/v1
kind: TeleportProvisionToken
metadata:
  name:  name="kube-cluster-name"/>-oidc
spec:
  roles: ['Kube']
  join_method: "kubernetes"
  kubernetes:
    type: oidc
    oidc:
      issuer: "https://oidc.example.com/path/to/issuer/"/>"
    allow:
      - service_account: "teleport"/>: name="teleport-agent"/>"
Note

Kubernetes는 모든 커스텀 리소스 이름이 RFC 1123을 따르도록 검증합니다. RFC 1123에는 호스트명 사양이 포함됩니다. 따라서 오퍼레이터가 제어하는 Teleport 리소스의 metadata.name 필드는 소문자 영숫자, - 또는 .로 구성되고 영숫자로 시작하고 끝나야 합니다.

다음 내용으로 token.tf 파일을 생성합니다:

resource "teleport_provision_token" "" {
  version = "v2"
  metadata = {
    name = "-oidc"
  }

  spec = {
    roles = ["Kube"]
    join_method = "kubernetes"
    kubernetes = {
      type = "oidc"
      oidc = {
        issuer = ""
      }
      allow = [
        {
          service_account = ":"
        }
      ]
    }
  }
}

매니페스트 적용#

$ tctl create -f token.yaml
token '-oidc' has been created
$ kubectl apply -n "$OPERATOR_NAMESPACE" -f token.yaml

teleportprovisiontokenv2.resources.teleport.dev/-oidc created

생성된 Kubernetes 리소스를 나열합니다:

$ kubectl get teleportprovisiontokenv2 -n "$OPERATOR_NAMESPACE"

NAME                                  AGE
-oidc   10m
$ terraform plan
[...]
Plan: 1 to add, 0 to change, 0 to destroy.

$ terraform apply
teleport_provision_token.-oidc: Creating...
teleport_provision_token.-oidc: Creation complete after 0s [id=-oidc]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

3/4단계. 에이전트 구성#

이 단계에서는 에이전트가 이전에 생성한 토큰을 사용하여 조인하도록 teleport-kube-agent Helm 차트 구성을 작성합니다.

다음 정보가 필요합니다:

  • Teleport 클러스터 주소:
  • Teleport 클러스터 이름:
  • 연결하는 Kubernetes 클러스터 이름:

다음 values.yaml YAML 매니페스트를 작성합니다.

roles: "kube"
proxyAddr:  name="teleport.example.com:443"/>
# Teleport Community Edition 또는 AGPL을 사용하는 경우 false로 설정
enterprise: true
updater:
  enabled: true
joinParams:
  method: "kubernetes"
  tokenName:  name="kube-cluster-name"/>-oidc
kubeClusterName:  name="kube-cluster-name"/>
teleportClusterName:  name="teleport.example.com"/>

4/4단계. 에이전트 배포#

이 단계에서는 이전에 작성한 values를 사용하여 teleport-kube-agent 차트의 릴리즈를 배포합니다.

Configure Helm to fetch Teleport charts from the Teleport Helm repository:

$ helm repo add teleport (=teleport.helm_repo_url=)

Refresh the local Helm cache by fetching the latest charts:

$ helm repo update

마지막으로 프로비전 토큰에서 이전에 설정한 values를 사용하여 Teleport Kubernetes 에이전트를 배포합니다:

  • 에이전트를 배포할 네임스페이스:
  • Teleport 에이전트 릴리즈 이름:
$ helm upgrade --install  teleport/teleport-kube-agent \
  --namespace  --create-namespace \
  --version (=teleport.version=) \
  --values values.yaml

파드 준비 상태를 확인하여 에이전트가 클러스터에 성공적으로 조인했는지 검증합니다(몇 분 정도 걸릴 수 있습니다):

$ kubectl get pods -n 

NAME                                     READY   STATUS    RESTARTS   AGE
-0                         1/1     Running   0          9s
-updater-6b8b74996-jz4qg   1/1     Running   0          15s

다음 단계#

지원되는 values 목록은 teleport-kube-agent Helm 차트 참조를 참조하세요.

IaC로 Kubernetes OIDC 조인 구성하기

원문 보기
요약

이 가이드에서는 Kubernetes 에이전트가 시크릿 토큰 없이 Teleport에 조인할 수 있도록 Teleport를 구성하는 방법을 알아봅니다. 이 가이드는 Kubernetes 조인 방법의 OIDC 변형을 사용합니다.

이 가이드에서는 Kubernetes 에이전트가 시크릿 토큰 없이 Teleport에 조인할 수 있도록 Teleport를 구성하는 방법을 알아봅니다. Teleport는 코드에서 리소스를 동적으로 생성하는 세 가지 방법을 지원합니다:

  • Kubernetes에서 Teleport 리소스를 관리할 수 있는 Teleport Kubernetes Operator
  • Terraform을 통해 Teleport 리소스를 관리할 수 있는 Teleport Terraform 프로바이더
  • 로컬 컴퓨터나 CI 환경에서 Teleport 리소스를 관리할 수 있는 tctl CLI

작동 방식#

이 가이드는 Kubernetes 조인 방법의 OIDC 변형을 사용합니다. 대부분의 Kubernetes 클러스터는 OpenID Connect(OIDC) 프로바이더를 사용하여 서비스 어카운트 토큰에 서명합니다.

이 가이드에서는 Kubernetes 클러스터에서 실행 중인 에이전트가 Kubernetes 발급 토큰을 사용하여 Teleport 클러스터에 조인할 수 있도록 Teleport를 구성합니다.

사전 요구 사항#

이 가이드를 따르려면 다음이 필요합니다:

  • v18.1.5 이상을 실행 중인 Teleport 클러스터
  • 등록하려는 Kubernetes 클러스터로, 서비스 어카운트 토큰이 공개적으로 접근 가능한 OIDC 프로바이더에 의해 서명되어야 합니다.
Note

클라우드 관리형 Kubernetes 클러스터는 기본적으로 공개 OIDC 프로바이더를 사용하거나, 클러스터 생성 시 구성할 수 있습니다:

클러스터 자체는 공개일 필요가 없으며, OIDC 프로바이더만 공개이면 됩니다.

  • A running Teleport cluster. If you want to get started with Teleport, sign up for a free trial or set up a demo environment.

  • The tctl and tsh clients.

    Installing `tctl` and `tsh` clients
    1. Determine the version of your Teleport cluster. The tctl and tsh clients must be at most one major version behind your Teleport cluster version. Send a GET request to the Proxy Service at /v1/webapi/find and use a JSON query tool to obtain your cluster version. Replace with the web address of your Teleport Proxy Service:

      $ TELEPORT_DOMAIN=
      $ TELEPORT_VERSION="$(curl -s https://$TELEPORT_DOMAIN/v1/webapi/find | jq -r '.server_version')"
      
    2. Follow the instructions for your platform to install tctl and tsh clients:

다음 중 하나를 따라 실행 중인 오퍼레이터:

오퍼레이터를 배포한 네임스페이스도 설정해야 합니다. 이 네임스페이스가 CustomResources를 배포하는 곳입니다:

# `teleport-cluster` Helm 차트로 배포된 오퍼레이터의 경우
$ export OPERATOR_NAMESPACE="teleport-cluster"

# 독립 실행형 오퍼레이터의 경우
$ export OPERATOR_NAMESPACE="teleport-iac"

Terraform 프로바이더 가이드를 따라 Teleport Terraform 프로바이더를 작동 중인 상태로 준비합니다.

1/4단계. OIDC 프로바이더 URL 감지#

이 단계에서는 클러스터에 연결하고 OIDC 프로바이더 URL을 복구합니다. 이미 클러스터의 OIDC 프로바이더 URL이 있는 경우(예: 클러스터 프로비저닝의 출력으로) 2단계로 건너뛸 수 있습니다.

접근 권한이 있는지 확인합니다:

$ kubectl cluster-info

Kubernetes control plane is running at https://kube.example.com:443
CoreDNS is running at https://kube.example.com:443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://kube.example.com:443/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

OIDC 구성 엔드포인트의 issuer 필드에서 OIDC 발급자 URL을 가져옵니다:

$ kubectl get --raw=/.well-known/openid-configuration

{"issuer":"",
"jwks_uri":"https://kube.example.com:443/openid/v1/jwks","response_types_supported":["id_token"],
"subject_types_supported":["public"],"id_token_signing_alg_values_supported":["RS256"]}

위의 예에서는 입니다.

Warning

발급자 URL은 URL 끝의 / 유무를 포함하여 정확하게 복사해야 합니다.

다음 명령을 실행하여 OIDC 프로바이더가 공개적으로 접근 가능한지 확인하고 JSON이 반환되는지 확인합니다:

$ curl .well-known/openid-configuration

{
  "issuer": "",
  "jwks_uri": "openid/v1/jwks",
  "response_types_supported": [
    "id_token"
  ],
  "subject_types_supported": [
    "public"
  ],
  "id_token_signing_alg_values_supported": [
    "RS256"
  ]
}

2/4단계. 조인 토큰 생성#

이 단계에서는 Kubernetes OIDC 프로바이더가 서명한 토큰을 신뢰하도록 Teleport를 구성합니다. 이를 통해 이 Kubernetes 클러스터에서 실행 중인 에이전트가 Teleport 클러스터에 조인할 수 있습니다.

Note

토큰 이름은 신뢰하는 Kubernetes 클러스터의 이름을 따르는 것을 권장합니다. 이를 통해 토큰 이름 충돌 없이 다른 클러스터를 등록할 수 있습니다.

매니페스트 작성#

토큰을 생성할 때 미래 에이전트 네임스페이스()와 에이전트 릴리즈 이름()을 지정해야 합니다. 이를 통해 Teleport는 에이전트가 조인할 수 있는지 확인합니다.

다음 내용으로 token.yaml 파일을 생성합니다:

kind: token
version: v2
metadata:
  name:  name="kube-cluster-name"/>-oidc
spec:
  roles: ['Kube']
  join_method: "kubernetes"
  kubernetes:
    type: oidc
    oidc:
      issuer: "https://oidc.example.com/path/to/issuer/"/>"
    allow:
      - service_account: "teleport"/>: name="teleport-agent"/>"

다음 내용으로 token.yaml 파일을 생성합니다:

apiVersion: resources.teleport.dev/v1
kind: TeleportProvisionToken
metadata:
  name:  name="kube-cluster-name"/>-oidc
spec:
  roles: ['Kube']
  join_method: "kubernetes"
  kubernetes:
    type: oidc
    oidc:
      issuer: "https://oidc.example.com/path/to/issuer/"/>"
    allow:
      - service_account: "teleport"/>: name="teleport-agent"/>"
Note

Kubernetes는 모든 커스텀 리소스 이름이 RFC 1123을 따르도록 검증합니다. RFC 1123에는 호스트명 사양이 포함됩니다. 따라서 오퍼레이터가 제어하는 Teleport 리소스의 metadata.name 필드는 소문자 영숫자, - 또는 .로 구성되고 영숫자로 시작하고 끝나야 합니다.

다음 내용으로 token.tf 파일을 생성합니다:

resource "teleport_provision_token" "" {
  version = "v2"
  metadata = {
    name = "-oidc"
  }

  spec = {
    roles = ["Kube"]
    join_method = "kubernetes"
    kubernetes = {
      type = "oidc"
      oidc = {
        issuer = ""
      }
      allow = [
        {
          service_account = ":"
        }
      ]
    }
  }
}

매니페스트 적용#

$ tctl create -f token.yaml
token '-oidc' has been created
$ kubectl apply -n "$OPERATOR_NAMESPACE" -f token.yaml

teleportprovisiontokenv2.resources.teleport.dev/-oidc created

생성된 Kubernetes 리소스를 나열합니다:

$ kubectl get teleportprovisiontokenv2 -n "$OPERATOR_NAMESPACE"

NAME                                  AGE
-oidc   10m
$ terraform plan
[...]
Plan: 1 to add, 0 to change, 0 to destroy.

$ terraform apply
teleport_provision_token.-oidc: Creating...
teleport_provision_token.-oidc: Creation complete after 0s [id=-oidc]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

3/4단계. 에이전트 구성#

이 단계에서는 에이전트가 이전에 생성한 토큰을 사용하여 조인하도록 teleport-kube-agent Helm 차트 구성을 작성합니다.

다음 정보가 필요합니다:

  • Teleport 클러스터 주소:
  • Teleport 클러스터 이름:
  • 연결하는 Kubernetes 클러스터 이름:

다음 values.yaml YAML 매니페스트를 작성합니다.

roles: "kube"
proxyAddr:  name="teleport.example.com:443"/>
# Teleport Community Edition 또는 AGPL을 사용하는 경우 false로 설정
enterprise: true
updater:
  enabled: true
joinParams:
  method: "kubernetes"
  tokenName:  name="kube-cluster-name"/>-oidc
kubeClusterName:  name="kube-cluster-name"/>
teleportClusterName:  name="teleport.example.com"/>

4/4단계. 에이전트 배포#

이 단계에서는 이전에 작성한 values를 사용하여 teleport-kube-agent 차트의 릴리즈를 배포합니다.

Configure Helm to fetch Teleport charts from the Teleport Helm repository:

$ helm repo add teleport (=teleport.helm_repo_url=)

Refresh the local Helm cache by fetching the latest charts:

$ helm repo update

마지막으로 프로비전 토큰에서 이전에 설정한 values를 사용하여 Teleport Kubernetes 에이전트를 배포합니다:

  • 에이전트를 배포할 네임스페이스:
  • Teleport 에이전트 릴리즈 이름:
$ helm upgrade --install  teleport/teleport-kube-agent \
  --namespace  --create-namespace \
  --version (=teleport.version=) \
  --values values.yaml

파드 준비 상태를 확인하여 에이전트가 클러스터에 성공적으로 조인했는지 검증합니다(몇 분 정도 걸릴 수 있습니다):

$ kubectl get pods -n 

NAME                                     READY   STATUS    RESTARTS   AGE
-0                         1/1     Running   0          9s
-updater-6b8b74996-jz4qg   1/1     Running   0          15s

다음 단계#

지원되는 values 목록은 teleport-kube-agent Helm 차트 참조를 참조하세요.