fix: seed CA trust for pinned CUDA Docker build
Linux / verify (pull_request) Successful in 2m6s
Linux / keyless-cuda (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-cli-container (pull_request) Successful in 16s
Linux / linux-static-cli (pull_request) Successful in 7m5s
Linux / release-cli (pull_request) Skipped
Linux / verify (pull_request) Successful in 2m6s
Linux / keyless-cuda (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-cli-container (pull_request) Successful in 16s
Linux / linux-static-cli (pull_request) Successful in 7m5s
Linux / release-cli (pull_request) Skipped
This commit is contained in:
@@ -2,6 +2,10 @@ FROM --platform=linux/amd64 ubuntu:24.04@sha256:f610ab94648195aa356059f5b41d6085
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# The minimal pinned Ubuntu base has no CA store. Seed it from the trusted
|
||||
# Linux CI runner so HTTPS verification works before apt installs ca-certificates.
|
||||
COPY runner-ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
# Freeze Ubuntu's package view as well as the base-image digest. CUDA itself is
|
||||
# supplied separately by the checksum-pinned redistributable bundle.
|
||||
RUN rm -f /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list && \
|
||||
|
||||
@@ -9,6 +9,7 @@ from pathlib import Path
|
||||
from pathlib import PurePosixPath
|
||||
import re
|
||||
import shutil
|
||||
import ssl
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
@@ -144,6 +145,23 @@ def capture(command):
|
||||
return subprocess.check_output([str(arg) for arg in command], text=True).strip()
|
||||
|
||||
|
||||
def runner_ca_bundle():
|
||||
"""Return the runner's CA bundle for bootstrapping HTTPS in the base image."""
|
||||
cafile = ssl.get_default_verify_paths().cafile
|
||||
if not cafile:
|
||||
raise ValueError('Linux runner has no default CA bundle path')
|
||||
try:
|
||||
path = Path(cafile).resolve(strict=True)
|
||||
except OSError as error:
|
||||
raise ValueError('Linux runner CA bundle is missing or unreadable') from error
|
||||
if not path.is_file():
|
||||
raise ValueError('Linux runner CA bundle is not a regular file')
|
||||
contents = path.read_bytes()
|
||||
if not contents or b'-----BEGIN CERTIFICATE-----' not in contents:
|
||||
raise ValueError('Linux runner CA bundle is empty or invalid')
|
||||
return contents
|
||||
|
||||
|
||||
def build(args):
|
||||
docker = shutil.which(args.docker) if '/' not in args.docker else args.docker
|
||||
if not docker:
|
||||
@@ -186,11 +204,14 @@ def build(args):
|
||||
try:
|
||||
source.mkdir(mode=0o700)
|
||||
source_commit, source_archive_sha256 = stage_tracked_source(source)
|
||||
ca_bundle = runner_ca_bundle()
|
||||
ca_bundle_sha256 = hashlib.sha256(ca_bundle).hexdigest()
|
||||
with tempfile.TemporaryDirectory(prefix='leleka-cuda-docker-context-') as context_name:
|
||||
context = Path(context_name)
|
||||
image_context = context / 'image'
|
||||
image_context.mkdir()
|
||||
shutil.copyfile(DOCKERFILE, image_context / 'Dockerfile')
|
||||
(image_context / 'runner-ca-certificates.crt').write_bytes(ca_bundle)
|
||||
run([docker, 'build', '--platform', PLATFORM, '--pull', '--file', image_context / 'Dockerfile',
|
||||
'--label', f'leleka.cuda-builder.run={args.image_tag}', '--tag', tag, image_context])
|
||||
image_built = True
|
||||
@@ -246,7 +267,8 @@ def build(args):
|
||||
if any(container_metadata.get(key) != value for key, value in expected.items()):
|
||||
raise ValueError('container toolchain metadata violates CPU-only builder policy')
|
||||
metadata = {'schema_version': 1, **container_metadata, 'source_commit': source_commit,
|
||||
'source_archive_sha256': source_archive_sha256, 'builder_image_id': image_id,
|
||||
'source_archive_sha256': source_archive_sha256,
|
||||
'runner_ca_bundle_sha256': ca_bundle_sha256, 'builder_image_id': image_id,
|
||||
'engine_sha256': digest(engine_output), 'engine_bytes': engine_output.stat().st_size,
|
||||
'gpu_tested': False, 'model_tested': False,
|
||||
'qualification': 'CUDA compilation, ELF dependency audit and GPU-hidden --help only.'}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
"""CPU-only contract tests for the Docker CUDA builder wrapper."""
|
||||
import importlib.util
|
||||
import hashlib
|
||||
from io import BytesIO
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
from types import SimpleNamespace
|
||||
import tempfile
|
||||
import tarfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
MODULE = Path(__file__).with_name('build-cuda-engine-in-docker.py')
|
||||
spec = importlib.util.spec_from_file_location('cuda_docker_builder', MODULE)
|
||||
@@ -33,8 +36,12 @@ class Tests(unittest.TestCase):
|
||||
'scripts/build-static-cuda.sh', 'scripts/check-static-cuda-elf.py'], check=True)
|
||||
subprocess.run(['git', '-C', str(self.source_repo), 'commit', '-qm', 'fixture'], check=True)
|
||||
(self.source_repo / '.env').write_text('must not be staged', encoding='utf-8')
|
||||
self.original_runner_ca_bundle = builder.runner_ca_bundle
|
||||
self.original_repo = builder.REPO
|
||||
self.original_dockerfile = builder.DOCKERFILE
|
||||
self.ca_bundle = b'-----BEGIN CERTIFICATE-----\nfixture\n-----END CERTIFICATE-----\n'
|
||||
self.ca_patch = patch.object(builder, 'runner_ca_bundle', return_value=self.ca_bundle)
|
||||
self.ca_patch.start()
|
||||
builder.REPO = self.source_repo.resolve()
|
||||
builder.DOCKERFILE = self.source_repo / 'deploy/Dockerfile.cuda-builder'
|
||||
self.toolkit = self.root / 'toolkit'
|
||||
@@ -50,7 +57,10 @@ args=sys.argv[1:]
|
||||
with open(__LOG_PATH__, 'a') as f: f.write(json.dumps(args)+'\n')
|
||||
if args[0] == 'build':
|
||||
dockerfile=pathlib.Path(args[args.index('--file')+1]).read_text()
|
||||
context=pathlib.Path(args[-1])
|
||||
assert 'ubuntu:24.04@sha256:f610ab94648195aa356059f5b41d6085c9d4d903c072430cdd1af7bdb646106b' in dockerfile
|
||||
assert (context/'runner-ca-certificates.crt').is_file()
|
||||
assert 'COPY runner-ca-certificates.crt /etc/ssl/certs/ca-certificates.crt' in dockerfile
|
||||
elif args[:2] == ['image','inspect']:
|
||||
print('sha256:' + 'a'*64)
|
||||
elif args[:2] == ['volume','create']:
|
||||
@@ -93,6 +103,7 @@ else:
|
||||
self.fake_docker.chmod(0o755)
|
||||
|
||||
def tearDown(self):
|
||||
self.ca_patch.stop()
|
||||
builder.REPO = self.original_repo
|
||||
builder.DOCKERFILE = self.original_dockerfile
|
||||
self.temp.cleanup()
|
||||
@@ -110,6 +121,22 @@ else:
|
||||
def docker_calls(self):
|
||||
return [json.loads(line) for line in self.log.read_text().splitlines()]
|
||||
|
||||
def test_runner_ca_bundle_resolves_a_default_symlink(self):
|
||||
pem = self.root / 'runner-ca.pem'
|
||||
pem.write_bytes(self.ca_bundle)
|
||||
link = self.root / 'runner-ca-link.pem'
|
||||
link.symlink_to(pem)
|
||||
with patch.object(builder.ssl, 'get_default_verify_paths',
|
||||
return_value=SimpleNamespace(cafile=str(link))):
|
||||
self.assertEqual(self.original_runner_ca_bundle(), self.ca_bundle)
|
||||
|
||||
def test_runner_ca_bundle_rejects_missing_path(self):
|
||||
missing = self.root / 'missing-ca.pem'
|
||||
with patch.object(builder.ssl, 'get_default_verify_paths',
|
||||
return_value=SimpleNamespace(cafile=str(missing))):
|
||||
with self.assertRaisesRegex(ValueError, 'missing or unreadable'):
|
||||
self.original_runner_ca_bundle()
|
||||
|
||||
def test_container_build_has_pinned_cpu_only_invocation(self):
|
||||
result = builder.build(self.arguments())
|
||||
self.assertEqual(result['builder_base'], builder.BASE)
|
||||
@@ -126,6 +153,7 @@ else:
|
||||
self.assertIn(['rm', '--force', 'b'*64], calls)
|
||||
self.assertTrue(any(call[:2] == ['volume', 'rm'] for call in calls))
|
||||
self.assertEqual(calls[-1][:2], ['image','rm'])
|
||||
self.assertEqual(result['runner_ca_bundle_sha256'], hashlib.sha256(self.ca_bundle).hexdigest())
|
||||
subprocess.run(['bash','-n','-c',builder.CONTAINER_BUILD], check=True)
|
||||
|
||||
def test_owned_docker_resources_are_removed_when_build_fails(self):
|
||||
|
||||
Reference in New Issue
Block a user