MongoDB Atlas로 데이터베이스 액세스
Teleport can provide secure access to MongoDB Atlas via the Teleport Database Service. In this guide, you will: Teleport Database Service는 상호 TLS 또는 AWS IAM을 사용하여 MongoDB Atlas와 통신합니다:
Teleport can provide secure access to MongoDB Atlas via the Teleport Database Service. This allows for fine-grained access control through Teleport's RBAC.
In this guide, you will:
- Configure your MongoDB Atlas database 상호 TLS 또는 AWS IAM 인증으로.
- Add the database to your Teleport cluster.
- Connect to the database via Teleport.
작동 방식#
Teleport Database Service는 상호 TLS 또는 AWS IAM을 사용하여 MongoDB Atlas와 통신합니다:
- 상호 TLS: MongoDB Atlas가 데이터베이스 클라이언트용 Teleport 인증 기관을 신뢰하도록 구성하고, Teleport가 MongoDB Atlas용 인증서에 서명하는 Let's Encrypt CA를 신뢰하도록 구성합니다. 사용자가 Teleport를 통해 MongoDB Atlas에 연결하면 Teleport Database Service는 인증서를 사용하여 인증하고 사용자 트래픽을 MongoDB Atlas로 전달합니다.
- AWS IAM: MongoDB 사용자가 "MONGODB-AWS" 인증 메커니즘을 사용하도록 구성하고, Teleport가 MongoDB Atlas용 인증서에 서명하는 Let's Encrypt CA를 신뢰하도록 구성합니다. 사용자가 Teleport를 통해 MongoDB Atlas에 연결하면 Teleport Database Service는 인증을 위해 연결된 IAM 역할을 맡아 사용자 트래픽을 MongoDB Atlas로 전달합니다.


사전 조건#
-
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:
-
- MongoDB Atlas 클러스터.
- Teleport Database Service를 실행할 호스트(예: Amazon 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/4단계. Teleport Database Service 설정#
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=)
Teleport Database Service를 실행할 호스트에 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
다음으로 Database Service를 시작합니다.
Database Service를 실행할 노드에서 Teleport를 시작하고 --auth-server 플래그를 Teleport Proxy Service 주소로 지정합니다:
$ sudo teleport db start \
--token=/tmp/token \
--auth-server= \
--name=mongodb-atlas \
--protocol=mongodb \
--uri=mongodb+srv://cluster0.abcde.mongodb.net \
--labels=env=dev
--auth-server 플래그는 Database Service가 항상 역방향 터널을 통해 클러스터에 연결하기 때문에 Teleport 클러스터의 Proxy Service 엔드포인트를 가리켜야 합니다.
Teleport Database Service를 실행할 노드에서 /etc/teleport.yaml에 다음을 추가합니다:
version: v3
teleport:
auth_token: "/tmp/token"
proxy_server:
You can check the status of the Teleport Database Service with systemctl status teleport
and view its logs with journalctl -fu teleport.
자세한 내용은 전체 YAML 참조를 확인하세요.
Teleport Database Service 구성 방법에 대한 자세한 내용은 아래를 참조하세요.
연결 엔드포인트#
db_service.databases[*].uri 구성 옵션 또는 --uri CLI 플래그에 Atlas 클러스터의 연결 엔드포인트를 제공해야 합니다. Database Deployments 개요 페이지의 Connect 대화 상자에서 확인할 수 있습니다:

"Setup connection security" 단계를 진행하고 "Connect with the MongoDB shell"을 선택하여 연결 문자열을 확인합니다:

URI에는 연결 문자열의 스킴과 호스트명 부분만 사용합니다:
$ --uri=mongodb+srv://cluster0.abcde.mongodb.net
2/4단계. Teleport 사용자 생성#
| Flag | Description |
|---|---|
--roles |
List of roles to assign to the user. The builtin access role allows them to connect to any database server registered with Teleport. |
--db-users |
List of database usernames the user will be allowed to use when connecting to the databases. A wildcard allows any user. |
--db-names |
List 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.
If you opt for a stricter selection of database names for your user, which
differs from the wildcard approach illustrated in this guide, it is essential
to include the admin database. This ensures MongoDB clients won't have
issues while connecting and executing operations such as retrieving server
information, listing databases, and aborting transactions.
3/4단계. Atlas 구성#
Teleport MongoDB Atlas 통합은 두 가지 인증 방법을 지원합니다:
- 자체 관리 X.509: 이 방법은 인증에 인증서를 사용하며 MongoDB Atlas가 Teleport 인증서를 신뢰합니다.
- AWS IAM: Teleport가 가져온 AWS 자격 증명을 사용하여 인증합니다.
먼저 Teleport 클러스터에 대해 다음 tctl auth sign 명령을 실행하여 Teleport CA 인증서를 가져옵니다:
$ tctl auth sign --format=mongodb --host=mongo --out=mongo
이 경우 --host 및 --ttl 플래그 값은 중요하지 않으며, 이 명령이 mongo.cas 파일에 출력할 CA 인증서만 사용합니다.
나머지 mongo.crt 파일은 삭제해도 됩니다.
Atlas 클러스터의 Security / Advanced configuration 섹션으로 이동하여 "Self-managed X.509 Authentication"을 켭니다:

