mirror of
https://github.com/docker/docker-bench-security.git
synced 2025-01-19 00:32:34 +01:00
add include option #286
Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com>
This commit is contained in:
parent
9ca5b8b2e1
commit
36b73c4398
1 changed files with 11 additions and 13 deletions
|
@ -44,6 +44,7 @@ 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
|
||||||
-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 name to exclude from check
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
@ -51,13 +52,14 @@ EOF
|
||||||
# Get the flags
|
# Get the flags
|
||||||
# If you add an option here, please
|
# If you add an option here, please
|
||||||
# remember to update usage() above.
|
# remember to update usage() above.
|
||||||
while getopts hl:c:e:x: args
|
while getopts hl:c:e:i:x: args
|
||||||
do
|
do
|
||||||
case $args in
|
case $args in
|
||||||
h) usage; exit 0 ;;
|
h) usage; exit 0 ;;
|
||||||
l) logger="$OPTARG" ;;
|
l) logger="$OPTARG" ;;
|
||||||
c) check="$OPTARG" ;;
|
c) check="$OPTARG" ;;
|
||||||
e) checkexclude="$OPTARG" ;;
|
e) checkexclude="$OPTARG" ;;
|
||||||
|
i) include="$OPTARG" ;;
|
||||||
x) exclude="$OPTARG" ;;
|
x) exclude="$OPTARG" ;;
|
||||||
*) usage; exit 1 ;;
|
*) usage; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
@ -87,13 +89,6 @@ beginjson "$version" "$(date +%s)"
|
||||||
|
|
||||||
# Load all the tests from tests/ and run them
|
# Load all the tests from tests/ and run them
|
||||||
main () {
|
main () {
|
||||||
# List all running containers
|
|
||||||
if [ -z "$exclude" ]; then
|
|
||||||
containers=$(docker ps | sed '1d' | awk '{print $NF}')
|
|
||||||
else
|
|
||||||
pattern=$(echo "$exclude" | sed 's/,/|/g')
|
|
||||||
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -Ev "$pattern" )
|
|
||||||
fi
|
|
||||||
# If there is a container with label docker_bench_security, memorize it:
|
# If there is a container with label docker_bench_security, memorize it:
|
||||||
benchcont="nil"
|
benchcont="nil"
|
||||||
for c in $containers; do
|
for c in $containers; do
|
||||||
|
@ -102,12 +97,15 @@ main () {
|
||||||
benchcont="$c"
|
benchcont="$c"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# List all running containers except docker-bench (use names to improve readability in logs)
|
|
||||||
if [ -z "$exclude" ]; then
|
if [ -n "$include" ]; then
|
||||||
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont")
|
pattern=$(echo "$include" | sed 's/,/|/g')
|
||||||
else
|
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont" | grep -E "$pattern")
|
||||||
|
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 -Ev "$pattern" | grep -v "$benchcont")
|
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont" | grep -Ev "$pattern")
|
||||||
|
else
|
||||||
|
containers=$(docker ps | sed '1d' | awk '{print $NF}' | grep -v "$benchcont")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$containers" ]; then
|
if [ -z "$containers" ]; then
|
||||||
|
|
Loading…
Reference in a new issue