[Hardeneks 시리즈 1편] EKS 클러스터 보안 검사 도구 가이드

목차

Hardeneks 시리즈

  1. [현재 글] EKS 클러스터 보안 검사 도구 가이드
  2. [다음 글] 테라폼으로 구축한 EKS 클러스터 보안 검사하기

들어가며

Amazon EKS(Elastic Kubernetes Service)를 운영하다 보면 보안 설정이 제대로 되어 있는지 확인하는 게 중요합니다. 그런데 AWS에서 제공하는 EKS Best Practices를 하나하나 수동으로 확인하기는 번거롭고 시간도 많이 걸리죠.

이럴 때 쓸 수 있도록 AWS에서 공식적으로 제공하는 도구가 Hardeneks입니다. EKS 클러스터가 AWS 모범 사례를 얼마나 잘 따르고 있는지 자동으로 검사해 주는 Python 기반 CLI 도구입니다.

이번 시리즈에서는 Hardeneks의 기본 사용법부터 실제 EKS 클러스터에 활용하는 과정까지 단계별로 다뤄 보겠습니다.

Hardeneks란?

Hardeneks는 AWS Samples에서 제공하는 오픈소스 도구로, EKS 클러스터의 보안 상태를 여러 영역에 걸쳐 분석합니다. 검사하는 영역은 아래와 같습니다.

보안 (Security)

안정성 (Reliability)

설치 및 기본 사용법

1. 설치

가장 간단한 방법은 pip로 설치하는 것입니다.

bash
# 가상환경 생성 (권장)
python3 -m venv hardeneks-env
source hardeneks-env/bin/activate

# hardeneks 설치
pip install hardeneks

2. 기본 사용법

bash
# 기본 실행 (현재 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 권한

json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "eks:ListClusters",
                "eks:DescribeCluster",
                "ecr:DescribeRepositories",
                "inspector2:BatchGetAccountStatus",
                "ec2:DescribeFlowLogs",
                "ec2:DescribeInstances"
            ],
            "Resource": "*"
        }
    ]
}

Kubernetes ClusterRole

yaml
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는 설정 파일을 통한 커스터마이징을 지원합니다. 기본적으로는 모든 검사를 수행하지만, 환경에 맞게 특정 검사만 실행하거나 특정 네임스페이스를 제외할 수 있습니다.

설정 파일 예시

yaml
# 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

설정 파일 사용법

bash
# 커스텀 설정 파일로 실행
hardeneks --config hardeneks-config.yaml

# 설정 파일과 함께 결과 내보내기
hardeneks --config hardeneks-config.yaml --export-html custom-report.html

주요 검사 항목별 상세 설명

1. IAM 관련 검사

2. 네트워크 보안

3. Pod 보안

4. 리소스 관리

실제 사용 시나리오

시나리오 1: 프로덕션 환경 점검

bash
# 프로덕션 클러스터 전체 검사
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: 특정 네임스페이스 집중 검사

bash
# 특정 애플리케이션 네임스페이스만 검사
hardeneks --namespace my-app --export-json app-security-report.json

시나리오 3: CI/CD 파이프라인 통합

bash
# 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. 높은 우선순위 수정 사항

2. 중간 우선순위 수정 사항

3. 장기적 개선 사항

마무리

Hardeneks를 쓰면 EKS 클러스터의 보안 상태를 항목별로 점검할 수 있습니다. 정기적으로 실행해 보안 기준을 유지하고, CI/CD 파이프라인에 통합해 지속적으로 보안을 검증하는 것을 권장합니다.

설정 파일로 커스터마이징하면 조직의 보안 정책에 맞게 검사 항목을 조정할 수도 있습니다.

다음 시리즈 예고

다음 편에서는 테라폼으로 구축한 EKS 클러스터에 Hardeneks를 실제로 적용해 보겠습니다.

참고 자료


도식

100%

끌어서 이동, 두 손가락이나 휠로 확대·축소. 키보드: 화살표 이동, + − 확대·축소, 0 맞춤, Esc 닫기. 같은 내용은 그림 아래 “그림 관계를 글로 읽기”에 있다.