InfoGrab Docs

Amazon DynamoDB를 이용한 데이터베이스 접근

요약

Teleport can provide secure access to Amazon DynamoDB via the Teleport Database Service. In this guide, you will: Teleport 사용자는 Teleport 프록시 서비스를 통해 Teleport 데이터베이스 서비스로 요청을 전달하는 로컬 프록시 서버를 사용하여 DynamoDB에 연결합니다.

Teleport can provide secure access to Amazon DynamoDB via the Teleport Database Service. This allows for fine-grained access control through Teleport's RBAC.

In this guide, you will:

  1. Configure your Amazon DynamoDB database IAM 인증을 사용하여.
  2. Add the database to your Teleport cluster.
  3. Connect to the database via Teleport.

작동 원리#

Teleport 사용자는 Teleport 프록시 서비스를 통해 Teleport 데이터베이스 서비스로 요청을 전달하는 로컬 프록시 서버를 사용하여 DynamoDB에 연결합니다. 연결 시, 사용자는 수임할 IAM 역할을 선택합니다. Teleport 데이터베이스 서비스는 이 역할과 잠재적으로 다른 IAM 역할을 수임할 권한을 가집니다. Teleport 데이터베이스 서비스가 사용자 요청을 받으면 AWS의 자격 증명으로 요청을 다시 작성한 다음 DynamoDB API로 전달합니다.

DynamoDB 자체 호스팅

DynamoDB 클라우드

필수 조건#

  • DynamoDB 데이터베이스가 있는 AWS 계정.
  • IAM 역할을 생성할 IAM 권한.
  • $PATH에 설치된 aws 명령줄 인터페이스(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 tctl and tsh clients.

    Installing `tctl` and `tsh` clients
    1. Determine the version of your Teleport cluster. The tctl and tsh clients must be at most one major version behind your Teleport cluster version. Send a GET request to the Proxy Service at /v1/webapi/find and 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')"
      
    2. Follow the instructions for your platform to install tctl and tsh clients:

  • 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 권한을 조정해야 합니다.

1/4단계. DynamoDB 액세스를 위한 IAM 역할 생성#

이 가이드에 설명된 설정에는 두 가지 IAM 역할이 필요합니다:

  • Teleport 데이터베이스 서비스를 실행하는 EC2 인스턴스와 연결된 역할로, 사용자에게 부여된 추가 역할을 수임할 수 있게 합니다.
  • EC2 인스턴스 역할이 수임할 수 있으며 사용자에게 DynamoDB 서비스에 대한 액세스를 부여하는 역할.

EC2 인스턴스 역할#

AWS 콘솔의 IAM > 역할 페이지를 방문한 다음 "역할 생성"을 클릭합니다. 신뢰할 수 있는 엔터티 유형 아래에서 "AWS 서비스"를 선택합니다. 사용 사례 아래에서 "EC2"를 선택한 다음 다음을 클릭합니다.

EC2 인스턴스 식별을 위한 역할 생성

"권한 추가" 페이지에서 이 역할에는 권한이 필요하지 않으므로 다음을 클릭합니다. 이 가이드에서는 이 역할에 예제 이름 TeleportDatabaseService를 사용합니다. 이름을 선택한 후 역할 생성을 클릭하여 프로세스를 완료합니다.

DynamoDB 액세스 역할#

역할 페이지로 돌아가서 새 역할을 생성합니다. "AWS 계정" 옵션을 선택하면 이 계정의 다른 엔터티가 이 역할을 수임할 수 있도록 기본 신뢰 정책이 생성됩니다:

역할 생성 1단계

다음을 클릭합니다. AWS 관리형 정책 AmazonDynamoDBFullAccess를 찾아 선택합니다:

역할 생성 2단계

최소 권한 적용

AmazonDynamoDBFullAccess 정책은 원하는 것보다 더 많은 권한을 부여할 수 있습니다. 권한을 줄이기 위해 다른 IAM 정책을 사용하려면 Amazon DynamoDB 리소스에 대한 액세스 권한 관리를 참조하세요.

다음을 클릭합니다. 다음 페이지에서 역할 이름을 입력합니다. 이 가이드에서는 이 역할에 예제 이름 ExampleTeleportDynamoDBRole을 사용합니다.

"신뢰할 수 있는 엔터티 선택" 아래에서 TeleportDatabaseService 역할이 이 역할을 수임할 수 있도록 JSON을 업데이트합니다:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "arn:aws:iam::(=aws.aws_access_key=):role/TeleportDatabaseService"
                ]
            },
            "Action": "sts:AssumeRole",
            "Condition": {}
        }
    ]
}

