AWS Organizations용 Terraform EC2 자동 검색 구성
Teleport v18.11요약
이 가이드는 Terraform을 사용하여 AWS 조직의 EC2 인스턴스를 Teleport 클러스터에 자동으로 등록하도록 Teleport와 AWS를 구성하는 방법을 설명합니다. teleport-discovery-aws Terraform 모듈은 Teleport EC2 자동 검색을 활성화하기 위해 Teleport 클러스터와 AWS 조직에 리소스를 생성합니다.
이 가이드는 Terraform을 사용하여 AWS 조직의 EC2 인스턴스를 Teleport 클러스터에 자동으로 등록하도록 Teleport와 AWS를 구성하는 방법을 설명합니다.
작동 방식#
teleport-discovery-aws Terraform 모듈은 Teleport EC2 자동 검색을 활성화하기 위해 Teleport 클러스터와 AWS 조직에 리소스를 생성합니다.
Teleport Discovery Service는 AWS API를 쿼리하여 조건에 일치하는 계정 목록과 각 계정의 EC2 인스턴스 목록을 가져옵니다. Discovery Service는 검색된 각 EC2 인스턴스에 대해 AWS Systems Manager(SSM)를 사용하여 해당 인스턴스에 Teleport를 설치하고 이를 Teleport가 보호하는 서버로 클러스터에 조인시킵니다.
사전 요구사항#
-
실행 중인 Teleport 클러스터. Teleport를 시작하려면 무료 체험판에 가입하거나 데모 환경을 구성하세요.
-
tctlandtshclients.Installing `tctl` and `tsh` clients
-
Teleport 클러스터의 버전을 확인합니다.
tctlandtshclients는 Teleport 클러스터 버전보다 최대 한 개의 메이저 버전까지만 뒤처질 수 있습니다. Proxy Service의/v1/webapi/find로 GET 요청을 보내고 JSON 쿼리 도구를 사용하여 클러스터 버전을 확인합니다.teleport.example.com:443를 Teleport Proxy Service의 웹 주소로 바꿉니다:$ TELEPORT_DOMAIN=teleport.example.com:443 $ TELEPORT_VERSION="$(curl -s https://$TELEPORT_DOMAIN/v1/webapi/find | jq -r '.server_version')" -
사용 중인 플랫폼에 대한 지침에 따라
tctlandtshclients를 설치합니다:
-
Mac
`tctl` and `tsh` clients가 포함된, 서명된 Teleport macOS .pkg 설치 프로그램을 다운로드합니다:
```code
$ curl -O https://cdn.teleport.dev/teleport-${TELEPORT_VERSION?}.pkg
```
Finder에서 `pkg` 파일을 더블 클릭하여 설치를 시작합니다.
Homebrew를 사용하여 Teleport를 설치하는 것은 지원되지 않습니다. Homebrew의
Teleport 패키지는 Teleport에서 유지 관리하지 않으므로 신뢰성이나 보안을
보장할 수 없습니다.
Windows - Powershell
```code
$ curl.exe -O https://cdn.teleport.dev/teleport-v${TELEPORT_VERSION?}-windows-amd64-bin.zip
# Unzip the archive and move the `tctl` and `tsh` clients to your %PATH%
# NOTE: Do not place the `tctl` and `tsh` clients in the System32 directory, as this can cause issues when using WinSCP.
# Use %SystemRoot% (C:\Windows) or %USERPROFILE% (C:\Users\<username>) instead.
```
Linux
Linux 설치판의 모든 Teleport 바이너리에는 `tctl` and `tsh` clients가 포함되어 있습니다. RPM/DEB
패키지 및 i386/ARM/ARM64용 다운로드를 포함한 더 많은 옵션은
[설치 페이지](../installation/installation.mdx)를 참조하세요.
```code
$ curl -O https://cdn.teleport.dev/teleport-v${TELEPORT_VERSION?}-linux-amd64-bin.tar.gz
$ tar -xzf teleport-v${TELEPORT_VERSION?}-linux-amd64-bin.tar.gz
$ cd teleport
$ sudo ./install
# Teleport binaries have been copied to /usr/local/bin
```
- Ubuntu/Debian/RHEL/Amazon Linux 2/Amazon Linux 2023을 실행하는 EC2 인스턴스와 SSM Agent 버전 3.1 이상
Teleport cluster에 연결할 수 있는지 확인하려면 tsh login으로 로그인한 다음,
현재 자격 증명으로 tctl 명령을 실행할 수 있는지 확인합니다.
예를 들어, teleport.example.com에 cluster 내 Teleport Proxy Service의
도메인 이름을, email@example.com에 Teleport 사용자 이름을 지정하여
다음 명령을 실행합니다:
$ tsh login --proxy=teleport.example.com --user=email@example.com
$ tctl status
# Cluster (=teleport.url=)
# Version (=teleport.version=)
# CA pin (=presets.ca_pin=)
cluster에 연결하여 tctl status 명령을 실행할 수 있다면, 현재 자격 증명을 사용하여
워크스테이션에서 이후의 tctl 명령을 실행할 수 있습니다.
자체 Teleport cluster를 호스팅하는 경우, 전체 권한을 얻기 위해 Teleport Auth Service를
호스팅하는 컴퓨터에서 tctl 명령을 실행할 수도 있습니다.
- 관리 계정 또는 위임된 관리자인 멤버 계정에 대한 접근 권한.
- 관리 계정 또는 위임된 관리자인 멤버 계정의 자격 증명으로 구성된 AWS Terraform 공급자.
- Teleport Terraform 공급자 사용하기에 설명된 방법 중 하나로 구성된 Teleport Terraform 공급자.
Discovery Service에 의해 Teleport 클러스터에 추가된 모든 EC2 인스턴스는 Discovery Service로부터
명령을 수신하기 위해 AmazonSSMManagedInstanceCore IAM 정책을 반드시
포함해야 합니다. 해당 정책에 포함된 권한 목록은
AWS
문서를 참조합니다.
AWS Terraform 공급자에 필요한 AWS IAM 권한
AWS Terraform 공급자가 teleport-discovery-aws 모듈이 생성한 AWS 리소스를 관리하려면 다음 AWS IAM 권한이 필요합니다:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "TerraformIdentity",
"Effect": "Allow",
"Action": "sts:GetCallerIdentity",
"Resource": "*"
},
{
"Sid": "ManageIamRole",
"Effect": "Allow",
"Action": [
"iam:CreateRole",
"iam:DeleteRole",
"iam:GetRole",
"iam:ListInstanceProfilesForRole",
"iam:ListRolePolicies",
"iam:ListRoles",
"iam:ListRoleTags",
"iam:TagRole",
"iam:UntagRole",
"iam:UpdateAssumeRolePolicy"
],
"Resource": "*"
},
{
"Sid": "ManageIamPolicy",
"Effect": "Allow",
"Action": [
"iam:CreatePolicy",
"iam:CreatePolicyVersion",
"iam:DeletePolicy",
"iam:DeletePolicyVersion",
"iam:GetPolicy",
"iam:GetPolicyVersion",
"iam:ListPolicies",
"iam:ListPolicyTags",
"iam:ListPolicyVersions",
"iam:TagPolicy",
"iam:UntagPolicy"
],
"Resource": "*"
},
{
"Sid": "ManageRolePolicyAttachments",
"Effect": "Allow",
"Action": [
"iam:AttachRolePolicy",
"iam:DetachRolePolicy",
"iam:ListAttachedRolePolicies"
],
"Resource": "*"
},
{
"Sid": "ManageOidcProvider",
"Effect": "Allow",
"Action": [
"iam:CreateOpenIDConnectProvider",
"iam:DeleteOpenIDConnectProvider",
"iam:GetOpenIDConnectProvider",
"iam:ListOpenIDConnectProviders",
"iam:TagOpenIDConnectProvider",
"iam:UntagOpenIDConnectProvider",
"iam:UpdateOpenIDConnectProviderThumbprint"
],
"Resource": "*"
},
{
"Sid": "Organization",
"Effect": "Allow",
"Action": [
"organizations:ListAccounts",
"organizations:ListRoots",
"organizations:ListAWSServiceAccessForOrganization",
"organizations:DescribeOrganization"
],
"Resource": "*"
}
]
}
1/7단계. Discovery Service를 실행할 Teleport 설치#
이미 실행 중인 Discovery Service 인스턴스가 있다면 해당 인스턴스의 discovery_group을 discovery-group-name에 할당하고 4단계: AWS Terraform 공급자 구성으로 진행합니다.
모든 Teleport Cloud 클러스터는 Discovery Service를 대신 실행하므로, Teleport Cloud 구독자도 이 설치 단계를 모두 건너뛸 수 있습니다.
Discovery Service를 이미 다른 Teleport 서비스(예: Auth 또는 Proxy)가 실행 중인 호스트에서 실행할 계획이라면 이 단계를 건너뛸 수 있습니다.
Discovery Service를 실행할 호스트 인스턴스에 Teleport를 설치합니다:
Linux 서버에 Teleport Agent를 설치하려면:
권장 설치 방법은 클러스터 설치 스크립트입니다. 이 스크립트는 클러스터에 맞는 올바른 버전, 에디션, 설치 모드를 선택합니다.
-
teleport.example.com:443에 Teleport 클러스터의 호스트명과 포트를 할당하되, 스킴(https://)은 포함하지 마십시오. -
클러스터의 설치 스크립트를 실행하십시오:
$ curl "https://teleport.example.com:443/scripts/install.sh" | sudo bash
2/7단계. Discovery Service 구성#
Discovery Service를 독립된 호스트에서 실행하는 경우, 서비스가 클러스터에 연결하려면 유효한 초대 토큰이 필요합니다. Teleport Auth Service에 대해 다음 명령을 실행하여 토큰을 생성합니다:
$ tctl tokens add --type=discovery
생성된 토큰을 Discovery Service를 실행할 Teleport 에이전트 인스턴스의 /tmp/token에 저장합니다.
Discovery Service는 검색된 리소스를 서로 다른 집합으로 그룹화할 수 있게 하는
구성 파라미터 discovery_service.discovery_group을 제공합니다. 이 파라미터는
서로 다른 클라우드 리소스 집합을 감시하는 Discovery Agent들이 서로 충돌하여
다른 서비스가 생성한 리소스를 삭제하는 것을 방지하는 데 사용됩니다.
여러 개의 Discovery Service를 실행할 때, 동일한 클라우드 리소스를 감시하는
경우에는 각 서비스가 동일한 discovery_group 값으로 구성되어 있는지 확인해야
하며, 서로 다른 클라우드 리소스를 감시하는 경우에는 서로 다른 값으로 구성해야
합니다.
동일한 Teleport 클러스터에서 구성을 혼합하여 실행할 수 있습니다. 즉 일부 Discovery Service는 동일한 클라우드 리소스를 감시하도록 구성하고 다른 서비스는 서로 다른 리소스를 감시하도록 구성할 수 있습니다. 예를 들어, 서로 다른 두 개의 클라우드 계정에서 데이터를 분석하는 4개 에이전트 고가용성 구성은 다음과 같은 구성으로 실행됩니다.
- Production 계정에서 데이터를 폴링하는
discovery_group: "prod"로 구성된 Discovery Service 2개. - Staging 계정에서 데이터를 폴링하는
discovery_group: "staging"로 구성된 Discovery Service 2개.
teleport.example.com:443에 클러스터의 Teleport 프록시 서비스 호스트와 포트를,
discovery-group-name에 등록할 리소스 그룹을 식별하는 이름을 할당합니다:
# teleport.yaml
version: v3
teleport:
join_params:
# token_name can be a literal token string or a path to a file.
# File path is preferable to avoid including a secret in the config file.
token_name: "/tmp/token"
method: token
proxy_server: "teleport.example.com:443"
auth_service:
enabled: false
proxy_service:
enabled: false
ssh_service:
enabled: false
discovery_service:
enabled: true
discovery_group: "discovery-group-name"
3/7단계. Teleport Discovery Service 시작#
the Discovery Service이(가) AWS에 인증하는 데 사용할 수 있는 자격 증명에 대한 접근 권한을 부여합니다.
- the Discovery Service을(를) EC2 인스턴스에서 실행하는 경우 EC2 Instance Metadata Service 방식을 사용할 수 있습니다
- the Discovery Service을(를) Kubernetes에서 실행하는 경우 IAM Roles for Service Accounts (IRSA)를 사용할 수 있습니다
- 그 외의 경우에는 환경 변수를 사용해야 합니다
Instance Metadata Service
Teleport는 EC2 인스턴스에서 실행 중일 때를 감지하고 Instance Metadata Service를 사용하여 자격 증명을 가져옵니다.
EC2 인스턴스는 EC2 인스턴스 프로파일을 사용하도록 구성되어야 합니다. 자세한 내용은 Using Instance Profiles를 참고하세요.
Kubernetes IRSA
AWS에서 OIDC provider를 설정하고 pod의 서비스 계정이 role을 assume할 수 있도록 허용하는 AWS IAM role을 구성하려면 IAM Roles for Service Accounts (IRSA)를 참고하세요.
Environment Variables
Teleport의 내장 AWS 클라이언트는 다음 환경 변수에서 자격 증명을 읽습니다:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_DEFAULT_REGION
the Discovery Service을(를) 시작하면 서비스는 /etc/default/teleport 경로의
파일에서 환경 변수를 읽습니다. 이러한 자격 증명은 조직에서 얻으세요. 각
변수의 값을 교체하여 /etc/default/teleport가 다음 내용을 담도록 하세요:
AWS_ACCESS_KEY_ID=00000000000000000000
AWS_SECRET_ACCESS_KEY=0000000000000000000000000000000000000000
AWS_DEFAULT_REGION=
AWS 자격 증명 소스가 여러 개인가요?
Teleport의 AWS 클라이언트는 다음 순서로 여러 소스에서 자격 증명을 로드합니다:
- 환경 변수
- 공유 자격 증명 파일
- 공유 구성 파일 (Teleport는 항상 공유 구성을 활성화합니다)
- EC2 Instance Metadata (자격 증명만)
공유 자격 증명 파일이나 공유 구성 파일을 통해 AWS 자격 증명을 제공할 수
있지만, 원하는 프로파일의 이름을 AWS_PROFILE 환경 변수에 할당하여
the Discovery Service을(를) 실행해야 합니다.
위의 지침이 다루지 않는 특정 사용 사례가 있다면, 자격 증명 로딩 동작에 대한 자세한 설명은 AWS SDK for Go 문서를 참고하세요.
systemd 서비스를 생성하여 호스트가 부팅될 때 the Discovery Service이 자동으로 시작되도록 구성합니다. 지침은 the Discovery Service을 어떻게 설치했는지에 따라 다릅니다.
Package Manager
the Discovery Service을 실행할 호스트에서 Teleport를 활성화하고 시작합니다:
$ sudo systemctl enable teleport
$ sudo systemctl start teleport
TAR Archive
the Discovery Service을 실행할 호스트에서 Teleport용 systemd 서비스 구성을 생성하고, Teleport 서비스를 활성화한 후 Teleport를 시작합니다:
$ sudo teleport install systemd -o /etc/systemd/system/teleport.service
$ sudo systemctl enable teleport
$ sudo systemctl start teleport
systemctl status teleport로 the Discovery Service의 상태를 확인하고 journalctl -fu teleport로
로그를 볼 수 있습니다.
4/7단계. Terraform 모듈 입력값 구성#
Terraform 구성에 teleport-discovery-aws 모듈을 추가합니다.
module "aws_discovery" {
source = "terraform.releases.teleport.dev/teleport/discovery/aws"
version = "~> (=cloud.major_version=).0"
# Required inputs:
# Assign example.teleport.sh:443 to the public address of the Teleport Proxy Service in your cluster in host:port form.
teleport_proxy_public_addr = "example.teleport.sh:443"
# teleport_discovery_group_name must match the discovery group name in your Discovery Service config file.
# Teleport Cloud clusters run the Discovery Service in the group name "cloud-discovery-group".
# Do not modify this input unless you intend to run your own Discovery Service.
teleport_discovery_group_name = "cloud-discovery-group"
# Enable AWS Organization discovery.
aws_organization_discovery = {
organizational_units = {
# The wildcard "*" matches all organizational units.
# You can also specify a list of organizational unit IDs to match (eg, "ou-1a2b-rg12qq2b")
include = ["*"]
# You can also specify a list of organizational unit IDs to exclude from discovery.
# exclude = ["ou-1a2b-rg12qq2b"]
# Excluded organizational units will not be discovered, even if they are included in the "include" list.
}
}
# Each child account in the organization must have an IAM role with this name.
# This role is assumed by the Discovery Service to enroll resources from that account.
# The required trust relationship and permissions for this role can be found in the module outputs and documentation.
aws_child_account_iam_role_name = "teleport-organization-discovery-child-account-role"
# Optional inputs:
# Apply the additional AWS tag "origin=example" to all AWS resources created by this module
apply_aws_tags = { origin = "example" }
# Apply the additional Teleport label "origin=example" to all Teleport resources created by this module
apply_teleport_resource_labels = { origin = "example" }
# Discover EC2 instances using matching rules.
# Accepts "*" to discover across all enabled regions.
# The module adds account:ListRegions to the IAM policy automatically when "*" is used.
aws_matchers = [
{
types = ["ec2"]
# EC2 discovery supports a wildcard to find instances in all regions.
regions = ["*"]
tags = {
env = ["prod"]
}
}
]
}
module "aws_discovery" {
source = "terraform.releases.teleport.dev/teleport/discovery/aws"
version = "~> (=teleport.major_version=).0"
# Required inputs:
# Edit this input to the host and port of the Teleport Proxy Service in your cluster
teleport_proxy_public_addr = "teleport.example.com:443"
# Edit this input to match the discovery group name in your Discovery Service config file
teleport_discovery_group_name = "discovery-group-name"
# Enable AWS Organization discovery.
aws_organization_discovery = {
organizational_units = {
# The wildcard "*" matches all organizational units.
# You can also specify a list of organizational unit IDs to match (eg, "ou-1a2b-rg12qq2b")
include = ["*"]
# You can also specify a list of organizational unit IDs to exclude from discovery.
# exclude = ["ou-1a2b-rg12qq2b"]
# Excluded organizational units will not be discovered, even if they are included in the "include" list.
}
}
# Each child account in the organization must have an IAM role with this name.
# This role is assumed by the Discovery Service to enroll resources from that account.
# The required trust relationship and permissions for this role can be found in the module outputs and documentation.
aws_child_account_iam_role_name = "teleport-organization-discovery-child-account-role"
# Discover EC2 instances using matching rules.
# Accepts "*" to discover across all enabled regions.
# The module adds account:ListRegions to the IAM policy automatically when "*" is used.
aws_matchers = [
{
types = ["ec2"]
# EC2 discovery supports a wildcard to find instances in all regions.
regions = ["*"]
tags = {
env = ["prod"]
}
}
]
}
기본적으로 teleport-discovery-aws Terraform 모듈은 EC2 인스턴스의 검색과 등록을 위해 AWS OIDC 연동을 구성합니다.
다만 이를 위해서는 Teleport 프록시 서비스가 퍼블릭 인터넷에서 접근 가능해야 합니다.
클러스터가 프라이빗 네트워크에서 실행 중이고 프록시 서비스가 퍼블릭 인터넷에서 접근할 수 없다면, OIDC 연동을 비활성화하고 EC2 인스턴스를 검색하고 등록하는 데 필요한 IAM 권한을 직접 할당할 수 있습니다.
다음과 같이 설정하여 AWS OIDC 연동을 비활성화할 수 있습니다:
discovery_service_iam_credential_source = {
use_oidc_integration = false
}
# This role must be created manually and be assigned to the Discovery Service.
aws_organization_discovery_iam_principal_arn = "arn:aws:iam::<root-account-id>:role/teleport-organization-account-enumeration"
Terraform 모듈을 적용한 후 terraform output을 실행하여 Discovery Service와 Auth Service용 IAM 역할 템플릿을 확인합니다:
aws_discovery = {
# ...
"teleport_organization_account_enumeration_iam_role_template" = {
"policy" = <<-EOT
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"organizations:ListRoots",
"organizations:ListChildren",
"organizations:ListAccountsForParent"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::*:role/teleport-organization-discovery-child-account-role",
"Condition": {
"StringEquals": {
"aws:ResourceOrgID": "<aws-organization-id>"
}
}
}
]
}
EOT
"role_name" = "teleport-organization-account-enumeration"
}
"teleport_organization_join_validation_iam_role_template" = {
"policy" = <<-EOT
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "organizations:DescribeAccount",
"Resource": "*"
}
]
}
EOT
"role_name" = "teleport-organization-join-validation"
}
}
Discovery Service에 연결된 IAM 역할에는 teleport_organization_account_enumeration_iam_role_template에 정의된 정책이 있어야 합니다.
Auth Service에 연결된 역할에는 teleport_organization_join_validation_iam_role_template에 정의된 정책이 있어야 합니다.
Discovery Service와 Auth Service가 같은 프로세스에서 실행되는 구성에서는 두 정책을 하나의 IAM 역할로 합쳐 해당 서비스를 실행하는 인스턴스에 연결할 수 있습니다.
Terraform이 모듈의 출력값을 표시하도록 모듈에 대한 Terraform output을 추가합니다:
output "aws_discovery" {
value = module.aws_discovery
}
모듈 입력값과 출력값에 대한 전체 설명은 teleport-discovery-aws 레퍼런스를 참조합니다.
5/7단계. Terraform 모듈 적용#
$ terraform init
$ terraform apply
Terraform은 다음 리소스를 생성하도록 계획해야 합니다:
- Teleport Discovery Service가 맡을 AWS IAM 역할
- Teleport가 AWS 계정을 열거하고 AWS 조직 내 다른 계정의 역할을 맡는 데 필요한 AWS 권한을 부여하는 AWS IAM 정책
- IAM 정책을 Discovery Service IAM 역할에 연결하는 AWS IAM 정책 연결
- Teleport Discovery Service가 OIDC를 사용하여 IAM 역할을 맡기 위한 AWS OIDC 공급자.
- AWS 리소스 검색을 위해 Teleport를 구성하는 Teleport
discovery_config클러스터 리소스. - AWS OIDC용 Teleport
integration클러스터 리소스 - Teleport 노드가 AWS IAM 자격 증명을 사용하여 클러스터에 조인할 수 있도록 하는 Teleport
token클러스터 리소스
Terraform 계획을 검토하고 계획된 작업을 확인합니다.
Terraform이 계획 적용을 마치면 모듈 출력값이 표시됩니다:
aws_discovery = {
"aws_child_account_iam_role_template" = {
"assume_role_policy" = <<-EOT
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Principal": {
"AWS": "arn:aws:iam::<root-account-id>:role/teleport-discovery-<random-id>"
},
"Condition": {
"StringEquals": {
"aws:PrincipalOrgID": "<aws-organization-id>"
}
}
}
]
}
EOT
"policy" = <<-EOT
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:SendCommand",
"ssm:ListCommandInvocations",
"ssm:GetCommandInvocation",
"ssm:DescribeInstanceInformation",
"ec2:DescribeInstances",
"account:ListRegions"
],
"Resource": "*"
}
]
}
EOT
"role_name" = "teleport-organization-discovery-child-account-role"
}
"aws_oidc_provider_arn" = "arn:aws:iam::<root-account-id>:oidc-provider/example.teleport.sh"
"teleport_discovery_config_name" = "discovery-aws-organization-<aws-organization-id>"
"teleport_discovery_service_iam_policy_arn" = null
"teleport_discovery_service_iam_role_arn" = "arn:aws:iam::<root-account-id>:role/teleport-discovery-<random-id>"
"teleport_integration_name" = "discovery-aws-organization-<aws-organization-id>"
"teleport_organization_account_enumeration_iam_policy_arn" = "arn:aws:iam::<root-account-id>:policy/teleport-organization-account-enumeration-<random-id>"
"teleport_organization_account_enumeration_iam_role_template" = null /* object */
"teleport_organization_join_validation_iam_policy_arn" = "arn:aws:iam::<root-account-id>:policy/teleport-organization-join-validation-<random-id>"
"teleport_organization_join_validation_iam_role_template" = null /* object */
"teleport_provision_token_name" = "discovery-aws-organization-<aws-organization-id>"
}
AWS 리소스에는 다음 태그가 있어야 합니다:
origin=exampleteleport.dev/cluster=<cluster-name>teleport.dev/integration=discovery-aws-organization-<aws-organization-id>teleport.dev/iac-tool=terraform
Teleport 리소스에는 다음 라벨이 있어야 합니다:
origin=exampleteleport.dev/iac-tool=terraform
6/7단계. 하위 계정 구성#
조직 내 각 AWS 계정에는 Teleport Discovery Service가 해당 계정의 EC2 인스턴스를 검색하고 등록하기 위해 맡을 IAM 역할이 있어야 합니다.
다음 명령을 실행하여 IAM 역할 이름, 신뢰 관계 정책, 권한 정책을 확인합니다:
$ terraform output
다음과 같은 출력을 확인할 수 있습니다:
$ terraform output
aws_discovery = {
"aws_child_account_iam_role_template" = {
"assume_role_policy" = <<-EOT
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Principal": {
"AWS": "arn:aws:iam::<root-account-id>:role/teleport-discovery-<random-id>"
},
"Condition": {
"StringEquals": {
"aws:PrincipalOrgID": "<aws-organization-id>"
}
}
}
]
}
EOT
"policy" = <<-EOT
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:SendCommand",
"ssm:ListCommandInvocations",
"ssm:GetCommandInvocation",
"ssm:DescribeInstanceInformation",
"ec2:DescribeInstances",
"account:ListRegions"
],
"Resource": "*"
}
]
}
EOT
"role_name" = "teleport-organization-discovery-child-account-role"
}
// ...
}
Terraform 출력 변수 aws_child_account_iam_role_template의 role_name, assume_role_policy, policy를 사용하여 각 대상 계정에 IAM 역할을 생성합니다.
7/7단계. 검색 상태 확인#
Terraform 모듈을 적용하고 각 하위 계정에 IAM 역할을 생성하면, Teleport Discovery Service가 AWS 조직의 EC2 인스턴스를 검색하여 보호 리소스로 클러스터에 등록하기 시작합니다.
EC2 인스턴스가 검색되고 등록되기까지 몇 분이 걸릴 수 있습니다.
Teleport 웹 UI로 이동하여 Zero Trust Access > Integrations를 선택합니다.
기본적으로 teleport-discovery-aws Terraform 모듈이 생성한 연동의 이름은 discovery-aws-organization-<aws-organization-id>입니다.
AWS 조직의 연동을 클릭하여 검색 상태를 확인합니다.
연동 페이지에서는 검색된 EC2 인스턴스 수와 검색 과정에서 발생한 문제에 대한 개요를 확인할 수 있습니다.

