23.06.15
DEVOTEE를 활성화 시키면
지금 작성한 커뮤니티 글에 대해 1개의 댓글을 달아줍니다.
버튼을 누르면 글 수정 시 ChatGPT가 작성한 댓글이 수정됩니다.
| 컨텐츠 유형 | 제목 | 저장일 | 삭제 |
|---|
본인인증 로그인에 실패하였습니다.
회원이 아니시거나 본인인증 등록이
완료되지 않은 사용자입니다.
넷스케이프라는 툴을 기억하는가? 기억한다면 아재라 불릴만한 세대이다. 넷스케이프가 네트워크 상의 여러가지 정보들을 찾아다닌다면 쿠버네티스 환경에서 내부의 정보들을 누비고 다닐듯한 이름인 kubescape라는 오픈소스가 있어 이를 자세히 들여다 보고자 한다.
넷스케이프는 최초의 대중적 인터넷 브라우저의 이름이자 이를 유지보수하던 회사의 이름이기도 했다. 마이크로소프트의 인터넷 익스플로러 끼워팔기로 입지를 잃으면서 점유율이 급격히 하락하였고 결국 회사는 파산하였다. 추후 마이크로 소프트가 반독점 금지법에 걸리고 잘못한 것으로 판결받았으나 넷스케이프는 이미 역사속으로 사라진 후 였다. :(

kubescape는 DevOps를 위한 kubernetes용 보안 플랫폼이다. NSA/CISA의 ‘쿠버네티스 보안강화지침(kubernetest hadrdening guidance)’에 맞게 안전하게 배포되었는지 테스트하는 도구로 단일 yaml파일부터 클러스터 단위의 테스트를 수행한다. 또한 그 결과로 JSON 형태의 출력을 하여 이를 기반으로 CI를 비롯한 다른 시스템의 연동이 용이하다.
쿠버네티스 보안강화지침의 주요 내용
취약점 또는 잘못된 구성을 찾기 위해 컨테이너와 포드 스캔하기
최소한의 권한으로 컨테이너와 포드 실행하기
네트워크를 분리하여 발생할 수 있는 데미지를 제어하기
방화벽을 사용해서 필요없는 네트웍 연결을 제한하고, 암호화하기
강력한 인증 및 권한관리를 통해서 사용자 및 관리자의 접근을 제한하고, 공격 표면(Attack Surface)을 한정시키기.
관리자가 활동을 모니터링하고, 잠재적인 위험 동작에 대해 경고할 수 있도록 Log Auditing 사용하기
정기적으로 모든 k8s 설정을 검토하고, Vulnerability 스캔을 사용해서 위험 방지및 보안 패치가 적용되었는지 확인하기
쿠버네티스 상에서 잘못된 설정정보나 취약점을 감지
이를 수치화해서 위험정도를 체크하고 과거의 수치들을 기반으로 경향도 파악
실시간 설정변경파악
특정 기준(NSA, Mitre, Devops best practice)을 준수하도록 프레임 워크들 제공하고 사용자화도 할수 있음
예외관리를 통해 무분별한 알람발생 제어
다양한 devops 도구들고 연동 (Jenkins, CircleCI, Github workflows, Gitlab, Prometheus, Slack,…)
사용하기 쉬운 cli 제공과 유연한 결과출력 조정 (json, junit xml..)
쿠버네티스의 상태와 정책의 준수를 보여주는 ui
복구지원 - 장애지정과 원인을 알려주고 자원 선택시 crd에서 문제를 일이킨 지점으로 이동
이미지 스캔 - 취약점을 보여주는데 편리하게 정령이나 필터등 가능
RBAC 생성지원 - 시각화 지원을 통해 클러스터에 추가되는 rbac의 복잡도를 줄여줌
OPA 엔진을 기반으로 하고 있고 ARMO의 조작도구를 사용한다.
ARMO가 개발한 rego snippet 들을 실행하여 스캔을 수행
다양한 기준을 얼마나 준수하고 있는지 파악
웹을 통해 스크립트를 받아 실행하면 cli가 설치되고 scan명령을 통해 kubeconfig에 연동된 클러스터에 대한 취약점 체크를 수행한다.
# install
curl -s https://raw.githubusercontent.com/armosec/kubescape/master/install.sh | /bin/bash
# scan cluster
kubescape scan --submit --enable-host-scan --verbose
출처: https://github.com/armosec/kubescape
클러스터의 정책별 수행: framework nsa|mitre
Control별 수행: **controls 리스트
네임스페이스별 지정: --include-namespaces, --exclude-namespaces
로컬 리소스파일(*.yaml) 또는 helm(디렉토리) 지정
helm 저장소 지정
다양한 포맷으로 출력가능 --format json|junit|pdf|prometheus
개발용 소프트웨어나 운영툴에 연동되어 최약점을 실시간 분석하도록 구성가능
VS Code: plugin으로 제공하고 있음, 공식페이지

출처: https://github.com/armosec/vscode-kubescape/blob/master/README.md
Lens: 확장모듈로 제공하고 있음, 공식페이지

출처: https://github.com/armosec/lens-kubescape/blob/master/README.md
SaaS를 통해 다음과 같은 기능을 추가적으로 제공한다.
최근 수행한 스캔을 기반으로 매우 간결하고 쉽게 클러스터의 상태를 확인할 수 있다.
Your K8s has never looked better - A super friendly UI to manage tests, scans and get an instantly calculated risk score based on the current scan. You can now make quick, smart decisions based on your K8s’ real-time standing.
CISA-NSA, MITRE, ARMO, DevOps 그룹들이 제공하는 안전지침을 하나 또는 다수를 선택하여 기준으로 가져갈수 있다.
CISA-NSA or MITRE? ARMO|Best or DevOps best practices? - You can decide which framework to work with or run all of them in one click or you can customized your own compliance framework.
과거의 기록을 통해 미래를 확인할 수 있다.
Don’t forget your past, look into the future - Easy access to a history of past scans for a quick review of total risk scores trends from one scan to the next. You can track your organization’s progress with hyper-accuracy, determine whether your risk has changed for better or worse over time, and manage configuration drifts.
예외 처리를 통해 알람을 조절할 수 있다.
Dealing with too many alerts? - Manage exceptions and stop seeing annoying alerts.
RBAC의 작성을 지원한다.
RBAC made easy - Kubescape simplifies RBAC complexity by providing an easy-to-use and easy-to-understand, visual graph which shows the RBAC configuration in your cluster. It comes with built-in queries of things you need to be aware of in your RBAC configuration
개선을 지원한다.
Assisted Remediation - Kubescape will show you exactly where your resource has failed and what was the cause. Once you click on a resource, you will be able to see the exact and specific which caused the resource to fail in the resource definition file (e.g. YAML.)
사용하는 이미지를 스캔한다.
Image scanning - You can scan containers for vulnerabilities, and easily see, sort, and filter which vulnerability to patch first
당신의 데브옵스 도구들과 연동한다.
Works well with your DevOps toolsYou can integrate Kubescape with tools like Jenkins, CircleCI, Github actions, Gitlab, Prometheus, Slack, and more.
앞의 예시로 살펴보았던 cli에서도 SaaS로 연동하여 테스트한 결과를 보낼수 있도록 되어 있으며 클러스터 내부에 배포해서 주기적으로 테스트를 수행하고 결과를 SaaS로 전달하는 방법도 사용할 수 있다.
10개의 Worker노드에 대해서는 무료로 사용할 수 있으며 https://cloud.armosec.io/ 주소를 통해 접근가능하다.


kubescape는 다양한 기능을 OPA에 여러 정책을 통해 제어할수 있도록 되어있으며 이에 대한 소스를 공개하고 있다. (https://github.com/armosec/regolibrary/tree/master/rules)
CVE-2021-25741: 사용자가 컨테이너를 띄워서 권한이 없는 파일이나 디렉토리에 접근할 수 있음
CVE-2021-25742: ingress-nginx의 버그로 인해 custom snippet 기능으로부터 클러스터의 모든 secret에 접근가능
CVE-2022-0185: 버퍼 오버플로우 관련 결함으로 권한없는 파일접근
CVE-2022-0492: cgroup관련 커널결함으로 허용되지 않은 네임스페이스에 접근가능
CVE-2022-23648: containerd에서 발견된 버그로 이미지를 조작하여 만들고 cri를 통하면 호스트의 모든 파일을 복제해 갈수 있음
CVE-2022-24348: Argo CD의 버그로 Helm chart들과 관련된 디렉토리를 탐색할 수 있음
위 분류는 명칭을 기반으로 수행한 것으로 코드를 확인하지 않은 개인적인 분류이므로 참조만 하자. 전체적으로는 해당 리포의 홈에 분류표가 존재하므로 이를 신뢰하도록 한다. (‣)
코드를 보는데 참고하자.
OPA를 활용하는 대표적인 프레임웍으로 과거부터 사용해왔던 conftest (kube-mgmt)와 kubernetes gatekeeper 방식이 있고 OPA 서버를 직접 연동하여 자신만의 프레임워크를 만들어 쓰는 경우가 있다.
conftest는 deny라는 매직 키워드를 검사한다.
kubernetes gatekeeper는 violation이라는 매직 키워드를 검사한다.
해당 repo에는 정책의 테스트를 위한 예제 입력들이 존재하고 있으며 이를 통해 conf test가 가능하다.
regolibrary/rules-tests at master · kubescape/regolibrary
RBAC-enabled: kubeapi에서 rbac을 켰는지 체크
access-container-service-account-v1: 전달된 사용자의 접근권한 검색
access-container-service-account:
anonymous-requests-to-kubelet:
automount-service-account
rule-can-bash-cmd-inside-container
rule-can-create-bind-escalate-role
rule-can-create-bind-escalate-role-v1
rule-can-create-modify-pod
rule-can-create-modify-pod-v1
rule-can-create-pod-kube-system
rule-can-create-pod-kube-system-v1
rule-can-delete-create-service
rule-can-delete-create-service-v1
rule-can-delete-k8s-events
rule-can-delete-k8s-events-v1
rule-can-delete-logs
rule-can-delete-logs-v1
rule-can-impersonate-users-groups
rule-can-impersonate-users-groups-v1
rule-can-list-get-secrets
rule-can-list-get-secrets-v1
rule-can-portforward
rule-can-portforward-v1
rule-can-ssh-to-pod
rule-can-ssh-to-pod-v1
rule-can-update-configmap
rule-can-update-configmap-v1
rbac-enabled-native
rule-access-dashboard
rule-access-dashboard-subject-v1
rule-access-dashboard-wl-v1
rule-access-kubelet-API
rule-allow-privilege-escalation
rule-deny-cronjobs
rule-excessive-delete-rights
rule-excessive-delete-rights-v1
rule-exposed-dashboard
rule-exposed-dashboard-v1
rule-list-all-cluster-admins
rule-list-all-cluster-admins-v1
psp-enabled-cloud
psp-enabled-native
rbac-enabled-cloud
K8s common labels usage: 지정한 레이블이 있는데(data로 입력해 줌) 이를 지정하지 않았는지 체크
access-tiller-endpoint
alert-any-hostpath: hostpath 사용하면 알람
alert-rw-hostpath: hostpath에 쓰기기능이 있으면 알람
configured-liveness-probe
configured-readiness-probe
container-hostPort
container-image-repository
containers-mounting-docker-socket
deny-RCE-vuln-image-pods
deny-vuln-image-pods
enforce-kubelet-client-tls-authentication
etcd-encryption-native
excessive_amount_of_vulnerabilities_pods
exec-into-container
exec-into-container-v1
exposed-critical-pods
exposed-rce-pods
exposed-sensitive-interfaces
exposed-sensitive-interfaces-v1
has-critical-vulnerability
host-network-access
host-pid-ipc-privileges
image-pull-policy-is-not-set-to-always
image-pull-secrets
immutable-container-filesystem
ingress-and-egress-blocked
insecure-capabilities
insecure-port-flag
instance-metadata-api-access
internal-networking
k8s-audit-logs-enabled-cloud
k8s-audit-logs-enabled-native
label-usage-for-resources
linux-hardening
list-all-mutating-webhooks
list-all-validating-webhooks
more-than-one-replicas
naked-pods
namespace-without-service-account
non-root-containers
pod-specific-version-tag
pods-in-default-namespace
read-only-port-enabled
resource-policies
resources-cpu-limit-and-request
resources-memory-limit-and-request
rule-credentials-configmap
rule-credentials-in-env-var
rule-deny-cronjobs
rule-identify-blocklisted-image-registries
rule-list-all-cluster-admins
rule-list-all-cluster-admins-v1
rule-name-similarity
rule-privileged-container
secret-etcd-encryption-cloud
security-context-in-pod
sidecar-injection
sudo-in-container-entrypoint
user-id-less-than-thousands
validate-kubelet-tls-configuration
본 페이지를 통해 OPA를 활용한 오픈소스 보안솔루션인 kubescape에 대해 간략하게 소개하고 공개된 rego 정책들을 살펴보았다. 라이브러리에 소개된 코드를 이해하기에는 ‘OPA의 정책활용의 예 (feat. CVE-2021-25741 대비하기)’ -현재는 내부적으로만 접근가능-을 참조하길 권장한다. 소개한 repo에서는 테스트를 위한 데이터까지 함께 제공하고 있으므로 이 데이터들로 opa playground를 활용하면 conf test의 설치없이도 테스트 해볼수 있다. (사용자 권한체크 - https://play.openpolicyagent.org/p/Xtz4cb5H9U)
DEVOTEE를 활성화 시키면
지금 작성한 댓글에 AI가 댓글을 달아줍니다.