Amazon OpenSearch를 이용한 데이터베이스 접근
Teleport can provide secure access to Amazon OpenSearch via the Teleport Database Service. In this guide, you will: Teleport 데이터베이스 서비스는 IAM 역할을 백엔드 OpenSearch 역할에 매핑하는 세분화된 액세스 제어를 활용합니다.
Teleport can provide secure access to Amazon OpenSearch via the Teleport Database Service. This allows for fine-grained access control through Teleport's RBAC.
In this guide, you will:
- Configure your Amazon OpenSearch database IAM 인증을 사용하여 REST API를 통해.
- Add the database to your Teleport cluster.
- Connect to the database via Teleport.
작동 원리#
Teleport 데이터베이스 서비스는 IAM 역할을 백엔드 OpenSearch 역할에 매핑하는 세분화된 액세스 제어를 활용합니다. Teleport 사용자는 IAM 역할을 선택하고 로컬 프록시 서버를 통해 OpenSearch에 연결합니다. 로컬 프록시 서버는 Teleport 프록시 서비스를 통해 Teleport 데이터베이스 서비스로 요청을 전달합니다. 데이터베이스 서비스는 사용자가 선택한 IAM 역할을 수임하고, AWS 자격 증명으로 요청을 다시 작성한 후 OpenSearch API로 전달합니다.


This guide shows how to register a single OpenSearch database 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.
필수 조건#
- Amazon OpenSearch 도메인.
- Amazon OpenSearch Service 세분화된 액세스 제어 활성화
- IAM 역할을 생성할 IAM 권한.
$PATH에 설치된 opensearchsql 명령줄 인터페이스(CLI) 도구.
-
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:
-
- Teleport 데이터베이스 서비스를 실행할 호스트 (예: EC2 인스턴스). 이 가이드는 IAM 역할 생성 및 적용 시 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.
이 가이드는 모델로서 IAM 액세스 역할의 예제 구성을 제공하며, Teleport 데이터베이스 서비스를 제공하기 위해 EC2 인스턴스를 사용합니다. 제공되는 액세스 수준이 필요에 맞지 않거나 조직의 액세스 규칙에 맞지 않을 수 있습니다. 필요에 맞게 AWS IAM 권한을 조정해야 합니다.
Teleport를 사용하여 프라이빗 VPC 서브넷 내에 배포된 OpenSearch 대시보드에 접근하려면 Teleport에서 대시보드를 웹 애플리케이션으로 등록할 수 있습니다.
1/4단계. OpenSearch 관리형 클러스터 접근을 위한 IAM 역할 생성#
이 가이드에 설명된 설정에는 두 가지 IAM 역할이 필요합니다:
- Teleport 데이터베이스 서비스를 실행하는 EC2 인스턴스와 연결된 역할로, 사용자에게 부여된 추가 역할을 수임할 수 있게 합니다.
- EC2 인스턴스 역할이 수임할 수 있으며 사용자에게 OpenSearch 관리형 클러스터에 대한 액세스를 부여하는 역할.
EC2 인스턴스 역할#
AWS 콘솔의 IAM > 역할 페이지를 방문한 다음 "역할 생성"을 클릭합니다. 신뢰할 수 있는 엔터티 유형 아래에서 "AWS 서비스"를 선택합니다. 사용 사례 아래에서 "EC2"를 선택한 다음 다음을 클릭합니다.

"권한 추가" 페이지에서 이 역할에는 권한이 필요하지 않으므로 다음을 클릭합니다. 이 가이드에서는 이 역할에 예제 이름 TeleportDatabaseService를 사용합니다. 이름을 선택한 후 역할 생성을 클릭하여 프로세스를 완료합니다.
OpenSearch 서비스 클러스터 액세스 역할#
역할 페이지로 돌아가서 새 역할을 생성합니다. "AWS 계정" 옵션을 선택하면 이 계정의 다른 엔터티가 이 역할을 수임할 수 있도록 기본 신뢰 정책이 생성됩니다:

다음을 클릭합니다. 다음 페이지에서 역할 이름을 입력합니다. 이 가이드에서는 이 역할에 예제 이름 ExampleTeleportOpenSearchRole을 사용합니다.
"신뢰할 수 있는 엔터티 선택" 아래에서 TeleportDatabaseService 역할이 이 역할을 수임할 수 있도록 JSON을 업데이트합니다:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::(=aws.aws_access_key=):role/TeleportDatabaseService"
]
},
"Action": "sts:AssumeRole",
"Condition": {}
}
]
}
마지막으로 역할 생성을 클릭합니다.
Amazon OpenSearch 관리형 클러스터에서 클러스터 세분화된 액세스 제어 IAM 역할 매핑 구성#
Teleport Amazon OpenSearch 서비스 통합은 IAM 역할 또는 사용자가 OpenSearch 역할에 매핑되는 OpenSearch 세분화된 액세스 제어를 활용합니다.
역할 매핑을 구성하려면 마스터 사용자를 사용하여 OpenSearch 도메인 대시보드에 로그인하고 Security 설정으로 이동합니다:

최소 권한으로 새 역할을 생성하거나 기존 역할을 선택합니다.
이 예제의 목적으로는 readall OpenSearch 역할이 사용됩니다.
OpenSearch 역할을 선택하고 Mapped users 탭으로 이동합니다:

이전 단계에서 생성한 AWS IAM ExampleTeleportOpenSearchRole 역할과 OpenSearch 역할 간의 매핑을 추가합니다.

