TMAegisBeta
More rules for gke

Google Kubernetes Engine (GKE)

TMA-GKE-3.1.1

Ensure that the kubeconfig file permissions are set to 644 or more restrictive

MediumLevel 1Automatedgke

Description

If kubelet is running, and if it is configured by a kubeconfig file, ensure that the proxy kubeconfig file has permissions of 644 or more restrictive. Runs on each GKE node (path from the kubelet argument).

How it is checked

Audit method: Shell command

shell
set -f
psarg() { ps -eo args 2>/dev/null | grep -E "^([^ ]*/)?$1( |\$)" | head -n 1 | awk -v k="--$2" '{for(i=1;i<=NF;i++){if($i==k&&i<NF)v=$(i+1); else if(index($i,k"=")==1)v=substr($i,length(k)+2)}} END{if(v!="")print v}'; }
p0=$(psarg kubelet kubeconfig)
f=""; for x in ${p0:-} /var/lib/kubelet/kubeconfig; do if [ -e "$x" ]; then f=$x; break; fi; done
[ -n "$f" ] || exit 1
p=$(stat -Lc %a "$f") || exit 1
if [ $((0$p & 0133)) -eq 0 ]; then echo compliant; else echo "noncompliant: $f mode $p"; fi
Expected output
compliant

How it is fixed

Fix method: Guidance or infrastructure patch

Run the below command (based on the file location on your system) on the each worker node. For example, chmod 644 <kubeconfig file>

Properties

Operating systems
Any
Tags
gkeworker-nodefile-permissions
Reference
CIS Google Kubernetes Engine (GKE) Benchmark v2.0.0 - 3.1.1 Ensure that the kubeconfig file permissions are set to 644 or more restrictive

Check this host

Run this on a machine you are allowed to audit. The scan is read-only.

shell
tmaegis scan --target gke