fix(STRA-101): support Python 3.11 CUDA bootstrap

This commit is contained in:
Pavlo Ratushnyi
2026-10-07 17:12:25 +02:00
parent 8ec9ab5bce
commit 712de0f6bc
4 changed files with 136 additions and 8 deletions
+18 -1
View File
@@ -39,8 +39,25 @@ jobs:
- name: Local checks
run: scripts/check-local.sh
keyless-cuda-gate:
if: gitea.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
outputs:
enabled: ${{ steps.select.outputs.enabled }}
steps:
- id: select
env:
KEYLESS_GPU: ${{ gitea.event.inputs.keyless_gpu }}
run: |
case "${KEYLESS_GPU:-false}" in
true) echo 'enabled=true' >> "$GITHUB_OUTPUT" ;;
false|'') echo 'enabled=false' >> "$GITHUB_OUTPUT" ;;
*) echo 'keyless_gpu must be a boolean input' >&2; exit 2 ;;
esac
keyless-cuda:
if: gitea.event_name == 'workflow_dispatch' && gitea.event.inputs.keyless_gpu == 'true'
needs: [verify, keyless-cuda-gate]
if: needs.keyless-cuda-gate.outputs.enabled == 'true'
runs-on: [self-hosted, linux, x64, strata-gpu]
steps:
- uses: actions/checkout@v4
+18
View File
@@ -1,5 +1,23 @@
# Build validation
## 2026-10-07 — Gitea Python 3.11 archive validation
- Exact-head Gitea run `2700` (`8ec9ab5bce6442acf3629b3b03967cdc42311918`) ran in
`node:24-bookworm` / Debian 12 with Python `3.11.2`. `verify` exposed that
`tarfile.extractall(filter="data")` requires Python 3.12; the CUDA bootstrap
now validates member paths, link containment, topology, types, and modes before
using the Python 3.11-compatible standard-library extractor. No PyPI packages
are added for this script.
- The focused archive suite passed on the same `node:24-bookworm` image. It covers
valid file/symlink/hardlink trees, traversal and link-parent attacks, privileged
mode rejection, conflicting merges, download integrity, and lock validation.
- The manual keyless-GPU path is now preceded by a CPU-side input gate and depends
on `verify`; a false selection must be resolved as skipped before any GPU runner
is eligible. This gate does not execute GPU checks or imply GPU availability.
- Run `2700` itself remains a failed historical run, and its unmatched keyless
job is still queued; this change is not validated until one exact-head Gitea
run proves the keyless job skipped and the hosted PLE package completes.
## 2026-10-03 — experimental PLE quality arm
The imported engine builds on Linux CUDA 13.2/sm_120 with the optional
+71 -7
View File
@@ -5,12 +5,14 @@ No driver installation, model access, root privileges or inference. NVIDIA's
redistrib archives are assembly inputs, not a general-purpose CUDA installer.
"""
import argparse
import copy
import hashlib
import json
import os
from pathlib import Path, PurePosixPath
import platform
import shutil
import stat
import tarfile
import tempfile
import time
@@ -54,21 +56,83 @@ def validate_lock(lock, manifest):
def extract(archive, destination, root_name):
if not root_name or '/' in root_name or '\\' in root_name or root_name in ('.','..'):
raise ValueError('invalid component root')
with tarfile.open(archive, 'r:xz') as source:
members=source.getmembers()
if len(members)>50000 or sum(x.size for x in members)>6*1024**3:
if len(members)>50000 or any(x.size<0 for x in members) or sum(x.size for x in members)>6*1024**3:
raise ValueError('archive expansion limit exceeded')
seen=set()
seen={}
for item in members:
path=PurePosixPath(item.name)
if path.is_absolute() or '..' in path.parts or not path.parts or path.parts[0]!=root_name:
raw_name=item.name
if not raw_name or '\x00' in raw_name or '\\' in raw_name or raw_name.startswith('/'):
raise ValueError('archive path outside component root')
if item.name in seen:
parts=raw_name.split('/')
if parts[-1]=='' and item.isdir():parts.pop()
if not parts or any(part in ('','.','..') for part in parts) or parts[0]!=root_name:
raise ValueError('archive path outside component root')
name='/'.join(parts)
if name in seen:
raise ValueError('duplicate archive member')
seen.add(item.name)
if name==root_name and not item.isdir():
raise ValueError('component root is not a directory')
if not (item.isdir() or item.isfile() or item.issym() or item.islnk()):
raise ValueError('unsupported archive member')
source.extractall(destination, members=members, filter='data')
if item.mode & (stat.S_ISUID|stat.S_ISGID|stat.S_ISVTX):
raise ValueError('archive member has privileged mode bits')
clone=copy.copy(item);clone.name=name
if item.issym() or item.islnk():
link=item.linkname
if not link or '\x00' in link or '\\' in link or link.startswith('/'):
raise ValueError('archive link outside component root')
target=list(parts[:-1] if item.issym() else [])
for part in link.split('/'):
if part in ('','.'):continue
if part=='..':
if len(target)<=1:raise ValueError('archive link outside component root')
target.pop()
else:target.append(part)
if not target or target[0]!=root_name:
raise ValueError('archive link outside component root')
if item.islnk():clone.linkname='/'.join(target)
if item.isdir():
clone.mode=(item.mode & 0o755)|0o700
elif item.isfile():
clone.mode=(item.mode & 0o755)|0o600
if item.mode & 0o111:clone.mode|=0o100
# Never apply archive ownership. Numeric IDs are the builder's own
# identity; tarfile 3.11's root-only chown path therefore stays put.
clone.uid=os.geteuid();clone.gid=os.getegid();clone.uname=clone.gname=''
seen[name]=(item,clone)
for name,(item,_) in seen.items():
parts=name.split('/')
for depth in range(1,len(parts)):
parent='/'.join(parts[:depth])
if parent in seen and not seen[parent][0].isdir():
raise ValueError('archive member is nested under a non-directory')
if item.islnk():
target=item.linkname
if target not in seen or not (seen[target][0].isfile() or seen[target][0].islnk()):
raise ValueError('archive hard link target is missing or unsupported')
# Python 3.11 (Debian Bookworm) lacks tarfile's `filter=` argument.
# Every member is normalized and validated above before the legacy
# extractor sees it; links are constrained to the private component tree.
destination.mkdir(mode=0o700,parents=True,exist_ok=True)
if os.path.lexists(destination/root_name):raise ValueError('component root already exists')
(destination/root_name).mkdir(mode=0o700)
dirs=sorted((v[1] for v in seen.values() if v[0].isdir()),key=lambda x:(x.name.count('/'),x.name))
files=sorted((v[1] for v in seen.values() if v[0].isfile()),key=lambda x:x.name)
symlinks=sorted((v[1] for v in seen.values() if v[0].issym()),key=lambda x:x.name)
hardlinks={name:clone for name,(item,clone) in seen.items() if item.islnk()}
ordered_hardlinks=[];visiting=set();emitted=set()
def emit_hardlink(name):
if name in emitted:return
if name in visiting:raise ValueError('archive hard link cycle')
visiting.add(name);target=hardlinks[name].linkname
if target in hardlinks:emit_hardlink(target)
visiting.remove(name);emitted.add(name);ordered_hardlinks.append(hardlinks[name])
for name in sorted(hardlinks):emit_hardlink(name)
source.extractall(destination,members=dirs+files+ordered_hardlinks+symlinks,numeric_owner=True)
return destination/root_name
+29
View File
@@ -20,6 +20,16 @@ class Tests(unittest.TestCase):
item=tarfile.TarInfo('component/lib/b');item.type=tarfile.SYMTYPE;item.linkname='a';t.addfile(item)
out=m.extract(archive,root/'out','component')
self.assertEqual((out/'lib/b').read_bytes(),b'a')
def test_safe_hardlink_and_archive_permissions(self):
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp);archive=root/'test.tar.xz'
with tarfile.open(archive,'w:xz') as t:
item=tarfile.TarInfo('component/lib/a');item.size=1;item.mode=0o777;t.addfile(item,io.BytesIO(b'a'))
item=tarfile.TarInfo('component/lib/b');item.type=tarfile.LNKTYPE;item.linkname='component/lib/a';t.addfile(item)
out=m.extract(archive,root/'out','component')
self.assertEqual((out/'lib/b').read_bytes(),b'a')
self.assertFalse((out/'lib/a').stat().st_mode & 0o7000)
self.assertFalse((out/'lib/a').stat().st_mode & 0o022)
def test_bad_archive_paths_and_links(self):
for name,link in [('../escape',None),('/escape',None),('other/file',None),('component/b','../../escape')]:
with self.subTest(name=name),tempfile.TemporaryDirectory() as tmp:
@@ -30,6 +40,25 @@ class Tests(unittest.TestCase):
t.addfile(item)
with self.assertRaises((ValueError,tarfile.TarError)):m.extract(archive,root/'out','component')
self.assertFalse((root/'escape').exists())
def test_reject_link_ancestor_and_hardlink_escape(self):
for entries in [
[('component/link',tarfile.SYMTYPE,'lib'),('component/link/escape',tarfile.REGTYPE,'')],
[('component/file',tarfile.LNKTYPE,'../../escape')],
]:
with self.subTest(entries=entries),tempfile.TemporaryDirectory() as tmp:
root=Path(tmp);archive=root/'test.tar.xz'
with tarfile.open(archive,'w:xz') as t:
for name,kind,link in entries:
item=tarfile.TarInfo(name);item.type=kind
if kind==tarfile.REGTYPE:item.size=1;t.addfile(item,io.BytesIO(b'x'))
else:item.linkname=link;t.addfile(item)
with self.assertRaises(ValueError):m.extract(archive,root/'out','component')
def test_reject_privileged_modes(self):
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp);archive=root/'test.tar.xz'
with tarfile.open(archive,'w:xz') as t:
item=tarfile.TarInfo('component/file');item.size=1;item.mode=0o4755;t.addfile(item,io.BytesIO(b'x'))
with self.assertRaises(ValueError):m.extract(archive,root/'out','component')
def test_component_merge_rejects_conflict(self):
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp);a=root/'a';b=root/'b';a.mkdir();b.mkdir()