InfoGrab Docs

Teleport로 Google Cloud API 접근 보호

요약

Teleport를 사용하여 Google Cloud의 API와 상호 작용하는 CLI 도구에 대한 접근을 관리할 수 있습니다. Teleport Application Service는 CLI 애플리케이션의 요청을 프록시하여 Google Cloud의 API에 대한 접근을 관리합니다.

Teleport를 사용하여 Google Cloud의 API와 상호 작용하는 CLI 도구에 대한 접근을 관리할 수 있습니다. 이를 통해 인프라 자체를 보호하는 데 사용하는 것과 동일한 RBAC 시스템을 사용하여 인프라의 관리 API에 대한 접근을 제어할 수 있습니다.

작동 방식#

Teleport Application Service는 CLI 애플리케이션의 요청을 프록시하여 Google Cloud의 API에 대한 접근을 관리합니다. Application Service는 Google Cloud에서 검색된 토큰을 사용하여 이러한 요청을 인증합니다. 이를 통해 Teleport 운영자는 사용자가 Google Cloud API와 상호 작용하기 위해 가장할 수 있는 서비스 계정을 제어할 수 있습니다.

Teleport Application Service는 역방향 터널을 통해 Teleport Proxy Service에 연결되므로, 프라이빗 네트워크에서 Application Service를 실행하고 조직의 Google Cloud 서비스 계정에 대한 무단 접근을 방지할 수 있습니다.

사전 요건#

  • 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:

  • IAM 역할 및 서비스 계정을 생성하고, 서비스 계정 및 프로젝트에 대한 IAM 역할 바인딩을 생성할 수 있는 권한을 가진 Google Cloud 계정.

  • gcloud CLI 도구. gcloud를 설치하고 인증하려면 Google Cloud 문서 페이지를 참고하세요.

    Tip

이 가이드는 gcloud에 초점을 맞추지만, Teleport로 Google Cloud API 접근을 설정하면 Teleport Application Service를 사용하여 다른 Google Cloud CLI 도구에 대한 접근도 관리할 수 있습니다.

기존 서비스 계정 사용

이 가이드에서는 Teleport 사용자가 인증할 수 있는 서비스 계정인 teleport-vm-viewer를 생성하여 Google Cloud CLI 접근을 시연합니다. Google Cloud 프로젝트의 기존 서비스 계정에 대한 접근을 활성화하려면, 가이드를 진행하면서 teleport-vm-viewer를 해당 계정으로 교체할 수 있습니다.

To check that you can connect to your Teleport cluster, sign in with tsh login, then verify that you can run tctl commands using your current credentials.

For example, run the following command, assigning to the domain name of the Teleport Proxy Service in your cluster and to your Teleport username:

$ tsh login --proxy= --user=
$ tctl status
# Cluster  (=teleport.url=)
# Version  (=teleport.version=)
# CA pin   (=presets.ca_pin=)

If you can connect to the cluster and run the tctl status command, you can use your current credentials to run subsequent tctl commands from your workstation. If you host your own Teleport cluster, you can also run tctl commands on the computer that hosts the Teleport Auth Service for full permissions.

1단계/4단계. Google Cloud 설정#

Teleport Application Service가 Teleport 사용자의 요청을 Google Cloud의 API로 프록시하려면 Google Cloud의 권한이 필요합니다. 이 단계에서는 Teleport Application Service를 시작하기 전에 이러한 권한을 설정합니다.

Teleport로 Google Cloud API 접근을 설정할 때, 두 가지 다른 기능을 가진 서비스 계정을 설정합니다:

Application Service를 위한 서비스 계정 생성#

Application Service는 제어 서비스 계정을 사용하여 대상 서비스 계정에 대한 서명된 토큰을 생성하고, Teleport 사용자의 요청을 Google Cloud로 전달하기 전에 서명하여 Google Cloud API에 접근합니다. 이런 방식으로 로컬 Google Cloud CLI 도구는 이러한 토큰에 접근할 수 없습니다.

이 섹션에서는 Application Service를 위한 제어 서비스 계정을 만들고 권한을 할당합니다.

teleport-google-cloud-cli라는 서비스 계정을 생성합니다:

$ gcloud iam service-accounts create teleport-google-cloud-cli \
  --description="Google Cloud CLI access" \
  --display-name="teleport-google-cloud-cli"

Teleport 사용자가 접근할 수 있는 서비스 계정 설정#

Teleport 사용자가 Teleport Application Service에 대해 Google Cloud CLI 명령을 실행하면, Application Service는 앞서 생성한 teleport-google-cloud-cli 서비스 계정을 사용하여 대상 서비스 계정을 가장합니다.

이 섹션에서는 Application Service에 대상 서비스 계정을 가장할 수 있는 권한을 부여하는 방법을 보여줍니다.

서비스 계정 생성 및 리소스 조회 활성화#

Tip

기존 서비스 계정에 대한 접근을 활성화하는 경우 다음 섹션으로 건너뛸 수 있습니다.

대상 서비스 계정을 생성합니다:

$ gcloud iam service-accounts create teleport-vm-viewer \
  --description="Sample service account to demonstrate Teleport" \
  --display-name="teleport-vm-viewer"

이 서비스 계정을 사전 정의된 "Compute Viewer" 역할에 바인딩합니다. 이 역할을 가진 사용자는 Google Compute Engine 리소스를 나열할 수 있습니다:

$ gcloud projects add-iam-policy-binding  \
   --member="serviceAccount:teleport-vm-viewer@.iam.gserviceaccount.com" \
   --role="roles/compute.viewer"

teleport-google-cloud-cli가 대상 서비스 계정을 가장하도록 활성화#

사용자 요청을 인증하기 위해 teleport-google-cloud-cli 서비스 계정이 teleport-vm-viewer를 가장할 수 있도록 활성화합니다. 이를 위해 teleport-vm-viewer 서비스 계정에 대해 teleport-google-cloud-cli 계정을 사전 정의된 "Service Account Token Creator Role"에 바인딩합니다:

Tip

기존 서비스 계정에 대한 Google Cloud CLI 접근을 활성화하려면 각 서비스 계정에 대해 이 명령을 실행해야 합니다.

