Amazon DocumentDB를 이용한 데이터베이스 접근
Teleport can provide secure access to Amazon DocumentDB via the Teleport Database Service. In this guide, you will: The Teleport Database Service uses IAM authentication to communicate with Amazon DocumentDB.
Teleport can provide secure access to Amazon DocumentDB via the Teleport Database Service. This allows for fine-grained access control through Teleport's RBAC.
In this guide, you will:
- Configure your Amazon DocumentDB database IAM 인증을 사용하여.
- Add the database to your Teleport cluster.
- Connect to the database via Teleport.
작동 원리#
The Teleport Database Service uses IAM authentication to communicate with Amazon DocumentDB. 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.
This guide shows how to register a single Amazon DocumentDB cluster with your Teleport cluster. For a more scalable approach, learn how to set up Database Auto-Discovery to automatically enroll all AWS databases in your infrastructure.
필수 조건#
-
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:
-
- DocumentDB 클러스터가 있는 AWS 계정.
IAM 인증 및 TLS
Teleport는 DocumentDB에 사용자를 연결하기 위해 IAM 인증을 사용하며, 이는 DocumentDB 5.0 이상에서만 지원됩니다.
또한, DocumentDB 클러스터에 전송 계층 보안(TLS)이 활성화되어 있어야 합니다. TLS는 기본 파라미터 그룹을 사용할 때 기본적으로 활성화됩니다.
mongosh또는mongo커맨드라인 클라이언트가 설치되어 시스템의PATH환경 변수에 추가된 상태.- Teleport 데이터베이스 서비스를 실행할 호스트 (예: EC2 인스턴스).
To check that you can connect to your Teleport cluster, sign in with
tsh login, then verify that you can runtctlcommands 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 statuscommand, you can use your current credentials to run subsequenttctlcommands from your workstation. If you host your own Teleport cluster, you can also runtctlcommands on the computer that hosts the Teleport Auth Service for full permissions.1/6단계. Teleport 사용자 생성#
Flag Description --rolesList of roles to assign to the user. The builtin accessrole allows them to connect to any database server registered with Teleport.--db-usersList of database usernames the user will be allowed to use when connecting to the databases. A wildcard allows any user. --db-namesList of logical databases (aka schemas) the user will be allowed to connect to within a database server. A wildcard allows any database. For more detailed information about database access controls and how to restrict access see RBAC documentation.
2/6단계. 데이터베이스 서비스 구성 생성#
The Database Service requires a valid join token to join your Teleport cluster. Run the following
tctlcommand and save the token output in/tmp/tokenon 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:
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
데이터베이스 서비스를 실행하는 노드에서 구성 파일을 생성합니다. URI로 DocumentDB 클러스터 엔드포인트와 포트를 사용하고, 을 교체합니다:
$ sudo teleport db configure create \ -o file \ --name="my-docdb" \ --proxy= \ --protocol=mongodb \ --token=/tmp/token \ --uri=""이 명령은 AWS DocumentDB 클러스터를 프록시하는 데이터베이스 서비스 구성을 생성하고 구성을
/etc/teleport.yaml에 저장합니다.3/6단계. 데이터베이스 서비스용 IAM 역할 생성#
먼저 AWS 콘솔의 IAM > 정책 페이지를 방문한 다음 "정책 생성"을 클릭합니다.
정책 편집기로 JSON 옵션을 사용하고 다음 정책을 붙여넣습니다:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "rds:DescribeDBClusters" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "sts:AssumeRole" ], "Resource": "*", "Condition": { "StringEquals": {"iam:ResourceTag/TeleportDatabaseService": "Allowed"} } } ] }이 정책은 Teleport 데이터베이스 서비스가 DocumentDB 클러스터 메타데이터를 검색하고 Teleport 사용자를 대신하여 DocumentDB 사용자로 인증하기 위해 IAM 역할을 수임할 수 있도록 합니다.
sts:AssumeRole에는 Teleport 데이터베이스 서비스가 수임할 수 있는 IAM 역할을 제한하기 위한 리소스 태그 조건이 있습니다.다음을 클릭하고 정책에 이름을 지정합니다. 이 가이드에서는 예제 이름
TeleportDatabaseAccessDocumentDB를 사용합니다.이제 AWS 콘솔의 IAM > 역할 페이지를 방문한 다음 "역할 생성"을 클릭합니다. 신뢰할 수 있는 엔터티 유형 아래에서 "AWS 서비스"를 선택합니다. 사용 사례 아래에서 "EC2" 또는 원하는 사용 사례를 선택한 다음 다음을 클릭합니다.

