-
Notifications
You must be signed in to change notification settings - Fork 3
/
oscap-docker
executable file
·101 lines (83 loc) · 1.8 KB
/
oscap-docker
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
set -e -o pipefail
function catch-all(){
echo oscap-docker -- Compliance and Vulnerability scanning tool for containers.
echo
echo Usage:
echo oscap-docker image
echo or
echo oscap-docker container
}
function mount_docker(){
#Creates a temporary directory for the docker image
echo Mounting image:
local name=$1;
echo " $name"
local target=$2;
echo " $target"
<<<<<<< Updated upstream
mkdir tmp || echo tmp directory exists
local tmp=`mktemp -d docker.XXXXXX`
echo $tmp
docker save $name | tar x -C $tmp
=======
local tmp=`mktemp -d docker.XXXXXX`
echo $tmp
echo "$tmp"
docker save $name | tar x --directory $tmp
>>>>>>> Stashed changes
echo 4
for layer in `find $tmp/* -maxdepth 1 -type d`; do
if tar tvf $layer/layer.tar | grep . > /dev/null; then
tar xf $layer/layer.tar --directory $target_dir
fi
done
rm -r $tmp
}
function unmount_docker(){
#Deletes the specified image
echo UnMounting image
rm -r $1
}
function get_oscap_content(){
local target=$1;
local image_name=$2;
local image_path=$3;
shift shift shift
local oscap_params=$*
export oscap_path="$(cd $path; pwd)"
export oscap_os="Linux"
export oscap_version='uname --kernel-release'
export oscap_platform='uname --hardware-plaform'
export oscap_host='docker-$target-$image'
#echo "$oscap_path"
oscap $oscap_arguments
}
module=$1;shift
case $module in
image)
echo Scanning image:
name=$1;shift
echo " $name"
echo
oscap_params=$*
#Make a temporary directory
image_root=`mktemp -d docker.XXXXXX`
mount_docker $name $image_dir
get_oscap_content "image" $name $image_dir $oscap_params
echo Scanning with the following oscap parameters:
echo " $oscap_params"
unmount_docker $name
exit 0
;;
container)
echo Scanning container
name=$2;
oscap_params=$*
exit 0
;;
*)
catch-all
exit 1
;;
esac