마지막으로 역할 생성을 클릭합니다.

2/4단계. Teleport IAM 역할 매핑 구성#

다음 단계는 Teleport 사용자에게 Teleport 클러스터를 통해 AWS 리소스에 접근할 때 AWS IAM 역할을 수임할 권한을 부여하는 것입니다.

이전 단계에서 생성한 IAM 역할 ARN을 나열하는 db_users 필드가 있는 Teleport 역할을 생성하여 이를 수행할 수 있습니다. 다음 내용으로 aws-dynamodb-access.yaml 파일을 생성합니다:

kind: role
version: v7
metadata:
  name: aws-dynamodb-access
spec:
  allow:
    db_labels:
      '*': '*'
    db_users:
    - 'ExampleTeleportDynamoDBRole'

새 역할을 생성합니다:

$ tctl create -f aws-dynamodb-access.yaml

Assign the aws-dynamodb-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 리전

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.

  1. Assign to your Teleport cluster hostname and port, but not the scheme (https://).

  2. Run your cluster's install script:

    $ curl "https:///scripts/install.sh" | sudo bash
    

다음 내용으로 /etc/teleport.yaml 파일을 생성합니다:

version: v3
teleport:
  nodename: CHANGEME
  data_dir: /var/lib/teleport
  proxy_server: teleport.example.com:443
  auth_token: /tmp/token
db_service:
  enabled: true
  # 이 에이전트가 프록시하는 정적 등록 데이터베이스 목록.
  databases:
    - name: "example-dynamodb"
      protocol: "dynamodb"
      # 선택적 URI, URI가 설정된 경우 AWS 리전을 추출하거나
      # AWS 리전이 이미 설정된 경우 리전이 일치해야 합니다.
      # uri: "dynamodb.us-east-1.amazonaws.com:443"
      static_labels:
        env: "dev"
      aws:
        region: "us-east-1"
        account_id: "(=aws.aws_access_key=)"

teleport.example.com을 Teleport 프록시 서비스의 주소로 교체합니다. (Teleport 클라우드 고객의 경우 mytenant.teleport.sh와 유사합니다.) 생성된 토큰은 /tmp/token 파일에 저장되어야 합니다.

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단계. 연결#

데이터베이스 서비스가 시작되고 클러스터에 참가하면 DynamoDB 데이터베이스에 연결을 시작할 수 있습니다.

프록시 터널을 생성합니다:

$ tsh proxy db --tunnel --port 8000 --db-user=ExampleTeleportDynamoDBRole example-dynamodb

aws CLI를 통해 데이터베이스 연결을 테스트할 수 있습니다:

$ aws dynamodb list-tables --endpoint-url=http://localhost:8000
{
    "TableNames": [
        "table1",
        "table2",
        "table3"
    ]
}

데이터베이스 접근 GUI 클라이언트 가이드에 문서화된 대로 AWS NoSQL Workbench에서도 이 데이터베이스에 연결할 수 있습니다.

프로그래밍 방식 액세스에도 이 터널을 사용할 수 있습니다. 아래 예제는 AWS의 boto3 SDK를 사용합니다:

$ python3
Python 3.10.4 (main, Mar 31 2022, 03:37:37) [Clang 12.0.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
>>> clt = boto3.client('dynamodb', endpoint_url='http://localhost:8000')
>>> res = clt.list_tables()
>>> print(res)
{'TableNames': *snip output*}
>>>

다음 단계#

  • 인프라에서 접근 가능한 데이터베이스를 Teleport가 최신 상태로 유지하기 위해 리소스 레이블을 사용하는 방법을 알아보려면 동적 데이터베이스 등록을 참조하세요.

Amazon DynamoDB를 이용한 데이터베이스 접근

원문 보기
요약

Teleport can provide secure access to Amazon DynamoDB via the Teleport Database Service. In this guide, you will: Teleport 사용자는 Teleport 프록시 서비스를 통해 Teleport 데이터베이스 서비스로 요청을 전달하는 로컬 프록시 서버를 사용하여 DynamoDB에 연결합니다.

Teleport can provide secure access to Amazon DynamoDB via the Teleport Database Service. This allows for fine-grained access control through Teleport's RBAC.

In this guide, you will:

  1. Configure your Amazon DynamoDB database IAM 인증을 사용하여.
  2. Add the database to your Teleport cluster.
  3. Connect to the database via Teleport.

작동 원리#

Teleport 사용자는 Teleport 프록시 서비스를 통해 Teleport 데이터베이스 서비스로 요청을 전달하는 로컬 프록시 서버를 사용하여 DynamoDB에 연결합니다. 연결 시, 사용자는 수임할 IAM 역할을 선택합니다. Teleport 데이터베이스 서비스는 이 역할과 잠재적으로 다른 IAM 역할을 수임할 권한을 가집니다. Teleport 데이터베이스 서비스가 사용자 요청을 받으면 AWS의 자격 증명으로 요청을 다시 작성한 다음 DynamoDB API로 전달합니다.

DynamoDB 자체 호스팅

DynamoDB 클라우드

필수 조건#

  • DynamoDB 데이터베이스가 있는 AWS 계정.
  • IAM 역할을 생성할 IAM 권한.
  • $PATH에 설치된 aws 명령줄 인터페이스(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 tctl and tsh clients.

    Installing `tctl` and `tsh` clients
    1. Determine the version of your Teleport cluster. The tctl and tsh clients must be at most one major version behind your Teleport cluster version. Send a GET request to the Proxy Service at /v1/webapi/find and 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')"
      
    2. Follow the instructions for your platform to install tctl and tsh clients:

  • 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 권한을 조정해야 합니다.

1/4단계. DynamoDB 액세스를 위한 IAM 역할 생성#

이 가이드에 설명된 설정에는 두 가지 IAM 역할이 필요합니다:

  • Teleport 데이터베이스 서비스를 실행하는 EC2 인스턴스와 연결된 역할로, 사용자에게 부여된 추가 역할을 수임할 수 있게 합니다.
  • EC2 인스턴스 역할이 수임할 수 있으며 사용자에게 DynamoDB 서비스에 대한 액세스를 부여하는 역할.

EC2 인스턴스 역할#

AWS 콘솔의 IAM > 역할 페이지를 방문한 다음 "역할 생성"을 클릭합니다. 신뢰할 수 있는 엔터티 유형 아래에서 "AWS 서비스"를 선택합니다. 사용 사례 아래에서 "EC2"를 선택한 다음 다음을 클릭합니다.

EC2 인스턴스 식별을 위한 역할 생성

"권한 추가" 페이지에서 이 역할에는 권한이 필요하지 않으므로 다음을 클릭합니다. 이 가이드에서는 이 역할에 예제 이름 TeleportDatabaseService를 사용합니다. 이름을 선택한 후 역할 생성을 클릭하여 프로세스를 완료합니다.

DynamoDB 액세스 역할#

역할 페이지로 돌아가서 새 역할을 생성합니다. "AWS 계정" 옵션을 선택하면 이 계정의 다른 엔터티가 이 역할을 수임할 수 있도록 기본 신뢰 정책이 생성됩니다:

역할 생성 1단계

다음을 클릭합니다. AWS 관리형 정책 AmazonDynamoDBFullAccess를 찾아 선택합니다:

역할 생성 2단계

최소 권한 적용

AmazonDynamoDBFullAccess 정책은 원하는 것보다 더 많은 권한을 부여할 수 있습니다. 권한을 줄이기 위해 다른 IAM 정책을 사용하려면 Amazon DynamoDB 리소스에 대한 액세스 권한 관리를 참조하세요.

다음을 클릭합니다. 다음 페이지에서 역할 이름을 입력합니다. 이 가이드에서는 이 역할에 예제 이름 ExampleTeleportDynamoDBRole을 사용합니다.

"신뢰할 수 있는 엔터티 선택" 아래에서 TeleportDatabaseService 역할이 이 역할을 수임할 수 있도록 JSON을 업데이트합니다:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "arn:aws:iam::(=aws.aws_access_key=):role/TeleportDatabaseService"
                ]
            },
            "Action": "sts:AssumeRole",
            "Condition": {}
        }
    ]
}

