ironic-python-agent 11.2.0__py3-none-any.whl → 11.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ironic_python_agent/agent.py +63 -12
- ironic_python_agent/api/app.py +2 -12
- ironic_python_agent/config.py +7 -0
- ironic_python_agent/device_hints.py +53 -10
- ironic_python_agent/extensions/image.py +20 -11
- ironic_python_agent/extensions/standby.py +90 -21
- ironic_python_agent/hardware.py +482 -232
- ironic_python_agent/raid_utils.py +8 -3
- ironic_python_agent/tests/functional/base.py +6 -2
- ironic_python_agent/tests/functional/test_commands.py +7 -2
- ironic_python_agent/tests/unit/extensions/test_image.py +32 -0
- ironic_python_agent/tests/unit/extensions/test_standby.py +189 -25
- ironic_python_agent/tests/unit/samples/hardware_samples.py +1 -1
- ironic_python_agent/tests/unit/test_agent.py +217 -10
- ironic_python_agent/tests/unit/test_api.py +17 -26
- ironic_python_agent/tests/unit/test_device_hints.py +35 -3
- ironic_python_agent/tests/unit/test_hardware.py +988 -51
- ironic_python_agent/tests/unit/test_raid_utils.py +7 -0
- ironic_python_agent/tests/unit/test_utils.py +121 -1
- ironic_python_agent/utils.py +27 -2
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.2.1.dist-info}/METADATA +36 -25
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.2.1.dist-info}/RECORD +28 -28
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.2.1.dist-info}/WHEEL +1 -1
- ironic_python_agent-11.2.1.dist-info/pbr.json +1 -0
- ironic_python_agent-11.2.0.dist-info/pbr.json +0 -1
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.2.1.dist-info}/entry_points.txt +0 -0
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.2.1.dist-info/licenses}/AUTHORS +0 -0
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.2.1.dist-info/licenses}/LICENSE +0 -0
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.2.1.dist-info}/top_level.txt +0 -0
ironic_python_agent/agent.py
CHANGED
|
@@ -22,6 +22,8 @@ import threading
|
|
|
22
22
|
import time
|
|
23
23
|
from urllib import parse as urlparse
|
|
24
24
|
|
|
25
|
+
import requests
|
|
26
|
+
|
|
25
27
|
from oslo_concurrency import processutils
|
|
26
28
|
from oslo_config import cfg
|
|
27
29
|
from oslo_log import log
|
|
@@ -38,6 +40,7 @@ from ironic_python_agent import mdns
|
|
|
38
40
|
from ironic_python_agent import netutils
|
|
39
41
|
from ironic_python_agent import utils
|
|
40
42
|
|
|
43
|
+
CONF = cfg.CONF
|
|
41
44
|
LOG = log.getLogger(__name__)
|
|
42
45
|
|
|
43
46
|
# Time(in seconds) to wait for any of the interfaces to be up
|
|
@@ -174,7 +177,10 @@ class IronicPythonAgentHeartbeater(threading.Thread):
|
|
|
174
177
|
"""Stop the heartbeat thread."""
|
|
175
178
|
LOG.info('stopping heartbeater')
|
|
176
179
|
self.stop_event.set()
|
|
177
|
-
|
|
180
|
+
# Only join if the thread was actually started
|
|
181
|
+
if self.is_alive():
|
|
182
|
+
return self.join()
|
|
183
|
+
return None
|
|
178
184
|
|
|
179
185
|
|
|
180
186
|
class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
@@ -302,19 +308,59 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
302
308
|
|
|
303
309
|
return source
|
|
304
310
|
|
|
311
|
+
def _test_ip_reachability(self, api_url):
|
|
312
|
+
"""Test if an API URL is reachable via HTTP GET request.
|
|
313
|
+
|
|
314
|
+
:param api_url: The full API URL to test (including protocol and port)
|
|
315
|
+
:returns: True if the URL is reachable, False otherwise
|
|
316
|
+
"""
|
|
317
|
+
try:
|
|
318
|
+
# Disable SSL verification for reachability testing only
|
|
319
|
+
response = requests.get(
|
|
320
|
+
api_url, timeout=CONF.http_request_timeout, verify=False
|
|
321
|
+
) # nosec
|
|
322
|
+
# Any HTTP response (even 404, 500, etc.) indicates reachability
|
|
323
|
+
LOG.debug('API URL %s is reachable (status: %s)',
|
|
324
|
+
api_url, response.status_code)
|
|
325
|
+
return True
|
|
326
|
+
except requests.exceptions.RequestException as e:
|
|
327
|
+
LOG.debug('API URL %s not reachable: %s', api_url, e)
|
|
328
|
+
return False
|
|
329
|
+
|
|
305
330
|
def _find_routable_addr(self):
|
|
331
|
+
# Process API URLs: check reachability and collect IPs in one pass
|
|
332
|
+
reachable_api_urls = []
|
|
306
333
|
ips = set()
|
|
334
|
+
|
|
307
335
|
for api_url in self.api_urls:
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
336
|
+
parsed = urlparse.urlparse(api_url)
|
|
337
|
+
ironic_host = parsed.hostname
|
|
338
|
+
|
|
339
|
+
# Test reachability using the full URL (including port)
|
|
340
|
+
if self._test_ip_reachability(api_url):
|
|
341
|
+
reachable_api_urls.append(api_url)
|
|
342
|
+
LOG.debug('API URL %s is reachable', api_url)
|
|
343
|
+
|
|
344
|
+
# Collect IPs for reachable hosts
|
|
345
|
+
try:
|
|
346
|
+
addrs = socket.getaddrinfo(ironic_host, 0)
|
|
347
|
+
ips.update(addr for _, _, _, _, (addr, *_) in addrs)
|
|
348
|
+
except socket.gaierror:
|
|
349
|
+
LOG.debug('Could not resolve %s, maybe no DNS',
|
|
350
|
+
ironic_host)
|
|
351
|
+
ips.add(ironic_host)
|
|
352
|
+
else:
|
|
353
|
+
LOG.debug('API URL %s is not reachable, skipping', api_url)
|
|
354
|
+
|
|
355
|
+
# Update api_urls configuration to only include reachable endpoints
|
|
356
|
+
if reachable_api_urls:
|
|
357
|
+
LOG.info('Filtered API URLs from %d to %d reachable endpoints',
|
|
358
|
+
len(self.api_urls), len(reachable_api_urls))
|
|
359
|
+
self.api_urls = reachable_api_urls
|
|
360
|
+
else:
|
|
361
|
+
LOG.warning('No reachable Ironic API URLs found, keeping all URLs')
|
|
317
362
|
|
|
363
|
+
# Find routable address using collected IPs
|
|
318
364
|
for attempt in range(self.ip_lookup_attempts):
|
|
319
365
|
for ironic_host in ips:
|
|
320
366
|
found_ip = self._get_route_source(ironic_host)
|
|
@@ -453,6 +499,9 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
453
499
|
|
|
454
500
|
# Update config with values from Ironic
|
|
455
501
|
config = content.get('config', {})
|
|
502
|
+
if config.get('enable_bios_bootloader_install'):
|
|
503
|
+
cfg.CONF.set_override('enable_bios_bootloader_install',
|
|
504
|
+
config['enable_bios_bootloader_install'])
|
|
456
505
|
if config.get('agent_containers'):
|
|
457
506
|
for opt, val in config['agent_containers'].items():
|
|
458
507
|
cfg.CONF.set_override(opt, val, group='container')
|
|
@@ -569,13 +618,15 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
569
618
|
# rescue operations.
|
|
570
619
|
LOG.info('Found rescue state marker file, locking down IPA '
|
|
571
620
|
'in disabled mode')
|
|
572
|
-
self.heartbeater.
|
|
621
|
+
if hasattr(self, 'heartbeater') and self.heartbeater.is_alive():
|
|
622
|
+
self.heartbeater.stop()
|
|
573
623
|
self.serve_api = False
|
|
574
624
|
while True:
|
|
575
625
|
time.sleep(100)
|
|
576
626
|
|
|
577
627
|
if not self.standalone and self.api_urls:
|
|
578
|
-
self.heartbeater.
|
|
628
|
+
if hasattr(self, 'heartbeater') and self.heartbeater.is_alive():
|
|
629
|
+
self.heartbeater.stop()
|
|
579
630
|
|
|
580
631
|
if self.lockdown:
|
|
581
632
|
self._lockdown_system()
|
ironic_python_agent/api/app.py
CHANGED
|
@@ -115,7 +115,6 @@ class Application(object):
|
|
|
115
115
|
routing.Rule('/commands/', endpoint='run_command',
|
|
116
116
|
methods=['POST']),
|
|
117
117
|
])
|
|
118
|
-
self.security_get_token_support = False
|
|
119
118
|
|
|
120
119
|
def __call__(self, environ, start_response):
|
|
121
120
|
"""WSGI entry point."""
|
|
@@ -217,13 +216,7 @@ class Application(object):
|
|
|
217
216
|
def require_agent_token_for_command(func):
|
|
218
217
|
def wrapper(self, request, *args, **kwargs):
|
|
219
218
|
token = request.args.get('agent_token', None)
|
|
220
|
-
if token:
|
|
221
|
-
# TODO(TheJulia): At some point down the road, remove the
|
|
222
|
-
# self.security_get_token_support flag and use the same
|
|
223
|
-
# decorator for the api_run_command endpoint.
|
|
224
|
-
self.security_get_token_support = True
|
|
225
|
-
if (self.security_get_token_support
|
|
226
|
-
and not self.agent.validate_agent_token(token)):
|
|
219
|
+
if not self.agent.validate_agent_token(token):
|
|
227
220
|
raise http_exc.Unauthorized('Token invalid.')
|
|
228
221
|
return func(self, request, *args, **kwargs)
|
|
229
222
|
return wrapper
|
|
@@ -245,15 +238,12 @@ class Application(object):
|
|
|
245
238
|
|
|
246
239
|
return jsonify(result)
|
|
247
240
|
|
|
241
|
+
@require_agent_token_for_command
|
|
248
242
|
def api_run_command(self, request):
|
|
249
243
|
body = request.get_json(force=True)
|
|
250
244
|
if ('name' not in body or 'params' not in body
|
|
251
245
|
or not isinstance(body['params'], dict)):
|
|
252
246
|
raise http_exc.BadRequest('Missing or invalid name or params')
|
|
253
|
-
token = request.args.get('agent_token', None)
|
|
254
|
-
if not self.agent.validate_agent_token(token):
|
|
255
|
-
raise http_exc.Unauthorized(
|
|
256
|
-
'Token invalid.')
|
|
257
247
|
with metrics_utils.get_metrics_logger(__name__).timer('run_command'):
|
|
258
248
|
result = self.agent.execute_command(body['name'], **body['params'])
|
|
259
249
|
wait = request.args.get('wait')
|
ironic_python_agent/config.py
CHANGED
|
@@ -404,6 +404,13 @@ cli_opts = [
|
|
|
404
404
|
help='This disables bootc deployment methods in the ramdisk '
|
|
405
405
|
'because the bootc command inside of the ramdisk '
|
|
406
406
|
'comes from the supplied image to be deployed.'),
|
|
407
|
+
cfg.BoolOpt('enable_bios_bootloader_install',
|
|
408
|
+
default=False,
|
|
409
|
+
help='Enables support for partition images which require a '
|
|
410
|
+
'legacy bootloader -- and a call to ``grub-install``. '
|
|
411
|
+
'Generally, this should remain disabled for maximum '
|
|
412
|
+
'security, however, this option allows it to be '
|
|
413
|
+
're-enabled for compatibility.'),
|
|
407
414
|
]
|
|
408
415
|
|
|
409
416
|
disk_utils_opts = [
|
|
@@ -191,11 +191,12 @@ def find_devices_by_hints(devices, root_device_hints):
|
|
|
191
191
|
:size: (Integer) Size of the device in *bytes*
|
|
192
192
|
:model: (String) Device model
|
|
193
193
|
:vendor: (String) Device vendor name
|
|
194
|
-
:serial: (String) Device serial number
|
|
195
|
-
:wwn: (String) Unique storage identifier
|
|
196
|
-
:wwn_with_extension: (String): Unique storage
|
|
197
|
-
the vendor extension appended
|
|
198
|
-
:wwn_vendor_extension: (String): United vendor
|
|
194
|
+
:serial: (String or List[String]) Device serial number(s)
|
|
195
|
+
:wwn: (String or List[String]) Unique storage identifier(s)
|
|
196
|
+
:wwn_with_extension: (String or List[String]): Unique storage
|
|
197
|
+
identifier(s) with the vendor extension appended
|
|
198
|
+
:wwn_vendor_extension: (String or List[String]): United vendor
|
|
199
|
+
storage identifier(s)
|
|
199
200
|
:rotational: (Boolean) Whether it's a rotational device or
|
|
200
201
|
not. Useful to distinguish HDDs (rotational) and SSDs
|
|
201
202
|
(not rotational).
|
|
@@ -221,6 +222,47 @@ def find_devices_by_hints(devices, root_device_hints):
|
|
|
221
222
|
device_value = dev.get(hint)
|
|
222
223
|
hint_value = parsed_hints[hint]
|
|
223
224
|
|
|
225
|
+
# Handle device attributes that are a list of strings
|
|
226
|
+
# (serial, wwn, wwn_with_extension, and wwn_vendor_extension).
|
|
227
|
+
if hint_type is str and isinstance(device_value, list):
|
|
228
|
+
# NOTE(mostepha): Device value is a list. Consider it matched
|
|
229
|
+
# if any value in the list matches the hint.
|
|
230
|
+
device_values = [v for v in device_value if v is not None]
|
|
231
|
+
if not device_values:
|
|
232
|
+
LOG.warning(
|
|
233
|
+
'The attribute "%(attr)s" of the device "%(dev)s" '
|
|
234
|
+
'has an empty value. Skipping device.',
|
|
235
|
+
{'attr': hint, 'dev': device_name})
|
|
236
|
+
break
|
|
237
|
+
|
|
238
|
+
matched = False
|
|
239
|
+
for val in device_values:
|
|
240
|
+
try:
|
|
241
|
+
normalized_val = _normalize_hint_expression(val, hint)
|
|
242
|
+
if specs_matcher.match(normalized_val, hint_value):
|
|
243
|
+
LOG.info('The attribute "%(attr)s" of device '
|
|
244
|
+
'"%(dev)s" matched hint %(hint)s with '
|
|
245
|
+
'value "%(value)s"',
|
|
246
|
+
{'attr': hint, 'dev': device_name,
|
|
247
|
+
'hint': hint_value, 'value': val})
|
|
248
|
+
matched = True
|
|
249
|
+
break
|
|
250
|
+
except ValueError:
|
|
251
|
+
# Skip invalid/empty values in the list
|
|
252
|
+
continue
|
|
253
|
+
|
|
254
|
+
# Continue to next hint if any value matched. Otherwise, break
|
|
255
|
+
# and try the next device.
|
|
256
|
+
if matched:
|
|
257
|
+
continue
|
|
258
|
+
else:
|
|
259
|
+
LOG.info('None of the values %(values)s for attribute '
|
|
260
|
+
'"%(attr)s" of device "%(dev)s" match the hint '
|
|
261
|
+
'%(hint)s',
|
|
262
|
+
{'values': device_values, 'attr': hint,
|
|
263
|
+
'dev': device_name, 'hint': hint_value})
|
|
264
|
+
break
|
|
265
|
+
|
|
224
266
|
if hint_type is str:
|
|
225
267
|
try:
|
|
226
268
|
device_value = _normalize_hint_expression(device_value,
|
|
@@ -286,11 +328,12 @@ def match_root_device_hints(devices, root_device_hints):
|
|
|
286
328
|
:size: (Integer) Size of the device in *bytes*
|
|
287
329
|
:model: (String) Device model
|
|
288
330
|
:vendor: (String) Device vendor name
|
|
289
|
-
:serial: (String) Device serial number
|
|
290
|
-
:wwn: (String) Unique storage identifier
|
|
291
|
-
:wwn_with_extension: (String): Unique storage
|
|
292
|
-
the vendor extension appended
|
|
293
|
-
:wwn_vendor_extension: (String): United vendor
|
|
331
|
+
:serial: (String or List[String]) Device serial number(s)
|
|
332
|
+
:wwn: (String or List[String]) Unique storage identifier(s)
|
|
333
|
+
:wwn_with_extension: (String or List[String]): Unique storage
|
|
334
|
+
identifier(s) with the vendor extension appended
|
|
335
|
+
:wwn_vendor_extension: (String or List[String]): United vendor
|
|
336
|
+
storage identifier(s)
|
|
294
337
|
:rotational: (Boolean) Whether it's a rotational device or
|
|
295
338
|
not. Useful to distinguish HDDs (rotational) and SSDs
|
|
296
339
|
(not rotational).
|
|
@@ -715,15 +715,24 @@ class ImageExtension(base.BaseAgentExtension):
|
|
|
715
715
|
' Assuming a whole disk image')
|
|
716
716
|
return
|
|
717
717
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
718
|
+
if CONF.enable_bios_bootloader_install:
|
|
719
|
+
# In case we can't use efibootmgr for uefi we will continue
|
|
720
|
+
# using grub2
|
|
721
|
+
LOG.debug('Using grub2-install to set up boot files')
|
|
722
|
+
try:
|
|
723
|
+
_install_grub2(device,
|
|
724
|
+
root_uuid=root_uuid,
|
|
725
|
+
efi_system_part_uuid=efi_system_part_uuid,
|
|
726
|
+
prep_boot_part_uuid=prep_boot_part_uuid,
|
|
727
|
+
target_boot_mode=target_boot_mode)
|
|
728
|
+
except Exception as e:
|
|
729
|
+
LOG.error('Error setting up bootloader. Error %s', e)
|
|
730
|
+
if not ignore_failure:
|
|
731
|
+
raise
|
|
732
|
+
else:
|
|
733
|
+
msg = ("Install of legacy BIOS bootloaders disabled by "
|
|
734
|
+
"CONF.enable_bios_bootloader_install as part of "
|
|
735
|
+
"CVE-2026-43003 mitigation.")
|
|
736
|
+
LOG.error(msg)
|
|
728
737
|
if not ignore_failure:
|
|
729
|
-
raise
|
|
738
|
+
raise errors.InvalidImage(details=msg)
|
|
@@ -1242,8 +1242,24 @@ class StandbyExtension(base.BaseAgentExtension):
|
|
|
1242
1242
|
# This works because the path is maintained.
|
|
1243
1243
|
container_url = url.netloc + url.path
|
|
1244
1244
|
|
|
1245
|
+
# Always pull the image in a separate step so that
|
|
1246
|
+
# ``podman run`` uses the locally cached image and does
|
|
1247
|
+
# not need an ``--authfile`` flag. When a pull secret is
|
|
1248
|
+
# present the auth file is written to a temporary path,
|
|
1249
|
+
# passed to ``podman pull``, and then deleted before any
|
|
1250
|
+
# tenant-controlled container code can run. This prevents
|
|
1251
|
+
# the tenant bootc image from reading the credential via
|
|
1252
|
+
# /proc/1/root/<path> when running with --pid=host.
|
|
1253
|
+
# This fixes the security issue tracked by:
|
|
1254
|
+
# https://bugs.launchpad.net/ironic/+bug/2155826
|
|
1245
1255
|
if pull_secret:
|
|
1246
|
-
self._write_container_auth(pull_secret, url.netloc)
|
|
1256
|
+
auth_path = self._write_container_auth(pull_secret, url.netloc)
|
|
1257
|
+
try:
|
|
1258
|
+
self._pull_container_image(container_url, auth_path)
|
|
1259
|
+
finally:
|
|
1260
|
+
self._cleanup_container_auth(auth_path)
|
|
1261
|
+
else:
|
|
1262
|
+
self._pull_container_image(container_url)
|
|
1247
1263
|
|
|
1248
1264
|
# Get the disk size, and convert it to megabtyes.
|
|
1249
1265
|
disk_size = disk_utils.get_dev_byte_size(device) // 1024 // 1024
|
|
@@ -1279,20 +1295,19 @@ class StandbyExtension(base.BaseAgentExtension):
|
|
|
1279
1295
|
# but that is not the best idea.
|
|
1280
1296
|
# --disable-selinux is alternatively needed if selinux is *not*
|
|
1281
1297
|
# enabled on the host.
|
|
1298
|
+
#
|
|
1299
|
+
# NOTE: The image has already been pulled above (with auth if
|
|
1300
|
+
# needed), so we intentionally do NOT pass --authfile here.
|
|
1301
|
+
# This prevents tenant-controlled code in the bootc image
|
|
1302
|
+
# from accessing registry credentials via /proc/1/root.
|
|
1282
1303
|
command = [
|
|
1283
1304
|
'podman',
|
|
1284
1305
|
'--log-level=debug',
|
|
1285
1306
|
'run', '--rm', '--privileged', '--pid=host',
|
|
1307
|
+
'--pull=never',
|
|
1286
1308
|
'-v', '/var/lib/containers:/var/lib/containers',
|
|
1287
1309
|
'-v', '/dev:/dev',
|
|
1288
|
-
# By default, podman's retry starts at 3s and extends
|
|
1289
|
-
# expentionally, which can lead to podman appearing
|
|
1290
|
-
# to hang when downloading. This pins it so it just
|
|
1291
|
-
# retires in relatively short order.
|
|
1292
|
-
'--retry-delay=5s',
|
|
1293
1310
|
]
|
|
1294
|
-
if pull_secret:
|
|
1295
|
-
command.append('--authfile=/root/.config/containers/auth.json')
|
|
1296
1311
|
if authorized_keys:
|
|
1297
1312
|
# NOTE(TheJulia): Bandit flags on this, but we need a folder which
|
|
1298
1313
|
# should exist in the container *and* locally to the ramdisk.
|
|
@@ -1352,6 +1367,58 @@ class StandbyExtension(base.BaseAgentExtension):
|
|
|
1352
1367
|
with open(file_path, 'w') as file:
|
|
1353
1368
|
file.write(file_content)
|
|
1354
1369
|
|
|
1370
|
+
def _pull_container_image(self, container_url, auth_path=None):
|
|
1371
|
+
"""Pre-pull a container image into the local podman store.
|
|
1372
|
+
|
|
1373
|
+
Pulls the image so that a subsequent ``podman run`` can use
|
|
1374
|
+
the locally cached image without needing an ``--authfile``
|
|
1375
|
+
flag, keeping registry credentials out of the tenant-visible
|
|
1376
|
+
host filesystem during container execution.
|
|
1377
|
+
|
|
1378
|
+
:param container_url: The container image URL to pull.
|
|
1379
|
+
:param auth_path: Optional path to an authentication JSON
|
|
1380
|
+
file. When provided, ``--authfile`` is passed to podman.
|
|
1381
|
+
:raises: ImageDownloadError if the pull fails.
|
|
1382
|
+
"""
|
|
1383
|
+
pull_command = [
|
|
1384
|
+
'podman', 'pull',
|
|
1385
|
+
]
|
|
1386
|
+
if auth_path:
|
|
1387
|
+
pull_command.append('--authfile=' + auth_path)
|
|
1388
|
+
pull_command.extend([
|
|
1389
|
+
'--retry-delay=5s',
|
|
1390
|
+
container_url,
|
|
1391
|
+
])
|
|
1392
|
+
try:
|
|
1393
|
+
utils.execute(*pull_command, use_standard_locale=True)
|
|
1394
|
+
except processutils.ProcessExecutionError as e:
|
|
1395
|
+
LOG.debug('Failed to pull container image %s: %s',
|
|
1396
|
+
container_url, e)
|
|
1397
|
+
raise errors.ImageDownloadError(
|
|
1398
|
+
container_url,
|
|
1399
|
+
"Failed to pull container image: %s" % e)
|
|
1400
|
+
|
|
1401
|
+
def _cleanup_container_auth(self, auth_path):
|
|
1402
|
+
"""Remove the container registry authentication file.
|
|
1403
|
+
|
|
1404
|
+
Ensures that the pull secret is not present on the host
|
|
1405
|
+
filesystem when tenant-controlled container code runs.
|
|
1406
|
+
|
|
1407
|
+
:param auth_path: Path to the authentication JSON file to remove.
|
|
1408
|
+
"""
|
|
1409
|
+
try:
|
|
1410
|
+
os.remove(auth_path)
|
|
1411
|
+
LOG.debug('Removed container auth file %s', auth_path)
|
|
1412
|
+
except OSError as e:
|
|
1413
|
+
LOG.warning('Failed to remove container auth file %s: %s',
|
|
1414
|
+
auth_path, e)
|
|
1415
|
+
# Also try to remove the parent directory if it is empty,
|
|
1416
|
+
# to avoid leaving a trace of the credential path.
|
|
1417
|
+
try:
|
|
1418
|
+
os.rmdir(os.path.dirname(auth_path))
|
|
1419
|
+
except OSError:
|
|
1420
|
+
pass
|
|
1421
|
+
|
|
1355
1422
|
def _write_container_auth(self, pull_secret, netloc):
|
|
1356
1423
|
"""Write authentication configuration for container registry auth.
|
|
1357
1424
|
|
|
@@ -1359,6 +1426,7 @@ class StandbyExtension(base.BaseAgentExtension):
|
|
|
1359
1426
|
interacting with a remote container registry.
|
|
1360
1427
|
:param netloc: The FQDN, or network location portion of the URL
|
|
1361
1428
|
used to access the container registry.
|
|
1429
|
+
:returns: The path to the written authentication file.
|
|
1362
1430
|
"""
|
|
1363
1431
|
# extract secret
|
|
1364
1432
|
decoded_pull_secret = base64.standard_b64decode(
|
|
@@ -1370,19 +1438,20 @@ class StandbyExtension(base.BaseAgentExtension):
|
|
|
1370
1438
|
auth_dict = {
|
|
1371
1439
|
"auths": {netloc: {"auth": decoded_pull_secret}}}
|
|
1372
1440
|
|
|
1373
|
-
#
|
|
1374
|
-
#
|
|
1375
|
-
#
|
|
1376
|
-
#
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1441
|
+
# Write auth to a temporary file rather than a well-known
|
|
1442
|
+
# path such as $HOME/.config/containers/auth.json. Using a
|
|
1443
|
+
# temporary path provides defense-in-depth: even if cleanup
|
|
1444
|
+
# fails, the credential is not at a predictable location.
|
|
1445
|
+
fd, auth_path = tempfile.mkstemp(suffix='.json',
|
|
1446
|
+
prefix='ipa-container-auth-')
|
|
1447
|
+
try:
|
|
1448
|
+
with os.fdopen(fd, 'w') as file:
|
|
1449
|
+
json.dump(auth_dict, file)
|
|
1450
|
+
except Exception:
|
|
1451
|
+
os.close(fd)
|
|
1452
|
+
raise
|
|
1453
|
+
|
|
1454
|
+
return auth_path
|
|
1386
1455
|
|
|
1387
1456
|
def _write_authorized_keys(self, authorized_keys):
|
|
1388
1457
|
"""Write a temporary authorized keys file for bootc use."""
|