Skip to content

Commit

Permalink
FIX| RKE-CIS-1.24- CHECK 1.1.19
Browse files Browse the repository at this point in the history
We have added the missing script required for check 1.1.19 in rke-cis-1.24 and made it available to the kube-bench file system(https://github.com/rancher/security-scan/blob/master/package/helper_scripts/check_files_owner_in_dir.sh).
  • Loading branch information
sm171190 committed Nov 8, 2024
1 parent 74f5c8b commit 586a721
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ RUN make build && cp kube-bench /go/bin/kube-bench
ARG KUBECTL_VERSION TARGETARCH
RUN wget -O /usr/local/bin/kubectl "https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl"
RUN wget -O kubectl.sha256 "https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl.sha256"

# Verify kubectl sha256sum
RUN /bin/bash -c 'echo "$(<kubectl.sha256) /usr/local/bin/kubectl" | sha256sum -c -'

RUN chmod +x /usr/local/bin/kubectl

FROM alpine:3.20.3 AS run
Expand Down Expand Up @@ -57,3 +59,5 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/aquasecurity/kube-bench" \
org.label-schema.schema-version="1.0"

COPY helper_scripts/check_files_owner_in_dir.sh /go/bin
21 changes: 20 additions & 1 deletion cfg/rke-cis-1.24/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,26 @@ groups:

- id: 1.1.19
text: "Ensure that the Kubernetes PKI directory and file ownership is set to root:root (Automated)"
audit: "check_files_owner_in_dir.sh /node/etc/kubernetes/ssl"
audit: |
#!/bin/bash
if [[ $(stat -c %U:%G "/node/etc/kubernetes/ssl") != "root:root" ]]; then
echo "false"
exit 1
fi
for f in "/node/etc/kubernetes/ssl"/*; do
if [[ $(basename "$f" .pem) == "kube-etcd-"* ]]; then
if [[ $(stat -c %U:%G "$f") != "root:root" && $(stat -c %U:%G "$f") != "etcd:etcd" ]]; then
echo "false"
exit 1
fi
else
if [[ $(stat -c %U:%G "$f") != "root:root" ]]; then
echo "false"
exit 1
fi
fi
done
echo "true"
tests:
test_items:
- flag: "true"
Expand Down
44 changes: 44 additions & 0 deletions helper_scripts/check_files_owner_in_dir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# This script is used to ensure the owner is set to root:root for
# the given directory and all the files in it
#
# inputs:
# $1 = /full/path/to/directory
#
# outputs:
# true/false

INPUT_DIR=$1

if [[ "${INPUT_DIR}" == "" ]]; then
echo "false"
exit
fi

if [[ $(stat -c %U:%G ${INPUT_DIR}) != "root:root" ]]; then
echo "false"
exit
fi

statInfoLines=$(stat -c "%n %U:%G" ${INPUT_DIR}/*)
while read -r statInfoLine; do
f=$(echo ${statInfoLine} | cut -d' ' -f1)
p=$(echo ${statInfoLine} | cut -d' ' -f2)

if [[ $(basename "$f" .pem) == "kube-etcd-"* ]]; then
if [[ "$p" != "root:root" && "$p" != "etcd:etcd" ]]; then
echo "false"
exit
fi
else
if [[ "$p" != "root:root" ]]; then
echo "false"
exit
fi
fi
done <<< "${statInfoLines}"


echo "true"
exit

0 comments on commit 586a721

Please sign in to comment.