Skip to content

Commit 5501753

Browse files
authored
Merge pull request #1306 from matusmarhefka/oscap_podman
Added utils/oscap-podman for SCAP evaluation of podman images and containers
2 parents d7d497b + 4aef8af commit 5501753

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

utils/oscap-podman

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019 Red Hat Inc., Durham, North Carolina.
4+
#
5+
# This library is free software; you can redistribute it and/or
6+
# modify it under the terms of the GNU Lesser General Public
7+
# License as published by the Free Software Foundation; either
8+
# version 2 of the License, or (at your option) any later version.
9+
#
10+
# This library is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# Lesser General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Lesser General Public
16+
# License along with this library; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
19+
20+
function die()
21+
{
22+
echo "$*" >&2
23+
exit 1
24+
}
25+
26+
function usage()
27+
{
28+
echo "oscap-podman -- Tool for SCAP evaluation of Podman images and containers."
29+
echo
30+
echo "Compliance scan of Podman image:"
31+
echo "$ sudo oscap-podman IMAGE_NAME OSCAP_ARGUMENT [OSCAP_ARGUMENT...]"
32+
echo
33+
echo "Compliance scan of Podman container:"
34+
echo "$ sudo oscap-podman CONTAINER_NAME OSCAP_ARGUMENT [OSCAP_ARGUMENT...]"
35+
echo
36+
echo "See \`man oscap\` to learn more about semantics of OSCAP_ARGUMENT options."
37+
}
38+
39+
if [ $# -lt 1 ]; then
40+
echo "No arguments provided."
41+
usage
42+
die
43+
elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
44+
usage
45+
die
46+
elif [ "$#" -gt 1 ]; then
47+
true
48+
else
49+
echo "Invalid arguments provided."
50+
usage
51+
die
52+
fi
53+
54+
if [ $(id -u) -ne 0 ]; then
55+
echo "This script cannot run in rootless mode." >&2
56+
die
57+
fi
58+
if grep -q "\-\-remediate" <<< "$@"; then
59+
echo "This script does not support '--remediate' option." >&2
60+
die
61+
fi
62+
63+
# Check if the target of scan is image or container.
64+
CLEANUP=0
65+
if podman images | grep -q $1; then
66+
ID=$(podman create $1) || die
67+
IMG_NAME=$(podman images --format "{{.ID}} ({{.Repository}}:{{.Tag}})" | grep -m1 $1)
68+
TARGET="podman-image://$IMG_NAME"
69+
CLEANUP=1
70+
else
71+
# If the target was not found in images we suppose it is a container.
72+
ID=$1
73+
TARGET="podman-container://$1"
74+
fi
75+
DIR=$(podman mount $ID) || die
76+
77+
export OSCAP_PROBE_ROOT="$(cd "$DIR"; pwd)"
78+
export OSCAP_PROBE_OS_NAME="Linux"
79+
export OSCAP_PROBE_OS_VERSION="$(uname --kernel-release)"
80+
export OSCAP_PROBE_ARCHITECTURE="$(uname --hardware-platform)"
81+
export OSCAP_EVALUATION_TARGET="$TARGET"
82+
shift 1
83+
84+
oscap "$@"
85+
EXIT_CODE=$?
86+
podman umount $ID > /dev/null || die
87+
if [ $CLEANUP -eq 1 ]; then
88+
podman rm $ID > /dev/null || die
89+
fi
90+
exit $EXIT_CODE

0 commit comments

Comments
 (0)