Certificate Authority 편집 상자에 mongo.cas 파일의 내용을 붙여넣고 저장합니다.
MongoDB 사용자 생성#
Security / Database Access 페이지에서 Certificate 인증 방법으로 새 데이터베이스 사용자를 추가합니다:

MongoDB는 전체 인증서 주체를 사용자 이름으로 처리하므로 위와 같이 사용자를 CN=<user>로 지정해야 합니다. MongoDB 클러스터에 사용자 alice로 연결할 때 Teleport는 CN=alice 주체로 임시 인증서에 서명합니다.
대소문자가 구별되므로 사용자 이름에 대문자 CN=으로 Common Name을 지정해야 합니다.
Teleport Database Service에 AWS 자격 증명 액세스를 제공해야 합니다.
Grant the Database Service access to credentials that it can use to authenticate to AWS.
- If you are running the Database Service on an EC2 instance, you may use the EC2 Instance Metadata Service method
- If you are running the Database Service in Kubernetes, you can use IAM Roles for Service Accounts (IRSA)
- Otherwise, you must use environment variables
Have multiple sources of AWS credentials?
Teleport's AWS client loads credentials from different sources in the following order:
- Environment Variables
- Shared credentials file
- Shared configuration file (Teleport always enables shared configuration)
- EC2 Instance Metadata (credentials only)
While you can provide AWS credentials via a shared credentials file or shared
configuration file, you will need to run the Database Service with the AWS_PROFILE
environment variable assigned to the name of your profile of choice.
If you have a specific use case that the instructions above do not account for, consult the documentation for the AWS SDK for Go for a detailed description of credential loading behavior.
MongoDB IAM 역할 생성#
AWS IAM 콘솔로 이동합니다. 탐색 창에서 역할을 선택한 다음 역할 생성을 선택합니다. 그런 다음 "Custom trust policy" 유형을 선택합니다. Teleport Database Service IAM 역할이 이 역할을 맡을 수 있도록 신뢰 정책을 편집하여 Teleport가 MongoDB에 인증하는 데 필요한 자격 증명을 가져올 수 있도록 합니다:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:role/teleport-database-access",
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
역할에 권한이 필요하지 않으므로 권한 추가 단계에서 비워두어도 됩니다. 그런 다음 이름을 선택하고 생성합니다. 이 가이드에서는 teleport-access라는 이름을 사용합니다.
MongoDB 사용자 생성#
Security / Database Access 페이지에서 AWS IAM 인증 방법으로 새 데이터베이스 사용자를 추가하고 IAM 사용자 유형으로 "IAM Role"을 선택합니다. 그런 다음 새로 생성된 IAM 역할의 ARN을 AWS ARN 필드에 입력합니다. 데이터베이스 사용자 권한 섹션에서 원하는 데이터베이스 데이터에 액세스하기에 충분한 권한을 부여합니다.

Teleport는 AWS IAM 사용자를 사용한 인증을 지원하지 않으며 AWS IAM 역할을 사용한 인증만 지원합니다.
4/4단계. 연결#
Teleport 클러스터에 로그인하고 사용 가능한 데이터베이스를 확인합니다:
$ tsh login --proxy=teleport.example.com --user=alice
$ tsh db ls
# Name Description Labels
# ------------- ----------- --------
# mongodb-atlas env=dev
$ tsh login --proxy=mytenant.teleport.sh --user=alice
$ tsh db ls
# Name Description Labels
# ------------- ----------- --------
# mongodb-atlas env=dev
데이터베이스의 자격 증명을 가져와 연결하려면:
$ tsh db connect --db-user=alice --db-name dev mongodb-atlas
데이터베이스의 자격 증명을 가져와 연결하려면 데이터베이스 사용자 이름을 role/<role-name> 형식으로 제공해야 합니다:
$ tsh db connect --db-user=role/teleport-access --db-name dev mongodb-atlas
또는 데이터베이스 인스턴스에 연결할 때 데이터베이스 사용자 이름으로 전체 ARN을 제공할 수 있습니다:
$ tsh db connect --db-user=arn:aws:iam::111111111111:role/teleport-access --db-name dev mongodb-atlas
이 섹션의 내용은 원문 문서를 참조하세요. (proxy-db-tunnel.mdx)
연결하려면 mongosh 또는 mongo 명령줄 클라이언트가 PATH에 있어야 합니다. Database Service는 먼저 mongosh 실행을 시도하고, mongosh가 PATH에 없으면 mongo를 실행합니다.
데이터베이스에서 로그아웃하고 자격 증명을 제거하려면:
# 특정 데이터베이스 인스턴스의 자격 증명 제거.
$ tsh db logout mongodb-atlas
# 모든 데이터베이스 인스턴스의 자격 증명 제거.
$ tsh db logout
다음 단계#
-
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.