마지막으로 역할 생성을 클릭합니다.

2/4단계. Teleport IAM 역할 매핑 구성#

다음 단계는 Teleport 사용자에게 Teleport 클러스터를 통해 AWS 리소스에 접근할 때 AWS IAM 역할을 수임할 권한을 부여하는 것입니다.

이전 단계에서 생성한 IAM 역할 ARN을 나열하는 db_users 필드가 있는 Teleport 역할을 생성하여 이를 수행할 수 있습니다. 다음 내용으로 aws-dynamodb-access.yaml 파일을 생성합니다:

kind: role
version: v7
metadata:
  name: aws-dynamodb-access
spec:
  allow:
    db_labels:
      '*': '*'
    db_users:
    - 'ExampleTeleportDynamoDBRole'

새 역할을 생성합니다:

$ tctl create -f aws-dynamodb-access.yaml

Assign the aws-dynamodb-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 리전

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.

  1. Assign to your Teleport cluster hostname and port, but not the scheme (https://).

  2. Run your cluster's install script:

    $ curl "https:///scripts/install.sh" | sudo bash
    

다음 내용으로 /etc/teleport.yaml 파일을 생성합니다:

version: v3
teleport:
  nodename: CHANGEME
  data_dir: /var/lib/teleport
  proxy_server: teleport.example.com:443
  auth_token: /tmp/token
db_service:
  enabled: true
  # 이 에이전트가 프록시하는 정적 등록 데이터베이스 목록.
  databases:
    - name: "example-dynamodb"
      protocol: "dynamodb"
      # 선택적 URI, URI가 설정된 경우 AWS 리전을 추출하거나
      # AWS 리전이 이미 설정된 경우 리전이 일치해야 합니다.
      # uri: "dynamodb.us-east-1.amazonaws.com:443"
      static_labels:
        env: "dev"
      aws:
        region: "us-east-1"
        account_id: "(=aws.aws_access_key=)"

teleport.example.com을 Teleport 프록시 서비스의 주소로 교체합니다. (Teleport 클라우드 고객의 경우 mytenant.teleport.sh와 유사합니다.) 생성된 토큰은 /tmp/token 파일에 저장되어야 합니다.

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단계. 연결#

데이터베이스 서비스가 시작되고 클러스터에 참가하면 DynamoDB 데이터베이스에 연결을 시작할 수 있습니다.

프록시 터널을 생성합니다:

$ tsh proxy db --tunnel --port 8000 --db-user=ExampleTeleportDynamoDBRole example-dynamodb

aws CLI를 통해 데이터베이스 연결을 테스트할 수 있습니다:

$ aws dynamodb list-tables --endpoint-url=http://localhost:8000
{
    "TableNames": [
        "table1",
        "table2",
        "table3"
    ]
}

데이터베이스 접근 GUI 클라이언트 가이드에 문서화된 대로 AWS NoSQL Workbench에서도 이 데이터베이스에 연결할 수 있습니다.

프로그래밍 방식 액세스에도 이 터널을 사용할 수 있습니다. 아래 예제는 AWS의 boto3 SDK를 사용합니다:

$ python3
Python 3.10.4 (main, Mar 31 2022, 03:37:37) [Clang 12.0.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
>>> clt = boto3.client('dynamodb', endpoint_url='http://localhost:8000')
>>> res = clt.list_tables()
>>> print(res)
{'TableNames': *snip output*}
>>>

다음 단계#

  • 인프라에서 접근 가능한 데이터베이스를 Teleport가 최신 상태로 유지하기 위해 리소스 레이블을 사용하는 방법을 알아보려면 동적 데이터베이스 등록을 참조하세요.