$ gcloud iam service-accounts add-iam-policy-binding \
 teleport-vm-viewer@.iam.gserviceaccount.com \
 --member=serviceAccount:teleport-google-cloud-cli@.iam.gserviceaccount.com \
  --role="roles/iam.serviceAccountTokenCreator"

2단계/4단계. Teleport Application Service 배포#

이 시점에서 제어 서비스 계정을 생성하고 Teleport 사용자가 접근하려는 서비스 계정을 가장할 수 있도록 활성화했습니다.

이 단계에서는 제어 서비스 계정을 Google Compute Engine VM에 연결한 다음 Teleport Application Service를 실행합니다.

Application Service가 Google Cloud에 접근할 수 있도록 설정#

제어 서비스 계정을 생성하고 역할을 연결했으므로, Teleport Application Service를 실행하는 가상 머신과 서비스 계정을 연결합니다. 지침은 Teleport Application Service에 기존 가상 머신을 사용하는지 아니면 새 가상 머신을 시작하는지에 따라 다릅니다:

teleport-google-cloud 서비스 계정이 연결된 새 가상 머신을 생성합니다. 이 예시에서는 Debian 12를 지원하는 최신 머신 이미지를 사용합니다:

$ IMAGE=$(gcloud --format json compute images describe-from-family debian-12 --project debian-cloud | jq -r '.selfLink')
$ gcloud compute instances create teleport-app-service \
   --service-account=teleport-google-cloud-cli@.iam.gserviceaccount.com \
   --scopes=cloud-platform \
   --zone= \
   --image="$IMAGE"

여기에 나열된 대로 service-accountscopes 플래그를 사용해야 합니다. 그렇지 않으면 VM이 Google Cloud에 접근하는 데 필요한 인증을 얻지 못합니다. 나머지 플래그는 환경의 필요에 따라 조정하고 새 플래그를 추가해야 합니다.

서비스 계정을 연결하기 위해 VM을 중지합니다:

$ gcloud compute instances stop  --zone=

인스턴스에 서비스 계정을 연결합니다:

$ gcloud compute instances set-service-account  \
   --service-account teleport-google-cloud-cli@.iam.gserviceaccount.com \
   --zone  \
   --scopes=cloud-platform
Warning

gcloud compute instances set-service-account 명령에서 scopes 플래그를 사용해야 합니다. 그렇지 않으면 Google Cloud VM이 Google Cloud에 접근하는 데 필요한 인증을 얻지 못합니다.

서비스 계정을 연결한 후 VM을 다시 시작합니다:

$ gcloud compute instances start  --zone 

Get a join token#

Establish trust between your Teleport cluster and your new Application Service instance by creating a join token:

$ tctl tokens add --type=app --ttl=1h --format=text
(=presets.tokens.first=)

Assign to your token and, on the host where you will install the Teleport Application Service, run the following command to create a file called /tmp/token that consists only of your token:

$ echo  | sudo tee /tmp/token

Teleport Application Service 설치#

Teleport Application Service를 설치할 호스트에서 아래 지침을 따르세요.

To install a Teleport Agent on your Linux server:

