Hardeneks 시리즈
- [현재 글] EKS 클러스터 보안 검사 도구 가이드
- [다음 글] 테라폼으로 구축한 EKS 클러스터 보안 검사하기
들어가며
Amazon EKS(Elastic Kubernetes Service)를 운영하다 보면 보안 설정이 제대로 되어 있는지 확인하는 게 중요합니다. 그런데 AWS에서 제공하는 EKS Best Practices를 하나하나 수동으로 확인하기는 번거롭고 시간도 많이 걸리죠.
이럴 때 쓸 수 있도록 AWS에서 공식적으로 제공하는 도구가 Hardeneks입니다. EKS 클러스터가 AWS 모범 사례를 얼마나 잘 따르고 있는지 자동으로 검사해 주는 Python 기반 CLI 도구입니다.
이번 시리즈에서는 Hardeneks의 기본 사용법부터 실제 EKS 클러스터에 활용하는 과정까지 단계별로 다뤄 보겠습니다.
Hardeneks란?
Hardeneks는 AWS Samples에서 제공하는 오픈소스 도구로, EKS 클러스터의 보안 상태를 여러 영역에 걸쳐 분석합니다. 검사하는 영역은 아래와 같습니다.
보안 (Security)
- IAM: 익명 접근 제어, 서비스 계정 관리, 와일드카드 권한 제한
- 다중 테넌시: 네임스페이스 할당량 관리
- 탐지 제어: 로그 활성화 상태 확인
- 네트워크 보안: VPC Flow Logs, 네트워크 정책 확인
- 암호화: EBS, EFS 암호화 설정
- 인프라 보안: 프라이빗 서브넷 배포, Inspector 활성화
- Pod 보안: PSA(Pod Security Admission) 설정
- 이미지 보안: ECR 불변 태그 사용
안정성 (Reliability)
- 애플리케이션: Metrics Server, VPA, HPA 설정
- 고가용성: 여러 노드에 걸친 레플리카 배포
- 리소스 관리: 컨테이너 리소스 제한 설정
설치 및 기본 사용법
1. 설치
가장 간단한 방법은 pip로 설치하는 것입니다.
# 가상환경 생성 (권장)
python3 -m venv hardeneks-env
source hardeneks-env/bin/activate
# hardeneks 설치
pip install hardeneks
2. 기본 사용법
# 기본 실행 (현재 kubectl 컨텍스트 사용)
hardeneks
# 특정 리전과 클러스터 지정
hardeneks --region us-east-1 --cluster my-eks-cluster
# 특정 네임스페이스만 검사
hardeneks --namespace production
# 결과를 다양한 형식으로 내보내기
hardeneks --export-html report.html
hardeneks --export-json report.json
hardeneks --export-csv report.csv
3. 필요한 권한 설정
Hardeneks를 실행하려면 AWS와 Kubernetes 양쪽에 권한이 필요합니다.
AWS IAM 권한
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"eks:ListClusters",
"eks:DescribeCluster",
"ecr:DescribeRepositories",
"inspector2:BatchGetAccountStatus",
"ec2:DescribeFlowLogs",
"ec2:DescribeInstances"
],
"Resource": "*"
}
]
}
Kubernetes ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: hardeneks-runner
rules:
- apiGroups: [""]
resources: ["namespaces", "resourcequotas", "persistentvolumes", "pods", "services", "nodes"]
verbs: ["list"]
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["clusterroles", "clusterrolebindings", "roles", "rolebindings"]
verbs: ["list"]
- apiGroups: ["networking.k8s.io"]
resources: ["networkpolicies"]
verbs: ["list"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["list"]
- apiGroups: ["apps"]
resources: ["deployments", "daemonsets", "statefulsets"]
verbs: ["list", "get"]
- apiGroups: ["autoscaling"]
resources: ["horizontalpodautoscalers"]
verbs: ["list"]
커스터마이징: 설정 파일 활용
Hardeneks는 설정 파일을 통한 커스터마이징을 지원합니다. 기본적으로는 모든 검사를 수행하지만, 환경에 맞게 특정 검사만 실행하거나 특정 네임스페이스를 제외할 수 있습니다.
설정 파일 예시
# hardeneks-config.yaml
---
# 검사에서 제외할 네임스페이스
ignore-namespaces:
- kube-node-lease
- kube-public
- kube-system
- kube-apiserver
- karpenter
- kubecost
- external-dns
- argocd
- aws-for-fluent-bit
- amazon-cloudwatch
- vpa
# 실행할 검사 규칙 정의
rules:
# 클러스터 전체 검사
cluster_wide:
security:
iam:
- disable_anonymous_access_for_cluster_roles
- check_endpoint_public_access
- check_aws_node_daemonset_service_account
- restrict_wildcard_for_cluster_roles
network_security:
- check_vpc_flow_logs
- check_awspca_exists
- check_default_deny_policy_exists
encryption_secrets:
- use_encryption_with_ebs
- use_encryption_with_efs
reliability:
applications:
- check_metrics_server_is_running
- check_vertical_pod_autoscaler_exists
# 네임스페이스 기반 검사
namespace_based:
security:
iam:
- disable_service_account_token_mounts
- disable_run_as_root_user
- use_dedicated_service_accounts_for_each_deployment
pod_security:
- disallow_container_socket_mount
- disallow_host_path_or_make_it_read_only
- set_requests_limits_for_containers
- disallow_privilege_escalation
- check_read_only_root_file_system
runtime_security:
- disallow_linux_capabilities
reliability:
applications:
- check_horizontal_pod_autoscaling_exists
- schedule_replicas_across_nodes
- run_multiple_replicas
설정 파일 사용법
# 커스텀 설정 파일로 실행
hardeneks --config hardeneks-config.yaml
# 설정 파일과 함께 결과 내보내기
hardeneks --config hardeneks-config.yaml --export-html custom-report.html
주요 검사 항목별 상세 설명
1. IAM 관련 검사
- 익명 접근 제어: ClusterRole과 Role에서 익명 사용자 접근을 차단
- 서비스 계정 관리: 각 배포마다 전용 서비스 계정 사용
- 와일드카드 권한 제한:
*권한 사용 최소화
2. 네트워크 보안
- VPC Flow Logs: 네트워크 트래픽 로깅 활성화
- 네트워크 정책: 기본 거부 정책 구현
- 로드 밸런서 암호화: AWS 로드 밸런서에서 TLS 사용
3. Pod 보안
- 권한 상승 방지:
allowPrivilegeEscalation: false설정 - 루트 사용자 금지: 컨테이너를 루트가 아닌 사용자로 실행
- 읽기 전용 파일 시스템: 루트 파일 시스템을 읽기 전용으로 설정
4. 리소스 관리
- 리소스 제한: CPU, 메모리 requests/limits 설정
- HPA 설정: 자동 스케일링 구성
- 다중 레플리카: 단일 장애점 제거
실제 사용 시나리오
시나리오 1: 프로덕션 환경 점검
# 프로덕션 클러스터 전체 검사
hardeneks --region us-east-1 --cluster production-cluster --export-html prod-security-report.html
# 결과를 Security Hub로 전송
hardeneks --region us-east-1 --cluster production-cluster --export-security-hub
시나리오 2: 특정 네임스페이스 집중 검사
# 특정 애플리케이션 네임스페이스만 검사
hardeneks --namespace my-app --export-json app-security-report.json
시나리오 3: CI/CD 파이프라인 통합
# JSON 형식으로 결과 출력하여 파이프라인에서 처리
hardeneks --config ci-config.yaml --export-json pipeline-report.json
# 실패한 검사가 있으면 빌드 실패 처리
if [ $(jq '.failed_checks | length' pipeline-report.json) -gt 0 ]; then
echo "Security checks failed!"
exit 1
fi
결과 해석 및 개선 방안
Hardeneks 실행 결과를 보고 진행할 수 있는 개선 작업을 우선순위별로 나누면 아래와 같습니다.
1. 높은 우선순위 수정 사항
- 루트 사용자로 실행되는 컨테이너 수정
- 과도한 권한을 가진 서비스 계정 정리
- 리소스 제한이 없는 Pod 수정
2. 중간 우선순위 수정 사항
- 네트워크 정책 구현
- 로그 활성화
- 암호화 설정 개선
3. 장기적 개선 사항
- 모니터링 도구 도입
- 자동화된 보안 스캔 파이프라인 구축
- 정기적인 보안 검토 프로세스 수립
마무리
Hardeneks를 쓰면 EKS 클러스터의 보안 상태를 항목별로 점검할 수 있습니다. 정기적으로 실행해 보안 기준을 유지하고, CI/CD 파이프라인에 통합해 지속적으로 보안을 검증하는 것을 권장합니다.
설정 파일로 커스터마이징하면 조직의 보안 정책에 맞게 검사 항목을 조정할 수도 있습니다.
다음 시리즈 예고
다음 편에서는 테라폼으로 구축한 EKS 클러스터에 Hardeneks를 실제로 적용해 보겠습니다.
- 테라폼 EKS 클러스터 구성 분석: Karpenter, Istio, 모니터링 스택이 포함된 실제 클러스터
- Hardeneks 실행 및 결과 분석: 실제 검사 결과와 발견된 보안 이슈
- 보안 이슈 해결 과정: 검사 결과에 따른 단계별 보안 강화
- 커스텀 설정 파일 작성: 실제 환경에 맞는 설정 파일 최적화
참고 자료
- Hardeneks GitHub Repository
- AWS 공식 블로그 - HardenEKS: Validating Best Practices For Amazon EKS Clusters Programmatically