Cloud Spanner를 통한 데이터베이스 액세스
Teleport v18.9Teleport는 Teleport Database Service를 통해 Cloud Spanner에 대한 보안 접근을 제공할 수 있습니다. Teleport Database Service는 IAM 인증을 사용하여 Spanner와 통신합니다.
Teleport는 Teleport Database Service를 통해 Cloud Spanner에 대한 보안 접근을 제공할 수 있습니다. 이를 통해 Teleport의 RBAC를 사용한 세분화된 접근 제어가 가능합니다.
이 가이드에서는 다음을 수행합니다:
- Cloud Spanner 데이터베이스를 구성합니다 with a service account.
- 데이터베이스를 Teleport 클러스터에 추가합니다.
- Teleport를 통해 데이터베이스에 연결합니다.
작동 방식#
Teleport Database Service는 IAM 인증을 사용하여 Spanner와 통신합니다. 사용자가 Teleport를 통해 데이터베이스에 연결하면 Teleport Database Service는 Google Cloud 자격 증명을 얻고 데이터베이스에 액세스할 수 있는 권한을 가진 IAM 주체(principal)로 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
```
- Google Cloud 계정
- Cloud Spanner 인스턴스 및 데이터베이스
- Teleport Database Service를 실행할 호스트(예: Compute Engine 인스턴스)로,
spanner.googleapis.com:443으로의 아웃바운드 HTTPS 액세스가 가능해야 합니다.
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/6단계. 서비스 계정 생성#
Teleport에는 두 가지 유형의 Google Cloud 서비스 계정이 필요합니다:
- Database Service: Teleport Database Service가 Google Cloud에 액세스하고 데이터베이스 사용자 서비스 계정을 가장하는 데 사용하는 단일 서비스 계정
- Database user: 연결마다 가장하여 데이터베이스 사용자를 나타내는 하나 이상의 서비스 계정
예를 들어 다음 단계에서는 teleport-db-service(Database Service 서비스 계정)와 spanner-user(Database user 서비스 계정)를 생성합니다.
Database Service 계정 생성#
이 계정은 Teleport Database Service가 Google Cloud에 액세스하고 데이터베이스 사용자 계정을 가장하는 데 사용됩니다.
- IAM & Admin → Service Accounts로 이동합니다.
- Create Service Account를 클릭합니다.
- 이름을
teleport-db-service로 설정합니다. - 선택적 단계는 건너뛰고 Done을 클릭합니다. 권한은 나중에 부여합니다.
$ gcloud iam service-accounts create teleport-db-service --display-name="Teleport Database Service"
데이터베이스 사용자 계정 생성#
이 계정은 데이터베이스 사용자를 나타냅니다. Teleport 사용자는 연결 시 이 이름을 지정합니다.
- IAM & Admin → Service Accounts로 이동합니다.
- Create Service Account를 클릭합니다.
- 이름을
spanner-user로 설정합니다. - 선택적 단계는 건너뛰고 Done을 클릭합니다. 권한은 나중에 부여합니다.
$ gcloud iam service-accounts create spanner-user --display-name="Spanner User"
2/6단계. 권한 부여#
데이터베이스 사용자 계정에 Spanner 액세스 권한을 부여한 다음, Database Service 계정이 데이터베이스 사용자 계정을 가장할 수 있도록 허용합니다.
Spanner 액세스 권한 부여#
- Spanner → Instances로 이동합니다
- 인스턴스를 선택합니다
- Permissions → Add Principal을 클릭합니다
spanner-user서비스 계정을 입력합니다- Cloud Spanner Database User를 할당합니다
- Save를 클릭합니다
$ gcloud spanner instances add-iam-policy-binding instance-id \
--member="serviceAccount:spanner-user@project-id.iam.gserviceaccount.com" \
--role="roles/spanner.databaseUser"
Cloud Spanner Database User 역할은 사전 정의된 역할입니다. 필요한 경우 커스텀 IAM 역할을 생성하여 액세스를 더욱 제한할 수 있습니다.
서비스 계정 가장 허용#
Database Service 계정이 데이터베이스 사용자 계정을 가장할 수 있도록 권한을 부여합니다.
- IAM & Admin → Service Accounts로 이동합니다
spanner-user를 선택합니다- Permissions 탭을 엽니다
- Grant Access를 클릭합니다
teleport-db-service계정을 추가합니다- Service Account Token Creator를 할당합니다
- Save를 클릭합니다
$ gcloud iam service-accounts add-iam-policy-binding \
spanner-user@project-id.iam.gserviceaccount.com \
--member="serviceAccount:teleport-db-service@project-id.iam.gserviceaccount.com" \
--role="roles/iam.serviceAccountTokenCreator"
다음을 실행합니다:
$ gcloud iam service-accounts get-iam-policy \
spanner-user@project-id.iam.gserviceaccount.com
출력에는 teleport-db-service와 roles/iam.serviceAccountTokenCreator를 짝짓는 바인딩이 포함되어야 합니다:
bindings:
- members:
- serviceAccount:teleport-db-service@<project-id>.iam.gserviceaccount.com
role: roles/iam.serviceAccountTokenCreator
3/6단계. Teleport Database Service 설치 및 구성#
Linux 서버에 Teleport Agent를 설치하려면:
권장 설치 방법은 클러스터 설치 스크립트입니다. 이 스크립트는 클러스터에 맞는 올바른 버전, 에디션, 설치 모드를 선택합니다.
-
teleport.example.com:443에 Teleport 클러스터의 호스트명과 포트를 할당하되, 스킴(https://)은 포함하지 마십시오. -
클러스터의 설치 스크립트를 실행하십시오:
$ curl "https://teleport.example.com:443/scripts/install.sh" | sudo bash
Database Service가 Teleport 클러스터에 조인하려면 유효한 조인 토큰이 필요합니다.
다음 tctl 명령을 실행하고 Database Service를 실행할 서버에서
토큰 출력을 /tmp/token에 저장합니다:
$ tctl tokens add --type=db --format=text
(=presets.tokens.first=)
다음 정보를 제공한 후 Teleport Database Service의 구성 파일을 생성합니다:
example.teleport.sh:443Teleport Proxy Service 또는 클라우드 호스팅 Teleport Enterprise 사이트의 호스트 및 포트.project-idGCP 프로젝트 ID. 일반적으로 GCP 대시보드 상단의 조직 보기에서 확인할 수 있습니다.instance-idCloud Spanner 인스턴스의 이름.
$ sudo teleport db configure create \
-o file \
--name=spanner-example \
--protocol=spanner \
--labels=env=dev \
--token=/tmp/token \
--uri=spanner.googleapis.com:443 \
--proxy=example.teleport.sh:443 \
--gcp-project-id=project-id \
--gcp-instance-id=instance-id
4/6단계. GCP 자격 증명 구성#
Teleport Database Service에는 "teleport-db-service" GCP 서비스 계정에 대한 자격 증명이 있어야 합니다.
Teleport Database Service가 GCE 인스턴스에서 호스팅되는 경우, 연결된 서비스 계정을 변경할 수 있습니다. GCE가 아닌 Teleport 배포의 경우 workload identity 사용을 권장합니다.
서비스 계정 키 사용(안전하지 않음)
또는 해당 서비스 계정의 Keys 탭으로 이동하여 새 키를 생성하십시오:
반드시 JSON 형식을 선택하십시오:

파일을 저장하십시오. GOOGLE_APPLICATION_CREDENTIALS 환경 변수가 앞서 다운로드한
JSON 자격 증명 파일을 가리키도록 설정하십시오. 예를 들어, systemd를 사용하여
teleport를 시작하는 경우, 해당 서비스의 EnvironmentFile을 편집하여
환경 변수를 포함시켜야 합니다:
$ echo 'GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json' | sudo tee -a /etc/default/teleport
서비스 계정 키는 보안 위험이 될 수 있으며, 이 가이드에서는 단순함을 위해서만 키 사용을 설명합니다. 프로덕션 환경에서는 서비스 계정 키 사용을 권장하지 않습니다. 서비스 계정 인증 방식에 대한 자세한 내용은 Google Cloud 문서의 authentication을 참조하십시오.
5/6단계. Teleport Database Service 시작#
systemd 서비스를 생성하여 호스트가 부팅될 때 the Teleport Database Service이 자동으로 시작되도록 구성합니다. 지침은 the Teleport Database Service을 어떻게 설치했는지에 따라 다릅니다.
Package Manager
the Teleport Database Service을 실행할 호스트에서 Teleport를 활성화하고 시작합니다:
$ sudo systemctl enable teleport
$ sudo systemctl start teleport
TAR Archive
the Teleport Database Service을 실행할 호스트에서 Teleport용 systemd 서비스 구성을 생성하고, Teleport 서비스를 활성화한 후 Teleport를 시작합니다:
$ sudo teleport install systemd -o /etc/systemd/system/teleport.service
$ sudo systemctl enable teleport
$ sudo systemctl start teleport
systemctl status teleport로 the Teleport Database Service의 상태를 확인하고 journalctl -fu teleport로
로그를 볼 수 있습니다.
문제의 프록시 및 사용자 이름으로 example.teleport.sh와 example-user를 바꿉니다.
$ tsh login --proxy=example.teleport.sh --user=example-user
$ tsh db ls
다음과 같이 표시되어야 합니다:
Name Description Allowed Users Labels Connect
--------------- ----------------- ------------- ------- -------
spanner-example GCP Cloud Spanner [*] env=dev
데이터베이스가 표시되지 않으면 Teleport 역할 권한을 확인하세요. RBAC 가이드를 참조하세요.
6/6단계. 서비스 계정을 사용하여 연결#
이 단계에서는 Spanner 데이터베이스에 액세스할 수 있는 Teleport 사용자를 생성하고, 데이터베이스 사용자 서비스 계정을 사용하여 연결한 다음, 필요하면 저장된 자격 증명을 제거합니다.
기존 사용자를 수정하여 Database Service 접근 권한을 부여하려면 Database Access Controls를 참조하십시오.
Teleport Community Edition
내장 access 역할을 가진 로컬 Teleport 사용자를 생성합니다:
$ tctl users add \
--roles=access \
--db-users="*" \
--db-names="*" \
alice
Teleport Enterprise/Enterprise Cloud
내장 access 및 requester 역할을 가진 로컬 Teleport 사용자를 생성합니다:
$ tctl users add \
--roles=access,requester \
--db-users="*" \
--db-names="*" \
alice
| Flag | 설명 |
|---|---|
--roles |
사용자에게 할당할 역할 목록입니다. 내장 access 역할은 Teleport에 등록된 모든 데이터베이스 서버에 연결할 수 있게 합니다. |
--db-users |
사용자가 데이터베이스에 연결할 때 사용할 수 있는 데이터베이스 사용자명 목록입니다. 와일드카드는 모든 사용자를 허용합니다. |
--db-names |
사용자가 데이터베이스 서버 내에서 연결할 수 있는 논리적 데이터베이스(즉, 스키마) 목록입니다. 와일드카드는 모든 데이터베이스를 허용합니다. |
데이터베이스 이름은 PostgreSQL, MongoDB, Cloud Spanner 데이터베이스에서만 적용됩니다.
데이터베이스 접근 제어 및 접근 제한 방법에 대한 자세한 정보는 RBAC 문서를 참조하십시오.
방금 생성한 새 사용자로 Teleport 클러스터에 로그인합니다:
$ tsh login --proxy=example.teleport.sh --user=example-user
서비스 계정 이름(도메인 접미사 제외)을 사용하여 연결합니다:
(참고: 여기서 --db-name은 Spanner 인스턴스 내의 특정 데이터베이스 ID를 나타냅니다.)
$ tsh db connect --db-user=spanner-user --db-name=database-name spanner-example
이제 가장된 서비스 계정을 사용하여 인증된 연결이 이루어져야 합니다.
자격 증명을 제거하려면:
$ tsh db logout spanner-example
모든 데이터베이스 자격 증명을 제거하려면:
$ tsh db logout
문제 해결#
Could not find default credentials#
이 오류는 클라이언트 애플리케이션 또는 Teleport 중 어느 쪽에서든 발생할 수 있습니다.
클라이언트 애플리케이션의 경우 GCP 자격 증명 로딩을 비활성화했는지 확인합니다. GCP 자격 증명은 Teleport Database Service가 제공하므로 클라이언트는 자격 증명을 로드하려고 시도해서는 안 됩니다.
Teleport Database Service 로그(DEBUG 로그 레벨)에서 자격 증명 오류 메시지가 보인다면, Teleport Database Service에 GCP 자격 증명이 올바르게 구성되지 않은 것입니다.
서비스 계정 키를 사용하는 경우 환경 변수
GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json가 설정되어 있는지
확인하고, 해당 환경 변수가 teleport에서 사용 가능하도록 Teleport Database
Service를 재시작합니다.
예를 들어 Teleport Database Service가 systemd 서비스로 실행되는 경우:
$ echo 'GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json' | sudo tee -a /etc/default/teleport
$ sudo systemctl restart teleport
서비스 계정 인증 방식에 대한 자세한 내용은 Google Cloud 문서의 authentication을 참조하십시오.