1
1
#!@OSCAP_DOCKER_PYTHON@
2
2
3
3
# Copyright (C) 2015 Brent Baude <
[email protected] >
4
- # Copyright (C) 2019 Dominique Blaze <
[email protected] >
4
+ # Copyright (C) 2019 Dominique Blaze <
[email protected] >
5
5
#
6
6
# This library is free software; you can redistribute it and/or
7
7
# modify it under the terms of the GNU Lesser General Public
@@ -44,39 +44,40 @@ if __name__ == '__main__':
44
44
epilog='See `man oscap` to learn \
45
45
more about OSCAP-ARGUMENTS')
46
46
parser.add_argument('--oscap', dest='oscap_binary', default='', help='Set the oscap binary to use')
47
+ parser.add_argument('--disable-atomic', dest='noatomic', action='store_true', help="Force to use native docker API instead of atomic")
47
48
subparser = parser.add_subparsers(help="commands")
48
49
49
50
# Scan CVEs in image
50
51
image_cve = subparser.add_parser('image-cve', help='Scan a docker image \
51
52
for known vulnerabilities.')
52
- image_cve.set_defaults(func=OscapScan. scan_cve)
53
+ image_cve.set_defaults(action=" scan_cve", is_image=True )
53
54
image_cve.add_argument('scan_target', help='Container or image to scan')
54
55
55
56
# Scan an Image
56
57
image = subparser.add_parser('image', help='Scan a docker image')
57
58
image.add_argument('scan_target',
58
59
help='Container or image to scan')
59
60
60
- image.set_defaults(func=OscapScan. scan)
61
+ image.set_defaults(action=" scan", is_image=True )
61
62
# Scan a container
62
63
container = subparser.add_parser('container', help='Scan a running docker\
63
64
container of given name.')
64
65
container.add_argument('scan_target',
65
66
help='Container or image to scan')
66
- container.set_defaults(func=OscapScan. scan)
67
+ container.set_defaults(action=" scan", is_image=False )
67
68
68
69
# Scan CVEs in container
69
70
container_cve = subparser.add_parser('container-cve', help='Scan a \
70
71
running container for known \
71
72
vulnerabilities.')
72
73
73
- container_cve.set_defaults(func=OscapScan. scan_cve)
74
+ container_cve.set_defaults(action=" scan_cve", is_image=False )
74
75
container_cve.add_argument('scan_target',
75
76
help='Container or image to scan')
76
77
77
78
args, leftover_args = parser.parse_known_args()
78
79
79
- if "func " not in args:
80
+ if "action " not in args:
80
81
parser.print_help()
81
82
sys.exit(2)
82
83
@@ -88,10 +89,40 @@ if __name__ == '__main__':
88
89
sys.exit(1)
89
90
90
91
try:
91
- OS = OscapScan(oscap_binary=args.oscap_binary)
92
- rc = args.func(OS, args.scan_target, leftover_args)
92
+ if isAtomicLoaded and not args.noatomic:
93
+ OS = OscapAtomicScan(oscap_binary=args.oscap_binary)
94
+ if args.action == "scan":
95
+ rc = OscapAtomicScan.scan(OS, args.scan_target, leftover_args)
96
+ elif args.action == "scan_cve":
97
+ rc = OscapAtomicScan.scan_cve(OS, args.scan_target, leftover_args)
98
+ else:
99
+ parser.print_help()
100
+ sys.exit(2)
101
+
102
+ else: # without atomic
103
+ if args.noatomic:
104
+ print("Running oscap-docker with native docker api instead of atomic ...")
105
+
106
+ ODS = OscapDockerScan(args.scan_target, args.is_image, args.oscap_binary)
107
+ if args.action == "scan":
108
+ rc = OscapDockerScan.scan(ODS, leftover_args)
109
+ elif args.action == "scan_cve":
110
+ print("Scan cve !")
111
+ rc = OscapDockerScan.scan_cve(ODS, leftover_args)
112
+ else:
113
+ parser.print_help()
114
+ sys.exit(2)
115
+
116
+ except ValueError as e:
117
+ raise e
118
+ sys.exit(255)
119
+ except RuntimeError as e:
120
+ raise e
121
+ sys.exit(255)
93
122
except Exception as exc:
123
+ traceback.print_exc(file=sys.stdout)
124
+ sys.stderr.write("!!! WARNING !!! This software have crash, so you should "
125
+ "check that no temporary container is still running\n")
94
126
sys.exit(255)
95
- raise exc
96
127
97
128
sys.exit(rc)
0 commit comments