-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·36 lines (30 loc) · 1.29 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
set -e
RUN_CHECKOV_POLICIES=${RUN_CHECKOV_POLICIES:-false}
RUN_KYVERNO_POLICIES=${RUN_KYVERNO_POLICIES:-false}
POLICY_REPO_DIR="${POLICY_REPO_DIR:-/tmp/policy}"
# Arg 1: json content, Arg 2: key
function jq_fetch () {
jq -r "if has (\"$2\") then .$2 else error(\"Missing Key: $2\") end" <<< $1
}
if $RUN_CHECKOV_POLICIES ; then
echo "Locating policy-checker variables within policy_checker.json file..."
POLICY_CHECKER_VARIABLES=`cat policy_checker.json`
POLICY_SOURCE=$(jq_fetch "${POLICY_CHECKER_VARIABLES}" "source")
POLICY_VERSION=$(jq_fetch "${POLICY_CHECKER_VARIABLES}" "version")
POLICY_CONFIG=$(jq_fetch "${POLICY_CHECKER_VARIABLES}" "config")
echo "Policy Package: ${POLICY_SOURCE}:${POLICY_VERSION}"
echo "Fetching Policies..."
git -c advice.detachedHead=false clone --quiet --depth 1 --branch ${POLICY_VERSION} ${POLICY_SOURCE} ${POLICY_REPO_DIR}
echo "Policies fetched."
echo "Running checkov policies..."
checkov \
--config-file ${POLICY_REPO_DIR}/${POLICY_CONFIG} \
--download-external-modules true \
--directory .
else
echo "Skipping Checkov tests.. Set 'RUN_CHECKOV_POLICIES' to true to execute these."
fi
if $RUN_KYVERNO_POLICIES ; then
echo "Skipping Kyverno tests.. Not currently implemented."
fi