mirror of
https://github.com/docker/docker-bench-security.git
synced 2025-01-19 00:32:34 +01:00
Merge pull request #390 from jammasterj89/master
Issue #383 ability to exclude images Closes #383, #369
This commit is contained in:
commit
d1934b614e
3 changed files with 16 additions and 22 deletions
|
@ -54,9 +54,8 @@ version 1.13.0 or later.
|
||||||
-l FILE optional Log output in FILE
|
-l FILE optional Log output in FILE
|
||||||
-c CHECK optional Comma delimited list of specific check(s)
|
-c CHECK optional Comma delimited list of specific check(s)
|
||||||
-e CHECK optional Comma delimited list of specific check(s) to exclude
|
-e CHECK optional Comma delimited list of specific check(s) to exclude
|
||||||
-i INCLUDE optional Comma delimited list of patterns within a container name to check
|
-i INCLUDE optional Comma delimited list of patterns within a container or image name to check
|
||||||
-x EXCLUDE optional Comma delimited list of patterns within a container name to exclude from check
|
-x EXCLUDE optional Comma delimited list of patterns within a container or image name to exclude from check
|
||||||
-t TARGET optional Comma delimited list of images name to check
|
|
||||||
```
|
```
|
||||||
|
|
||||||
By default the Docker Bench for Security script will run all available CIS tests
|
By default the Docker Bench for Security script will run all available CIS tests
|
||||||
|
|
|
@ -44,9 +44,8 @@ usage () {
|
||||||
-l FILE optional Log output in FILE
|
-l FILE optional Log output in FILE
|
||||||
-c CHECK optional Comma delimited list of specific check(s)
|
-c CHECK optional Comma delimited list of specific check(s)
|
||||||
-e CHECK optional Comma delimited list of specific check(s) to exclude
|
-e CHECK optional Comma delimited list of specific check(s) to exclude
|
||||||
-i INCLUDE optional Comma delimited list of patterns within a container name to check
|
-i INCLUDE optional Comma delimited list of patterns within a container or image name to check
|
||||||
-x EXCLUDE optional Comma delimited list of patterns within a container name to exclude from check
|
-x EXCLUDE optional Comma delimited list of patterns within a container or image name to exclude from check
|
||||||
-t TARGET optional Comma delimited list of images name to check
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +62,6 @@ do
|
||||||
e) checkexclude="$OPTARG" ;;
|
e) checkexclude="$OPTARG" ;;
|
||||||
i) include="$OPTARG" ;;
|
i) include="$OPTARG" ;;
|
||||||
x) exclude="$OPTARG" ;;
|
x) exclude="$OPTARG" ;;
|
||||||
t) imgList="$OPTARG" ;;
|
|
||||||
*) usage; exit 1 ;;
|
*) usage; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
@ -104,14 +102,26 @@ main () {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# get the image id of the docker_bench_security_image, memorize it:
|
||||||
|
benchimagecont="nil"
|
||||||
|
for c in $(docker images | sed '1d' | awk '{print $3}'); do
|
||||||
|
if docker inspect --format '{{ .Config.Labels }}' "$c" | \
|
||||||
|
grep -e 'docker.bench.security' >/dev/null 2>&1; then
|
||||||
|
benchimagecont="$c"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
if [ -n "$include" ]; then
|
if [ -n "$include" ]; then
|
||||||
pattern=$(echo "$include" | sed 's/,/|/g')
|
pattern=$(echo "$include" | sed 's/,/|/g')
|
||||||
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont" | grep -E "$pattern")
|
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont" | grep -E "$pattern")
|
||||||
|
images=$(docker images | grep -E "$pattern" | sed '1d' | awk '{print $3}' | grep -v "$benchimagecont")
|
||||||
elif [ -n "$exclude" ]; then
|
elif [ -n "$exclude" ]; then
|
||||||
pattern=$(echo "$exclude" | sed 's/,/|/g')
|
pattern=$(echo "$exclude" | sed 's/,/|/g')
|
||||||
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont" | grep -Ev "$pattern")
|
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont" | grep -Ev "$pattern")
|
||||||
|
images=$(docker images | grep -Ev "$pattern" | sed '1d' | awk '{print $3}' | grep -v "$benchimagecont")
|
||||||
else
|
else
|
||||||
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont")
|
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont")
|
||||||
|
images=$(docker images -q | grep -v "$benchcont")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$containers" ]; then
|
if [ -z "$containers" ]; then
|
||||||
|
|
|
@ -1,20 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
if [ -n "$imgList" ]; then
|
|
||||||
pattern=$(echo "$imgList" | sed 's/,/ /g')
|
|
||||||
for img in $pattern; do
|
|
||||||
echo "Looking for image $img"
|
|
||||||
sha256=$(docker image ls "$img" -q)
|
|
||||||
if [ -z "$sha256" ]; then
|
|
||||||
echo "Image $img not found. Exiting."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
images="$images $sha256 "
|
|
||||||
done
|
|
||||||
else
|
|
||||||
images=$(docker images -q)
|
|
||||||
fi
|
|
||||||
|
|
||||||
check_4() {
|
check_4() {
|
||||||
logit "\n"
|
logit "\n"
|
||||||
id_4="4"
|
id_4="4"
|
||||||
|
|
Loading…
Reference in a new issue