Amazon EKS 보안 평가 - Kube Bench
8678 단어 securityawscontainerskubernetes
소개
Center for Internet Security는 코드 보안의 모범 사례에 대한 많은 지침과 벤치마크 테스트를 제공합니다. CIS는 benchmark for Kubernetes . kube-bench은 CIS benchmark for Kubernetes 검사를 실행하여 Kubernetes가 안전하게 배포되었는지 확인하는 오픈 소스 도구입니다. Go 애플리케이션으로 작성되었으며 컨테이너로도 배포됩니다. 각 테스트는 YAML에서 정의되며 Kubernetes와 함께 발전하고 자동화 도구와 통합하는 데 사용할 수 있는 JSON 형식 출력도 지원합니다.
관리형 Kubernetes 및 CIS Amazon EKS 벤치마크
CIS Kubernetes Benchmark는 etcd, API 서버, 컨트롤러, 스케줄러 및 하나 이상의 노드 또는 EC2 인스턴스로 구성된 데이터 플레인을 포함하는 컨트롤 플레인을 모두 관리하는 구현에 대해 범위가 지정됩니다.
관리형 Kubernetes 클러스터는 이미 적용된 수준의 CIS 강화를 제공하고 일부 설정을 사용자에게 위임합니다. 워크로드 및 작업자 노드가 이러한 지침을 구현하도록 적절하게 설정되었는지 이해하려는 경우 가장 잘 작동합니다. CIS Amazon EKS Benchmark v1.0.0은 Kubernetes의 노드 보안 구성에 대한 지침을 제공하고 CIS Kubernetes Benchmark와 일치합니다.
kube-bench 실행
아래 YAML 파일을 사용하여 Kubernetes 작업을 배포합니다. kube-bench를 노드에 직접 설치할 수도 있습니다. 이 블로그에서는 kubernetes 작업으로 kube-bench를 실행할 것입니다.
# eks-kube-bench-job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: kube-bench
spec:
template:
spec:
hostPID: true
containers:
- name: kube-bench
image: aquasec/kube-bench:latest
command: ["kube-bench", "--benchmark", "eks-1.0"]
volumeMounts:
- name: var-lib-kubelet
mountPath: /var/lib/kubelet
readOnly: true
- name: etc-systemd
mountPath: /etc/systemd
readOnly: true
- name: etc-kubernetes
mountPath: /etc/kubernetes
readOnly: true
restartPolicy: Never
volumes:
- name: var-lib-kubelet
hostPath:
path: "/var/lib/kubelet"
- name: etc-systemd
hostPath:
path: "/etc/systemd"
- name: etc-kubernetes
hostPath:
path: "/etc/kubernetes"
EKS 클러스터에서 작업 실행
kubectl apply -f eks-kube-bench-job.yaml
kube-bench 작업이 완료되면 Pod의 로그를 보고 kube-bench의 결과를 확인할 수 있습니다.
[INFO] 3 Worker Node Security Configuration
[INFO] 3.1 Worker Node Configuration Files
[PASS] 3.1.1 Ensure that the proxy kubeconfig file permissions are set to 644 or more restrictive (Scored)
[PASS] 3.1.2 Ensure that the proxy kubeconfig file ownership is set to root:root (Scored)
[PASS] 3.1.3 Ensure that the kubelet configuration file has permissions set to 644 or more restrictive (Scored)
[PASS] 3.1.4 Ensure that the kubelet configuration file ownership is set to root:root (Scored)
[INFO] 3.2 Kubelet
[PASS] 3.2.1 Ensure that the --anonymous-auth argument is set to false (Scored)
[PASS] 3.2.2 Ensure that the --authorization-mode argument is not set to AlwaysAllow (Scored)
[PASS] 3.2.3 Ensure that the --client-ca-file argument is set as appropriate (Scored)
[PASS] 3.2.4 Ensure that the --read-only-port argument is set to 0 (Scored)
[PASS] 3.2.5 Ensure that the --streaming-connection-idle-timeout argument is not set to 0 (Scored)
[PASS] 3.2.6 Ensure that the --protect-kernel-defaults argument is set to true (Scored)
[PASS] 3.2.7 Ensure that the --make-iptables-util-chains argument is set to true (Scored)
[PASS] 3.2.8 Ensure that the --hostname-override argument is not set (Scored)
[WARN] 3.2.9 Ensure that the --event-qps argument is set to 0 or a level which ensures appropriate event capture (Scored)
[PASS] 3.2.10 Ensure that the --rotate-certificates argument is not set to false (Scored)
[PASS] 3.2.11 Ensure that the RotateKubeletServerCertificate argument is set to true (Scored)
== Remediations ==
3.2.9 If using a Kubelet config file, edit the file to set eventRecordQPS: to an appropriate level.
If using command line arguments, edit the kubelet service file
/etc/systemd/system/kubelet.service on each worker node and
set the below parameter in KUBELET_SYSTEM_PODS_ARGS variable.
Based on your system, restart the kubelet service. For example:
systemctl daemon-reload
systemctl restart kubelet.service
== Summary ==
14 checks PASS
0 checks FAIL
1 checks WARN
0 checks INFO
작업 삭제
아래 명령을 실행하여 kube-bench 작업을 삭제합니다.
kubectl delete -f job-eks.yaml
kube-bench와 AWS Security Hub 통합
결과를 AWS Security Hub로 보내도록 --asff로 kube-bench를 구성할 수 있습니다. 그 전에 AWS Security Hub 통합을 활성화하고 결과를 AWS Security Hub로 전달하는 데 필요한 IAM 역할 및 정책을 설정해야 합니다.
AWS Security Hub 통합 활성화
계정에서 AWS Security Hub를 활성화해야 합니다. Security Hub 콘솔의 통합에서 kube-bench를 검색합니다. 결과 수락을 클릭하여 "Aqua Security kube 벤치"를 AWS Security Hub와 통합할 수 있도록 합니다.
이제 보고서를 AWS Security Hub로 보내도록 kube-bench 작업을 구성해 보겠습니다.
AWS Security Hub로 보낼 IAM 정책
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "securityhub:BatchImportFindings",
"Resource": [
"arn:aws:securityhub:us-east-1::product/aqua-security/kube-bench"
]
}
]
}
서비스 계정 IAM 역할 및 정책 만들기
kube-bench 작업을 실행하는 포드의 서비스 계정에 연결할 IAM 역할 및 정책 생성this guide을 사용하십시오.
asff를 사용한 kube-bench
--------
apiVersion: v1
kind: ServiceAccount
metadata:
name: kube-bench
# If using a dedicated IAM role for kube-bench, uncomment the annotations
# block below and replace the ROLE_ARN
# annotations:
# eks.amazonaws.com/role-arn: "<ROLE_ARN>"
--------
apiVersion: v1
kind: ConfigMap
metadata:
name: kube-bench-eks-config
data:
config.yaml: |
AWS_ACCOUNT: "<AWS_ACCT_NUMBER>"
AWS_REGION: "<AWS_REGION>"
CLUSTER_ARN: "<AWS_CLUSTER_ARN>"
--------
apiVersion: batch/v1
kind: Job
metadata:
name: kube-bench
spec:
template:
spec:
hostPID: true
containers:
- name: kube-bench
image: aquasec/kube-bench:latest
command: ["kube-bench", "node", "--benchmark", "eks-1.0", "--asff"]
volumeMounts:
- name: var-lib-kubelet
mountPath: /var/lib/kubelet
readOnly: true
- name: etc-systemd
mountPath: /etc/systemd
readOnly: true
- name: etc-kubernetes
mountPath: /etc/kubernetes
readOnly: true
- name: kube-bench-eks-config
mountPath: "/opt/kube-bench/cfg/eks-1.0/config.yaml"
subPath: config.yaml
readOnly: true
restartPolicy: Never
serviceAccountName: kube-bench
volumes:
- name: var-lib-kubelet
hostPath:
path: "/var/lib/kubelet"
- name: etc-systemd
hostPath:
path: "/etc/systemd"
- name: etc-kubernetes
hostPath:
path: "/etc/kubernetes"
- name: kube-bench-eks-config
configMap:
name: kube-bench-eks-config
items:
- key: config.yaml
path: config.yaml
위의 yaml을 사용하여 작업을 실행하여 결과를 AWS Security Hub로 보냅니다.
Security Hub 결과
결론
이 블로그 게시물에서는 EKS 작업자 노드에 대해 kube-bench 테스트를 실행하고 kube-bench 요약을 AWS Security Hub로 전달하는 방법을 살펴보았습니다. CIS Amazon EKS 벤치마크를 사용하여 Amazon EKS 클러스터 노드의 보안 구성을 정확하게 평가할 수 있습니다.
Reference
이 문제에 관하여(Amazon EKS 보안 평가 - Kube Bench), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/aws-builders/amazon-eks-security-assessment-kube-bench-203텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)