해당과정에서 검출된 EKS Account 토큰 탈취에 대해 조치를 취해보겠다.
[AWS SecurityHub] AWS GuardDuty를 통한 Runtime 탐지 조사하기 [T]
필자의 EKS의 pod 서버는 누군가가 nc 명령어로 reverse shell을 외부로 연결시키는 공격을 당했다.AWS GuardDuty에서 어떻게 탐지되는지 확인해보자. 해당 환경에서 이어서 진행한다. [AWS SecurityHub] AWS Gu
seongduck.tistory.com
- 공격자는 탈취한 EC2의 자격증명을 이용하여 EKS Pod에서 사용하는 Service Account를 탈취 후 Secret에 대한 접근까지 가능
- 공격자는 Pod에 접근 시 kubectl exec 명령을 사용하여 Pod에 배포된 Container에 Shell 접근이 가능
- 이를 통해 Service Account 탈취
EC2 인스턴스의 자격증명에 부여된 EKS 관리 권한 중 kubectl exec 권한을 제거하여 tdir-ns 환경에서는 Container에 대한 Shell 접근을 차단해보자
EC2 인스턴스 자격증명에 할당된 EKS Role을 수정해주자.
기존
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: dev-role
namespace: tdir-ns
rules:
- apiGroups:
- ""
- "apps"
- "batch"
- "extensions"
resources:
- "configmaps"
- "cronjobs"
- "deployments"
- "events"
- "ingresses"
- "jobs"
- "pods"
- "pods/attach"
- "pods/exec"
- "pods/log"
- "pods/portforward"
- "secrets"
- "services"
verbs:
- "create"
- "delete"
- "describe"
- "get"
- "list"
- "patch"
- "update"
변경 (pods/exec를 제외하고 권한 부여)
- 배포된 Pod에 운영자나 공격자가 Shell로 접근을 막음
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: dev-role
namespace: tdir-ns
rules:
- apiGroups:
- ""
- "apps"
- "batch"
- "extensions"
resources:
- "configmaps"
- "cronjobs"
- "deployments"
- "events"
- "ingresses"
- "jobs"
- "pods"
- "pods/attach"
- "pods/log"
- "pods/portforward"
- "secrets"
- "services"
verbs:
- "create"
- "delete"
- "describe"
- "get"
- "list"
- "patch"
- "update"
그 외의 방법 해결
- pod에서 외부로의 접속을 Network Polices를 통해 제한한다. https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/cni-network-policy.html
- AWS Network Firewall을 구성하여 egress control을 적절하게 구성한다. https://aws.amazon.com/ko/blogs/security/use-aws-network-firewall-to-filter-outbound-https-traffic-from-applications-hosted-on-amazon-eks/
- pod간의 통신을 세밀하게 조절할 수 있도록 Security groups for Pod를 구성한다. https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/security-groups-for-pods.html
- 문제가 되는 pod에서 참조하는 image가 저장된 ECR Amazon Inspector의 Scan결과를 확인하고, 이상이 있는 경우 image를 안전한 이미지로 새로 build 한다.
https://docs.aws.amazon.com/ko_kr/AmazonECR/latest/userguide/image-scanning.html - non-root 유저로 실행 실행되도록 권한을 제약한다.
https://docs.aws.amazon.com/ko_kr/whitepapers/latest/security-practices-multi-tenant-saas-applications-eks/forbid-running-tenant-containers-as-root.html
'Cloud Infra Architecture (AWS) > AWS Build' 카테고리의 다른 글
AWS TGW (Transit Gateway)를 통해 VPC간 연결하는 방법 (0) | 2025.01.13 |
---|---|
AWS VPC Peering 하는 방법 (0) | 2025.01.13 |
[AWS SecurityHub] AWS 인스턴스에 침투한 CVE 취약점 해결 및 조치 방법 [T] (1) | 2024.11.03 |
[AWS SecurityHub] 인스턴스 및 계정이 해킹당해 자격증명이 유출되었을 때 조치 [T] (0) | 2024.11.03 |
[AWS SecurityHub] AWS GuardDuty로 침입 감지한(SSH BruteForce) 로그를 경감조치 (자동 조치 취하기) [T] (0) | 2024.11.03 |