Terraform을 사용하여 Amazon ECS에 Teleport 설치
Amazon ECS와 Terraform을 사용하면 AWS 리소스에 더 가까운 Teleport 에이전트를 쉽게 배포하고 관리할 수 있습니다. 이 흐름은 EKS 클러스터, RDS 데이터베이스 또는 기타 지원되는 AWS 리소스에 대한 접근을 자동으로 검색하고 보안을 강화하고자 할 때 이상적입니다.
Amazon ECS와 Terraform을 사용하면 AWS 리소스에 더 가까운 Teleport 에이전트를 쉽게 배포하고 관리할 수 있습니다.
이 흐름은 EKS 클러스터, RDS 데이터베이스 또는 기타 지원되는 AWS 리소스에 대한 접근을 자동으로 검색하고 보안을 강화하고자 할 때 이상적입니다.
작동 방식#
Terraform 모듈이 Amazon ECS에 Teleport 에이전트를 배포하고 최신 상태로 유지합니다. Terraform 구성을 다시 적용하면 Teleport 에이전트 버전이 최신 상태로 유지됩니다.
에이전트가 클러스터에 조인할 수 있도록 IAM 조인 토큰을 생성하거나 재사용해야 합니다.
실행할 Teleport 서비스(예: 검색 서비스 또는 데이터베이스 서비스)를 구성한 다음 접근하려는 리소스에 접근할 수 있는 서브넷과 보안 그룹을 선택해야 합니다.
배포 후 에이전트는 클러스터의 일부가 되어 리소스 검색 또는 요청 프록시를 시작합니다.
필요에 따라 에이전트 구성을 사용자 지정하고 재배포할 수 있습니다.
사전 조건#
다음 설정이 필요합니다:
terraform설치- AWS 자격 증명 구성
- 에이전트가 Teleport 클러스터에 안전하게 조인할 수 있도록 Teleport IAM 조인 토큰 생성
1/3단계. Terraform 모듈 다운로드#
예시 소스 코드를 다운로드합니다:
$ git clone https://github.com/gravitational/teleport -b branch/v(=teleport.major_version=)
$ cd teleport/examples/aws/terraform/ecs-agent
2/3단계. 배포 구성#
variables.tf 파일에는 Teleport 에이전트 배포에 대한 모든 구성 가능한 파라미터가 포함되어 있습니다. 기본값을 재정의하는 .tfvars 파일을 검토하고 생성합니다.
Amazon EKS 클러스터를 자동 검색하고 접근하려면 다음 구성으로 시작합니다:
teleport_proxy_server = "proxy.example.com:443"
// AWS Region where the Teleport Agent is deployed
aws_region = "eu-south-2"
// ECS cluster name to use.
ecs_cluster = "teleport-ecs-guide"
// ECS Service networking configuration.
// Ensure this allows connectivity to the target EKS Clusters.
teleport_agent_subnets = ["subnet-123"]
teleport_agent_security_groups = ["sg-456"]
// Default tags to add to AWS resources when creating them.
default_tags = {
"DeployedBy" = "TeleportAmazonECSGuide"
}
// Teleport Agent configuration.
teleport_agent_config = {
version = "v3"
teleport = {
join_params = {
// Create a new IAM Join Token that allows joining from your AWS Account.
// Ensure it allows Discovery and Kubernetes system roles.
token_name = "token-ecs-guide"
method = "iam"
}
proxy_server = "proxy.example.com:443"
log = {
severity = "DEBUG"
}
}
auth_service = {
enabled = "no"
}
proxy_service = {
enabled = "no"
}
ssh_service = {
enabled = "no"
}
discovery_service = {
enabled = "yes"
discovery_group = "discover-eks"
aws = [
{
types = ["eks"]
regions = ["eu-south-2"]
tags = [
{ "*" = "*" }
]
}
]
}
kubernetes_service = {
enabled = "yes"
resources = [
{
labels = {
"region" = "eu-south-2"
"account-id" = data.aws_caller_identity.current.account_id
"teleport.dev/cloud" = "AWS"
"teleport.dev/discovery-type" = "eks"
"teleport.internal/discovery-group-name" = "discover-eks"
}
}
]
}
}
// Depending on your use case, you may want to allow additional permissions for the IAM Role which will be assumed by the agent.
ecs_taskrole = "ecs-guide-teleport_agent_role"
ecs_taskrole_policy = {
Version = "2012-10-17"
Statement = [
{
Sid = "EKSDiscovery"
Action = [
"eks:DescribeCluster",
"eks:ListClusters"
]
Effect = "Allow"
Resource = "*"
},
{
Sid = "EKSManageAccess"
Action = [
"eks:AssociateAccessPolicy",
"eks:CreateAccessEntry",
"eks:DeleteAccessEntry",
"eks:DescribeAccessEntry",
"eks:TagResource",
"eks:UpdateAccessEntry"
]
Effect = "Allow"
Resource = "*"
},
]
}
ecs_executionrole = "ecs-guide-teleport_agent_executionrole"
다음은 사용 사례에 맞게 조정할 수 있는 기본 ECS Teleport 에이전트 구성 예시입니다.
teleport_proxy_server = "proxy.example.com:443"
// AWS Region where the Teleport Agent is deployed
aws_region = "eu-south-2"
// ECS cluster name to use.
ecs_cluster = "teleport-ecs-guide"
// ECS Service networking configuration.
teleport_agent_subnets = ["subnet-123"]
teleport_agent_security_groups = ["sg-456"]
// Default tags to add to AWS resources when creating them.
default_tags = {
"DeployedBy" = "TeleportAmazonECSGuide"
}
// Teleport Agent configuration.
teleport_agent_config = {
version = "v3"
teleport = {
join_params = {
// Create a new IAM Join Token that allows joining from your AWS Account.
token_name = "token-ecs-guide"
method = "iam"
}
// Teleport Proxy server endpoint.
proxy_server = "proxy.example.com:443"
log = {
severity = "DEBUG"
}
}
auth_service = {
enabled = "no"
}
proxy_service = {
enabled = "no"
}
ssh_service = {
enabled = "yes"
}
}
// Depending on your use case, you may want to allow additional permissions for the IAM Role which will be assumed by the agent.
ecs_taskrole = "ecs-guide-teleport_agent_role"
ecs_taskrole_policy = {
Version = "2012-10-17"
Statement = [
{
Action = [
"sts:GetCallerIdentity",
]
Effect = "Allow"
Resource = "*"
},
]
}
ecs_executionrole = "ecs-guide-teleport_agent_executionrole"
배포는 다음 AWS 리소스를 생성합니다:
- AWS API 접근에 필요한 권한이 있는 IAM 역할
- Teleport 에이전트의 로그 스트림을 CloudWatch로 허용하는 IAM 역할
- Teleport 에이전트를 실행하는 ECS 태스크 정의
- 위의 태스크 정의를 실행하는 ECS 클러스터 및 ECS 서비스
teleport_agent_config 및 ecs_taskrole_policy 변수를 편집하고 필요에 맞게 조정해야 합니다.
.tfvars 파일을 my-deployment.tfvars로 저장하고 다음 단계에서 사용합니다.
3/3단계. Terraform 구성 초기화 및 적용#
구성을 적용하면 리소스가 생성되고 Teleport 에이전트가 배포됩니다.
$ terraform init
$ terraform apply -var-file=my-deployment.tfvars
배포 후 에이전트는 Teleport 클러스터의 일부가 됩니다.
배포된 Teleport 에이전트 버전이 업데이트되도록 정기적으로 terraform apply ...를 실행합니다.
문제 해결#
Amazon ECS 콘솔로 이동하여 클러스터와 서비스를 선택하고 CloudWatch에 저장된 로그 탭을 확인합니다.
다음 단계#
이 가이드를 AWS 리소스에 대한 자동 검색 구현의 시작점으로 사용합니다:
