데이터베이스 접근 시작 가이드
Teleport can provide secure access to PostgreSQL Amazon Aurora via the Teleport Database Service. In this guide, you will:
Teleport can provide secure access to PostgreSQL Amazon Aurora via the Teleport Database Service. This allows for fine-grained access control through Teleport's RBAC.
In this guide, you will:
- Configure your PostgreSQL Amazon Aurora database with IAM authentication.
- Add the database to your Teleport cluster.
- Connect to the database via Teleport.
작동 방식#


The Teleport Database Service uses IAM authentication to communicate with Amazon Aurora. When a user connects to the database via Teleport, the Teleport Database Service obtains AWS credentials and authenticates to AWS as an IAM principal with permissions to access the database.
사전 요구 사항#
-
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
tctlandtshclients.Installing `tctl` and `tsh` clients
-
Determine the version of your Teleport cluster. The
tctlandtshclients must be at most one major version behind your Teleport cluster version. Send a GET request to the Proxy Service at/v1/webapi/findand 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')" -
Follow the instructions for your platform to install
tctlandtshclients:
-
- PostgreSQL Amazon Aurora 데이터베이스와 IAM 정책 생성 및 연결 권한이 있는 AWS 계정.
- Teleport 데이터베이스 서비스를 실행할 호스트(예: EC2 인스턴스).
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단계/5단계. Aurora 설정#
Teleport가 Aurora 인스턴스에 연결할 수 있도록 하려면 인스턴스가 IAM 인증을 지원해야 합니다.
아직 데이터베이스를 프로비저닝하지 않은 경우 RDS 콘솔에서 Aurora PostgreSQL 인스턴스를 생성하세요. "Standard create" 데이터베이스 생성 방법을 선택하고 데이터베이스 인증 대화 상자에서 "Password and IAM database authentication"을 활성화해야 합니다.
기존 Aurora 인스턴스의 경우 IAM 인증 상태가 구성 탭에 표시되며 데이터베이스 인스턴스를 수정하여 활성화할 수 있습니다.
다음으로 다음 IAM 정책을 생성하여 AWS 사용자 또는 서비스 계정에 연결합니다. Teleport 데이터베이스 서비스는 이 정책을 사용하기 위해 이 AWS 사용자 또는 서비스 계정의 자격 증명을 사용해야 합니다.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"rds-db:connect"
],
"Resource": [
"arn:aws:rds-db:<region>:<account-id>:dbuser:<resource-id>/*"
]
}
]
}
이 정책은 IAM 인증을 사용하여 리소스 ID로 지정된 Aurora 인스턴스에 모든 데이터베이스 계정이 연결할 수 있도록 허용합니다.
데이터베이스 리소스 ID는 RDS 콘솔에서 특정 데이터베이스 인스턴스의 구성 탭에 "Resource id" 아래에 표시됩니다. 일반 RDS 데이터베이스의 경우 db- 접두사로 시작합니다. Aurora의 경우 개별 인스턴스 ID가 아닌 데이터베이스 클러스터 리소스 ID(cluster-)를 사용합니다.
마지막으로, 데이터베이스에 연결하여 IAM 인증을 지원하는 데이터베이스 계정을 생성합니다(또는 기존 계정을 업데이트합니다). 연결 후 다음 SQL 문을 실행하여 새 데이터베이스 계정을 생성하고 IAM 인증을 허용합니다:
CREATE USER alice;
GRANT rds_iam TO alice;
PostgreSQL 인스턴스에 직접 연결하는 방법에 대한 자세한 내용은 AWS 설명서를 참조하세요.
PostgreSQL 사용자를 위한 계정을 Teleport가 온디맨드로 생성하도록 구성하는 방법은 자동 사용자 프로비저닝 가이드를 참조하세요.
2단계/5단계. Teleport 데이터베이스 서비스 구성#
The Database Service requires a valid join token to join your Teleport cluster.
Run the following tctl command and save the token output in /tmp/token
on the server that will run the Database Service:
$ tctl tokens add --type=db --format=text
(=presets.tokens.first=)
Alternative methods
For users with a lot of infrastructure in AWS, or who might create or recreate many instances, consider alternative methods for joining new EC2 instances running Teleport:
Teleport 데이터베이스 서비스를 실행할 호스트에 Teleport를 설치합니다:
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.
-
Assign to your Teleport cluster hostname and port, but not the scheme (https://).
-
Run your cluster's install script:
$ curl "https:///scripts/install.sh" | sudo bash
Teleport 데이터베이스 서비스를 실행할 노드에서 Teleport를 구성하고 Aurora 데이터베이스 인스턴스를 지정합니다. 데이터베이스 엔드포인트와 리전을 적절하게 업데이트해야 합니다. --proxy 플래그는 Teleport 프록시 서비스의 주소를 가리켜야 합니다.
$ sudo teleport db configure create \
--token=/tmp/token \
--name= \
--proxy=:443 \
--protocol=postgres \
--uri=:5432 \
--aws-region= \
--output file:///etc/teleport.yaml
Teleport 데이터베이스 서비스를 실행할 노드에서 Teleport를 구성하고 Aurora 데이터베이스 인스턴스를 지정합니다. 데이터베이스 엔드포인트와 리전을 적절하게 업데이트해야 합니다. --proxy 플래그는 Teleport Cloud 테넌트의 주소를 가리켜야 합니다.
$ sudo teleport db configure create \
--token=/tmp/token \
--name= \
--proxy=:443 \
--protocol=postgres \
--uri=:5432 \
--aws-region= \
--output file:///etc/teleport.yaml
데이터베이스에 연결하는 노드에는 1단계의 정책으로 구성된 AWS 자격 증명이 있어야 합니다.
3단계/5단계. 데이터베이스 서비스 시작#
환경에서 Teleport 데이터베이스 서비스를 시작합니다:
Configure the Database Service to start automatically when the host boots up by creating a systemd service for it. The instructions depend on how you installed the Database Service.
You can check the status of the Database Service with systemctl status teleport
and view its logs with journalctl -fu teleport.
4단계/5단계. 사용자 및 역할 생성#
임의의 데이터베이스 계정을 사용하여 모든 데이터베이스에 연결할 수 있는 사용자를 허용하는 역할을 생성합니다:
$ tctl create <
방금 생성한 db 역할이 할당된 Teleport 사용자를 생성합니다:
$ tctl users add --roles=access,db alice
$ tctl users add --roles=access,requester,db alice
5단계/5단계. 연결#
이제 Aurora가 IAM 인증으로 구성되고, Teleport가 실행 중이며, 로컬 사용자가 생성되었으므로 데이터베이스에 연결할 준비가 되었습니다.
방금 생성한 사용자로 Teleport에 로그인합니다.
$ tsh login --proxy= --user=
$ tsh login --proxy= --user=
이제 사용 가능한 데이터베이스를 조회할 수 있습니다:
$ tsh db ls
마지막으로 데이터베이스에 연결합니다:
$ tsh db connect --db-user=alice --db-name postgres aurora
Note이 섹션의 내용은 원문 문서를 참조하세요. (proxy-db-tunnel.mdx)
감사#
You can view database session activity in the audit log.
After a session is uploaded, you can play back the audit data
with the tsh play command.
Database session ID will be in a UUID format (ex: 307b49d6-56c7-4d20-8cf0-5bc5348a7101)
See the audit log to get a database session ID with a key of sid.
PostgreSQL database recordings are available in interactive format:
$ tsh play 307b49d6-56c7-4d20-8cf0-5bc5348a7101
Session started to database "postgres-database" at Mon Jul 20 20:00 UTC
postgres=> SELECT * FROM products;
SUCCESS
(10 rows affected)
postgres=> INSERT INTO products (name, price) VALUES ('Phone', 150.00);
ERROR: permission denied for table products (SQLSTATE 42501)
Session ended at Mon Jul 20 20:30 UTC
All database protocols recordings are supported in JSON format (--format json):
$ tsh play --format json 307b49d6-56c7-4d20-8cf0-5bc5348a7101
{
"cluster_name": "teleport.example.com",
"code": "TDB02I",
"db_name": "example",
"db_origin": "dynamic",
"db_protocol": "postgres",
"db_query": "select * from sample;",
"db_roles": [
"access"
],
"db_service": "example",
"db_type": "rds",
"db_uri": "databases-1.us-east-1.rds.amazonaws.com:5432",
"db_user": "alice",
"ei": 2,
"event": "db.session.query",
"sid": "307b49d6-56c7-4d20-8cf0-5bc5348a7101",
"success": true,
"time": "2023-10-06T10:58:32.88Z",
"uid": "a649d925-9dac-44cc-bd04-4387c295580f",
"user": "alice"
}
The audit log is viewable under Audit in the left-hand pane via the Web UI
for users with permission to the event resources. Database sessions are listed
on the session recordings page, but only PostgreSQL sessions are playable.
문제 해결#
Certificate error#
If your tsh db connect error includes the following text, you likely have an RDS or DocumentDB database created before July 28, 2020, which presents an X.509 certificate that is incompatible with Teleport:
x509: certificate relies on legacy Common Name field, use SANs instead
AWS provides instructions to rotate your SSL/TLS certificate.
(!docs/pages/includes/aws-no-credential-provider.mdx service="Database"!)
Timeout errors#
(!docs/pages/includes/database-access/connection-timeout-troubleshooting.mdx!)
Not authorized to perform sts:AssumeRole#
The Database Service assumes an IAM role in one of following situations:
- A Teleport user specifies an IAM role as the database user they wish to use
when accessing AWS services that require IAM roles as database users.
Databases that support using an IAM role as a database user include: DynamoDB,
Keyspaces, Opensearch, Redshift, and Redshift Serverless.
- The
assume_role_arn field is specified for the database resources or
dynamic resource matchers.
What if both situations apply? (role chaining)
When both of the above conditions are true for a database connection, the
Database Service performs a role chaining by assuming the IAM role specified
in `assume_role_arn` first, then using that IAM role to assume the IAM role for
the database user.
You may encounter the following error if the trust relationship is not
configured properly between the IAM roles:
AccessDenied: User: arn:aws:sts::111111111111:assumed-role/teleport-db-service-role/i-* is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::111111111111:role/db-user-role
how to properly configure the trust relationship?
(!docs/pages/includes/database-access/iam_role_trust_relationship.mdx role1="teleport-db-service-role" role2="db-user-role" !)
You can test the trust relationship by running this AWS CLI command as teleport-db-service-role:
$ aws sts assume-role --role-arn arn:aws:iam::111111111111:role/db-user-role --role-session-name test-trust-relationship
Learn more on how to use trust policies with IAM
roles.
다음 단계#
다음 단계로, 데이터베이스 접근 사용 사례와 관련된 주제를 더 깊이 살펴보세요. 예를 들어:
- 구성 가이드를 확인하세요.
- GUI 클라이언트 구성 방법을 알아보세요.
- 데이터베이스 접근 역할 기반 접근 제어에 대해 알아보세요.
- 자주 묻는 질문을 확인하세요.