마지막으로 Map 버튼을 클릭하여 설정을 적용합니다.
2/4단계. Teleport IAM 역할 매핑 구성#
다음 단계는 Teleport 사용자에게 Teleport 클러스터를 통해 AWS 리소스에 접근할 때 AWS IAM 역할을 수임할 권한을 부여하는 것입니다.
이전 단계에서 생성한 IAM 역할 ARN을 나열하는 db_users 필드가 있는 Teleport 역할을 생성하여 이를 수행할 수 있습니다. 다음 내용으로 aws-opensearch-access.yaml 파일을 생성합니다:
kind: role
version: v7
metadata:
name: aws-opensearch-access
spec:
allow:
db_labels:
'env': 'dev'
db_users:
- 'ExampleTeleportOpenSearchRole'
새 역할을 생성합니다:
$ tctl create -f aws-opensearch-access.yaml
Assign the aws-opensearch-access role to your Teleport user by running the appropriate
commands for your authentication provider:
3/4단계. Teleport 데이터베이스 서비스 설치#
Teleport 데이터베이스 서비스를 호스팅하기 위한 EC2 인스턴스를 생성하고, TeleportDatabaseService AWS IAM 역할을 연결합니다. 다른 방법으로 서비스를 호스팅하는 경우, AWS 자격 증명을 서비스에 제공해야 합니다 - 자세한 내용은 AWS 자격 증명 구성을 참조하세요.
AWS GovCloud (US) 리전 및 AWS 중국 리전과 같은 비표준 AWS 리전의 경우, 데이터베이스 서비스가 올바른 STS 엔드포인트를 사용할 수 있도록 AWS_REGION 환경 변수 또는 AWS 자격 증명 파일에서 해당 리전을 설정하세요.
토큰 생성#
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:
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 설치 및 시작#
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를 시작합니다.
단일 Teleport 프로세스는 여러 다른 서비스를 실행할 수 있습니다. 예를 들어 여러 데이터베이스 서비스 에이전트뿐만 아니라 SSH 서비스 또는 애플리케이션 서비스도 함께 실행할 수 있습니다. 아래 단계는 기존 구성 파일을 덮어쓰므로, 여러 서비스를 실행하는 경우 --output=stdout을 추가하여 터미널에 구성을 출력하고 /etc/teleport.yaml을 수동으로 조정하세요.
데이터베이스 서비스의 구성 파일을 /etc/teleport.yaml에 생성합니다.
--proxy 명령줄 옵션을 Teleport 클러스터의 주소로 설정하고 데이터베이스 파라미터를 AWS 환경으로 설정합니다. 를 OpenSearch 인스턴스의 호스트명으로 지정합니다:
$ sudo teleport db configure create \
-o file \
--token=/tmp/token \
--proxy=:443 \
--name=example-opensearch \
--protocol=opensearch \
--uri=:443 \
--aws-account-id=(=aws.aws_access_key=) \
--labels=env=dev
Configure the Teleport 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 Teleport Database Service.
You can check the status of the Teleport Database Service with systemctl status teleport
and view its logs with journalctl -fu teleport.
4/4단계. 연결#
데이터베이스 서비스가 시작되고 클러스터에 참가하면 Amazon OpenSearch API에 접근하기 시작할 수 있습니다:
프록시 터널을 생성합니다:
$ tsh proxy db --tunnel --port=8000 --db-user=ExampleTeleportOpenSearchRole example-opensearch
Started authenticated tunnel for the OpenSearch database "example-opensearch" in cluster on 127.0.0.1:8000.
Use one of the following commands to connect to the database or to the address above using other database GUI/CLI clients:
* start interactive session with opensearchsql:
$ opensearchsql http://localhost:8000
* run request with opensearch-cli:
$ opensearch-cli --profile teleport --config /Users/alice/.tsh//example-opensearch/opensearch-cli/8a5ce249.yml curl get --path /
* run request with curl:
$ curl http://localhost:8000/
tsh proxy db 명령으로 생성된 로컬 터널을 통해 Amazon OpenSearch API와 상호작용할 수 있습니다:
$ curl http://localhost:8000/movies/_search \
-H 'Content-Type: application/json' \
-d '{ "query": { "match_all": {} } }'
{"took":170,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":{"value":1,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"movies","_id":"1","_score":1.0,"_source":{"director": "Burton, Tim", "genre": ["Comedy","Sci-Fi"], "year": 1996, "actor": ["Jack Nicholson","Pierce Brosnan","Sarah Jessica Parker"], "title": "Mars Attacks!"}}]}}
tsh db connect 명령을 사용하여 인터랙티브 세션을 시작할 수 있으며, 이 명령은 내부적으로 opensearchsql 바이너리를 인터랙티브 모드로 호출합니다:
$ tsh db connect example-opensearch --db-user=ExampleTeleportOpenSearchRole
# ____ _____ __
# / __ \____ ___ ____ / ___/___ ____ ___________/ /_
# / / / / __ \/ _ \/ __ \\__ \/ _ \/ __ `/ ___/ ___/ __ \
#/ /_/ / /_/ / __/ / / /__/ / __/ /_/ / / / /__/ / / /
#\____/ .___/\___/_/ /_/____/\___/\__,_/_/ \___/_/ /_/
# /_/
#
#Server: OpenSearch 2.5.0
#CLI Version: 1.0.0
#Endpoint: http://localhost:56766
#Query Language: sql
opensearchsql> select * from movies;
#fetched rows / total rows = 1/1
#+----------------+---------+---------------+--------+-------------+
#| actor | genre | title | year | director |
#|----------------+---------+---------------+--------+-------------|
#| Jack Nicholson | Comedy | Mars Attacks! | 1996 | Burton, Tim |
#+----------------+---------+---------------+--------+-------------+
opensearchsql>