The recommended installation method is the cluster install script. It will select the correct version, edition, and installation mode for your cluster.

  1. Assign to your Teleport cluster hostname and port, but not the scheme (https://).

  2. Run your cluster's install script:

    $ curl "https:///scripts/install.sh" | sudo bash
    

Teleport Application Service 설정#

Teleport Application Service를 실행할 호스트에서 다음 내용으로 /etc/teleport.yaml 파일을 생성합니다:

version: v3
teleport:
  join_params:
    token_name: "/tmp/token"
    method: token
  proxy_server: "teleport.example.com:443"
auth_service:
  enabled: false
proxy_service:
  enabled: false
ssh_service:
  enabled: false
app_service:
  enabled: true
  apps:
  - name: google-cloud-cli
    cloud: GCP

/etc/teleport.yaml을 편집하여 teleport.example.com:443을 Teleport Proxy Service 또는 Teleport Cloud 테넌트의 호스트 및 포트로 교체합니다(예: mytenant.teleport.sh:443).

app_service 필드는 Teleport Application Service를 설정합니다. app_service.apps 내의 각 항목은 애플리케이션 설정입니다.

위의 예에서, cloud 필드를 GCP로 설정하여 google-cloud-cli라는 애플리케이션을 등록함으로써 Google Cloud CLI 접근을 활성화했습니다. Teleport Application Service는 이 애플리케이션에 대한 요청을 Google Cloud로 전달합니다.

Teleport Application Service 실행#

Teleport Application Service를 실행할 호스트에서, Teleport를 패키지 관리자로 설치했는지 TAR 아카이브로 설치했는지에 따라 다음 명령을 실행합니다:

Configure the Teleport Application Service to start automatically when the host boots up by creating a systemd service for it. The instructions depend on how you installed the Teleport Application Service.

You can check the status of the Teleport Application Service with systemctl status teleport and view its logs with journalctl -fu teleport.

3단계/4단계. 사용자가 Google Cloud CLI에 접근할 수 있도록 설정#

다음 단계는 Teleport 사용자가 대상 서비스 계정에 접근하고 Teleport를 통해 Google Cloud CLI 명령을 실행할 수 있도록 권한을 부여하는 것입니다. 사용자의 역할이 접근할 수 있는 Google Cloud 서비스 계정을 결정하는 Teleport의 RBAC 시스템을 사용하여 서비스 계정에 대한 접근을 보호합니다.

사용자가 Google Cloud 서비스 계정에 접근할 수 있도록 권한을 부여하는 두 가지 접근 방식이 있습니다:

접근 방식 설명 지원되는 사용자 유형
동적 Teleport 역할에 사용자에게 직접 할당된 모든 Google Cloud 서비스 계정에 대한 접근 권한을 부여하는 템플릿 변수 포함. 로컬 사용자, OIDC, SAML
정적 Teleport 역할이 사용자가 가장할 수 있는 Google Cloud 서비스 계정을 명시적으로 지정. 로컬 사용자, OIDC, SAML, GitHub
Tip

Google Cloud 계정에 서비스 계정을 추가함에 따라 더 쉽게 확장할 수 있으므로 동적 접근 방식을 권장합니다. GitHub SSO를 통해 사용자를 인증하도록 오픈 소스 Teleport 클러스터를 설정한 경우, OAuth 기반 GitHub 애플리케이션은 사용자 정의 클레임을 지원하지 않으므로 정적 접근 방식을 사용해야 합니다.

동적 ID#

동적 ID를 사용하는 경우, 선택하는 접근 방식은 로컬 Teleport 사용자를 사용하는지 SSO Teleport 사용자를 사용하는지에 따라 다릅니다:

다음 내용으로 google-cloud-cli-access.yaml 파일을 생성합니다:

kind: role
version: v7
metadata:
  name: google-cloud-cli-access
spec:
  allow:
    app_labels:
      '*': '*'
    gcp_service_accounts:
      - '{{internal.gcp_service_accounts}}'

google-cloud-cli-access 역할을 가진 사용자가 Teleport를 통해 Google Cloud CLI에 인증하면, Teleport Auth Service는 {{internal.gcp_service_accounts}} 템플릿 변수를 사용자에게 할당된 Google Cloud 서비스 계정으로 채웁니다.

다음 명령을 실행하여 앞서 생성한 대상 서비스 계정(또는 다른 서비스 계정)을 Teleport 사용자에게 할당합니다. 를 Teleport 사용자 이름으로 설정합니다:

$ tctl users update  \
--set-gcp-service-accounts teleport-vm-viewer@.iam.gserviceaccount.com

이 명령은 --set-gcp-service-accounts 플래그를 사용하여 사용자에게 Google Cloud 서비스 계정을 추가합니다. --set-gcp-service-accounts를 쉼표로 구분된 서비스 계정 URI 목록으로 설정하여 사용자에게 여러 서비스 계정을 할당할 수 있습니다.

역할을 생성합니다:

$ tctl create -f google-cloud-cli-access.yaml

ID 제공자에서 gcp_service_accounts라는 사용자 정의 SAML 속성 또는 OIDC 클레임을 정의합니다. 각 사용자의 gcp_service_accounts 속성 또는 클레임은 다음 형식을 사용하는 Google Cloud 서비스 계정 URI 목록이어야 합니다:

<service_account_name>@<project_id>.iam.gserviceaccount.com

예를 들어, <project_id>를 Google Cloud 프로젝트 이름으로 교체하여 다음 URI를 사용해 사용자의 gcp_service_accountsteleport-vm-viewer로 설정할 수 있습니다:

teleport-vm-viewer@my-project.iam.gserviceaccount.com

다음 내용으로 google-cloud-cli-access.yaml 파일을 생성합니다:

kind: role
version: v7
metadata:
  name: google-cloud-cli-access
spec:
  allow:
    app_labels:
      '*': '*'
    gcp_service_accounts:
      - '{{external.gcp_service_accounts}}'

google-cloud-cli-access 역할을 가진 사용자가 Teleport를 통해 Google Cloud CLI에 인증하면, Teleport Auth Service는 {{external.gcp_service_accounts}} 템플릿 변수를 사용자에게 할당된 Google Cloud 서비스 계정으로 채웁니다.

역할을 생성합니다:

$ tctl create -f google-cloud-cli-access.yaml

정적 ID#

정적 ID를 사용하는 경우 다음 지침을 완료합니다.

특정 Google Cloud 서비스 계정에 대한 접근이 있는 역할을 정의합니다. 이는 이 역할을 맡은 Teleport 사용자가 해당(그리고 오직 그) ID만을 사용하여 Google Cloud CLI를 통해 명령을 실행할 수 있음을 의미합니다.

다음 내용으로 google-cloud-cli-access.yaml 파일을 생성합니다. gcp_service_accounts 값의 my-project를 Google Cloud 프로젝트 ID로 교체합니다:

kind: role
version: v7
metadata:
  name: google-cloud-cli-access
spec:
  allow:
    app_labels:
      '*': '*'
    gcp_service_accounts:
      - teleport-vm-viewer@my-project.iam.gserviceaccount.com

이 역할은 사용자에게 앞서 정의한 google-cloud-cli 애플리케이션과 같이 Teleport에 등록된 모든 애플리케이션에 대한 접근 권한을 부여하고, 사용자가 앞서 생성한 teleport-vm-viewer 서비스 계정을 가장할 수 있도록 합니다.

역할을 생성합니다:

$ tctl create -f google-cloud-cli-access.yaml
Google Cloud 서비스 계정에 대한 접근 거부

사용자가 하나 이상의 Google Cloud 서비스 계정에 접근하는 것을 거부하는 Teleport 역할을 정의할 수 있습니다. 이를 위해 role 리소스의 spec.deny 섹션 내 gcp_service_accounts 필드에 값을 할당합니다.

예를 들어, 이 역할은 사용자가 모든 Google Cloud 서비스 계정에 접근하는 것을 거부합니다:

kind: role
version: v7
metadata:
  name: "no-google-cloud"
spec:
  allow:
    app_labels:
      '*': '*'
  deny:
    gcp_service_accounts:
      - '*'

no-google-cloud 역할은 사용자가 등록된 모든 애플리케이션에 접근할 수 있도록 하지만, deny.gcp_service_accounts 필드 내의 와일드카드 문자(*)를 활용하여 사용자가 Google Cloud 서비스 계정을 가장하는 것을 방지합니다.

allow.gcp_service_accounts의 값과 달리, deny.gcp_service_accounts의 값은 특정 Google Cloud 서비스 계정 URI 외에도 와일드카드 표현식을 포함할 수 있습니다.

Teleport Auth Service는 사용자의 역할을 평가할 때 allow 규칙보다 deny 규칙을 우선시합니다.

Assign the google-cloud-cli-access role to your Teleport user by running the appropriate commands for your authentication provider:

4단계/4단계. Teleport로 Google Cloud CLI 사용#

Teleport Application Service를 시작하고 Teleport 사용자가 Google Cloud CLI에 접근할 수 있도록 권한을 부여했으므로, 이제 Teleport를 통해 Google Cloud CLI 명령을 실행할 수 있습니다.

Google Cloud CLI 애플리케이션 나열#

Teleport 사용자가 앞서 등록한 google-cloud-cli 애플리케이션을 볼 수 있는지 확인합니다:

$ tsh apps ls
Application      Description Type Public Address                        Labels
---------------- ----------- ---- ------------------------------------- -------------------
google-cloud-cli             HTTP google-cloud-cli.teleport.example.com teleport.dev/origin

Google Cloud CLI 사용을 위한 로그인#

teleport-vm-viewer 서비스 계정을 가장하도록 지정하여 애플리케이션에 로그인합니다:

$ tsh apps login google-cloud-cli --gcp-service-account teleport-vm-viewer

이 명령은 --gcp-service-account 플래그의 값을 사용자가 가장할 수 있도록 권한이 부여된 값과 비교하여 검증합니다. 플래그의 값은 서비스 계정의 전체 URI이거나 ID 이름(예: teleport-vm-viewer)일 수 있습니다.

사용자가 하나의 Google Cloud 서비스 계정에만 접근할 권한이 있는 경우 --gcp-service-account 플래그를 생략할 수 있지만, 그렇지 않으면 빈 --gcp-service-account 플래그는 오류를 발생시킵니다.

명령이 성공하면 다음과 유사한 사용자의 선택된 Google Cloud 서비스 계정에 대한 정보가 표시됩니다:

Logged into GCP app "google-cloud-cli".
Your service account: teleport-vm-viewer@my-project.iam.gserviceaccount.com
Example command: tsh gcloud compute instances list

Google Cloud CLI 명령 실행#

이 시점에서 tsh를 접두사로 사용하여 Teleport Application Service를 통해 gcloud 명령을 실행할 수 있습니다. 사용자가 VM을 나열할 수 있는 서비스 계정으로 Google Cloud CLI 애플리케이션에 인증했으므로, 예를 들어 이 명령을 실행하여 VM을 나열합니다:

$ tsh gcloud compute instances list

Google Cloud 프로젝트의 가상 머신 목록이 표시됩니다.

그러나 서비스 계정에 해당 권한이 없으므로 Teleport 사용자는 VM을 생성할 수 없습니다:

$ tsh gcloud compute instances create another-instance --zone=
ERROR: (gcloud.compute.instances.create) Could not fetch resource:
 - Required 'compute.instances.create' permission for 'projects/my-project/zones/my-zone/instances/another-instance'

ERROR: exit status 1

tsh 없이 Google Cloud CLI 애플리케이션 사용#

tsh를 통해 gcloud 명령을 실행하는 것 외에도, Google Cloud의 API에 대해 명령을 실행하는 모든 CLI 애플리케이션에 안전한 접근 권한을 부여할 수 있습니다.

이를 위해 tsh를 사용하여 CLI 애플리케이션에서 Teleport Application Service로 트래픽을 전달하는 로컬 프록시를 시작합니다. Application Service는 앞서 생성한 teleport-google-cloud-cli 서비스 계정을 사용하여 Google Cloud에서 인증 토큰을 가져옵니다. CLI 애플리케이션은 이 토큰을 사용하여 Google Cloud의 API에 대한 요청을 인증합니다.

로컬 프록시를 시작하려면 다음 tsh 명령을 실행합니다:

$ tsh proxy gcloud

이 명령은 로컬 프록시 서버의 주소와 환경 변수를 할당하기 위한 export 명령을 출력합니다. Google Cloud CLI 애플리케이션은 Google Cloud의 API에 대한 인증 토큰을 요청하기 위해 이 변수들을 읽습니다:

Started GCP proxy on http://127.0.0.1:50614.
To avoid port randomization, you can choose the listening port using the --port flag.

Use the following credentials and HTTPS proxy setting to connect to the proxy:

  export BOTO_CONFIG=/Users/myuser/.tsh/gcp/teleport.example.com/google-cloud-cli/00000000_boto.cfg
  export CLOUDSDK_AUTH_ACCESS_TOKEN=00000000000000000000000000000000
  export CLOUDSDK_CONFIG=/Users/myuser/.tsh/gcp/teleport.example.com/google-cloud-cli/gcloud
  export CLOUDSDK_CORE_CUSTOM_CA_CERTS_FILE=/Users/myuser/.tsh/keys/teleport.example.com/myuser-google-cloud-cli/teleport.example.com/google-cloud-cli-localca.pem
  export CLOUDSDK_CORE_PROJECT=my-project
  export HTTPS_PROXY=http://127.0.0.1:50614
Warning

tsh proxy gcloud는 포그라운드에서 로컬 프록시를 실행하므로, 로컬 프록시를 닫을 준비가 될 때까지 프로세스를 중단하거나 명령을 실행한 터미널을 종료하지 마세요.

export 명령을 복사하여 두 번째 터미널에 붙여넣습니다. 해당 터미널에서 이제 원하는 Google Cloud CLI 애플리케이션을 실행할 수 있습니다. 예를 들어, 다음 명령을 실행하여 Google Compute Engine VM을 나열할 수 있습니다:

$ gcloud compute instances list

이 가이드의 앞부분에서 셸에서 gcloud iam service-accounts create를 실행할 수 있었습니다. tsh proxy gcloud가 출력한 export 명령을 입력한 후, 이 명령은 제한된 사용자로 실행되어 권한 문제가 발생합니다:

$ gcloud iam service-accounts create demo-service-account
ERROR: (gcloud.iam.service-accounts.create) User [myuser] does not have permission to access projects instance [myproject] (or it may not exist): Permission 'iam.serviceAccounts.create' denied on resource (or it may not exist).
- '@type': type.googleapis.com/google.rpc.ErrorInfo
  domain: iam.googleapis.com
  metadata:
    permission: iam.serviceAccounts.create
  reason: IAM_PERMISSION_DENIED
Info

tsh gcloud를 통해 gcloud 명령을 실행할 때, tsh는 백그라운드에서 로컬 프록시를 시작하고 이를 사용하여 명령을 실행합니다.

다음 단계#

Teleport로 Google Cloud API 접근 보호

원문 보기
요약

Teleport를 사용하여 Google Cloud의 API와 상호 작용하는 CLI 도구에 대한 접근을 관리할 수 있습니다. Teleport Application Service는 CLI 애플리케이션의 요청을 프록시하여 Google Cloud의 API에 대한 접근을 관리합니다.

Teleport를 사용하여 Google Cloud의 API와 상호 작용하는 CLI 도구에 대한 접근을 관리할 수 있습니다. 이를 통해 인프라 자체를 보호하는 데 사용하는 것과 동일한 RBAC 시스템을 사용하여 인프라의 관리 API에 대한 접근을 제어할 수 있습니다.

작동 방식#

Teleport Application Service는 CLI 애플리케이션의 요청을 프록시하여 Google Cloud의 API에 대한 접근을 관리합니다. Application Service는 Google Cloud에서 검색된 토큰을 사용하여 이러한 요청을 인증합니다. 이를 통해 Teleport 운영자는 사용자가 Google Cloud API와 상호 작용하기 위해 가장할 수 있는 서비스 계정을 제어할 수 있습니다.

Teleport Application Service는 역방향 터널을 통해 Teleport Proxy Service에 연결되므로, 프라이빗 네트워크에서 Application Service를 실행하고 조직의 Google Cloud 서비스 계정에 대한 무단 접근을 방지할 수 있습니다.

사전 요건#

  • 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:

  • IAM 역할 및 서비스 계정을 생성하고, 서비스 계정 및 프로젝트에 대한 IAM 역할 바인딩을 생성할 수 있는 권한을 가진 Google Cloud 계정.

  • gcloud CLI 도구. gcloud를 설치하고 인증하려면 Google Cloud 문서 페이지를 참고하세요.

    Tip

이 가이드는 gcloud에 초점을 맞추지만, Teleport로 Google Cloud API 접근을 설정하면 Teleport Application Service를 사용하여 다른 Google Cloud CLI 도구에 대한 접근도 관리할 수 있습니다.

기존 서비스 계정 사용

이 가이드에서는 Teleport 사용자가 인증할 수 있는 서비스 계정인 teleport-vm-viewer를 생성하여 Google Cloud CLI 접근을 시연합니다. Google Cloud 프로젝트의 기존 서비스 계정에 대한 접근을 활성화하려면, 가이드를 진행하면서 teleport-vm-viewer를 해당 계정으로 교체할 수 있습니다.

To check that you can connect to your Teleport cluster, sign in with tsh login, then verify that you can run tctl commands using your current credentials.

For example, run the following command, assigning to the domain name of the Teleport Proxy Service in your cluster and to your Teleport username:

$ tsh login --proxy= --user=
$ tctl status
# Cluster  (=teleport.url=)
# Version  (=teleport.version=)
# CA pin   (=presets.ca_pin=)

If you can connect to the cluster and run the tctl status command, you can use your current credentials to run subsequent tctl commands from your workstation. If you host your own Teleport cluster, you can also run tctl commands on the computer that hosts the Teleport Auth Service for full permissions.

1단계/4단계. Google Cloud 설정#

Teleport Application Service가 Teleport 사용자의 요청을 Google Cloud의 API로 프록시하려면 Google Cloud의 권한이 필요합니다. 이 단계에서는 Teleport Application Service를 시작하기 전에 이러한 권한을 설정합니다.

Teleport로 Google Cloud API 접근을 설정할 때, 두 가지 다른 기능을 가진 서비스 계정을 설정합니다:

Application Service를 위한 서비스 계정 생성#

Application Service는 제어 서비스 계정을 사용하여 대상 서비스 계정에 대한 서명된 토큰을 생성하고, Teleport 사용자의 요청을 Google Cloud로 전달하기 전에 서명하여 Google Cloud API에 접근합니다. 이런 방식으로 로컬 Google Cloud CLI 도구는 이러한 토큰에 접근할 수 없습니다.

이 섹션에서는 Application Service를 위한 제어 서비스 계정을 만들고 권한을 할당합니다.

teleport-google-cloud-cli라는 서비스 계정을 생성합니다:

$ gcloud iam service-accounts create teleport-google-cloud-cli \
  --description="Google Cloud CLI access" \
  --display-name="teleport-google-cloud-cli"

Teleport 사용자가 접근할 수 있는 서비스 계정 설정#

Teleport 사용자가 Teleport Application Service에 대해 Google Cloud CLI 명령을 실행하면, Application Service는 앞서 생성한 teleport-google-cloud-cli 서비스 계정을 사용하여 대상 서비스 계정을 가장합니다.

이 섹션에서는 Application Service에 대상 서비스 계정을 가장할 수 있는 권한을 부여하는 방법을 보여줍니다.

서비스 계정 생성 및 리소스 조회 활성화#

Tip

기존 서비스 계정에 대한 접근을 활성화하는 경우 다음 섹션으로 건너뛸 수 있습니다.

대상 서비스 계정을 생성합니다:

$ gcloud iam service-accounts create teleport-vm-viewer \
  --description="Sample service account to demonstrate Teleport" \
  --display-name="teleport-vm-viewer"

이 서비스 계정을 사전 정의된 "Compute Viewer" 역할에 바인딩합니다. 이 역할을 가진 사용자는 Google Compute Engine 리소스를 나열할 수 있습니다:

$ gcloud projects add-iam-policy-binding  \
   --member="serviceAccount:teleport-vm-viewer@.iam.gserviceaccount.com" \
   --role="roles/compute.viewer"

teleport-google-cloud-cli가 대상 서비스 계정을 가장하도록 활성화#

사용자 요청을 인증하기 위해 teleport-google-cloud-cli 서비스 계정이 teleport-vm-viewer를 가장할 수 있도록 활성화합니다. 이를 위해 teleport-vm-viewer 서비스 계정에 대해 teleport-google-cloud-cli 계정을 사전 정의된 "Service Account Token Creator Role"에 바인딩합니다:

Tip

기존 서비스 계정에 대한 Google Cloud CLI 접근을 활성화하려면 각 서비스 계정에 대해 이 명령을 실행해야 합니다.

$ gcloud iam service-accounts add-iam-policy-binding \
 teleport-vm-viewer@.iam.gserviceaccount.com \
 --member=serviceAccount:teleport-google-cloud-cli@.iam.gserviceaccount.com \
  --role="roles/iam.serviceAccountTokenCreator"

2단계/4단계. Teleport Application Service 배포#

이 시점에서 제어 서비스 계정을 생성하고 Teleport 사용자가 접근하려는 서비스 계정을 가장할 수 있도록 활성화했습니다.

이 단계에서는 제어 서비스 계정을 Google Compute Engine VM에 연결한 다음 Teleport Application Service를 실행합니다.

Application Service가 Google Cloud에 접근할 수 있도록 설정#

제어 서비스 계정을 생성하고 역할을 연결했으므로, Teleport Application Service를 실행하는 가상 머신과 서비스 계정을 연결합니다. 지침은 Teleport Application Service에 기존 가상 머신을 사용하는지 아니면 새 가상 머신을 시작하는지에 따라 다릅니다:

teleport-google-cloud 서비스 계정이 연결된 새 가상 머신을 생성합니다. 이 예시에서는 Debian 12를 지원하는 최신 머신 이미지를 사용합니다:

$ IMAGE=$(gcloud --format json compute images describe-from-family debian-12 --project debian-cloud | jq -r '.selfLink')
$ gcloud compute instances create teleport-app-service \
   --service-account=teleport-google-cloud-cli@.iam.gserviceaccount.com \
   --scopes=cloud-platform \
   --zone= \
   --image="$IMAGE"

여기에 나열된 대로 service-accountscopes 플래그를 사용해야 합니다. 그렇지 않으면 VM이 Google Cloud에 접근하는 데 필요한 인증을 얻지 못합니다. 나머지 플래그는 환경의 필요에 따라 조정하고 새 플래그를 추가해야 합니다.

서비스 계정을 연결하기 위해 VM을 중지합니다:

$ gcloud compute instances stop  --zone=

인스턴스에 서비스 계정을 연결합니다:

$ gcloud compute instances set-service-account  \
   --service-account teleport-google-cloud-cli@.iam.gserviceaccount.com \
   --zone  \
   --scopes=cloud-platform
Warning

gcloud compute instances set-service-account 명령에서 scopes 플래그를 사용해야 합니다. 그렇지 않으면 Google Cloud VM이 Google Cloud에 접근하는 데 필요한 인증을 얻지 못합니다.

서비스 계정을 연결한 후 VM을 다시 시작합니다:

$ gcloud compute instances start  --zone 

Get a join token#

Establish trust between your Teleport cluster and your new Application Service instance by creating a join token:

$ tctl tokens add --type=app --ttl=1h --format=text
(=presets.tokens.first=)

Assign to your token and, on the host where you will install the Teleport Application Service, run the following command to create a file called /tmp/token that consists only of your token:

$ echo  | sudo tee /tmp/token

Teleport Application Service 설치#

Teleport Application Service를 설치할 호스트에서 아래 지침을 따르세요.

To install a Teleport Agent on your Linux server:

The recommended installation method is the cluster install script. It will select the correct version, edition, and installation mode for your cluster.

  1. Assign to your Teleport cluster hostname and port, but not the scheme (https://).

  2. Run your cluster's install script:

    $ curl "https:///scripts/install.sh" | sudo bash
    

Teleport Application Service 설정#

Teleport Application Service를 실행할 호스트에서 다음 내용으로 /etc/teleport.yaml 파일을 생성합니다:

version: v3
teleport:
  join_params:
    token_name: "/tmp/token"
    method: token
  proxy_server: "teleport.example.com:443"
auth_service:
  enabled: false
proxy_service:
  enabled: false
ssh_service:
  enabled: false
app_service:
  enabled: true
  apps:
  - name: google-cloud-cli
    cloud: GCP

/etc/teleport.yaml을 편집하여 teleport.example.com:443을 Teleport Proxy Service 또는 Teleport Cloud 테넌트의 호스트 및 포트로 교체합니다(예: mytenant.teleport.sh:443).

app_service 필드는 Teleport Application Service를 설정합니다. app_service.apps 내의 각 항목은 애플리케이션 설정입니다.

위의 예에서, cloud 필드를 GCP로 설정하여 google-cloud-cli라는 애플리케이션을 등록함으로써 Google Cloud CLI 접근을 활성화했습니다. Teleport Application Service는 이 애플리케이션에 대한 요청을 Google Cloud로 전달합니다.

Teleport Application Service 실행#

Teleport Application Service를 실행할 호스트에서, Teleport를 패키지 관리자로 설치했는지 TAR 아카이브로 설치했는지에 따라 다음 명령을 실행합니다:

Configure the Teleport Application Service to start automatically when the host boots up by creating a systemd service for it. The instructions depend on how you installed the Teleport Application Service.

You can check the status of the Teleport Application Service with systemctl status teleport and view its logs with journalctl -fu teleport.

3단계/4단계. 사용자가 Google Cloud CLI에 접근할 수 있도록 설정#

다음 단계는 Teleport 사용자가 대상 서비스 계정에 접근하고 Teleport를 통해 Google Cloud CLI 명령을 실행할 수 있도록 권한을 부여하는 것입니다. 사용자의 역할이 접근할 수 있는 Google Cloud 서비스 계정을 결정하는 Teleport의 RBAC 시스템을 사용하여 서비스 계정에 대한 접근을 보호합니다.

사용자가 Google Cloud 서비스 계정에 접근할 수 있도록 권한을 부여하는 두 가지 접근 방식이 있습니다:

접근 방식 설명 지원되는 사용자 유형
동적 Teleport 역할에 사용자에게 직접 할당된 모든 Google Cloud 서비스 계정에 대한 접근 권한을 부여하는 템플릿 변수 포함. 로컬 사용자, OIDC, SAML
정적 Teleport 역할이 사용자가 가장할 수 있는 Google Cloud 서비스 계정을 명시적으로 지정. 로컬 사용자, OIDC, SAML, GitHub
Tip

Google Cloud 계정에 서비스 계정을 추가함에 따라 더 쉽게 확장할 수 있으므로 동적 접근 방식을 권장합니다. GitHub SSO를 통해 사용자를 인증하도록 오픈 소스 Teleport 클러스터를 설정한 경우, OAuth 기반 GitHub 애플리케이션은 사용자 정의 클레임을 지원하지 않으므로 정적 접근 방식을 사용해야 합니다.

동적 ID#

동적 ID를 사용하는 경우, 선택하는 접근 방식은 로컬 Teleport 사용자를 사용하는지 SSO Teleport 사용자를 사용하는지에 따라 다릅니다:

다음 내용으로 google-cloud-cli-access.yaml 파일을 생성합니다:

kind: role
version: v7
metadata:
  name: google-cloud-cli-access
spec:
  allow:
    app_labels:
      '*': '*'
    gcp_service_accounts:
      - '{{internal.gcp_service_accounts}}'

google-cloud-cli-access 역할을 가진 사용자가 Teleport를 통해 Google Cloud CLI에 인증하면, Teleport Auth Service는 {{internal.gcp_service_accounts}} 템플릿 변수를 사용자에게 할당된 Google Cloud 서비스 계정으로 채웁니다.

다음 명령을 실행하여 앞서 생성한 대상 서비스 계정(또는 다른 서비스 계정)을 Teleport 사용자에게 할당합니다. 를 Teleport 사용자 이름으로 설정합니다:

$ tctl users update  \
--set-gcp-service-accounts teleport-vm-viewer@.iam.gserviceaccount.com

이 명령은 --set-gcp-service-accounts 플래그를 사용하여 사용자에게 Google Cloud 서비스 계정을 추가합니다. --set-gcp-service-accounts를 쉼표로 구분된 서비스 계정 URI 목록으로 설정하여 사용자에게 여러 서비스 계정을 할당할 수 있습니다.

역할을 생성합니다:

$ tctl create -f google-cloud-cli-access.yaml

ID 제공자에서 gcp_service_accounts라는 사용자 정의 SAML 속성 또는 OIDC 클레임을 정의합니다. 각 사용자의 gcp_service_accounts 속성 또는 클레임은 다음 형식을 사용하는 Google Cloud 서비스 계정 URI 목록이어야 합니다:

<service_account_name>@<project_id>.iam.gserviceaccount.com

예를 들어, <project_id>를 Google Cloud 프로젝트 이름으로 교체하여 다음 URI를 사용해 사용자의 gcp_service_accountsteleport-vm-viewer로 설정할 수 있습니다:

teleport-vm-viewer@my-project.iam.gserviceaccount.com

다음 내용으로 google-cloud-cli-access.yaml 파일을 생성합니다:

kind: role
version: v7
metadata:
  name: google-cloud-cli-access
spec:
  allow:
    app_labels:
      '*': '*'
    gcp_service_accounts:
      - '{{external.gcp_service_accounts}}'

google-cloud-cli-access 역할을 가진 사용자가 Teleport를 통해 Google Cloud CLI에 인증하면, Teleport Auth Service는 {{external.gcp_service_accounts}} 템플릿 변수를 사용자에게 할당된 Google Cloud 서비스 계정으로 채웁니다.

역할을 생성합니다:

$ tctl create -f google-cloud-cli-access.yaml

정적 ID#

정적 ID를 사용하는 경우 다음 지침을 완료합니다.

특정 Google Cloud 서비스 계정에 대한 접근이 있는 역할을 정의합니다. 이는 이 역할을 맡은 Teleport 사용자가 해당(그리고 오직 그) ID만을 사용하여 Google Cloud CLI를 통해 명령을 실행할 수 있음을 의미합니다.

다음 내용으로 google-cloud-cli-access.yaml 파일을 생성합니다. gcp_service_accounts 값의 my-project를 Google Cloud 프로젝트 ID로 교체합니다:

kind: role
version: v7
metadata:
  name: google-cloud-cli-access
spec:
  allow:
    app_labels:
      '*': '*'
    gcp_service_accounts:
      - teleport-vm-viewer@my-project.iam.gserviceaccount.com

이 역할은 사용자에게 앞서 정의한 google-cloud-cli 애플리케이션과 같이 Teleport에 등록된 모든 애플리케이션에 대한 접근 권한을 부여하고, 사용자가 앞서 생성한 teleport-vm-viewer 서비스 계정을 가장할 수 있도록 합니다.

역할을 생성합니다:

$ tctl create -f google-cloud-cli-access.yaml
Google Cloud 서비스 계정에 대한 접근 거부

사용자가 하나 이상의 Google Cloud 서비스 계정에 접근하는 것을 거부하는 Teleport 역할을 정의할 수 있습니다. 이를 위해 role 리소스의 spec.deny 섹션 내 gcp_service_accounts 필드에 값을 할당합니다.

예를 들어, 이 역할은 사용자가 모든 Google Cloud 서비스 계정에 접근하는 것을 거부합니다:

kind: role
version: v7
metadata:
  name: "no-google-cloud"
spec:
  allow:
    app_labels:
      '*': '*'
  deny:
    gcp_service_accounts:
      - '*'

no-google-cloud 역할은 사용자가 등록된 모든 애플리케이션에 접근할 수 있도록 하지만, deny.gcp_service_accounts 필드 내의 와일드카드 문자(*)를 활용하여 사용자가 Google Cloud 서비스 계정을 가장하는 것을 방지합니다.

allow.gcp_service_accounts의 값과 달리, deny.gcp_service_accounts의 값은 특정 Google Cloud 서비스 계정 URI 외에도 와일드카드 표현식을 포함할 수 있습니다.

Teleport Auth Service는 사용자의 역할을 평가할 때 allow 규칙보다 deny 규칙을 우선시합니다.

Assign the google-cloud-cli-access role to your Teleport user by running the appropriate commands for your authentication provider:

4단계/4단계. Teleport로 Google Cloud CLI 사용#

Teleport Application Service를 시작하고 Teleport 사용자가 Google Cloud CLI에 접근할 수 있도록 권한을 부여했으므로, 이제 Teleport를 통해 Google Cloud CLI 명령을 실행할 수 있습니다.

Google Cloud CLI 애플리케이션 나열#

Teleport 사용자가 앞서 등록한 google-cloud-cli 애플리케이션을 볼 수 있는지 확인합니다:

$ tsh apps ls
Application      Description Type Public Address                        Labels
---------------- ----------- ---- ------------------------------------- -------------------
google-cloud-cli             HTTP google-cloud-cli.teleport.example.com teleport.dev/origin

Google Cloud CLI 사용을 위한 로그인#

teleport-vm-viewer 서비스 계정을 가장하도록 지정하여 애플리케이션에 로그인합니다:

$ tsh apps login google-cloud-cli --gcp-service-account teleport-vm-viewer

이 명령은 --gcp-service-account 플래그의 값을 사용자가 가장할 수 있도록 권한이 부여된 값과 비교하여 검증합니다. 플래그의 값은 서비스 계정의 전체 URI이거나 ID 이름(예: teleport-vm-viewer)일 수 있습니다.

사용자가 하나의 Google Cloud 서비스 계정에만 접근할 권한이 있는 경우 --gcp-service-account 플래그를 생략할 수 있지만, 그렇지 않으면 빈 --gcp-service-account 플래그는 오류를 발생시킵니다.

명령이 성공하면 다음과 유사한 사용자의 선택된 Google Cloud 서비스 계정에 대한 정보가 표시됩니다:

Logged into GCP app "google-cloud-cli".
Your service account: teleport-vm-viewer@my-project.iam.gserviceaccount.com
Example command: tsh gcloud compute instances list

Google Cloud CLI 명령 실행#

이 시점에서 tsh를 접두사로 사용하여 Teleport Application Service를 통해 gcloud 명령을 실행할 수 있습니다. 사용자가 VM을 나열할 수 있는 서비스 계정으로 Google Cloud CLI 애플리케이션에 인증했으므로, 예를 들어 이 명령을 실행하여 VM을 나열합니다:

$ tsh gcloud compute instances list

Google Cloud 프로젝트의 가상 머신 목록이 표시됩니다.

그러나 서비스 계정에 해당 권한이 없으므로 Teleport 사용자는 VM을 생성할 수 없습니다:

$ tsh gcloud compute instances create another-instance --zone=
ERROR: (gcloud.compute.instances.create) Could not fetch resource:
 - Required 'compute.instances.create' permission for 'projects/my-project/zones/my-zone/instances/another-instance'

ERROR: exit status 1

tsh 없이 Google Cloud CLI 애플리케이션 사용#

tsh를 통해 gcloud 명령을 실행하는 것 외에도, Google Cloud의 API에 대해 명령을 실행하는 모든 CLI 애플리케이션에 안전한 접근 권한을 부여할 수 있습니다.

이를 위해 tsh를 사용하여 CLI 애플리케이션에서 Teleport Application Service로 트래픽을 전달하는 로컬 프록시를 시작합니다. Application Service는 앞서 생성한 teleport-google-cloud-cli 서비스 계정을 사용하여 Google Cloud에서 인증 토큰을 가져옵니다. CLI 애플리케이션은 이 토큰을 사용하여 Google Cloud의 API에 대한 요청을 인증합니다.

로컬 프록시를 시작하려면 다음 tsh 명령을 실행합니다:

$ tsh proxy gcloud

이 명령은 로컬 프록시 서버의 주소와 환경 변수를 할당하기 위한 export 명령을 출력합니다. Google Cloud CLI 애플리케이션은 Google Cloud의 API에 대한 인증 토큰을 요청하기 위해 이 변수들을 읽습니다:

Started GCP proxy on http://127.0.0.1:50614.
To avoid port randomization, you can choose the listening port using the --port flag.

Use the following credentials and HTTPS proxy setting to connect to the proxy:

  export BOTO_CONFIG=/Users/myuser/.tsh/gcp/teleport.example.com/google-cloud-cli/00000000_boto.cfg
  export CLOUDSDK_AUTH_ACCESS_TOKEN=00000000000000000000000000000000
  export CLOUDSDK_CONFIG=/Users/myuser/.tsh/gcp/teleport.example.com/google-cloud-cli/gcloud
  export CLOUDSDK_CORE_CUSTOM_CA_CERTS_FILE=/Users/myuser/.tsh/keys/teleport.example.com/myuser-google-cloud-cli/teleport.example.com/google-cloud-cli-localca.pem
  export CLOUDSDK_CORE_PROJECT=my-project
  export HTTPS_PROXY=http://127.0.0.1:50614
Warning

tsh proxy gcloud는 포그라운드에서 로컬 프록시를 실행하므로, 로컬 프록시를 닫을 준비가 될 때까지 프로세스를 중단하거나 명령을 실행한 터미널을 종료하지 마세요.

export 명령을 복사하여 두 번째 터미널에 붙여넣습니다. 해당 터미널에서 이제 원하는 Google Cloud CLI 애플리케이션을 실행할 수 있습니다. 예를 들어, 다음 명령을 실행하여 Google Compute Engine VM을 나열할 수 있습니다:

$ gcloud compute instances list

이 가이드의 앞부분에서 셸에서 gcloud iam service-accounts create를 실행할 수 있었습니다. tsh proxy gcloud가 출력한 export 명령을 입력한 후, 이 명령은 제한된 사용자로 실행되어 권한 문제가 발생합니다:

$ gcloud iam service-accounts create demo-service-account
ERROR: (gcloud.iam.service-accounts.create) User [myuser] does not have permission to access projects instance [myproject] (or it may not exist): Permission 'iam.serviceAccounts.create' denied on resource (or it may not exist).
- '@type': type.googleapis.com/google.rpc.ErrorInfo
  domain: iam.googleapis.com
  metadata:
    permission: iam.serviceAccounts.create
  reason: IAM_PERMISSION_DENIED
Info

tsh gcloud를 통해 gcloud 명령을 실행할 때, tsh는 백그라운드에서 로컬 프록시를 시작하고 이를 사용하여 명령을 실행합니다.

다음 단계#