@@ -115,7 +115,7 @@ def _get_dist(self, chroot, target):
115
115
if "{0}{1}: true" .format (self .CPE , dist ) in result .stdout :
116
116
return dist
117
117
118
- def _get_target_name (self , target ):
118
+ def _get_target_name_and_config (self , target ):
119
119
'''
120
120
Determines if target is image or container. For images returns full
121
121
image name if exists or image ID otherwise. For containers returns
@@ -131,28 +131,31 @@ def _get_target_name(self, target):
131
131
name = ", " .join (image ["RepoTags" ])
132
132
else :
133
133
name = image ["Id" ][len ("sha256:" ):][:10 ]
134
- return "docker-image://{}" .format (name )
134
+ return "docker-image://{}" .format (name ), image [ "Config" ]
135
135
except docker .errors .NotFound :
136
136
try :
137
137
container = client .inspect_container (target )
138
138
if container ["Name" ]:
139
139
name = container ["Name" ].lstrip ("/" )
140
140
else :
141
141
name = container ["Id" ][:10 ]
142
- return "docker-container://{}" .format (name )
142
+ return "docker-container://{}" .format (name ), container [ "Config" ]
143
143
except docker .errors .NotFound :
144
- return "unknown"
144
+ return "unknown" , {}
145
145
146
146
def oscap_chroot (self , chroot_path , target , * oscap_args ):
147
147
'''
148
148
Wrapper function for executing oscap in a subprocess
149
149
'''
150
-
151
150
os .environ ["OSCAP_PROBE_ARCHITECTURE" ] = platform .processor ()
152
151
os .environ ["OSCAP_PROBE_ROOT" ] = os .path .join (chroot_path )
153
152
os .environ ["OSCAP_PROBE_OS_NAME" ] = platform .system ()
154
153
os .environ ["OSCAP_PROBE_OS_VERSION" ] = platform .release ()
155
- os .environ ["OSCAP_EVALUATION_TARGET" ] = self ._get_target_name (target )
154
+ name , conf = self ._get_target_name_and_config (target )
155
+ os .environ ["OSCAP_EVALUATION_TARGET" ] = name
156
+ for var in config .get ("Env" , []):
157
+ vname , val = var .split ("=" , 1 )
158
+ os .environ [vname ] = val
156
159
cmd = [self .oscap_binary ] + [x for x in oscap_args ]
157
160
oscap_process = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
158
161
oscap_stdout , oscap_stderr = oscap_process .communicate ()
0 commit comments