위 예시에서는 인스턴스의 AWS SSM 에이전트에 문제가 있음을 확인할 수 있습니다.
"issues" 탭으로 이동하여 "Details"를 클릭하면 문제에 대한 자세한 정보를 확인할 수 있습니다:

이 경우 EC2 인스턴스에 AmazonSSMManagedInstanceCore IAM 정책이 연결된 IAM 역할이 없어 인스턴스가 SSM 명령을 수신할 수 없는 것이 문제입니다.
EC2 인스턴스의 역할에 AmazonSSMManagedInstanceCore IAM 정책을 연결하고 Discovery Service가 SSM으로 설치를 다시 시도하기를 기다리면 해결됩니다. 다음 검색 스캔이 실행되어 인스턴스에 Teleport를 설치하기까지 몇 분이 걸릴 수 있습니다.
검색된 모든 EC2 인스턴스가 Teleport 클러스터에 성공적으로 조인하면 개요 페이지에 정상 상태가 표시됩니다:

모듈 구성 업데이트#
모듈 입력값을 변경하고 다시 적용하여 AWS 검색 연동을 조정할 수 있습니다.
예를 들어 이전에 모든 리전을 의미하는 와일드카드 기본값 대신 특정 AWS 리전을 사용했다면, aws_matchers 안의 regions를 조정하여 EC2 검색에 리전을 추가하고 모듈을 다시 적용하면 해당 리전의 인스턴스도 등록하기 시작합니다.
-regions = ["us-west-1"]
+regions = ["us-west-1", "us-east-1"]
Terraform을 다시 적용합니다:
$ terraform apply
변경 사항을 확인하기 전에 Terraform 계획을 검토합니다.
Terraform이 계획 적용을 마치면 Discovery Service가 동적 discovery_config의 변경을 반영하여 us-east-1의 EC2 인스턴스도 등록하기 시작합니다.
문제 해결#
설치가 실패로 표시되거나 인스턴스가 나타나지 않는 경우, AWS System Manager -> Node Management -> Run Command에서 Command 이력을 확인하십시오. Target의 instance-id를 선택하여 오류를 검토하십시오.
cannot unmarshal object into Go struct field#
다음과 유사한 오류가 발생하는 경우:
invalid format in plugin properties map[destinationPath:/tmp/installTeleport.sh sourceInfo:map[url:[https://example.teleport.sh:443/webapi/scripts/installer/preprod-installer](https://example.teleport.sh/webapi/scripts/installer/preprod-installer)] sourceType:HTTP];
error json: cannot unmarshal object into Go struct field DownloadContentPlugin.sourceInfo of type string
이는 오래된 버전의 SSM agent를 실행하고 있을 가능성이 높습니다. 이 문제를 해결하려면 SSM agent 버전 3.1 이상으로 업그레이드하십시오.
InvalidInstanceId: Instances [[i-123]] not in a valid state for account 456#
다음과 같은 문제로 인해 이 오류가 발생할 수 있습니다:
- Discovery Service에 관리 노드에 접근할 권한이 없습니다.
- AWS Systems Manager Agent(SSM Agent)가 실행되고 있지 않습니다. SSM Agent가 실행 중인지 확인하십시오.
- SSM Agent가 SSM 엔드포인트에 등록되어 있지 않습니다. SSM Agent를 재설치해 보십시오.
- 발견된 인스턴스에 SSM 명령을 수신할 권한이 없습니다. 인스턴스에 AmazonSSMManagedInstanceCore IAM 정책이 포함되어 있는지 확인하십시오.
자세한 내용은 AWS 문서의 SSM RunCommand 오류 코드 및 문제 해결 정보를 참조하십시오:
- https://docs.aws.amazon.com/systems-manager/latest/userguide/troubleshooting-managed-instances.html
- https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_SendCommand.html#API_SendCommand_Errors
다음 단계#
- IAM Invite Token에 대한 자세한 내용은 AWS IAM Role을 통한 노드 참여를 참고하십시오.
- Systems Manager로 관리되는 EC2 인스턴스의 IAM 모범 사례에 대한 정보는 AWS Cloud Operations & Migrations Blog 에서 확인할 수 있습니다.
- EC2 디스커버리 구성에 대한 전체 문서는 구성 파일 레퍼런스 문서에서 확인할 수 있습니다.