Teleport로 Google Cloud API 접근 보호
Teleport v18.9Teleport를 사용하여 Google Cloud의 API와 상호 작용하는 CLI 도구에 대한 접근을 관리할 수 있습니다. 이 가이드에서는 Google Cloud API를 Teleport에 등록합니다. Teleport Application Service는 CLI 애플리케이션의 요청을 프록시하여 Google Cloud의 API에 대한 접근을 관리합니다.
Teleport를 사용하여 Google Cloud의 API와 상호 작용하는 CLI 도구에 대한 접근을 관리할 수 있습니다. 이를 통해 인프라 자체를 보호하는 데 사용하는 것과 동일한 RBAC 시스템을 사용하여 인프라의 관리 API에 대한 접근을 제어할 수 있습니다.
이 가이드에서는 Google Cloud API를 Teleport에 등록합니다.
작동 방식#
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 서비스 계정에 대한 무단 접근을 방지할 수 있습니다.
사전 요구 사항#
-
실행 중인 Teleport 클러스터. Teleport를 시작하려면 무료 체험판에 가입하거나 데모 환경을 구성하세요.
-
tctlandtshclients.Installing `tctl` and `tsh` clients
-
Teleport 클러스터의 버전을 확인합니다.
tctlandtshclients는 Teleport 클러스터 버전보다 최대 한 개의 메이저 버전까지만 뒤처질 수 있습니다. Proxy Service의/v1/webapi/find로 GET 요청을 보내고 JSON 쿼리 도구를 사용하여 클러스터 버전을 확인합니다.teleport.example.com:443를 Teleport Proxy Service의 웹 주소로 바꿉니다:$ TELEPORT_DOMAIN=teleport.example.com:443 $ TELEPORT_VERSION="$(curl -s https://$TELEPORT_DOMAIN/v1/webapi/find | jq -r '.server_version')" -
사용 중인 플랫폼에 대한 지침에 따라
tctlandtshclients를 설치합니다:
-
Mac
`tctl` and `tsh` clients가 포함된, 서명된 Teleport macOS .pkg 설치 프로그램을 다운로드합니다:
```code
$ curl -O https://cdn.teleport.dev/teleport-${TELEPORT_VERSION?}.pkg
```
Finder에서 `pkg` 파일을 더블 클릭하여 설치를 시작합니다.
Homebrew를 사용하여 Teleport를 설치하는 것은 지원되지 않습니다. Homebrew의
Teleport 패키지는 Teleport에서 유지 관리하지 않으므로 신뢰성이나 보안을
보장할 수 없습니다.
Windows - Powershell
```code
$ curl.exe -O https://cdn.teleport.dev/teleport-v${TELEPORT_VERSION?}-windows-amd64-bin.zip
# Unzip the archive and move the `tctl` and `tsh` clients to your %PATH%
# NOTE: Do not place the `tctl` and `tsh` clients in the System32 directory, as this can cause issues when using WinSCP.
# Use %SystemRoot% (C:\Windows) or %USERPROFILE% (C:\Users\<username>) instead.
```
Linux
Linux 설치판의 모든 Teleport 바이너리에는 `tctl` and `tsh` clients가 포함되어 있습니다. RPM/DEB
패키지 및 i386/ARM/ARM64용 다운로드를 포함한 더 많은 옵션은
[설치 페이지](../installation/installation.mdx)를 참조하세요.
```code
$ curl -O https://cdn.teleport.dev/teleport-v${TELEPORT_VERSION?}-linux-amd64-bin.tar.gz
$ tar -xzf teleport-v${TELEPORT_VERSION?}-linux-amd64-bin.tar.gz
$ cd teleport
$ sudo ./install
# Teleport binaries have been copied to /usr/local/bin
```
-
IAM 역할과 서비스 계정을 생성하고, 서비스 계정 및 프로젝트에 대한 IAM 역할 바인딩을 생성할 수 있는 권한을 가진 Google Cloud 계정.
-
gcloudCLI 도구.gcloud를 설치하고 인증하려면 Google Cloud 문서 페이지를 따르세요.Tip이 가이드는
gcloud에 초점을 맞추고 있지만, Teleport로 Google Cloud API 접근을 설정하고 나면 Teleport Application Service를 사용하여 다른 Google Cloud CLI 도구에 대한 접근도 관리할 수 있습니다.- Teleport Application Service를 실행할 Google Compute Engine VM 또는 Google Cloud 프로젝트에서 VM을 생성할 수 있는 권한. 기존 VM을 사용하는 경우, Linux 배포판을 실행 중이어야 하며 Google Compute Engine VM에 서비스 계정을 연결할 수 있는 권한이 있어야 합니다.
기존 서비스 계정 사용이 가이드에서는 Teleport 사용자가 인증할 서비스 계정
teleport-vm-viewer를 생성하여 Google Cloud CLI 접근을 시연합니다. Google Cloud 프로젝트의 기존 서비스 계정에 대한 접근을 활성화하려는 경우, 가이드를 진행하면서teleport-vm-viewer를 해당 계정으로 대체할 수 있습니다.Teleport cluster에 연결할 수 있는지 확인하려면
tsh login으로 로그인한 다음, 현재 자격 증명으로tctl명령을 실행할 수 있는지 확인합니다.예를 들어,
teleport.example.com에 cluster 내 Teleport Proxy Service의 도메인 이름을,email@example.com에 Teleport 사용자 이름을 지정하여 다음 명령을 실행합니다:$ tsh login --proxy=teleport.example.com --user=email@example.com $ tctl status # Cluster (=teleport.url=) # Version (=teleport.version=) # CA pin (=presets.ca_pin=)cluster에 연결하여
tctl status명령을 실행할 수 있다면, 현재 자격 증명을 사용하여 워크스테이션에서 이후의tctl명령을 실행할 수 있습니다. 자체 Teleport cluster를 호스팅하는 경우, 전체 권한을 얻기 위해 Teleport Auth Service를 호스팅하는 컴퓨터에서tctl명령을 실행할 수도 있습니다.1/4단계. Google Cloud 구성#
Teleport Application Service는 Teleport 사용자의 요청을 Google Cloud API로 프록시하기 위해 Google Cloud로부터 권한이 필요합니다. 이 단계에서는 Teleport Application Service를 시작하기 전에 이러한 권한을 구성합니다.
Teleport로 Google Cloud API 접근을 설정할 때, 두 가지 서로 다른 기능을 가진 서비스 계정을 구성하게 됩니다:
- 제어 서비스 계정(Controlling service account): Application Service는 이 서비스 계정을
사용하여 다른 서비스 계정을 가장(impersonate)하고 Google Cloud API에 대한 요청에 서명합니다.
이 가이드에서는
teleport-google-cloud-cli라는 제어 서비스 계정을 생성합니다. - 대상 서비스 계정(Target service accounts): 이는 조직의 Teleport 사용자가 Google Cloud
API에 접근할 때 가정하기를 원하는 서비스 계정입니다. 이 가이드에서는
teleport-vm-viewer라는 대상 서비스 계정 하나를 생성하며, 동일한 단계를 따라 다른 대상 서비스 계정에 대한 접근도 활성화할 수 있습니다.
Application Service를 위한 서비스 계정 생성#
Application Service는 대상 서비스 계정을 위해 서명된 토큰을 생성함으로써 제어 서비스 계정을 사용해 Google Cloud API에 접근하며, 이 토큰을 사용하여 Teleport 사용자의 요청을 Google Cloud로 전달하기 전에 서명합니다. 이 방식으로 로컬 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 google-cloud-project \ --member="serviceAccount:teleport-vm-viewer@google-cloud-project.iam.gserviceaccount.com" \ --role="roles/compute.viewer"teleport-google-cloud-cli가 대상 서비스 계정을 가장할 수 있도록 활성화#teleport-google-cloud-cli서비스 계정이 사용자 요청을 인증하기 위해teleport-vm-viewer를 가장할 수 있도록 활성화합니다. 이를 위해teleport-google-cloud-cli계정을teleport-vm-viewer서비스 계정에 대한 사전 정의된 "Service Account Token Creator Role"에 바인딩합니다:Tip기존 서비스 계정에 대해 Google Cloud CLI 접근을 활성화하려면, 각 서비스 계정에 대해 이 명령을 실행해야 합니다.
$ gcloud iam service-accounts add-iam-policy-binding \ teleport-vm-viewer@google-cloud-project.iam.gserviceaccount.com \ --member=serviceAccount:teleport-google-cloud-cli@google-cloud-project.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@google-cloud-project.iam.gserviceaccount.com \ --scopes=cloud-platform \ --zone=google-cloud-zone \ --image="$IMAGE"여기에 나열된 대로
service-account및scopes플래그를 사용해야 합니다. 그렇지 않으면 VM이 Google Cloud에 접근하는 데 필요한 권한을 얻는 데 실패합니다. 나머지 플래그는 환경의 필요에 따라 조정하고 새로운 플래그를 추가해야 합니다.서비스 계정을 연결할 수 있도록 VM을 중지합니다:
$ gcloud compute instances stop vm-name --zone=google-cloud-zone서비스 계정을 인스턴스에 연결합니다:
$ gcloud compute instances set-service-account vm-name \ --service-account teleport-google-cloud-cli@google-cloud-project.iam.gserviceaccount.com \ --zone google-cloud-zone \ --scopes=cloud-platformWarninggcloud compute instances set-service-account명령에서scopes플래그를 사용해야 합니다. 그렇지 않으면 Google Cloud VM이 Google Cloud에 접근하는 데 필요한 권한을 얻는 데 실패합니다.서비스 계정을 연결한 후, VM을 다시 시작합니다:
$ gcloud compute instances start vm-name --zone google-cloud-zonejoin token 가져오기#
join token을 생성하여 Teleport 클러스터와 새 Application Service 인스턴스 간의 신뢰를 설정하십시오:
$ tctl tokens add --type=app --ttl=1h --format=text (=presets.tokens.first=)join-token에 토큰을 할당하고, Teleport Application Service를 설치할 호스트에서 다음 명령을 실행하여 토큰만으로 구성된/tmp/token이라는 파일을 생성하십시오:$ echo join-token | sudo tee /tmp/tokenTeleport Application Service 설치#
Teleport Application Service를 설치할 호스트에서 아래 안내를 따르세요.
Linux 서버에 Teleport Agent를 설치하려면:
권장 설치 방법은 클러스터 설치 스크립트입니다. 이 스크립트는 클러스터에 맞는 올바른 버전, 에디션, 설치 모드를 선택합니다.
-
teleport.example.com:443에 Teleport 클러스터의 호스트명과 포트를 할당하되, 스킴(https://)은 포함하지 마십시오. -
클러스터의 설치 스크립트를 실행하십시오:
$ curl "https://teleport.example.com:443/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 아카이브를 통해 설치했는지에 따라 다음 명령을 실행합니다:
systemd 서비스를 생성하여 호스트가 부팅될 때 the Teleport Application Service이 자동으로 시작되도록 구성합니다. 지침은 the Teleport Application Service을 어떻게 설치했는지에 따라 다릅니다.
Package Manager
the Teleport Application Service을 실행할 호스트에서 Teleport를 활성화하고 시작합니다:
$ sudo systemctl enable teleport $ sudo systemctl start teleportTAR Archive
the Teleport Application Service을 실행할 호스트에서 Teleport용 systemd 서비스 구성을 생성하고, Teleport 서비스를 활성화한 후 Teleport를 시작합니다:
$ sudo teleport install systemd -o /etc/systemd/system/teleport.service $ sudo systemctl enable teleport $ sudo systemctl start teleportsystemctl status teleport로 the Teleport Application Service의 상태를 확인하고journalctl -fu teleport로 로그를 볼 수 있습니다.3/4단계. 사용자가 Google Cloud CLI에 접근할 수 있도록 활성화#
다음 단계는 Teleport 사용자가 대상 서비스 계정에 접근하고 Teleport를 통해 Google Cloud CLI 명령을 실행할 수 있도록 승인하는 것입니다. Teleport의 RBAC 시스템을 사용하여 서비스 계정에 대한 접근을 보호하며, 사용자의 역할에 따라 사용자가 접근할 수 있는 Google Cloud 서비스 계정(있는 경우)이 결정됩니다.
사용자가 Google Cloud 서비스 계정에 접근하도록 승인하는 방법에는 두 가지 접근 방식이 있습니다:
접근 방식 설명 지원되는 사용자 유형 동적(Dynamic) Teleport 역할에 사용자에게 직접 할당된 모든 Google Cloud 서비스 계정에 대한 접근 권한을 부여하는 템플릿 변수가 포함됩니다. 로컬 사용자, OIDC, SAML 정적(Static) Teleport 역할이 사용자가 가정할 수 있는 Google Cloud 서비스 계정을 명시적으로 지정합니다. 로컬 사용자, OIDC, SAML, GitHub TipGoogle Cloud 계정에 서비스 계정을 추가함에 따라 더 쉽게 확장되므로 동적 접근 방식을 사용할 것을 권장합니다. GitHub SSO를 통해 사용자를 인증하도록 오픈 소스 Teleport 클러스터를 구성한 경우, OAuth 기반 GitHub 애플리케이션이 사용자 지정 클레임을 지원하지 않으므로 정적 접근 방식을 사용해야 합니다.
동적 아이덴티티#
동적 아이덴티티를 사용하는 경우, 선택하는 접근 방식은 로컬 또는 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는 사용자에게 할당된 Google Cloud 서비스 계정으로{{internal.gcp_service_accounts}}템플릿 변수를 채웁니다.teleport-user를 Teleport 사용자의 이름으로 설정하여 다음 명령을 실행함으로써 앞서 생성한 대상 서비스 계정(또는 다른 서비스 계정)을 Teleport 사용자에게 할당합니다:$ tctl users update teleport-user \ --set-gcp-service-accounts teleport-vm-viewer@google-cloud-project.iam.gserviceaccount.com이 명령은
--set-gcp-service-accounts플래그를 사용하여 사용자에게 Google Cloud 서비스 계정을 추가합니다.--set-gcp-service-accounts를 서비스 계정 URI의 쉼표로 구분된 목록으로 설정하여 사용자에게 여러 서비스 계정을 할당할 수 있습니다.역할을 생성합니다:
$ tctl create -f google-cloud-cli-access.yamlTipWeb UI를 사용하여 역할을 생성하고 편집할 수도 있습니다. Access -> Roles로 이동하여 Create New Role을 클릭하거나 편집할 기존 역할을 선택하십시오.
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_accounts를teleport-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는 사용자에게 할당된 Google Cloud 서비스 계정으로{{external.gcp_service_accounts}}템플릿 변수를 채웁니다.역할을 생성합니다:
$ tctl create -f google-cloud-cli-access.yamlTipWeb UI를 사용하여 역할을 생성하고 편집할 수도 있습니다. Access -> Roles로 이동하여 Create New Role을 클릭하거나 편집할 기존 역할을 선택하십시오.
정적 아이덴티티#
정적 아이덴티티를 사용하는 경우, 다음 안내를 완료하세요.
특정 Google Cloud 서비스 계정에 대한 접근 권한을 가진 역할을 정의합니다. 이는 이 역할을 가정하는 Teleport 사용자가 Google Cloud CLI를 통해 명령을 실행하기 위해 해당 (그리고 오직 해당) 아이덴티티만 사용할 수 있음을 의미합니다.
gcp_service_accounts의 값에서my-project를 Google Cloud 프로젝트의 ID로 대체하여, 다음 내용을 가진google-cloud-cli-access.yaml파일을 생성합니다: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.yamlGoogle 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규칙을 우선합니다.인증 공급자에 맞는 적절한 명령을 실행하여
google-cloud-cli-access역할을 your Teleport user에게 할당하십시오:Local User
-
로컬 사용자의 역할을 쉼표로 구분된 목록으로 가져옵니다:
$ ROLES=$(tsh status -f json | jq -r '.active.roles | join(",")') -
로컬 사용자를 편집하여 새 역할을 추가합니다:
$ tctl users update $(tsh status -f json | jq -r '.active.username') \ --set-roles "${ROLES?},google-cloud-cli-access" -
Teleport 클러스터에서 로그아웃한 다음 다시 로그인하여 새 역할을 적용합니다.
GitHub
-
텍스트 편집기에서
github인증 커넥터를 엽니다:$ tctl edit github/github -
github커넥터를 편집하여teams_to_roles섹션에google-cloud-cli-access을 추가합니다.이 역할에 매핑해야 할 팀은 조직의 역할 기반 액세스 제어(RBAC)를 어떻게 설계했는지에 따라 달라집니다. 다만, 해당 팀은 여러분의 사용자 계정을 포함해야 하며 조직 내에서 가능한 한 가장 작은 팀이어야 합니다.
다음은 예시입니다:
teams_to_roles: - organization: octocats team: admins roles: - access + - google-cloud-cli-access -
편집기에서 파일을 저장하고 닫아 변경 사항을 적용합니다.
-
Teleport 클러스터에서 로그아웃한 다음 다시 로그인하여 새 역할을 적용합니다.
SAML
-
saml구성 리소스를 가져옵니다:$ tctl get --with-secrets saml/mysaml > saml.yaml--with-secrets플래그는spec.signing_key_pair.private_key값을saml.yaml파일에 추가한다는 점에 유의하십시오. 이 키에는 민감한 값이 포함되어 있으므로, 리소스를 업데이트한 직후 saml.yaml 파일을 삭제해야 합니다. -
saml.yaml을 편집하여attributes_to_roles섹션에google-cloud-cli-access을 추가합니다.이 역할에 매핑해야 할 속성은 조직의 역할 기반 액세스 제어(RBAC)를 어떻게 설계했는지에 따라 달라집니다. 다만, 해당 그룹은 여러분의 사용자 계정을 포함해야 하며 조직 내에서 가능한 한 가장 작은 그룹이어야 합니다.
다음은 예시입니다:
attributes_to_roles: - name: "groups" value: "my-group" roles: - access + - google-cloud-cli-access -
변경 사항을 적용합니다:
$ tctl create -f saml.yaml -
Teleport 클러스터에서 로그아웃한 다음 다시 로그인하여 새 역할을 적용합니다.
OIDC
-
oidc구성 리소스를 가져옵니다:$ tctl get oidc/myoidc --with-secrets > oidc.yaml--with-secrets플래그는spec.signing_key_pair.private_key값을oidc.yaml파일에 추가한다는 점에 유의하십시오. 이 키에는 민감한 값이 포함되어 있으므로, 리소스를 업데이트한 직후 oidc.yaml 파일을 삭제해야 합니다. -
oidc.yaml을 편집하여claims_to_roles섹션에google-cloud-cli-access을 추가합니다.이 역할에 매핑해야 할 클레임은 조직의 역할 기반 액세스 제어(RBAC)를 어떻게 설계했는지에 따라 달라집니다. 다만, 해당 그룹은 여러분의 사용자 계정을 포함해야 하며 조직 내에서 가능한 한 가장 작은 그룹이어야 합니다.
다음은 예시입니다:
claims_to_roles: - name: "groups" value: "my-group" roles: - access + - google-cloud-cli-access -
변경 사항을 적용합니다:
$ tctl create -f oidc.yaml -
Teleport 클러스터에서 로그아웃한 다음 다시 로그인하여 새 역할을 적용합니다.
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/originGoogle Cloud CLI를 사용하기 위해 로그인#
teleport-vm-viewer서비스 계정을 가정하고자 함을 지정하여 애플리케이션에 로그인합니다:$ tsh apps login google-cloud-cli --gcp-service-account teleport-vm-viewer이 명령은
--gcp-service-account플래그의 값을 사용자가 가정하도록 승인된 값과 비교하여 검증합니다. 플래그의 값은 서비스 계정의 전체 URI 또는 아이덴티티의 이름, 예를 들어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 listGoogle Cloud CLI 명령 실행#
이 시점에서,
tsh를 접두사로 붙여 Teleport Application Service를 사용하여gcloud명령을 실행할 수 있습니다. 예를 들어, 사용자가 VM을 나열할 수 있는 서비스 계정으로 Google Cloud CLI 애플리케이션에 인증했으므로, 다음 명령을 실행하여 이를 수행할 수 있습니다:$ tsh gcloud compute instances listGoogle Cloud 프로젝트의 가상 머신 목록이 표시됩니다.
그러나 Teleport 사용자는 해당 서비스 계정이 이 권한을 갖고 있지 않으므로 VM을 생성할 수 없습니다:
$ tsh gcloud compute instances create another-instance --zone=google-cloud-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 1tsh없이 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:50614Warningtsh 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_DENIEDInfotsh gcloud를 통해gcloud명령을 실행하면,tsh는 백그라운드에서 로컬 프록시를 시작하고 이를 사용하여 명령을 실행합니다.다음 단계#
- Teleport를 사용하여 Google Cloud CLI에 대한 접근을 보호하는 방법을 알았으므로, Teleport 사용자가 공격자가 탈취할 수 있는 장기적인 관리자 역할 없이 일시적으로만 Google Cloud 리소스를 관리할 수 있도록 하세요. 역할 접근 요청 및 접근 요청 플러그인에 대한 문서를 참조하세요.
- Teleport를 통해 모든
gcloud명령을 프록시할 수 있습니다. 전체 명령 참조는gcloud에 대한 Google Cloud 문서를 참조하세요. - 이 가이드에서 설명한 Teleport 역할 내의
internal및external트레이트를 Teleport가 채우는 방법에 대한 전체 세부 정보는 접근 제어 참조를 참조하세요. - 이 가이드를 따른 후, Teleport로 레거시
gsutil명령의 사용도 보호할 수 있습니다. 사용자는tsh gsutil로gsutil명령을 실행할 수 있습니다. 자세한 내용은 CLI 참조의tsh gsutil항목을 참조하세요.