"권한 추가" 페이지에서 이전 단계에서 생성한
TeleportDatabaseAccessDocumentDB정책을 찾아 선택합니다.
"다음"을 클릭하고 역할에 이름을 지정합니다. 이 가이드에서는 이 역할에 예제 이름
TeleportDatabaseService를 사용합니다. 이름을 선택한 후 역할 생성을 클릭하여 프로세스를 완료합니다.4/6단계. 데이터베이스 서비스 시작#
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 teleportand view its logs withjournalctl -fu teleport.데이터베이스 서비스는 이전에 지정한 URI를 사용하여 Amazon DocumentDB 클러스터를 프록시합니다. AWS IAM 변경 사항은 즉시 적용되지 않을 수 있으며 적용되는 데 몇 분이 걸릴 수 있습니다.
5/6단계. DocumentDB 사용자용 IAM 역할 생성#
이 단계에서는 Teleport 데이터베이스 서비스가 Teleport 사용자를 대신하여 DocumentDB에 인증하기 위해 수임할 수 있는 IAM 역할을 생성합니다.
IAM 역할 생성#
AWS 웹 콘솔의 역할 페이지로 돌아가서 새 역할을 생성합니다. "AWS 계정" 옵션을 선택하면 이 계정의 다른 엔터티가 이 역할을 수임할 수 있도록 기본 신뢰 정책이 생성됩니다:

"다음"을 클릭하여 "권한 추가" 페이지를 건너뛰고 역할에 이름을 지정합니다. 이 가이드에서는 이 역할에 "teleport-docdb-user" 예제를 사용합니다.
이제 3단계에서 새 태그 추가를 클릭하고, 키로
TeleportDatabaseService를, 값으로Allowed를 사용합니다. 그런 다음 역할 생성을 클릭하여 프로세스를 완료합니다.
DocumentDB 사용자 생성#
DocumentDB 클러스터에 대한 네트워크 액세스가 있는 머신에서 마스터 사용자 이름과 암호를 사용하여 DocumentDB 클러스터에 로그인합니다. IAM 역할 ARN을 사용자 이름으로 사용하고 인증 메커니즘에
MONGODB-AWS를 지정하여 DocumentDB 사용자를 생성합니다. [aws.aws_account_id]:role/teleport-docdb-user"/>를 DocumentDB 사용자의 ARN으로 교체합니다:use $external; db.createUser( { user: "", mechanisms: ["MONGODB-AWS"], roles: [ { role: "root", db: "admin" }, ] } );이 예제는 루트 권한을 가진 DocumentDB IAM 사용자를 생성합니다. 필요에 따라 권한을 조정할 수 있습니다.
비밀번호 인증 방지이 단계는 비밀번호 인증을 사용해야 하는 일회성 설정입니다. 그러나 첫 번째 IAM 사용자를 생성한 후에는 Teleport를 통해 DocumentDB에 접근하고 첫 번째 IAM 사용자를 사용하여 더 많은 DocumentDB IAM 사용자를 생성함으로써 비밀번호 인증을 건너뛸 수 있습니다.
6/6단계. 연결#
데이터베이스 서비스가 시작되고 클러스터에 참가하면 등록된 데이터베이스를 확인하기 위해 로그인합니다:
$ tsh login --proxy= --user=alice $ tsh db ls # Name Description Labels # -------- ----------- -------- # my-docdb env=dev데이터베이스의 자격 증명을 검색하고
teleport-docdb-user사용자로 연결합니다:$ tsh db connect --db-user=teleport-docdb-user --db-name=test my-docdbNote이 섹션의 내용은 원문 문서를 참조하세요. (
proxy-db-tunnel.mdx)데이터베이스에서 로그아웃하고 자격 증명을 제거합니다:
$ tsh db logout my-docdb문제 해결#
Certificate error#
If your
tsh db connecterror 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 insteadAWS 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_arnfield 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-rolehow 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-relationshipLearn more on how to use trust policies with IAM roles.
"MONGODB-AWS" 메커니즘을 사용하여 인증할 수 없음 오류#
IAM 인증이 실패할 때 다음 오류가 발생할 수 있습니다:
$ tsh db connect --db-user=teleport-docdb-user --db-name=test my-docdb ... MongoServerSelectionError: error connecting to the database connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "MONGODB-AWS": Authentication failed. ERROR: exit status 1IAM 역할이 대상 DocumentDB 클러스터의 "$external" 데이터베이스에 DocumentDB 사용자로 존재하고, DocumentDB 사용자가 인증을 위해
MONGODB-AWS메커니즘으로 구성되어 있는지 확인합니다.자세한 내용은 IAM ID를 사용한 인증을 참조하세요.
다음 단계#
-
Learn how to restrict access to certain users and databases.
-
View the High Availability (HA) guide.
-
Take a look at the YAML configuration reference.
-
See the full CLI reference.
- 자세한 내용은 DocumentDB용 IAM ID를 사용한 인증에 대해 자세히 알아보세요.
