Repository navigation
Approve exact 4.17.0 packaged lifecycle acceptance - #269
Conversation
|
The same-package logging consumer compiled offline with Cargo 1.86. It binds all 118 installed crate members, crates.io lock checksum, exact reviewed test SHA This is the concrete manual candidate invocation for source review before runtime, not a reusable-driver or published result. It captures and hashes parent bytes, seals a Linux memfd against writes/growth/shrink, then executes that descriptor; #267's The script takes only the prepared consumer root and accepted source checkout as path arguments. Those paths are local invocation details. The complete source below has SHA256 """One fixed candidate observation; public review packet contains these bytes."""
import base64
import fcntl
import hashlib
import json
import os
import pathlib
import resource
import secrets
import signal
import stat
import subprocess
import sys
import time
import urllib.error
import urllib.request
ROOT = pathlib.Path(sys.argv[1]).resolve()
SOURCE = pathlib.Path(sys.argv[2]).resolve()
IMAGE = 'ghcr.io/durable-workflow/server@sha256:9d64e9aeee84b46d21715826a3e7e5a96eb8d4ce7fccb126b88b15596ab14973'
REVISION = 'b6e04ce7e679464e91f6ceae83310d3bb3204092'
RECEIPT = '6f197812e8218fc44d513bfa1040b91b19fe168367c70e53e16882b0db13fe79'
BINARY = '89ae4f0fdea91e503d8b7e80426e7160259e324520341b2f325d7aed5edfb8b1'
TEST = '6d7b08d138fc13f9b513ce80c51a40fbec85beeb015e3a631598e7f8cdce4398'
def call(args, **kwargs):
return subprocess.run(args, capture_output=True, check=True, timeout=30, **kwargs)
def digest(data):
return hashlib.sha256(data).hexdigest()
receipt_bytes = (ROOT / 'build-receipt.json').read_bytes()
assert digest(receipt_bytes) == RECEIPT
receipt = json.loads(receipt_bytes)
assert receipt['executable_sha256'] == BINARY
assert digest((ROOT / 'fixture/tests/workflow_logging_server.rs').read_bytes()) == TEST
assert digest((ROOT / 'fixture/Cargo.lock').read_bytes()) == receipt['lock_sha256']
assert digest((ROOT / 'fixture/Cargo.toml').read_bytes()) == receipt['manifest_sha256']
assert digest((ROOT / 'fixture/logging-build.jsonl').read_bytes()) == receipt['build_messages_sha256']
binary = ROOT / receipt['executable_relative']
fd = os.open(binary, os.O_RDONLY | os.O_NOFOLLOW)
info = os.fstat(fd)
assert stat.S_ISREG(info.st_mode) and info.st_nlink == 1
binary_bytes = os.pread(fd, info.st_size + 1, 0)
assert len(binary_bytes) == info.st_size == receipt['executable_bytes']
assert digest(binary_bytes) == BINARY
os.close(fd)
fd = os.memfd_create('reviewed-logging-parent', os.MFD_ALLOW_SEALING)
with os.fdopen(os.dup(fd), 'wb') as image_file:
image_file.write(binary_bytes)
os.fchmod(fd, 0o500)
seals = fcntl.F_SEAL_WRITE | fcntl.F_SEAL_GROW | fcntl.F_SEAL_SHRINK | fcntl.F_SEAL_SEAL
fcntl.fcntl(fd, fcntl.F_ADD_SEALS, seals)
assert fcntl.fcntl(fd, fcntl.F_GET_SEALS) == seals
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
supervisor = SOURCE / 'scripts/acceptance/installed-native/cell-supervisor.sh'
assert supervisor.read_bytes() == call(['git', '-C', str(SOURCE), 'show',
'52208134296009bbae1af316c8efac89d3465990:scripts/acceptance/installed-native/cell-supervisor.sh']).stdout
image = json.loads(call(['docker', 'image', 'inspect', IMAGE]).stdout)[0]
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert image['Config']['Labels']['org.opencontainers.image.revision'] == REVISION
assert image['Config']['Labels']['dev.durable-workflow.release.tag'] == '3.10.0'
assert image['Config']['Entrypoint'] == ['/usr/local/bin/durable-workflow-server']
nonce = secrets.token_hex(16)
name = 'sdk-rust-417-logging-' + nonce[:12]
labels = {'owner': 'sdk-rust', 'task': 'logger227', 'qualification_nonce': nonce}
label_args = [argument for key, value in labels.items() for argument in ('--label', key + '=' + value)]
token = 'fixture-' + secrets.token_hex(24)
key = 'base64:' + base64.b64encode(secrets.token_bytes(32)).decode()
container_id = network_id = None
process = None
result = {'outcome': 'fail', 'build_receipt_sha256': RECEIPT,
'binary_sha256': BINARY, 'server_manifest': IMAGE, 'server_source': REVISION,
'started_at': time.time(), 'limits': {'consumer_cpus': 2, 'consumer_as': 2147483648,
'consumer_cpu_seconds': 60, 'consumer_wall_seconds': 180}}
def owned(kind, identity):
value = json.loads(call(['docker', kind, 'inspect', identity]).stdout)[0]
actual = value['Config']['Labels'] if kind == 'container' else value['Labels']
assert value['Id'] == identity and all(actual.get(k) == v for k, v in labels.items())
return value
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args):
raise AssertionError('redirect refused')
def consumer_limits():
os.sched_setaffinity(0, sorted(os.sched_getaffinity(0))[:2])
resource.setrlimit(resource.RLIMIT_AS, (2 * 1024**3, 2 * 1024**3))
resource.setrlimit(resource.RLIMIT_CPU, (60, 60))
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
try:
network_id = call(['docker', 'network', 'create', '--internal'] + label_args + [name]).stdout.decode().strip()
owned('network', network_id)
deadline = str(int(time.time()) + 240)
container_id = call(['docker', 'create', '--init', '--name', name] + label_args + [
'--cpus', '1', '--memory', '1g', '--pids-limit', '256', '--read-only', '--user', '1000:1000',
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--network', network_id,
'--publish', '127.0.0.1::8080', '--tmpfs', '/tmp:mode=1777,size=64m',
'--tmpfs', '/app/database:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/app/storage:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/credentials:uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev',
'--env', 'DB_CONNECTION=sqlite', '--env', 'DB_DATABASE=/app/database/runtime.sqlite',
'--env', 'DW_RUST_MAINTENANCE_LOOP=1', '--entrypoint', '/bin/sh',
'--mount', 'type=bind,src=' + str(supervisor) + ',dst=/harness/cell-supervisor.sh,readonly',
IMAGE, '/harness/cell-supervisor.sh', deadline, '10', 'both', '/usr/local/bin/durable-workflow-server']).stdout.decode().strip()
before = owned('container', container_id)
result['container_id'], result['network_id'] = container_id, network_id
host = before['HostConfig']
assert host['ReadonlyRootfs'] and host['Init'] and host['Memory'] == 1024**3
assert host['NanoCpus'] == 10**9 and host['PidsLimit'] == 256
call(['docker', 'start', container_id])
owned('container', container_id)
call(['docker', 'exec', '-i', container_id, '/bin/sh', '-c',
'umask 077; IFS= read -r token && IFS= read -r key && '
'printf %s "$token" > /credentials/token && printf %s "$key" > /credentials/server-key && '
': > /credentials/ready.tmp && mv /credentials/ready.tmp /credentials/ready'],
input=(token + '\n' + key + '\n').encode())
live = owned('container', container_id)
ports = live['NetworkSettings']['Ports']['8080/tcp']
assert len(ports) == 1 and ports[0]['HostIp'] == '127.0.0.1'
port = int(ports[0]['HostPort'])
assert 0 < port < 65536
origin = 'http://127.0.0.1:' + str(port)
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
for attempt in range(60):
try:
request = urllib.request.Request(origin + '/api/cluster/info',
headers={'Authorization': 'Bearer ' + token, 'X-Namespace': 'default'})
with opener.open(request, timeout=1) as response:
cluster = json.load(response)
assert cluster['version'] == '3.10.0'
result['cluster_info'] = cluster
break
except (urllib.error.URLError, ConnectionError):
time.sleep(.25)
else:
raise AssertionError('runtime readiness bound expired')
args = ['/proc/self/fd/' + str(fd), '--ignored', '--exact',
'published_logging_emits_once_per_committed_step_across_cold_worker_processes',
'--nocapture', '--test-threads=1']
env = {'DURABLE_WORKFLOW_LOCAL_ISOLATED': '1', 'DURABLE_WORKFLOW_SERVER_URL': origin,
'DURABLE_WORKFLOW_AUTH_TOKEN': token, 'DURABLE_WORKFLOW_EXPECT_SERVER_VERSION': '3.10.0'}
process = subprocess.Popen(args, env=env, pass_fds=(fd,), start_new_session=True,
preexec_fn=consumer_limits, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate(timeout=180)
assert len(stdout) + len(stderr) <= 1024**2
assert all(secret.encode() not in stdout + stderr for secret in (token, key))
(ROOT / 'logging.stdout').write_bytes(stdout)
(ROOT / 'logging.stderr').write_bytes(stderr)
result['parent_pid'], result['exit_code'] = process.pid, process.returncode
assert process.returncode == 0, 'logging parent failed'
assert b'PASS: four cold worker processes' in stdout
assert digest(os.pread(fd, info.st_size + 1, 0)) == BINARY
result['outcome'] = 'pass'
finally:
if process is not None:
try:
os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:
pass
process.wait(timeout=10)
os.close(fd)
errors = []
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity:
try:
value = owned(kind, identity)
if kind == 'container':
result['runtime_oom'] = value['State']['OOMKilled']
if result['runtime_oom']:
result['outcome'] = 'fail'
call(['docker', 'rm', '-f', '-v', identity] if kind == 'container'
else ['docker', 'network', 'rm', identity])
observed = subprocess.run(['docker', kind, 'inspect', identity], capture_output=True)
assert observed.returncode != 0 and b'no such' in observed.stderr.lower()
except Exception as error:
errors.append(type(error).__name__)
result['cleanup'] = {'pass': not errors, 'errors': errors}
if errors:
result['outcome'] = 'fail'
result['finished_at'] = time.time()
(ROOT / 'logging-result.json').write_text(json.dumps(result, indent=2) + '\n')
assert not errors, errors
print(json.dumps(result)) |
|
Security exact-record review: PASS, limited to the two generated approval artifacts at Independent checks:
This clears only the exact generated record/summary binding. Keep the PR draft. The separately supplied four-process logging controller and its installed result still require their own review; the recorded initial offline logging preparation remains NONPASS. No tag, upload, publication, registry equality, downstream selection, or adoption is authorized by this verdict. |
|
The manual invocation captures controller bytes before compiling/executing them, with the fixed SHA literal below. It supplies only the prepared consumer root and accepted-source checkout as arguments. No subprocess reopens the controller pathname. python3 -I -c 'import hashlib,pathlib,sys; p=pathlib.Path(sys.argv[1]); b=p.read_bytes(); assert hashlib.sha256(b).hexdigest()=="9420ed59345c34e2f8564d7bdb3fd2bb8456939ced19a94fc3ec4f8d22aec72d"; sys.argv=sys.argv[1:]; exec(compile(b,str(p),"exec"),{"__name__":"__main__"})' <controller.py> <prepared-consumer-root> <accepted-source-checkout> |
|
Security pre-execution review of the manual logging controller at comment The package/build side is coherent: the exact receipt hashes to
The ID-and-label cleanup loop, sealed parent memfd, closed consumer environment, process-group cleanup, loopback readiness, secret-output refusal and fixed resource deadlines are otherwise directionally sound. Preserve the initial unused-feature offline preparation as NONPASS. Send one frozen successor source/bootstrap plus predecessor-failing substitution/output/tool-environment controls for review; no runtime, reusable-driver, tag, upload or logging qualification is authorized yet. |
|
Frozen manual-controller successor SHA256 The controller now captures verified supervisor bytes and carries them only in container command arguments; no host source path or mount is consumed by Docker. It opens the private output root through no-follow directory descriptors and creates0600 output descriptors exclusively. Docker is fixed to the root-owned The literal bootstrap hashes the captured controller before compilation. Invoke with the fixed prepared consumer/source roots from this run; those local paths are not part of the public template: /usr/bin/python3 -I -c 'import hashlib,pathlib,sys; p=pathlib.Path(sys.argv[1]); b=p.read_bytes(); assert hashlib.sha256(b).hexdigest()=="6ec9706d5be1905cc6418e5e2f5e7fe89819d5ca43188443ee357d50eb12e0a5"; sys.argv=sys.argv[1:]; exec(compile(b,str(p),"exec"),{"__name__":"__main__"})' <controller.py> <prepared-consumer-root> <accepted-source-checkout>Complete controller source: """One fixed candidate observation; public review packet contains these bytes."""
import base64
import fcntl
import hashlib
import json
import os
import pathlib
import resource
import secrets
import signal
import stat
import subprocess
import sys
import time
import urllib.error
import urllib.request
ROOT = pathlib.Path(sys.argv[1]).absolute()
SOURCE = pathlib.Path(sys.argv[2]).absolute()
IMAGE = 'ghcr.io/durable-workflow/server@sha256:9d64e9aeee84b46d21715826a3e7e5a96eb8d4ce7fccb126b88b15596ab14973'
REVISION = 'b6e04ce7e679464e91f6ceae83310d3bb3204092'
RECEIPT = '6f197812e8218fc44d513bfa1040b91b19fe168367c70e53e16882b0db13fe79'
BINARY = '89ae4f0fdea91e503d8b7e80426e7160259e324520341b2f325d7aed5edfb8b1'
TEST = '6d7b08d138fc13f9b513ce80c51a40fbec85beeb015e3a631598e7f8cdce4398'
def digest(data):
return hashlib.sha256(data).hexdigest()
def directory(path):
assert path.is_absolute() and '..' not in path.parts
current = os.open('/', os.O_RDONLY | os.O_DIRECTORY)
try:
for part in path.parts[1:]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=current)
os.close(current)
current = following
return current
except BaseException:
os.close(current)
raise
def read_at(root, relative):
parts = pathlib.PurePosixPath(relative).parts
assert parts and not relative.startswith('/') and '..' not in parts
parent = os.dup(root)
try:
for part in parts[:-1]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=parent)
os.close(parent)
parent = following
fd = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=parent)
try:
info = os.fstat(fd)
assert stat.S_ISREG(info.st_mode) and info.st_nlink == 1 and info.st_uid == os.getuid()
assert info.st_size <= 64 * 1024**2
value = os.pread(fd, info.st_size + 1, 0)
after = os.fstat(fd)
fields = ('st_dev', 'st_ino', 'st_size', 'st_uid', 'st_gid', 'st_mode',
'st_nlink', 'st_mtime_ns', 'st_ctime_ns')
assert len(value) == info.st_size
assert all(getattr(info, field) == getattr(after, field) for field in fields)
return value
finally:
os.close(fd)
finally:
os.close(parent)
def exclusive(root, name):
assert '/' not in name and name not in ('', '.', '..')
return os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW,
0o600, dir_fd=root)
def output(root, fd, name, value):
before = os.fstat(fd)
named = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (named.st_dev, named.st_ino) == (before.st_dev, before.st_ino)
assert stat.S_ISREG(named.st_mode) and stat.S_IMODE(named.st_mode) == 0o600
assert named.st_uid == os.getuid() and named.st_nlink == 1
with os.fdopen(os.dup(fd), 'wb') as handle:
handle.write(value)
handle.flush()
after = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (after.st_dev, after.st_ino, after.st_nlink) == (before.st_dev, before.st_ino, 1)
root_fd = directory(ROOT)
root_info = os.fstat(root_fd)
assert root_info.st_uid == os.getuid() and stat.S_IMODE(root_info.st_mode) == 0o700
receipt_bytes = read_at(root_fd, 'build-receipt.json')
assert digest(receipt_bytes) == RECEIPT
receipt = json.loads(receipt_bytes)
assert receipt['executable_sha256'] == BINARY
assert digest(read_at(root_fd, 'fixture/tests/workflow_logging_server.rs')) == TEST
assert digest(read_at(root_fd, 'fixture/Cargo.lock')) == receipt['lock_sha256']
assert digest(read_at(root_fd, 'fixture/Cargo.toml')) == receipt['manifest_sha256']
assert digest(read_at(root_fd, 'fixture/logging-build.jsonl')) == receipt['build_messages_sha256']
binary_bytes = read_at(root_fd, receipt['executable_relative'])
assert len(binary_bytes) == receipt['executable_bytes']
assert digest(binary_bytes) == BINARY
fd = os.memfd_create('reviewed-logging-parent', os.MFD_ALLOW_SEALING)
with os.fdopen(os.dup(fd), 'wb') as image_file:
image_file.write(binary_bytes)
os.fchmod(fd, 0o500)
seals = fcntl.F_SEAL_WRITE | fcntl.F_SEAL_GROW | fcntl.F_SEAL_SHRINK | fcntl.F_SEAL_SEAL
fcntl.fcntl(fd, fcntl.F_ADD_SEALS, seals)
assert fcntl.fcntl(fd, fcntl.F_GET_SEALS) == seals
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
supervisor = SOURCE / 'scripts/acceptance/installed-native/cell-supervisor.sh'
source_fd = directory(SOURCE)
supervisor_bytes = read_at(source_fd, 'scripts/acceptance/installed-native/cell-supervisor.sh')
os.close(source_fd)
assert digest(supervisor_bytes) == '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b'
def runtime_command(script, deadline):
script = script.decode()
original = ' /bin/sh "$0" --command "$@"'
assert script.count(original) == 1
wrapper = 'supervisor=$1\nshift\n' + script.replace(original,
' /bin/sh -c "$supervisor" supervisor --command "$@"')
return ['-c', wrapper, 'supervisor', script, str(deadline), '10', 'both',
'/usr/local/bin/durable-workflow-server']
os.mkdir('docker-config', mode=0o700, dir_fd=root_fd)
config_fd = os.open('docker-config', os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=root_fd)
config_file = exclusive(config_fd, 'config.json')
os.write(config_file, b'{}\n')
os.close(config_file)
evidence = {name: exclusive(root_fd, name) for name in
('logging.stdout', 'logging.stderr', 'logging-result.json')}
CLOSED_ENV = {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'}
def docker_command(args, config):
assert args[0] == 'docker'
return ['/usr/bin/docker', '--host', 'unix:///run/docker.sock', '--config',
'/proc/self/fd/' + str(config)] + args[1:]
def call(args, **kwargs):
tool = os.stat('/usr/bin/docker', follow_symlinks=False)
assert stat.S_ISREG(tool.st_mode) and tool.st_uid == 0 and tool.st_nlink == 1
assert stat.S_IMODE(tool.st_mode) == 0o755
assert digest(pathlib.Path('/usr/bin/docker').read_bytes()) == '40cdaf7fd0f21089dd9e15b0c3a7dd7f2399027f010e366dac6304ae0615954a'
assert os.listdir(config_fd) == ['config.json'] and read_at(config_fd, 'config.json') == b'{}\n'
config_named = os.stat('docker-config', dir_fd=root_fd, follow_symlinks=False)
config_open = os.fstat(config_fd)
assert (config_named.st_dev, config_named.st_ino) == (config_open.st_dev, config_open.st_ino)
kwargs.setdefault('check', True)
return subprocess.run(docker_command(args, config_fd), capture_output=True, timeout=30,
cwd='/', env=CLOSED_ENV, pass_fds=(config_fd,), **kwargs)
socket_info = os.stat('/run/docker.sock', follow_symlinks=False)
assert stat.S_ISSOCK(socket_info.st_mode) and socket_info.st_uid == 0
def engine():
current = os.stat('/run/docker.sock', follow_symlinks=False)
assert (current.st_dev, current.st_ino, current.st_uid, current.st_gid, current.st_mode) == (
socket_info.st_dev, socket_info.st_ino, socket_info.st_uid, socket_info.st_gid, socket_info.st_mode)
identity = call(['docker', 'info', '--format', '{{.ID}}']).stdout.strip()
assert digest(identity) == '0a179ff32531e41cfc2d465b1d46afc1df91c0975e9627969f75c67e00b0e892'
def image_identity():
image = json.loads(call(['docker', 'image', 'inspect', IMAGE]).stdout)[0]
assert image['Id'] == IMAGE.split('@')[1]
assert image['RepoDigests'] == [IMAGE] and image['Descriptor']['digest'] == IMAGE.split('@')[1]
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert digest(json.dumps(image['Config'], sort_keys=True, separators=(',', ':')).encode()) == 'c88782b528aee2a1b7804cd62cb95afac9df8c5b2f89c471924c6c1085c63b62'
return image
engine()
image = image_identity()
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert image['Config']['Labels']['org.opencontainers.image.revision'] == REVISION
assert image['Config']['Labels']['dev.durable-workflow.release.tag'] == '3.10.0'
assert image['Config']['Entrypoint'] == ['/usr/local/bin/durable-workflow-server']
nonce = secrets.token_hex(16)
name = 'sdk-rust-417-logging-' + nonce[:12]
labels = {'owner': 'sdk-rust', 'task': 'logger227', 'qualification_nonce': nonce}
label_args = [argument for key, value in labels.items() for argument in ('--label', key + '=' + value)]
token = 'fixture-' + secrets.token_hex(24)
key = 'base64:' + base64.b64encode(secrets.token_bytes(32)).decode()
container_id = network_id = None
process = None
result = {'outcome': 'fail', 'build_receipt_sha256': RECEIPT,
'binary_sha256': BINARY, 'server_manifest': IMAGE, 'server_source': REVISION,
'started_at': time.time(), 'limits': {'consumer_cpus': 2, 'consumer_as': 2147483648,
'consumer_cpu_seconds': 60, 'consumer_wall_seconds': 180}}
def owned(kind, identity):
value = json.loads(call(['docker', kind, 'inspect', identity]).stdout)[0]
actual = value['Config']['Labels'] if kind == 'container' else value['Labels']
assert value['Id'] == identity and all(actual.get(k) == v for k, v in labels.items())
return value
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args):
raise AssertionError('redirect refused')
def consumer_limits():
os.sched_setaffinity(0, sorted(os.sched_getaffinity(0))[:2])
resource.setrlimit(resource.RLIMIT_AS, (2 * 1024**3, 2 * 1024**3))
resource.setrlimit(resource.RLIMIT_CPU, (60, 60))
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
def validate_container(value, image, network, name, command, labels, tmpfs):
assert value['Image'] == image['Id']
config, host = value['Config'], value['HostConfig']
expected_env = dict(entry.split('=', 1) for entry in image['Config']['Env'])
expected_env.update(DB_CONNECTION='sqlite', DB_DATABASE='/app/database/runtime.sqlite',
DW_RUST_MAINTENANCE_LOOP='1')
assert len(config['Env']) == len(expected_env)
assert dict(entry.split('=', 1) for entry in config['Env']) == expected_env
assert config['Image'] == IMAGE and config['Entrypoint'] == ['/bin/sh'] and config['Cmd'] == command
assert config['Hostname'] == name and config['User'] == '1000:1000'
assert config['WorkingDir'] == '/app' and config['StopSignal'] == 'SIGTERM'
assert config['Volumes'] == image['Config']['Volumes']
assert config['ExposedPorts'] == {'8080/tcp': {}}
assert config['Labels'] == dict(image['Config']['Labels'], **labels)
assert not config['Tty'] and not config['OpenStdin']
expected = {'ReadonlyRootfs': True, 'Init': True, 'Privileged': False,
'NanoCpus': 10**9, 'Memory': 1024**3, 'MemorySwap': 1024**3, 'PidsLimit': 256,
'CapAdd': None, 'CapDrop': ['ALL'], 'SecurityOpt': ['no-new-privileges'],
'NetworkMode': network, 'Binds': None, 'Tmpfs': tmpfs,
'PortBindings': {'8080/tcp': [{'HostIp': '127.0.0.1', 'HostPort': ''}]},
'PidMode': '', 'UTSMode': '', 'UsernsMode': '', 'IpcMode': 'private',
'Devices': [], 'DeviceRequests': None, 'VolumesFrom': None, 'ExtraHosts': None,
'AutoRemove': False, 'RestartPolicy': {'Name': 'no', 'MaximumRetryCount': 0}}
assert all(host.get(key) == val for key, val in expected.items())
assert not host.get('Mounts')
assert all(m['Type'] == 'tmpfs' and m['Destination'] in tmpfs for m in value['Mounts'])
return digest(json.dumps({k: value[k] for k in ('Image', 'Config', 'HostConfig', 'Mounts')},
sort_keys=True, separators=(',', ':')).encode())
tmpfs = {'/tmp': 'mode=1777,size=64m',
'/app/database': 'uid=1000,gid=1000,mode=0700,size=64m',
'/app/storage': 'uid=1000,gid=1000,mode=0700,size=64m',
'/credentials': 'uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev'}
command = None
created_config = None
try:
engine()
image_identity()
network_id = call(['docker', 'network', 'create', '--internal'] + label_args + [name]).stdout.decode().strip()
owned('network', network_id)
deadline = str(int(time.time()) + 240)
command = runtime_command(supervisor_bytes, deadline)
engine()
image_identity()
container_id = call(['docker', 'create', '--pull=never', '--init', '--name', name,
'--hostname', name] + label_args + [
'--cpus', '1', '--memory', '1g', '--memory-swap', '1g', '--pids-limit', '256', '--read-only', '--user', '1000:1000',
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--network', network_id,
'--publish', '127.0.0.1::8080', '--tmpfs', '/tmp:mode=1777,size=64m',
'--tmpfs', '/app/database:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/app/storage:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/credentials:uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev',
'--env', 'DB_CONNECTION=sqlite', '--env', 'DB_DATABASE=/app/database/runtime.sqlite',
'--env', 'DW_RUST_MAINTENANCE_LOOP=1', '--entrypoint', '/bin/sh', IMAGE] + command).stdout.decode().strip()
before = owned('container', container_id)
result['container_id'], result['network_id'] = container_id, network_id
created_config = validate_container(before, image, network_id, name, command, labels, tmpfs)
result['created_config_sha256'] = created_config
engine()
image_identity()
assert validate_container(owned('container', container_id), image, network_id,
name, command, labels, tmpfs) == created_config
call(['docker', 'start', container_id])
assert validate_container(owned('container', container_id), image, network_id,
name, command, labels, tmpfs) == created_config
call(['docker', 'exec', '-i', container_id, '/bin/sh', '-c',
'umask 077; IFS= read -r token && IFS= read -r key && '
'printf %s "$token" > /credentials/token && printf %s "$key" > /credentials/server-key && '
': > /credentials/ready.tmp && mv /credentials/ready.tmp /credentials/ready'],
input=(token + '\n' + key + '\n').encode())
live = owned('container', container_id)
ports = live['NetworkSettings']['Ports']['8080/tcp']
assert len(ports) == 1 and ports[0]['HostIp'] == '127.0.0.1'
port = int(ports[0]['HostPort'])
assert 0 < port < 65536
origin = 'http://127.0.0.1:' + str(port)
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
for attempt in range(60):
try:
request = urllib.request.Request(origin + '/api/cluster/info',
headers={'Authorization': 'Bearer ' + token, 'X-Namespace': 'default'})
with opener.open(request, timeout=1) as response:
cluster = json.load(response)
assert cluster['version'] == '3.10.0'
result['cluster_info'] = cluster
break
except (urllib.error.URLError, ConnectionError):
time.sleep(.25)
else:
raise AssertionError('runtime readiness bound expired')
args = ['/proc/self/fd/' + str(fd), '--ignored', '--exact',
'published_logging_emits_once_per_committed_step_across_cold_worker_processes',
'--nocapture', '--test-threads=1']
env = {'DURABLE_WORKFLOW_LOCAL_ISOLATED': '1', 'DURABLE_WORKFLOW_SERVER_URL': origin,
'DURABLE_WORKFLOW_AUTH_TOKEN': token, 'DURABLE_WORKFLOW_EXPECT_SERVER_VERSION': '3.10.0'}
process = subprocess.Popen(args, env=env, pass_fds=(fd,), start_new_session=True,
preexec_fn=consumer_limits, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate(timeout=180)
assert len(stdout) + len(stderr) <= 1024**2
assert all(secret.encode() not in stdout + stderr for secret in (token, key))
output(root_fd, evidence['logging.stdout'], 'logging.stdout', stdout)
output(root_fd, evidence['logging.stderr'], 'logging.stderr', stderr)
result['parent_pid'], result['exit_code'] = process.pid, process.returncode
assert process.returncode == 0, 'logging parent failed'
assert b'PASS: four cold worker processes' in stdout
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
engine()
image_identity()
assert validate_container(owned('container', container_id), image, network_id,
name, command, labels, tmpfs) == created_config
result['outcome'] = 'pass'
except BaseException as error:
result['error'] = type(error).__name__
raise
finally:
if process is not None:
try:
os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:
pass
process.wait(timeout=10)
os.close(fd)
errors = []
# Recover only this exact nonce/owner if an uncertain create returned no ID.
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity is None:
try:
filters = [arg for key, val in labels.items() for arg in ('--filter', 'label=' + key + '=' + val)]
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
candidates = call(query + filters).stdout.decode().split()
assert len(candidates) <= 1
if candidates:
owned(kind, candidates[0])
if kind == 'container':
container_id = candidates[0]
else:
network_id = candidates[0]
except Exception as error:
errors.append(type(error).__name__)
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity:
try:
value = owned(kind, identity)
if kind == 'container':
result['runtime_oom'] = value['State']['OOMKilled']
if result['runtime_oom']:
result['outcome'] = 'fail'
call(['docker', 'rm', '-f', '-v', identity] if kind == 'container'
else ['docker', 'network', 'rm', identity])
observed = call(['docker', kind, 'inspect', identity], check=False)
assert observed.returncode != 0 and b'no such' in observed.stderr.lower()
except Exception as error:
errors.append(type(error).__name__)
result['cleanup'] = {'pass': not errors, 'errors': errors}
if errors:
result['outcome'] = 'fail'
result['finished_at'] = time.time()
named_root = ROOT.stat(follow_symlinks=False)
assert (named_root.st_dev, named_root.st_ino) == (root_info.st_dev, root_info.st_ino)
output(root_fd, evidence['logging-result.json'], 'logging-result.json',
(json.dumps(result, indent=2) + '\n').encode())
for descriptor in evidence.values():
os.close(descriptor)
os.unlink('config.json', dir_fd=config_fd)
os.close(config_fd)
os.rmdir('docker-config', dir_fd=root_fd)
os.close(root_fd)
assert not errors, errors
print(json.dumps(result)) |
|
Complete inert controls, SHA256 import ast
import copy
import hashlib
import os
import pathlib
import stat
import subprocess
import sys
import tempfile
import time
import unittest
from unittest import mock
SOURCE = pathlib.Path(sys.argv[1])
SUPERVISOR = pathlib.Path(sys.argv[2])
sys.argv = sys.argv[:1]
module = ast.parse(SOURCE.read_text())
keep = {'digest', 'directory', 'read_at', 'exclusive', 'output', 'runtime_command', 'docker_command', 'call', 'validate_container'}
ns = {'pathlib': pathlib, 'os': os, 'stat': stat, 'hashlib': hashlib, 'subprocess': subprocess,
'json': __import__('json'), 'CLOSED_ENV': {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'},
'IMAGE': 'synthetic-image'}
exec(compile(ast.Module(body=[node for node in module.body if isinstance(node, ast.FunctionDef) and node.name in keep], type_ignores=[]), str(SOURCE), 'exec'), ns)
class Controls(unittest.TestCase):
def test_supervisor_replacement_discriminates_predecessor(self):
script = SUPERVISOR.read_bytes()
self.assertEqual(hashlib.sha256(script).hexdigest(), '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b')
with tempfile.TemporaryDirectory() as tmp:
path = pathlib.Path(tmp) / 'supervisor'
path.write_bytes(script)
captured = path.read_bytes()
command = ns['runtime_command'](captured, int(time.time()) + 10)
command[-2:] = ['none', '/bin/echo', 'ORIGINAL']
path.write_text('printf SUBSTITUTED')
predecessor = subprocess.check_output(['/bin/sh', str(path), '10', '10', 'none', '/bin/echo', 'ORIGINAL'])
self.assertEqual(predecessor, b'SUBSTITUTED')
self.assertEqual(subprocess.check_output(['/bin/sh'] + command), b'ORIGINAL\n')
self.assertNotIn(str(path), command)
def test_exclusive_output_refuses_symlink(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp)
marker = root / 'marker'; marker.write_bytes(b'unchanged')
(root / 'logging.stdout').symlink_to(marker)
(root / 'logging.stdout').write_bytes(b'PREDECESSOR')
self.assertEqual(marker.read_bytes(), b'PREDECESSOR')
marker.write_bytes(b'unchanged')
fd = ns['directory'](root)
try:
with self.assertRaises(FileExistsError): ns['exclusive'](fd, 'logging.stdout')
self.assertEqual(marker.read_bytes(), b'unchanged')
finally: os.close(fd)
def test_output_replacement_refuses_before_foreign_write(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp); fd = ns['directory'](root)
out = ns['exclusive'](fd, 'logging.stdout')
try:
self.assertEqual(stat.S_IMODE(os.fstat(out).st_mode), 0o600)
(root / 'logging.stdout').rename(root / 'held')
marker = root / 'marker'; marker.write_bytes(b'unchanged')
(root / 'logging.stdout').symlink_to(marker)
with self.assertRaises(AssertionError): ns['output'](fd, out, 'logging.stdout', b'bad')
self.assertEqual(marker.read_bytes(), b'unchanged')
finally: os.close(out); os.close(fd)
def test_input_and_root_links_refused(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp); (root / 'alias').symlink_to(root, target_is_directory=True)
with self.assertRaises(OSError): ns['directory'](root / 'alias')
fd = ns['directory'](root)
try:
(root / 'value').write_bytes(b'expected'); (root / 'link').symlink_to(root / 'value')
with self.assertRaises(OSError): ns['read_at'](fd, 'link')
self.assertEqual(ns['read_at'](fd, 'value'), b'expected')
finally: os.close(fd)
def test_effectful_tool_and_environment_are_closed(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp); (root / 'docker-config').mkdir(mode=0o700)
(root / 'docker-config/config.json').write_text('{}\n')
rootfd = ns['directory'](root); configfd = ns['directory'](root / 'docker-config')
ns.update(root_fd=rootfd, config_fd=configfd)
captured = []
def fake(*args, **kwargs): captured.append((args, kwargs)); return object()
try:
with mock.patch.dict(os.environ, {'PATH': '/synthetic-untrusted', 'DOCKER_HOST': 'tcp://wrong', 'DOCKER_CONFIG': '/wrong', 'DOCKER_CONTEXT': 'wrong'}):
with mock.patch.object(subprocess, 'run', side_effect=fake): ns['call'](['docker', 'create', '--pull=never'])
args, kwargs = captured[0]
self.assertEqual(args[0][:3], ['/usr/bin/docker', '--host', 'unix:///run/docker.sock'])
self.assertEqual(kwargs['env'], ns['CLOSED_ENV'])
self.assertEqual(kwargs['pass_fds'], (configfd,))
self.assertEqual(kwargs['cwd'], '/')
self.assertNotIn('DOCKER_HOST', kwargs['env'])
(root / 'docker-config/config.json').write_text('{"credsStore":"synthetic"}')
with mock.patch.object(subprocess, 'run') as run:
with self.assertRaises(AssertionError): ns['call'](['docker', 'create'])
run.assert_not_called()
finally: os.close(configfd); os.close(rootfd)
def test_configuration_mutations_are_refused(self):
image = {'Id': 'synthetic-id', 'Config': {'Env': ['PATH=/usr/bin'], 'Labels': {}, 'Volumes': {'/app/database': {}, '/app/storage': {}}}}
command = ['-c', 'captured']; tmpfs = {'/tmp': 'size=64m'}
config = {'Env': ['PATH=/usr/bin', 'DB_CONNECTION=sqlite', 'DB_DATABASE=/app/database/runtime.sqlite', 'DW_RUST_MAINTENANCE_LOOP=1'],
'Image':'synthetic-image','Entrypoint':['/bin/sh'],'Cmd':command,'Hostname':'owned','User':'1000:1000','WorkingDir':'/app','StopSignal':'SIGTERM',
'Volumes': image['Config']['Volumes'],'ExposedPorts':{'8080/tcp':{}},'Labels':{'owner':'sdk-rust'},'Tty':False,'OpenStdin':False}
host = {'ReadonlyRootfs':True,'Init':True,'Privileged':False,'NanoCpus':10**9,'Memory':1024**3,'MemorySwap':1024**3,'PidsLimit':256,
'CapAdd':None,'CapDrop':['ALL'],'SecurityOpt':['no-new-privileges'],'NetworkMode':'network-id','Binds':None,'Tmpfs':tmpfs,
'PortBindings':{'8080/tcp':[{'HostIp':'127.0.0.1','HostPort':''}]},'PidMode':'','UTSMode':'','UsernsMode':'','IpcMode':'private',
'Devices':[],'DeviceRequests':None,'VolumesFrom':None,'ExtraHosts':None,'AutoRemove':False,'RestartPolicy':{'Name':'no','MaximumRetryCount':0}}
value={'Image':'synthetic-id','Config':config,'HostConfig':host,'Mounts':[]}
check=lambda v: ns['validate_container'](v,image,'network-id','owned',command,{'owner':'sdk-rust'},tmpfs)
check(value)
mutations=[('Image',None,'wrong'),('Config','Cmd',['wrong']),('Config','Env',config['Env']+['INJECTED=yes']),('Config','Labels',{}),
('HostConfig','Privileged',True),('HostConfig','NanoCpus',0),('HostConfig','Memory',0),('HostConfig','ReadonlyRootfs',False),
('HostConfig','Binds',['synthetic:/app']),('HostConfig','NetworkMode','host'),('HostConfig','SecurityOpt',[]),('Mounts',None,[{'Type':'bind','Destination':'/app'}])]
for group,key,new in mutations:
with self.subTest(field=(group,key)):
changed=copy.deepcopy(value)
if key is None:changed[group]=new
else:changed[group][key]=new
with self.assertRaises(AssertionError):check(changed)
unittest.main() |
|
Security review of frozen controller Both public sources hash exactly as stated and parse successfully. The successor substantively closes the prior supervisor-path, literal-bootstrap, output-name, ambient tool/context, pull and core image/container-config findings: supervisor bytes travel only in argv, the parent is sealed, roots/inputs are no-follow captured, outputs are exclusive private descriptors, Docker/tool/socket/engine/image identities are fixed, Two concrete boundaries remain:
The remaining architecture is otherwise suitable for this bounded one-off. Return one frozen successor with those two controls and exact source/bootstrap hashes. Preserve the initial offline compile NONPASS and do not infer a reusable driver, installed logging result, tag, upload, registry equality or downstream adoption. |
|
Frozen manual successor Create output is now validated as an exact full lowercase64-hex ID before assignment grants authority. Empty/malformed/non-ASCII replies leave the corresponding resource uncertain. Actual cleanup helpers reconcile only exact owner/task/nonce labels, validate recovered full IDs, remove by that ID and independently inspect absence. Separate network/container controls cover four malformed reply forms each and retain the predecessor's skipped-recovery state. Parent/package/test/runtime limits and the other previously reviewed fixes are unchanged. All old HOLD controllers remain unexecuted and the first optional compile NONPASS stays recorded. Please review only this frozen successor before runtime. Literal captured-byte bootstrap: /usr/bin/python3 -I -c 'import hashlib,pathlib,sys; p=pathlib.Path(sys.argv[1]); b=p.read_bytes(); assert hashlib.sha256(b).hexdigest()=="c94a2f12f367f21d5882a358643a687e9fca61fb7b01f1fac9972b3f21108c1d"; sys.argv=sys.argv[1:]; exec(compile(b,str(p),"exec"),{"__name__":"__main__"})' <controller.py> <prepared-consumer-root> <accepted-source-checkout>Complete controller source: """One fixed candidate observation; public review packet contains these bytes."""
import base64
import fcntl
import hashlib
import json
import os
import pathlib
import resource
import re
import secrets
import signal
import stat
import subprocess
import sys
import time
import urllib.error
import urllib.request
ROOT = pathlib.Path(sys.argv[1]).absolute()
SOURCE = pathlib.Path(sys.argv[2]).absolute()
IMAGE = 'ghcr.io/durable-workflow/server@sha256:9d64e9aeee84b46d21715826a3e7e5a96eb8d4ce7fccb126b88b15596ab14973'
REVISION = 'b6e04ce7e679464e91f6ceae83310d3bb3204092'
RECEIPT = '6f197812e8218fc44d513bfa1040b91b19fe168367c70e53e16882b0db13fe79'
BINARY = '89ae4f0fdea91e503d8b7e80426e7160259e324520341b2f325d7aed5edfb8b1'
TEST = '6d7b08d138fc13f9b513ce80c51a40fbec85beeb015e3a631598e7f8cdce4398'
def digest(data):
return hashlib.sha256(data).hexdigest()
def directory(path):
assert path.is_absolute() and '..' not in path.parts
current = os.open('/', os.O_RDONLY | os.O_DIRECTORY)
try:
for part in path.parts[1:]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=current)
os.close(current)
current = following
return current
except BaseException:
os.close(current)
raise
def read_at(root, relative):
parts = pathlib.PurePosixPath(relative).parts
assert parts and not relative.startswith('/') and '..' not in parts
parent = os.dup(root)
try:
for part in parts[:-1]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=parent)
os.close(parent)
parent = following
fd = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=parent)
try:
info = os.fstat(fd)
assert stat.S_ISREG(info.st_mode) and info.st_nlink == 1 and info.st_uid == os.getuid()
assert info.st_size <= 64 * 1024**2
value = os.pread(fd, info.st_size + 1, 0)
after = os.fstat(fd)
fields = ('st_dev', 'st_ino', 'st_size', 'st_uid', 'st_gid', 'st_mode',
'st_nlink', 'st_mtime_ns', 'st_ctime_ns')
assert len(value) == info.st_size
assert all(getattr(info, field) == getattr(after, field) for field in fields)
return value
finally:
os.close(fd)
finally:
os.close(parent)
def exclusive(root, name):
assert '/' not in name and name not in ('', '.', '..')
return os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW,
0o600, dir_fd=root)
def output(root, fd, name, value):
before = os.fstat(fd)
named = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (named.st_dev, named.st_ino) == (before.st_dev, before.st_ino)
assert stat.S_ISREG(named.st_mode) and stat.S_IMODE(named.st_mode) == 0o600
assert named.st_uid == os.getuid() and named.st_nlink == 1
with os.fdopen(os.dup(fd), 'wb') as handle:
handle.write(value)
handle.flush()
after = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (after.st_dev, after.st_ino, after.st_nlink) == (before.st_dev, before.st_ino, 1)
root_fd = directory(ROOT)
root_info = os.fstat(root_fd)
assert root_info.st_uid == os.getuid() and stat.S_IMODE(root_info.st_mode) == 0o700
receipt_bytes = read_at(root_fd, 'build-receipt.json')
assert digest(receipt_bytes) == RECEIPT
receipt = json.loads(receipt_bytes)
assert receipt['executable_sha256'] == BINARY
assert digest(read_at(root_fd, 'fixture/tests/workflow_logging_server.rs')) == TEST
assert digest(read_at(root_fd, 'fixture/Cargo.lock')) == receipt['lock_sha256']
assert digest(read_at(root_fd, 'fixture/Cargo.toml')) == receipt['manifest_sha256']
assert digest(read_at(root_fd, 'fixture/logging-build.jsonl')) == receipt['build_messages_sha256']
binary_bytes = read_at(root_fd, receipt['executable_relative'])
assert len(binary_bytes) == receipt['executable_bytes']
assert digest(binary_bytes) == BINARY
fd = os.memfd_create('reviewed-logging-parent', os.MFD_ALLOW_SEALING)
with os.fdopen(os.dup(fd), 'wb') as image_file:
image_file.write(binary_bytes)
os.fchmod(fd, 0o500)
seals = fcntl.F_SEAL_WRITE | fcntl.F_SEAL_GROW | fcntl.F_SEAL_SHRINK | fcntl.F_SEAL_SEAL
fcntl.fcntl(fd, fcntl.F_ADD_SEALS, seals)
assert fcntl.fcntl(fd, fcntl.F_GET_SEALS) == seals
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
supervisor = SOURCE / 'scripts/acceptance/installed-native/cell-supervisor.sh'
source_fd = directory(SOURCE)
supervisor_bytes = read_at(source_fd, 'scripts/acceptance/installed-native/cell-supervisor.sh')
os.close(source_fd)
assert digest(supervisor_bytes) == '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b'
def runtime_command(script, deadline):
script = script.decode()
original = ' /bin/sh "$0" --command "$@"'
assert script.count(original) == 1
wrapper = 'supervisor=$1\nshift\n' + script.replace(original,
' /bin/sh -c "$supervisor" supervisor --command "$@"')
return ['-c', wrapper, 'supervisor', script, str(deadline), '10', 'both',
'/usr/local/bin/durable-workflow-server']
# procfs fdinfo admits only kernel-created decimal descriptor names. A same-UID
# writer cannot create config.json, contexts or plugin paths in this namespace.
config_path = '/proc/' + str(os.getpid()) + '/fdinfo'
config_fd = os.open(config_path, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
config_info = os.fstat(config_fd)
evidence = {name: exclusive(root_fd, name) for name in
('logging.stdout', 'logging.stderr', 'logging-result.json')}
CLOSED_ENV = {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'}
def docker_command(args, config):
assert args[0] == 'docker'
return ['/usr/bin/docker', '--host', 'unix:///run/docker.sock', '--config',
'/proc/self/fd/' + str(config)] + args[1:]
def call(args, **kwargs):
tool = os.stat('/usr/bin/docker', follow_symlinks=False)
assert stat.S_ISREG(tool.st_mode) and tool.st_uid == 0 and tool.st_nlink == 1
assert stat.S_IMODE(tool.st_mode) == 0o755
assert digest(pathlib.Path('/usr/bin/docker').read_bytes()) == '40cdaf7fd0f21089dd9e15b0c3a7dd7f2399027f010e366dac6304ae0615954a'
assert all(name.isdecimal() for name in os.listdir(config_fd))
config_named = os.stat(config_path, follow_symlinks=False)
config_open = os.fstat(config_fd)
assert (config_named.st_dev, config_named.st_ino) == (config_info.st_dev, config_info.st_ino)
assert (config_open.st_dev, config_open.st_ino) == (config_info.st_dev, config_info.st_ino)
kwargs.setdefault('check', True)
return subprocess.run(docker_command(args, config_fd), capture_output=True, timeout=30,
cwd='/', env=CLOSED_ENV, pass_fds=(config_fd,), **kwargs)
socket_info = os.stat('/run/docker.sock', follow_symlinks=False)
assert stat.S_ISSOCK(socket_info.st_mode) and socket_info.st_uid == 0
def engine():
current = os.stat('/run/docker.sock', follow_symlinks=False)
assert (current.st_dev, current.st_ino, current.st_uid, current.st_gid, current.st_mode) == (
socket_info.st_dev, socket_info.st_ino, socket_info.st_uid, socket_info.st_gid, socket_info.st_mode)
identity = call(['docker', 'info', '--format', '{{.ID}}']).stdout.strip()
assert digest(identity) == '0a179ff32531e41cfc2d465b1d46afc1df91c0975e9627969f75c67e00b0e892'
def image_identity():
image = json.loads(call(['docker', 'image', 'inspect', IMAGE]).stdout)[0]
assert image['Id'] == IMAGE.split('@')[1]
assert image['RepoDigests'] == [IMAGE] and image['Descriptor']['digest'] == IMAGE.split('@')[1]
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert digest(json.dumps(image['Config'], sort_keys=True, separators=(',', ':')).encode()) == 'c88782b528aee2a1b7804cd62cb95afac9df8c5b2f89c471924c6c1085c63b62'
return image
engine()
image = image_identity()
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert image['Config']['Labels']['org.opencontainers.image.revision'] == REVISION
assert image['Config']['Labels']['dev.durable-workflow.release.tag'] == '3.10.0'
assert image['Config']['Entrypoint'] == ['/usr/local/bin/durable-workflow-server']
nonce = secrets.token_hex(16)
name = 'sdk-rust-417-logging-' + nonce[:12]
labels = {'owner': 'sdk-rust', 'task': 'logger227', 'qualification_nonce': nonce}
label_args = [argument for key, value in labels.items() for argument in ('--label', key + '=' + value)]
token = 'fixture-' + secrets.token_hex(24)
key = 'base64:' + base64.b64encode(secrets.token_bytes(32)).decode()
container_id = network_id = None
process = None
result = {'outcome': 'fail', 'build_receipt_sha256': RECEIPT,
'binary_sha256': BINARY, 'server_manifest': IMAGE, 'server_source': REVISION,
'started_at': time.time(), 'limits': {'consumer_cpus': 2, 'consumer_as': 2147483648,
'consumer_cpu_seconds': 60, 'consumer_wall_seconds': 180}}
def owned(kind, identity):
value = json.loads(call(['docker', kind, 'inspect', identity]).stdout)[0]
actual = value['Config']['Labels'] if kind == 'container' else value['Labels']
assert value['Id'] == identity and all(actual.get(k) == v for k, v in labels.items())
return value
def full_id(raw):
identity = raw.decode('ascii').strip()
assert re.fullmatch('[0-9a-f]{64}', identity), 'uncertain create reply'
return identity
def reconcile_created(kind, identity):
if identity is not None:
assert re.fullmatch('[0-9a-f]{64}', identity)
return identity
filters = [arg for key, val in labels.items() for arg in ('--filter', 'label=' + key + '=' + val)]
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
candidates = call(query + filters).stdout.split()
assert len(candidates) <= 1
if candidates:
recovered = full_id(candidates[0])
owned(kind, recovered)
return recovered
return None
def remove_resource(kind, identity):
value = owned(kind, identity)
call(['docker', 'rm', '-f', '-v', identity] if kind == 'container'
else ['docker', 'network', 'rm', identity])
observed = call(['docker', kind, 'inspect', identity], check=False)
assert observed.returncode != 0 and b'no such' in observed.stderr.lower()
return value
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args):
raise AssertionError('redirect refused')
def consumer_limits():
os.sched_setaffinity(0, sorted(os.sched_getaffinity(0))[:2])
resource.setrlimit(resource.RLIMIT_AS, (2 * 1024**3, 2 * 1024**3))
resource.setrlimit(resource.RLIMIT_CPU, (60, 60))
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
def validate_container(value, image, network, name, command, labels, tmpfs):
assert value['Image'] == image['Id']
config, host = value['Config'], value['HostConfig']
expected_env = dict(entry.split('=', 1) for entry in image['Config']['Env'])
expected_env.update(DB_CONNECTION='sqlite', DB_DATABASE='/app/database/runtime.sqlite',
DW_RUST_MAINTENANCE_LOOP='1')
assert len(config['Env']) == len(expected_env)
assert dict(entry.split('=', 1) for entry in config['Env']) == expected_env
assert config['Image'] == IMAGE and config['Entrypoint'] == ['/bin/sh'] and config['Cmd'] == command
assert config['Hostname'] == name and config['User'] == '1000:1000'
assert config['WorkingDir'] == '/app' and config['StopSignal'] == 'SIGTERM'
assert config['Volumes'] == image['Config']['Volumes']
assert config['ExposedPorts'] == {'8080/tcp': {}}
assert config['Labels'] == dict(image['Config']['Labels'], **labels)
assert not config['Tty'] and not config['OpenStdin']
expected = {'ReadonlyRootfs': True, 'Init': True, 'Privileged': False,
'NanoCpus': 10**9, 'Memory': 1024**3, 'MemorySwap': 1024**3, 'PidsLimit': 256,
'CapAdd': None, 'CapDrop': ['ALL'], 'SecurityOpt': ['no-new-privileges'],
'NetworkMode': network, 'Binds': None, 'Tmpfs': tmpfs,
'PortBindings': {'8080/tcp': [{'HostIp': '127.0.0.1', 'HostPort': ''}]},
'PidMode': '', 'UTSMode': '', 'UsernsMode': '', 'IpcMode': 'private',
'Devices': [], 'DeviceRequests': None, 'VolumesFrom': None, 'ExtraHosts': None,
'AutoRemove': False, 'RestartPolicy': {'Name': 'no', 'MaximumRetryCount': 0}}
assert all(host.get(key) == val for key, val in expected.items())
assert not host.get('Mounts')
assert all(m['Type'] == 'tmpfs' and m['Destination'] in tmpfs for m in value['Mounts'])
return digest(json.dumps({k: value[k] for k in ('Image', 'Config', 'HostConfig', 'Mounts')},
sort_keys=True, separators=(',', ':')).encode())
tmpfs = {'/tmp': 'mode=1777,size=64m',
'/app/database': 'uid=1000,gid=1000,mode=0700,size=64m',
'/app/storage': 'uid=1000,gid=1000,mode=0700,size=64m',
'/credentials': 'uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev'}
command = None
created_config = None
try:
engine()
image_identity()
network_id = full_id(call(['docker', 'network', 'create', '--internal'] + label_args + [name]).stdout)
owned('network', network_id)
deadline = str(int(time.time()) + 240)
command = runtime_command(supervisor_bytes, deadline)
engine()
image_identity()
container_id = full_id(call(['docker', 'create', '--pull=never', '--init', '--name', name,
'--hostname', name] + label_args + [
'--cpus', '1', '--memory', '1g', '--memory-swap', '1g', '--pids-limit', '256', '--read-only', '--user', '1000:1000',
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--network', network_id,
'--publish', '127.0.0.1::8080', '--tmpfs', '/tmp:mode=1777,size=64m',
'--tmpfs', '/app/database:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/app/storage:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/credentials:uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev',
'--env', 'DB_CONNECTION=sqlite', '--env', 'DB_DATABASE=/app/database/runtime.sqlite',
'--env', 'DW_RUST_MAINTENANCE_LOOP=1', '--entrypoint', '/bin/sh', IMAGE] + command).stdout)
before = owned('container', container_id)
result['container_id'], result['network_id'] = container_id, network_id
created_config = validate_container(before, image, network_id, name, command, labels, tmpfs)
result['created_config_sha256'] = created_config
engine()
image_identity()
assert validate_container(owned('container', container_id), image, network_id,
name, command, labels, tmpfs) == created_config
call(['docker', 'start', container_id])
assert validate_container(owned('container', container_id), image, network_id,
name, command, labels, tmpfs) == created_config
call(['docker', 'exec', '-i', container_id, '/bin/sh', '-c',
'umask 077; IFS= read -r token && IFS= read -r key && '
'printf %s "$token" > /credentials/token && printf %s "$key" > /credentials/server-key && '
': > /credentials/ready.tmp && mv /credentials/ready.tmp /credentials/ready'],
input=(token + '\n' + key + '\n').encode())
live = owned('container', container_id)
ports = live['NetworkSettings']['Ports']['8080/tcp']
assert len(ports) == 1 and ports[0]['HostIp'] == '127.0.0.1'
port = int(ports[0]['HostPort'])
assert 0 < port < 65536
origin = 'http://127.0.0.1:' + str(port)
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
for attempt in range(60):
try:
request = urllib.request.Request(origin + '/api/cluster/info',
headers={'Authorization': 'Bearer ' + token, 'X-Namespace': 'default'})
with opener.open(request, timeout=1) as response:
cluster = json.load(response)
assert cluster['version'] == '3.10.0'
result['cluster_info'] = cluster
break
except (urllib.error.URLError, ConnectionError):
time.sleep(.25)
else:
raise AssertionError('runtime readiness bound expired')
args = ['/proc/self/fd/' + str(fd), '--ignored', '--exact',
'published_logging_emits_once_per_committed_step_across_cold_worker_processes',
'--nocapture', '--test-threads=1']
env = {'DURABLE_WORKFLOW_LOCAL_ISOLATED': '1', 'DURABLE_WORKFLOW_SERVER_URL': origin,
'DURABLE_WORKFLOW_AUTH_TOKEN': token, 'DURABLE_WORKFLOW_EXPECT_SERVER_VERSION': '3.10.0'}
process = subprocess.Popen(args, env=env, pass_fds=(fd,), start_new_session=True,
preexec_fn=consumer_limits, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate(timeout=180)
assert len(stdout) + len(stderr) <= 1024**2
assert all(secret.encode() not in stdout + stderr for secret in (token, key))
output(root_fd, evidence['logging.stdout'], 'logging.stdout', stdout)
output(root_fd, evidence['logging.stderr'], 'logging.stderr', stderr)
result['parent_pid'], result['exit_code'] = process.pid, process.returncode
assert process.returncode == 0, 'logging parent failed'
assert b'PASS: four cold worker processes' in stdout
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
engine()
image_identity()
assert validate_container(owned('container', container_id), image, network_id,
name, command, labels, tmpfs) == created_config
result['outcome'] = 'pass'
except BaseException as error:
result['error'] = type(error).__name__
raise
finally:
if process is not None:
try:
os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:
pass
process.wait(timeout=10)
os.close(fd)
errors = []
# Recover only this exact nonce/owner if an uncertain create returned no ID.
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity is None:
try:
recovered = reconcile_created(kind, identity)
if kind == 'container':
container_id = recovered
else:
network_id = recovered
except Exception as error:
errors.append(type(error).__name__)
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity:
try:
value = remove_resource(kind, identity)
if kind == 'container':
result['runtime_oom'] = value['State']['OOMKilled']
if result['runtime_oom']:
result['outcome'] = 'fail'
except Exception as error:
errors.append(type(error).__name__)
result['cleanup'] = {'pass': not errors, 'errors': errors}
if errors:
result['outcome'] = 'fail'
result['finished_at'] = time.time()
named_root = ROOT.stat(follow_symlinks=False)
assert (named_root.st_dev, named_root.st_ino) == (root_info.st_dev, root_info.st_ino)
output(root_fd, evidence['logging-result.json'], 'logging-result.json',
(json.dumps(result, indent=2) + '\n').encode())
for descriptor in evidence.values():
os.close(descriptor)
os.close(config_fd)
os.close(root_fd)
assert not errors, errors
print(json.dumps(result)) |
|
Full inert controls SHA256 import ast
import copy
import hashlib
import os
import pathlib
import re
import stat
import subprocess
import sys
import tempfile
import time
import unittest
from unittest import mock
SOURCE = pathlib.Path(sys.argv[1])
SUPERVISOR = pathlib.Path(sys.argv[2])
sys.argv = sys.argv[:1]
module = ast.parse(SOURCE.read_text())
keep = {'digest', 'directory', 'read_at', 'exclusive', 'output', 'runtime_command', 'docker_command', 'call', 'validate_container', 'full_id', 'reconcile_created', 'remove_resource', 'owned'}
ns = {'pathlib': pathlib, 'os': os, 'stat': stat, 'hashlib': hashlib, 'subprocess': subprocess,
'json': __import__('json'), 're': re, 'CLOSED_ENV': {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'},
'IMAGE': 'synthetic-image'}
exec(compile(ast.Module(body=[node for node in module.body if isinstance(node, ast.FunctionDef) and node.name in keep], type_ignores=[]), str(SOURCE), 'exec'), ns)
class Controls(unittest.TestCase):
def test_supervisor_replacement_discriminates_predecessor(self):
script = SUPERVISOR.read_bytes()
self.assertEqual(hashlib.sha256(script).hexdigest(), '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b')
with tempfile.TemporaryDirectory() as tmp:
path = pathlib.Path(tmp) / 'supervisor'
path.write_bytes(script)
captured = path.read_bytes()
command = ns['runtime_command'](captured, int(time.time()) + 10)
command[-2:] = ['none', '/bin/echo', 'ORIGINAL']
path.write_text('printf SUBSTITUTED')
predecessor = subprocess.check_output(['/bin/sh', str(path), '10', '10', 'none', '/bin/echo', 'ORIGINAL'])
self.assertEqual(predecessor, b'SUBSTITUTED')
self.assertEqual(subprocess.check_output(['/bin/sh'] + command), b'ORIGINAL\n')
self.assertNotIn(str(path), command)
def test_exclusive_output_refuses_symlink(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp)
marker = root / 'marker'; marker.write_bytes(b'unchanged')
(root / 'logging.stdout').symlink_to(marker)
(root / 'logging.stdout').write_bytes(b'PREDECESSOR')
self.assertEqual(marker.read_bytes(), b'PREDECESSOR')
marker.write_bytes(b'unchanged')
fd = ns['directory'](root)
try:
with self.assertRaises(FileExistsError): ns['exclusive'](fd, 'logging.stdout')
self.assertEqual(marker.read_bytes(), b'unchanged')
finally: os.close(fd)
def test_output_replacement_refuses_before_foreign_write(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp); fd = ns['directory'](root)
out = ns['exclusive'](fd, 'logging.stdout')
try:
self.assertEqual(stat.S_IMODE(os.fstat(out).st_mode), 0o600)
(root / 'logging.stdout').rename(root / 'held')
marker = root / 'marker'; marker.write_bytes(b'unchanged')
(root / 'logging.stdout').symlink_to(marker)
with self.assertRaises(AssertionError): ns['output'](fd, out, 'logging.stdout', b'bad')
self.assertEqual(marker.read_bytes(), b'unchanged')
finally: os.close(out); os.close(fd)
def test_input_and_root_links_refused(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp); (root / 'alias').symlink_to(root, target_is_directory=True)
with self.assertRaises(OSError): ns['directory'](root / 'alias')
fd = ns['directory'](root)
try:
(root / 'value').write_bytes(b'expected'); (root / 'link').symlink_to(root / 'value')
with self.assertRaises(OSError): ns['read_at'](fd, 'link')
self.assertEqual(ns['read_at'](fd, 'value'), b'expected')
finally: os.close(fd)
def test_effectful_tool_and_environment_are_closed(self):
configpath = '/proc/' + str(os.getpid()) + '/fdinfo'
configfd = os.open(configpath, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
ns.update(config_fd=configfd, config_path=configpath, config_info=os.fstat(configfd))
captured = []
def fake(*args, **kwargs):
# Runs after call validation, just before the consumer would open config.
with self.assertRaises(OSError):
opened = os.open('config.json', os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600, dir_fd=configfd)
os.close(opened)
self.assertFalse(os.path.lexists(pathlib.Path(configpath) / 'config.json'))
captured.append((args, kwargs)); return object()
try:
with mock.patch.dict(os.environ, {'PATH': '/synthetic-untrusted', 'DOCKER_HOST': 'tcp://wrong', 'DOCKER_CONFIG': '/wrong', 'DOCKER_CONTEXT': 'wrong'}):
with mock.patch.object(subprocess, 'run', side_effect=fake): ns['call'](['docker', 'create', '--pull=never'])
args, kwargs = captured[0]
self.assertEqual(args[0][:3], ['/usr/bin/docker', '--host', 'unix:///run/docker.sock'])
self.assertEqual(kwargs['env'], ns['CLOSED_ENV'])
self.assertEqual(kwargs['pass_fds'], (configfd,))
self.assertEqual(kwargs['cwd'], '/')
self.assertNotIn('DOCKER_HOST', kwargs['env'])
finally: os.close(configfd)
def test_predecessor_config_changes_between_check_and_open(self):
with tempfile.TemporaryDirectory() as tmp:
path = pathlib.Path(tmp) / 'config.json'; path.write_text('{}\n')
before = path.stat()
self.assertEqual(path.read_text(), '{}\n')
# The old validation has completed; a writer changes the same inode.
path.write_text('{"credsStore":"synthetic"}')
self.assertEqual(path.stat().st_ino, before.st_ino)
self.assertEqual(path.read_text(), '{"credsStore":"synthetic"}')
def test_uncertain_network_and_container_replies_recover_full_id(self):
from types import SimpleNamespace
for kind in ('network', 'container'):
for reply in (b'', b'not-an-id', b'A' * 64, b'\xff'):
with self.subTest(kind=kind, reply=reply):
identity = 'a' * 64
labels = {'owner':'sdk-rust','task':'logger227','qualification_nonce':'synthetic-nonce'}
present = {identity}; operations = []
def fake(args, **kwargs):
operations.append(args)
if 'inspect' in args:
selected = args[-1]
if selected not in present:
return SimpleNamespace(returncode=1, stderr=b'No such object', stdout=b'')
value={'Id':selected,'Config':{'Labels':labels},'Labels':labels,'State':{'OOMKilled':False}}
return SimpleNamespace(returncode=0, stderr=b'', stdout=ns['json'].dumps([value]).encode())
if 'rm' in args:
self.assertEqual(args[-1], identity); present.remove(identity)
return SimpleNamespace(returncode=0, stderr=b'', stdout=identity.encode())
for key,val in labels.items():self.assertIn('label='+key+'='+val, args)
self.assertIn('--no-trunc', args)
return SimpleNamespace(returncode=0, stderr=b'', stdout=(identity+'\n').encode())
old_identity = reply.decode('ascii', errors='replace').strip()
self.assertIsNotNone(old_identity) # Old is-None recovery skips every reply.
granted = None
with self.assertRaises((AssertionError,UnicodeError)):
granted = ns['full_id'](reply)
self.assertIsNone(granted)
with mock.patch.dict(ns, {'labels':labels,'call':fake}):
recovered=ns['reconcile_created'](kind,granted)
self.assertEqual(recovered,identity)
ns['remove_resource'](kind,recovered)
self.assertEqual(present,set())
self.assertIn('inspect',operations[-1])
def test_configuration_mutations_are_refused(self):
image = {'Id': 'synthetic-id', 'Config': {'Env': ['PATH=/usr/bin'], 'Labels': {}, 'Volumes': {'/app/database': {}, '/app/storage': {}}}}
command = ['-c', 'captured']; tmpfs = {'/tmp': 'size=64m'}
config = {'Env': ['PATH=/usr/bin', 'DB_CONNECTION=sqlite', 'DB_DATABASE=/app/database/runtime.sqlite', 'DW_RUST_MAINTENANCE_LOOP=1'],
'Image':'synthetic-image','Entrypoint':['/bin/sh'],'Cmd':command,'Hostname':'owned','User':'1000:1000','WorkingDir':'/app','StopSignal':'SIGTERM',
'Volumes': image['Config']['Volumes'],'ExposedPorts':{'8080/tcp':{}},'Labels':{'owner':'sdk-rust'},'Tty':False,'OpenStdin':False}
host = {'ReadonlyRootfs':True,'Init':True,'Privileged':False,'NanoCpus':10**9,'Memory':1024**3,'MemorySwap':1024**3,'PidsLimit':256,
'CapAdd':None,'CapDrop':['ALL'],'SecurityOpt':['no-new-privileges'],'NetworkMode':'network-id','Binds':None,'Tmpfs':tmpfs,
'PortBindings':{'8080/tcp':[{'HostIp':'127.0.0.1','HostPort':''}]},'PidMode':'','UTSMode':'','UsernsMode':'','IpcMode':'private',
'Devices':[],'DeviceRequests':None,'VolumesFrom':None,'ExtraHosts':None,'AutoRemove':False,'RestartPolicy':{'Name':'no','MaximumRetryCount':0}}
value={'Image':'synthetic-id','Config':config,'HostConfig':host,'Mounts':[]}
check=lambda v: ns['validate_container'](v,image,'network-id','owned',command,{'owner':'sdk-rust'},tmpfs)
check(value)
mutations=[('Image',None,'wrong'),('Config','Cmd',['wrong']),('Config','Env',config['Env']+['INJECTED=yes']),('Config','Labels',{}),
('HostConfig','Privileged',True),('HostConfig','NanoCpus',0),('HostConfig','Memory',0),('HostConfig','ReadonlyRootfs',False),
('HostConfig','Binds',['synthetic:/app']),('HostConfig','NetworkMode','host'),('HostConfig','SecurityOpt',[]),('Mounts',None,[{'Type':'bind','Destination':'/app'}])]
for group,key,new in mutations:
with self.subTest(field=(group,key)):
changed=copy.deepcopy(value)
if key is None:changed[group]=new
else:changed[group][key]=new
with self.assertRaises(AssertionError):check(changed)
unittest.main() |
|
Security review of frozen controller I independently extracted the two public code blocks and reproduced both SHA-256 identities. The accepted supervisor is still The two findings from the prior HOLD are closed:
The previously reviewed sealed parent/supervisor, root/input/output descriptors, exact package/build/test identities, explicit engine/socket/tool/image, pull-never, internal network, container projection, process limits, secret handling and ID-only cleanup remain intact. The first optional compile NONPASS remains historical. Run only the literal fixed-hash bootstrap and exact prepared inputs once, then return the full result, captured IDs, configuration hash, stdout/stderr bounds, OOM status and independent container/network absence for counter-review. This does not approve a reusable driver, source merge, tag/upload, registry equality, package publication or downstream adoption. |
|
First permitted candidate logging attempt is runner-blocked/NONPASS, before SDK consumer admission. Exact controllerc94/build6f197/parent89ae/package6de774 were unchanged. The pre-start configuration projection passed; after start, the full Docker configuration hash differed and the controller refused before synthetic credentials or SDK client execution. No four-process/product outcome is inferred. Captured runtime Next action is an inert cached-image lifecycle metadata comparison (no SDK/Server command, credentials, bind mounts or network) to identify the daemon field transition, then correct exact configuration/absence observers with controls and return one frozen successor for review. No unchanged logging retry, tag or upload is selected. |
|
One inert cached-Python sleep lifecycle comparison identified the actual Docker29 transition: HostConfig.OomKillDisable false→null, with no other Config/HostConfig/Mounts difference. Container Frozen corrected controller The cleanup observer now requires a matching full-ID missing message plus structured empty inspect output and an independently successful full-ID-filtered empty inventory. This accepts the observed Docker29 The prepared inputs are copied into a fresh private output root for a possible second reviewed attempt; build receipt6f197, parent89ae, crate6de774 and test6d7b remain byte-identical. The first result/traceback/output root is preserved unchanged. No second runtime has launched and no tag/upload exists. Please review this narrow observer delta before one fresh attempt. Literal bootstrap: /usr/bin/python3 -I -c 'import hashlib,pathlib,sys; p=pathlib.Path(sys.argv[1]); b=p.read_bytes(); assert hashlib.sha256(b).hexdigest()=="a2a6dc7c59933915b1fdf13d70b4d1e10c2bb588b3c339163aab23738a303bf1"; sys.argv=sys.argv[1:]; exec(compile(b,str(p),"exec"),{"__name__":"__main__"})' <controller.py> <prepared-consumer-r2-root> <accepted-source-checkout>"""One fixed candidate observation; public review packet contains these bytes."""
import base64
import fcntl
import hashlib
import json
import os
import pathlib
import resource
import re
import secrets
import signal
import stat
import subprocess
import sys
import time
import urllib.error
import urllib.request
ROOT = pathlib.Path(sys.argv[1]).absolute()
SOURCE = pathlib.Path(sys.argv[2]).absolute()
IMAGE = 'ghcr.io/durable-workflow/server@sha256:9d64e9aeee84b46d21715826a3e7e5a96eb8d4ce7fccb126b88b15596ab14973'
REVISION = 'b6e04ce7e679464e91f6ceae83310d3bb3204092'
RECEIPT = '6f197812e8218fc44d513bfa1040b91b19fe168367c70e53e16882b0db13fe79'
BINARY = '89ae4f0fdea91e503d8b7e80426e7160259e324520341b2f325d7aed5edfb8b1'
TEST = '6d7b08d138fc13f9b513ce80c51a40fbec85beeb015e3a631598e7f8cdce4398'
def digest(data):
return hashlib.sha256(data).hexdigest()
def directory(path):
assert path.is_absolute() and '..' not in path.parts
current = os.open('/', os.O_RDONLY | os.O_DIRECTORY)
try:
for part in path.parts[1:]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=current)
os.close(current)
current = following
return current
except BaseException:
os.close(current)
raise
def read_at(root, relative):
parts = pathlib.PurePosixPath(relative).parts
assert parts and not relative.startswith('/') and '..' not in parts
parent = os.dup(root)
try:
for part in parts[:-1]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=parent)
os.close(parent)
parent = following
fd = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=parent)
try:
info = os.fstat(fd)
assert stat.S_ISREG(info.st_mode) and info.st_nlink == 1 and info.st_uid == os.getuid()
assert info.st_size <= 64 * 1024**2
value = os.pread(fd, info.st_size + 1, 0)
after = os.fstat(fd)
fields = ('st_dev', 'st_ino', 'st_size', 'st_uid', 'st_gid', 'st_mode',
'st_nlink', 'st_mtime_ns', 'st_ctime_ns')
assert len(value) == info.st_size
assert all(getattr(info, field) == getattr(after, field) for field in fields)
return value
finally:
os.close(fd)
finally:
os.close(parent)
def exclusive(root, name):
assert '/' not in name and name not in ('', '.', '..')
return os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW,
0o600, dir_fd=root)
def output(root, fd, name, value):
before = os.fstat(fd)
named = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (named.st_dev, named.st_ino) == (before.st_dev, before.st_ino)
assert stat.S_ISREG(named.st_mode) and stat.S_IMODE(named.st_mode) == 0o600
assert named.st_uid == os.getuid() and named.st_nlink == 1
with os.fdopen(os.dup(fd), 'wb') as handle:
handle.write(value)
handle.flush()
after = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (after.st_dev, after.st_ino, after.st_nlink) == (before.st_dev, before.st_ino, 1)
root_fd = directory(ROOT)
root_info = os.fstat(root_fd)
assert root_info.st_uid == os.getuid() and stat.S_IMODE(root_info.st_mode) == 0o700
receipt_bytes = read_at(root_fd, 'build-receipt.json')
assert digest(receipt_bytes) == RECEIPT
receipt = json.loads(receipt_bytes)
assert receipt['executable_sha256'] == BINARY
assert digest(read_at(root_fd, 'fixture/tests/workflow_logging_server.rs')) == TEST
assert digest(read_at(root_fd, 'fixture/Cargo.lock')) == receipt['lock_sha256']
assert digest(read_at(root_fd, 'fixture/Cargo.toml')) == receipt['manifest_sha256']
assert digest(read_at(root_fd, 'fixture/logging-build.jsonl')) == receipt['build_messages_sha256']
binary_bytes = read_at(root_fd, receipt['executable_relative'])
assert len(binary_bytes) == receipt['executable_bytes']
assert digest(binary_bytes) == BINARY
fd = os.memfd_create('reviewed-logging-parent', os.MFD_ALLOW_SEALING)
with os.fdopen(os.dup(fd), 'wb') as image_file:
image_file.write(binary_bytes)
os.fchmod(fd, 0o500)
seals = fcntl.F_SEAL_WRITE | fcntl.F_SEAL_GROW | fcntl.F_SEAL_SHRINK | fcntl.F_SEAL_SEAL
fcntl.fcntl(fd, fcntl.F_ADD_SEALS, seals)
assert fcntl.fcntl(fd, fcntl.F_GET_SEALS) == seals
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
supervisor = SOURCE / 'scripts/acceptance/installed-native/cell-supervisor.sh'
source_fd = directory(SOURCE)
supervisor_bytes = read_at(source_fd, 'scripts/acceptance/installed-native/cell-supervisor.sh')
os.close(source_fd)
assert digest(supervisor_bytes) == '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b'
def runtime_command(script, deadline):
script = script.decode()
original = ' /bin/sh "$0" --command "$@"'
assert script.count(original) == 1
wrapper = 'supervisor=$1\nshift\n' + script.replace(original,
' /bin/sh -c "$supervisor" supervisor --command "$@"')
return ['-c', wrapper, 'supervisor', script, str(deadline), '10', 'both',
'/usr/local/bin/durable-workflow-server']
# procfs fdinfo admits only kernel-created decimal descriptor names. A same-UID
# writer cannot create config.json, contexts or plugin paths in this namespace.
config_path = '/proc/' + str(os.getpid()) + '/fdinfo'
config_fd = os.open(config_path, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
config_info = os.fstat(config_fd)
evidence = {name: exclusive(root_fd, name) for name in
('logging.stdout', 'logging.stderr', 'logging-result.json',
'container-created.json', 'container-started.json', 'container-returned.json')}
CLOSED_ENV = {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'}
def docker_command(args, config):
assert args[0] == 'docker'
return ['/usr/bin/docker', '--host', 'unix:///run/docker.sock', '--config',
'/proc/self/fd/' + str(config)] + args[1:]
def call(args, **kwargs):
tool = os.stat('/usr/bin/docker', follow_symlinks=False)
assert stat.S_ISREG(tool.st_mode) and tool.st_uid == 0 and tool.st_nlink == 1
assert stat.S_IMODE(tool.st_mode) == 0o755
assert digest(pathlib.Path('/usr/bin/docker').read_bytes()) == '40cdaf7fd0f21089dd9e15b0c3a7dd7f2399027f010e366dac6304ae0615954a'
assert all(name.isdecimal() for name in os.listdir(config_fd))
config_named = os.stat(config_path, follow_symlinks=False)
config_open = os.fstat(config_fd)
assert (config_named.st_dev, config_named.st_ino) == (config_info.st_dev, config_info.st_ino)
assert (config_open.st_dev, config_open.st_ino) == (config_info.st_dev, config_info.st_ino)
kwargs.setdefault('check', True)
return subprocess.run(docker_command(args, config_fd), capture_output=True, timeout=30,
cwd='/', env=CLOSED_ENV, pass_fds=(config_fd,), **kwargs)
socket_info = os.stat('/run/docker.sock', follow_symlinks=False)
assert stat.S_ISSOCK(socket_info.st_mode) and socket_info.st_uid == 0
def engine():
current = os.stat('/run/docker.sock', follow_symlinks=False)
assert (current.st_dev, current.st_ino, current.st_uid, current.st_gid, current.st_mode) == (
socket_info.st_dev, socket_info.st_ino, socket_info.st_uid, socket_info.st_gid, socket_info.st_mode)
identity = call(['docker', 'info', '--format', '{{.ID}}']).stdout.strip()
assert digest(identity) == '0a179ff32531e41cfc2d465b1d46afc1df91c0975e9627969f75c67e00b0e892'
def image_identity():
image = json.loads(call(['docker', 'image', 'inspect', IMAGE]).stdout)[0]
assert image['Id'] == IMAGE.split('@')[1]
assert image['RepoDigests'] == [IMAGE] and image['Descriptor']['digest'] == IMAGE.split('@')[1]
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert digest(json.dumps(image['Config'], sort_keys=True, separators=(',', ':')).encode()) == 'c88782b528aee2a1b7804cd62cb95afac9df8c5b2f89c471924c6c1085c63b62'
return image
engine()
image = image_identity()
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert image['Config']['Labels']['org.opencontainers.image.revision'] == REVISION
assert image['Config']['Labels']['dev.durable-workflow.release.tag'] == '3.10.0'
assert image['Config']['Entrypoint'] == ['/usr/local/bin/durable-workflow-server']
nonce = secrets.token_hex(16)
name = 'sdk-rust-417-logging-' + nonce[:12]
labels = {'owner': 'sdk-rust', 'task': 'logger227', 'qualification_nonce': nonce}
label_args = [argument for key, value in labels.items() for argument in ('--label', key + '=' + value)]
token = 'fixture-' + secrets.token_hex(24)
key = 'base64:' + base64.b64encode(secrets.token_bytes(32)).decode()
container_id = network_id = None
process = None
result = {'outcome': 'fail', 'build_receipt_sha256': RECEIPT,
'binary_sha256': BINARY, 'server_manifest': IMAGE, 'server_source': REVISION,
'started_at': time.time(), 'limits': {'consumer_cpus': 2, 'consumer_as': 2147483648,
'consumer_cpu_seconds': 60, 'consumer_wall_seconds': 180}}
def owned(kind, identity):
value = json.loads(call(['docker', kind, 'inspect', identity]).stdout)[0]
actual = value['Config']['Labels'] if kind == 'container' else value['Labels']
assert value['Id'] == identity and all(actual.get(k) == v for k, v in labels.items())
return value
def full_id(raw):
identity = raw.decode('ascii').strip()
assert re.fullmatch('[0-9a-f]{64}', identity), 'uncertain create reply'
return identity
def reconcile_created(kind, identity):
if identity is not None:
assert re.fullmatch('[0-9a-f]{64}', identity)
return identity
filters = [arg for key, val in labels.items() for arg in ('--filter', 'label=' + key + '=' + val)]
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
candidates = call(query + filters).stdout.split()
assert len(candidates) <= 1
if candidates:
recovered = full_id(candidates[0])
owned(kind, recovered)
return recovered
return None
def remove_resource(kind, identity):
value = owned(kind, identity)
call(['docker', 'rm', '-f', '-v', identity] if kind == 'container'
else ['docker', 'network', 'rm', identity])
observed = call(['docker', kind, 'inspect', identity], check=False)
missing = ('no such container: ' + identity if kind == 'container'
else 'network ' + identity + ' not found').encode()
assert observed.returncode != 0 and json.loads(observed.stdout) == []
assert missing in observed.stderr.lower()
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
assert call(query + ['--filter', 'id=' + identity]).stdout.strip() == b''
return value
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args):
raise AssertionError('redirect refused')
def consumer_limits():
os.sched_setaffinity(0, sorted(os.sched_getaffinity(0))[:2])
resource.setrlimit(resource.RLIMIT_AS, (2 * 1024**3, 2 * 1024**3))
resource.setrlimit(resource.RLIMIT_CPU, (60, 60))
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
def validate_container(value, image, network, name, command, labels, tmpfs):
assert value['Image'] == image['Id']
config, host = value['Config'], value['HostConfig']
expected_env = dict(entry.split('=', 1) for entry in image['Config']['Env'])
expected_env.update(DB_CONNECTION='sqlite', DB_DATABASE='/app/database/runtime.sqlite',
DW_RUST_MAINTENANCE_LOOP='1')
assert len(config['Env']) == len(expected_env)
assert dict(entry.split('=', 1) for entry in config['Env']) == expected_env
assert config['Image'] == IMAGE and config['Entrypoint'] == ['/bin/sh'] and config['Cmd'] == command
assert config['Hostname'] == name and config['User'] == '1000:1000'
assert config['WorkingDir'] == '/app' and config['StopSignal'] == 'SIGTERM'
assert config['Volumes'] == image['Config']['Volumes']
assert config['ExposedPorts'] == {'8080/tcp': {}}
assert config['Labels'] == dict(image['Config']['Labels'], **labels)
assert not config['Tty'] and not config['OpenStdin']
expected = {'ReadonlyRootfs': True, 'Init': True, 'Privileged': False,
'NanoCpus': 10**9, 'Memory': 1024**3, 'MemorySwap': 1024**3, 'PidsLimit': 256,
'CapAdd': None, 'CapDrop': ['ALL'], 'SecurityOpt': ['no-new-privileges'],
'NetworkMode': network, 'Binds': None, 'Tmpfs': tmpfs,
'PortBindings': {'8080/tcp': [{'HostIp': '127.0.0.1', 'HostPort': ''}]},
'PidMode': '', 'UTSMode': '', 'UsernsMode': '', 'IpcMode': 'private',
'Devices': [], 'DeviceRequests': None, 'VolumesFrom': None, 'ExtraHosts': None,
'AutoRemove': False, 'RestartPolicy': {'Name': 'no', 'MaximumRetryCount': 0}}
assert all(host.get(key) == val for key, val in expected.items())
assert 'OomKillDisable' in host and host['OomKillDisable'] in (False, None)
assert not host.get('Mounts')
assert all(m['Type'] == 'tmpfs' and m['Destination'] in tmpfs for m in value['Mounts'])
packet = json.loads(json.dumps({k: value[k] for k in ('Image', 'Config', 'HostConfig', 'Mounts')}))
# Docker29 changes this unset/false default during start. Both retain the
# kernel OOM killer; true is refused. Every other field remains exact.
packet['HostConfig']['OomKillDisable'] = False
return digest(json.dumps(packet, sort_keys=True, separators=(',', ':')).encode())
tmpfs = {'/tmp': 'mode=1777,size=64m',
'/app/database': 'uid=1000,gid=1000,mode=0700,size=64m',
'/app/storage': 'uid=1000,gid=1000,mode=0700,size=64m',
'/credentials': 'uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev'}
command = None
created_config = None
try:
engine()
image_identity()
network_id = full_id(call(['docker', 'network', 'create', '--internal'] + label_args + [name]).stdout)
owned('network', network_id)
deadline = str(int(time.time()) + 240)
command = runtime_command(supervisor_bytes, deadline)
engine()
image_identity()
container_id = full_id(call(['docker', 'create', '--pull=never', '--init', '--name', name,
'--hostname', name] + label_args + [
'--cpus', '1', '--memory', '1g', '--memory-swap', '1g', '--pids-limit', '256', '--read-only', '--user', '1000:1000',
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--network', network_id,
'--publish', '127.0.0.1::8080', '--tmpfs', '/tmp:mode=1777,size=64m',
'--tmpfs', '/app/database:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/app/storage:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/credentials:uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev',
'--env', 'DB_CONNECTION=sqlite', '--env', 'DB_DATABASE=/app/database/runtime.sqlite',
'--env', 'DW_RUST_MAINTENANCE_LOOP=1', '--entrypoint', '/bin/sh', IMAGE] + command).stdout)
before = owned('container', container_id)
output(root_fd, evidence['container-created.json'], 'container-created.json',
(json.dumps(before, indent=2) + '\n').encode())
result['container_id'], result['network_id'] = container_id, network_id
created_config = validate_container(before, image, network_id, name, command, labels, tmpfs)
result['created_config_sha256'] = created_config
engine()
image_identity()
assert validate_container(owned('container', container_id), image, network_id,
name, command, labels, tmpfs) == created_config
call(['docker', 'start', container_id])
started = owned('container', container_id)
output(root_fd, evidence['container-started.json'], 'container-started.json',
(json.dumps(started, indent=2) + '\n').encode())
assert validate_container(started, image, network_id,
name, command, labels, tmpfs) == created_config
call(['docker', 'exec', '-i', container_id, '/bin/sh', '-c',
'umask 077; IFS= read -r token && IFS= read -r key && '
'printf %s "$token" > /credentials/token && printf %s "$key" > /credentials/server-key && '
': > /credentials/ready.tmp && mv /credentials/ready.tmp /credentials/ready'],
input=(token + '\n' + key + '\n').encode())
live = owned('container', container_id)
ports = live['NetworkSettings']['Ports']['8080/tcp']
assert len(ports) == 1 and ports[0]['HostIp'] == '127.0.0.1'
port = int(ports[0]['HostPort'])
assert 0 < port < 65536
origin = 'http://127.0.0.1:' + str(port)
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
for attempt in range(60):
try:
request = urllib.request.Request(origin + '/api/cluster/info',
headers={'Authorization': 'Bearer ' + token, 'X-Namespace': 'default'})
with opener.open(request, timeout=1) as response:
cluster = json.load(response)
assert cluster['version'] == '3.10.0'
result['cluster_info'] = cluster
break
except (urllib.error.URLError, ConnectionError):
time.sleep(.25)
else:
raise AssertionError('runtime readiness bound expired')
args = ['/proc/self/fd/' + str(fd), '--ignored', '--exact',
'published_logging_emits_once_per_committed_step_across_cold_worker_processes',
'--nocapture', '--test-threads=1']
env = {'DURABLE_WORKFLOW_LOCAL_ISOLATED': '1', 'DURABLE_WORKFLOW_SERVER_URL': origin,
'DURABLE_WORKFLOW_AUTH_TOKEN': token, 'DURABLE_WORKFLOW_EXPECT_SERVER_VERSION': '3.10.0'}
process = subprocess.Popen(args, env=env, pass_fds=(fd,), start_new_session=True,
preexec_fn=consumer_limits, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate(timeout=180)
assert len(stdout) + len(stderr) <= 1024**2
assert all(secret.encode() not in stdout + stderr for secret in (token, key))
output(root_fd, evidence['logging.stdout'], 'logging.stdout', stdout)
output(root_fd, evidence['logging.stderr'], 'logging.stderr', stderr)
result['parent_pid'], result['exit_code'] = process.pid, process.returncode
assert process.returncode == 0, 'logging parent failed'
assert b'PASS: four cold worker processes' in stdout
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
engine()
image_identity()
returned = owned('container', container_id)
output(root_fd, evidence['container-returned.json'], 'container-returned.json',
(json.dumps(returned, indent=2) + '\n').encode())
assert validate_container(returned, image, network_id,
name, command, labels, tmpfs) == created_config
result['outcome'] = 'pass'
except BaseException as error:
result['error'] = type(error).__name__
raise
finally:
if process is not None:
try:
os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:
pass
process.wait(timeout=10)
os.close(fd)
errors = []
# Recover only this exact nonce/owner if an uncertain create returned no ID.
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity is None:
try:
recovered = reconcile_created(kind, identity)
if kind == 'container':
container_id = recovered
else:
network_id = recovered
except Exception as error:
errors.append(type(error).__name__)
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity:
try:
value = remove_resource(kind, identity)
if kind == 'container':
result['runtime_oom'] = value['State']['OOMKilled']
if result['runtime_oom']:
result['outcome'] = 'fail'
except Exception as error:
errors.append(type(error).__name__)
result['cleanup'] = {'pass': not errors, 'errors': errors}
if errors:
result['outcome'] = 'fail'
result['finished_at'] = time.time()
named_root = ROOT.stat(follow_symlinks=False)
assert (named_root.st_dev, named_root.st_ino) == (root_info.st_dev, root_info.st_ino)
output(root_fd, evidence['logging-result.json'], 'logging-result.json',
(json.dumps(result, indent=2) + '\n').encode())
for descriptor in evidence.values():
os.close(descriptor)
os.close(config_fd)
os.close(root_fd)
assert not errors, errors
print(json.dumps(result)) |
|
Frozen inert controls import ast
import copy
import hashlib
import os
import pathlib
import re
import stat
import subprocess
import sys
import tempfile
import time
import unittest
from unittest import mock
SOURCE = pathlib.Path(sys.argv[1])
SUPERVISOR = pathlib.Path(sys.argv[2])
sys.argv = sys.argv[:1]
module = ast.parse(SOURCE.read_text())
keep = {'digest', 'directory', 'read_at', 'exclusive', 'output', 'runtime_command', 'docker_command', 'call', 'validate_container', 'full_id', 'reconcile_created', 'remove_resource', 'owned'}
ns = {'pathlib': pathlib, 'os': os, 'stat': stat, 'hashlib': hashlib, 'subprocess': subprocess,
'json': __import__('json'), 're': re, 'CLOSED_ENV': {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'},
'IMAGE': 'synthetic-image'}
exec(compile(ast.Module(body=[node for node in module.body if isinstance(node, ast.FunctionDef) and node.name in keep], type_ignores=[]), str(SOURCE), 'exec'), ns)
class Controls(unittest.TestCase):
def test_supervisor_replacement_discriminates_predecessor(self):
script = SUPERVISOR.read_bytes()
self.assertEqual(hashlib.sha256(script).hexdigest(), '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b')
with tempfile.TemporaryDirectory() as tmp:
path = pathlib.Path(tmp) / 'supervisor'
path.write_bytes(script)
captured = path.read_bytes()
command = ns['runtime_command'](captured, int(time.time()) + 10)
command[-2:] = ['none', '/bin/echo', 'ORIGINAL']
path.write_text('printf SUBSTITUTED')
predecessor = subprocess.check_output(['/bin/sh', str(path), '10', '10', 'none', '/bin/echo', 'ORIGINAL'])
self.assertEqual(predecessor, b'SUBSTITUTED')
self.assertEqual(subprocess.check_output(['/bin/sh'] + command), b'ORIGINAL\n')
self.assertNotIn(str(path), command)
def test_exclusive_output_refuses_symlink(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp)
marker = root / 'marker'; marker.write_bytes(b'unchanged')
(root / 'logging.stdout').symlink_to(marker)
(root / 'logging.stdout').write_bytes(b'PREDECESSOR')
self.assertEqual(marker.read_bytes(), b'PREDECESSOR')
marker.write_bytes(b'unchanged')
fd = ns['directory'](root)
try:
with self.assertRaises(FileExistsError): ns['exclusive'](fd, 'logging.stdout')
self.assertEqual(marker.read_bytes(), b'unchanged')
finally: os.close(fd)
def test_output_replacement_refuses_before_foreign_write(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp); fd = ns['directory'](root)
out = ns['exclusive'](fd, 'logging.stdout')
try:
self.assertEqual(stat.S_IMODE(os.fstat(out).st_mode), 0o600)
(root / 'logging.stdout').rename(root / 'held')
marker = root / 'marker'; marker.write_bytes(b'unchanged')
(root / 'logging.stdout').symlink_to(marker)
with self.assertRaises(AssertionError): ns['output'](fd, out, 'logging.stdout', b'bad')
self.assertEqual(marker.read_bytes(), b'unchanged')
finally: os.close(out); os.close(fd)
def test_input_and_root_links_refused(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp); (root / 'alias').symlink_to(root, target_is_directory=True)
with self.assertRaises(OSError): ns['directory'](root / 'alias')
fd = ns['directory'](root)
try:
(root / 'value').write_bytes(b'expected'); (root / 'link').symlink_to(root / 'value')
with self.assertRaises(OSError): ns['read_at'](fd, 'link')
self.assertEqual(ns['read_at'](fd, 'value'), b'expected')
finally: os.close(fd)
def test_effectful_tool_and_environment_are_closed(self):
configpath = '/proc/' + str(os.getpid()) + '/fdinfo'
configfd = os.open(configpath, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
ns.update(config_fd=configfd, config_path=configpath, config_info=os.fstat(configfd))
captured = []
def fake(*args, **kwargs):
# Runs after call validation, just before the consumer would open config.
with self.assertRaises(OSError):
opened = os.open('config.json', os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600, dir_fd=configfd)
os.close(opened)
self.assertFalse(os.path.lexists(pathlib.Path(configpath) / 'config.json'))
captured.append((args, kwargs)); return object()
try:
with mock.patch.dict(os.environ, {'PATH': '/synthetic-untrusted', 'DOCKER_HOST': 'tcp://wrong', 'DOCKER_CONFIG': '/wrong', 'DOCKER_CONTEXT': 'wrong'}):
with mock.patch.object(subprocess, 'run', side_effect=fake): ns['call'](['docker', 'create', '--pull=never'])
args, kwargs = captured[0]
self.assertEqual(args[0][:3], ['/usr/bin/docker', '--host', 'unix:///run/docker.sock'])
self.assertEqual(kwargs['env'], ns['CLOSED_ENV'])
self.assertEqual(kwargs['pass_fds'], (configfd,))
self.assertEqual(kwargs['cwd'], '/')
self.assertNotIn('DOCKER_HOST', kwargs['env'])
finally: os.close(configfd)
def test_predecessor_config_changes_between_check_and_open(self):
with tempfile.TemporaryDirectory() as tmp:
path = pathlib.Path(tmp) / 'config.json'; path.write_text('{}\n')
before = path.stat()
self.assertEqual(path.read_text(), '{}\n')
# The old validation has completed; a writer changes the same inode.
path.write_text('{"credsStore":"synthetic"}')
self.assertEqual(path.stat().st_ino, before.st_ino)
self.assertEqual(path.read_text(), '{"credsStore":"synthetic"}')
def test_uncertain_network_and_container_replies_recover_full_id(self):
from types import SimpleNamespace
for kind in ('network', 'container'):
for reply in (b'', b'not-an-id', b'A' * 64, b'\xff'):
with self.subTest(kind=kind, reply=reply):
identity = 'a' * 64
labels = {'owner':'sdk-rust','task':'logger227','qualification_nonce':'synthetic-nonce'}
present = {identity}; operations = []
def fake(args, **kwargs):
operations.append(args)
if 'inspect' in args:
selected = args[-1]
if selected not in present:
message = ('No such container: '+selected if kind=='container' else 'network '+selected+' not found').encode()
return SimpleNamespace(returncode=1, stderr=message, stdout=b'[]\n')
value={'Id':selected,'Config':{'Labels':labels},'Labels':labels,'State':{'OOMKilled':False}}
return SimpleNamespace(returncode=0, stderr=b'', stdout=ns['json'].dumps([value]).encode())
if 'rm' in args:
self.assertEqual(args[-1], identity); present.remove(identity)
return SimpleNamespace(returncode=0, stderr=b'', stdout=identity.encode())
if 'id='+identity in args:
return SimpleNamespace(returncode=0, stderr=b'', stdout=(identity.encode() if present else b''))
for key,val in labels.items():self.assertIn('label='+key+'='+val, args)
self.assertIn('--no-trunc', args)
return SimpleNamespace(returncode=0, stderr=b'', stdout=(identity+'\n').encode())
old_identity = reply.decode('ascii', errors='replace').strip()
self.assertIsNotNone(old_identity) # Old is-None recovery skips every reply.
granted = None
with self.assertRaises((AssertionError,UnicodeError)):
granted = ns['full_id'](reply)
self.assertIsNone(granted)
with mock.patch.dict(ns, {'labels':labels,'call':fake}):
recovered=ns['reconcile_created'](kind,granted)
self.assertEqual(recovered,identity)
ns['remove_resource'](kind,recovered)
self.assertEqual(present,set())
self.assertIn('id='+identity,operations[-1])
def test_configuration_mutations_are_refused(self):
image = {'Id': 'synthetic-id', 'Config': {'Env': ['PATH=/usr/bin'], 'Labels': {}, 'Volumes': {'/app/database': {}, '/app/storage': {}}}}
command = ['-c', 'captured']; tmpfs = {'/tmp': 'size=64m'}
config = {'Env': ['PATH=/usr/bin', 'DB_CONNECTION=sqlite', 'DB_DATABASE=/app/database/runtime.sqlite', 'DW_RUST_MAINTENANCE_LOOP=1'],
'Image':'synthetic-image','Entrypoint':['/bin/sh'],'Cmd':command,'Hostname':'owned','User':'1000:1000','WorkingDir':'/app','StopSignal':'SIGTERM',
'Volumes': image['Config']['Volumes'],'ExposedPorts':{'8080/tcp':{}},'Labels':{'owner':'sdk-rust'},'Tty':False,'OpenStdin':False}
host = {'ReadonlyRootfs':True,'Init':True,'Privileged':False,'NanoCpus':10**9,'Memory':1024**3,'MemorySwap':1024**3,'PidsLimit':256,
'CapAdd':None,'CapDrop':['ALL'],'SecurityOpt':['no-new-privileges'],'NetworkMode':'network-id','Binds':None,'Tmpfs':tmpfs,
'PortBindings':{'8080/tcp':[{'HostIp':'127.0.0.1','HostPort':''}]},'PidMode':'','UTSMode':'','UsernsMode':'','IpcMode':'private',
'Devices':[],'DeviceRequests':None,'VolumesFrom':None,'ExtraHosts':None,'AutoRemove':False,'OomKillDisable':False,'RestartPolicy':{'Name':'no','MaximumRetryCount':0}}
value={'Image':'synthetic-id','Config':config,'HostConfig':host,'Mounts':[]}
check=lambda v: ns['validate_container'](v,image,'network-id','owned',command,{'owner':'sdk-rust'},tmpfs)
check(value)
started=copy.deepcopy(value);started['HostConfig']['OomKillDisable']=None
self.assertEqual(check(value),check(started))
mutations=[('Image',None,'wrong'),('Config','Cmd',['wrong']),('Config','Env',config['Env']+['INJECTED=yes']),('Config','Labels',{}),
('HostConfig','Privileged',True),('HostConfig','NanoCpus',0),('HostConfig','Memory',0),('HostConfig','ReadonlyRootfs',False),
('HostConfig','Binds',['synthetic:/app']),('HostConfig','NetworkMode','host'),('HostConfig','SecurityOpt',[]),('HostConfig','OomKillDisable',True),('Mounts',None,[{'Type':'bind','Destination':'/app'}])]
for group,key,new in mutations:
with self.subTest(field=(group,key)):
changed=copy.deepcopy(value)
if key is None:changed[group]=new
else:changed[group][key]=new
with self.assertRaises(AssertionError):check(changed)
unittest.main() |
|
Security review of frozen observer successor Independent checks:
The first |
|
The one reviewed a2a6dc7 attempt is runner-blocked/NONPASS, after runtime start/synthetic credential setup but before SDK consumer admission. Create/start configuration now matches after the narrowly verified OomKillDisable normalization. Docker29 exposes Runtime Next source return will make the Docker network profile support the already required numeric loopback publication explicitly, retaining the exact package/parent/test, resource/security configuration, closed tools and cleanup. No unchanged repeat is launched. |
|
The inert fixed-marker HTTP control reproduced the network prerequisite: the internal bridge publishes no host port; an explicit bridge with IP masquerading=false and inter-container communication=false publishes the requested127.0.0.1 ephemeral port and returns only the literal marker. Both sequential control containers/networks are independently absent. No SDK/Server command, package, credentials, bind mounts or external request ran. Frozen successor controller The first two launcher NONPASS results stay preserved, and r3 is only a fresh private copy of the same captured inputs. No third runtime has launched. Please review this explicit network-profile correction before one fresh bounded attempt. Literal bootstrap: /usr/bin/python3 -I -c 'import hashlib,pathlib,sys; p=pathlib.Path(sys.argv[1]); b=p.read_bytes(); assert hashlib.sha256(b).hexdigest()=="92dd2e4af3ae74e5e44ee3ab46557f0340045062025cc164daa01a15e9396783"; sys.argv=sys.argv[1:]; exec(compile(b,str(p),"exec"),{"__name__":"__main__"})' <controller.py> <prepared-consumer-r3-root> <accepted-source-checkout>"""One fixed candidate observation; public review packet contains these bytes."""
import base64
import fcntl
import hashlib
import json
import os
import pathlib
import resource
import re
import secrets
import signal
import stat
import subprocess
import sys
import time
import urllib.error
import urllib.request
ROOT = pathlib.Path(sys.argv[1]).absolute()
SOURCE = pathlib.Path(sys.argv[2]).absolute()
IMAGE = 'ghcr.io/durable-workflow/server@sha256:9d64e9aeee84b46d21715826a3e7e5a96eb8d4ce7fccb126b88b15596ab14973'
REVISION = 'b6e04ce7e679464e91f6ceae83310d3bb3204092'
RECEIPT = '6f197812e8218fc44d513bfa1040b91b19fe168367c70e53e16882b0db13fe79'
BINARY = '89ae4f0fdea91e503d8b7e80426e7160259e324520341b2f325d7aed5edfb8b1'
TEST = '6d7b08d138fc13f9b513ce80c51a40fbec85beeb015e3a631598e7f8cdce4398'
def digest(data):
return hashlib.sha256(data).hexdigest()
def directory(path):
assert path.is_absolute() and '..' not in path.parts
current = os.open('/', os.O_RDONLY | os.O_DIRECTORY)
try:
for part in path.parts[1:]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=current)
os.close(current)
current = following
return current
except BaseException:
os.close(current)
raise
def read_at(root, relative):
parts = pathlib.PurePosixPath(relative).parts
assert parts and not relative.startswith('/') and '..' not in parts
parent = os.dup(root)
try:
for part in parts[:-1]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=parent)
os.close(parent)
parent = following
fd = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=parent)
try:
info = os.fstat(fd)
assert stat.S_ISREG(info.st_mode) and info.st_nlink == 1 and info.st_uid == os.getuid()
assert info.st_size <= 64 * 1024**2
value = os.pread(fd, info.st_size + 1, 0)
after = os.fstat(fd)
fields = ('st_dev', 'st_ino', 'st_size', 'st_uid', 'st_gid', 'st_mode',
'st_nlink', 'st_mtime_ns', 'st_ctime_ns')
assert len(value) == info.st_size
assert all(getattr(info, field) == getattr(after, field) for field in fields)
return value
finally:
os.close(fd)
finally:
os.close(parent)
def exclusive(root, name):
assert '/' not in name and name not in ('', '.', '..')
return os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW,
0o600, dir_fd=root)
def output(root, fd, name, value):
before = os.fstat(fd)
named = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (named.st_dev, named.st_ino) == (before.st_dev, before.st_ino)
assert stat.S_ISREG(named.st_mode) and stat.S_IMODE(named.st_mode) == 0o600
assert named.st_uid == os.getuid() and named.st_nlink == 1
with os.fdopen(os.dup(fd), 'wb') as handle:
handle.write(value)
handle.flush()
after = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (after.st_dev, after.st_ino, after.st_nlink) == (before.st_dev, before.st_ino, 1)
root_fd = directory(ROOT)
root_info = os.fstat(root_fd)
assert root_info.st_uid == os.getuid() and stat.S_IMODE(root_info.st_mode) == 0o700
receipt_bytes = read_at(root_fd, 'build-receipt.json')
assert digest(receipt_bytes) == RECEIPT
receipt = json.loads(receipt_bytes)
assert receipt['executable_sha256'] == BINARY
assert digest(read_at(root_fd, 'fixture/tests/workflow_logging_server.rs')) == TEST
assert digest(read_at(root_fd, 'fixture/Cargo.lock')) == receipt['lock_sha256']
assert digest(read_at(root_fd, 'fixture/Cargo.toml')) == receipt['manifest_sha256']
assert digest(read_at(root_fd, 'fixture/logging-build.jsonl')) == receipt['build_messages_sha256']
binary_bytes = read_at(root_fd, receipt['executable_relative'])
assert len(binary_bytes) == receipt['executable_bytes']
assert digest(binary_bytes) == BINARY
fd = os.memfd_create('reviewed-logging-parent', os.MFD_ALLOW_SEALING)
with os.fdopen(os.dup(fd), 'wb') as image_file:
image_file.write(binary_bytes)
os.fchmod(fd, 0o500)
seals = fcntl.F_SEAL_WRITE | fcntl.F_SEAL_GROW | fcntl.F_SEAL_SHRINK | fcntl.F_SEAL_SEAL
fcntl.fcntl(fd, fcntl.F_ADD_SEALS, seals)
assert fcntl.fcntl(fd, fcntl.F_GET_SEALS) == seals
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
supervisor = SOURCE / 'scripts/acceptance/installed-native/cell-supervisor.sh'
source_fd = directory(SOURCE)
supervisor_bytes = read_at(source_fd, 'scripts/acceptance/installed-native/cell-supervisor.sh')
os.close(source_fd)
assert digest(supervisor_bytes) == '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b'
def runtime_command(script, deadline):
script = script.decode()
original = ' /bin/sh "$0" --command "$@"'
assert script.count(original) == 1
wrapper = 'supervisor=$1\nshift\n' + script.replace(original,
' /bin/sh -c "$supervisor" supervisor --command "$@"')
return ['-c', wrapper, 'supervisor', script, str(deadline), '10', 'both',
'/usr/local/bin/durable-workflow-server']
# procfs fdinfo admits only kernel-created decimal descriptor names. A same-UID
# writer cannot create config.json, contexts or plugin paths in this namespace.
config_path = '/proc/' + str(os.getpid()) + '/fdinfo'
config_fd = os.open(config_path, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
config_info = os.fstat(config_fd)
evidence = {name: exclusive(root_fd, name) for name in
('logging.stdout', 'logging.stderr', 'logging-result.json',
'container-created.json', 'container-started.json', 'container-returned.json')}
CLOSED_ENV = {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'}
def docker_command(args, config):
assert args[0] == 'docker'
return ['/usr/bin/docker', '--host', 'unix:///run/docker.sock', '--config',
'/proc/self/fd/' + str(config)] + args[1:]
def call(args, **kwargs):
tool = os.stat('/usr/bin/docker', follow_symlinks=False)
assert stat.S_ISREG(tool.st_mode) and tool.st_uid == 0 and tool.st_nlink == 1
assert stat.S_IMODE(tool.st_mode) == 0o755
assert digest(pathlib.Path('/usr/bin/docker').read_bytes()) == '40cdaf7fd0f21089dd9e15b0c3a7dd7f2399027f010e366dac6304ae0615954a'
assert all(name.isdecimal() for name in os.listdir(config_fd))
config_named = os.stat(config_path, follow_symlinks=False)
config_open = os.fstat(config_fd)
assert (config_named.st_dev, config_named.st_ino) == (config_info.st_dev, config_info.st_ino)
assert (config_open.st_dev, config_open.st_ino) == (config_info.st_dev, config_info.st_ino)
kwargs.setdefault('check', True)
return subprocess.run(docker_command(args, config_fd), capture_output=True, timeout=30,
cwd='/', env=CLOSED_ENV, pass_fds=(config_fd,), **kwargs)
socket_info = os.stat('/run/docker.sock', follow_symlinks=False)
assert stat.S_ISSOCK(socket_info.st_mode) and socket_info.st_uid == 0
def engine():
current = os.stat('/run/docker.sock', follow_symlinks=False)
assert (current.st_dev, current.st_ino, current.st_uid, current.st_gid, current.st_mode) == (
socket_info.st_dev, socket_info.st_ino, socket_info.st_uid, socket_info.st_gid, socket_info.st_mode)
identity = call(['docker', 'info', '--format', '{{.ID}}']).stdout.strip()
assert digest(identity) == '0a179ff32531e41cfc2d465b1d46afc1df91c0975e9627969f75c67e00b0e892'
def image_identity():
image = json.loads(call(['docker', 'image', 'inspect', IMAGE]).stdout)[0]
assert image['Id'] == IMAGE.split('@')[1]
assert image['RepoDigests'] == [IMAGE] and image['Descriptor']['digest'] == IMAGE.split('@')[1]
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert digest(json.dumps(image['Config'], sort_keys=True, separators=(',', ':')).encode()) == 'c88782b528aee2a1b7804cd62cb95afac9df8c5b2f89c471924c6c1085c63b62'
return image
engine()
image = image_identity()
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert image['Config']['Labels']['org.opencontainers.image.revision'] == REVISION
assert image['Config']['Labels']['dev.durable-workflow.release.tag'] == '3.10.0'
assert image['Config']['Entrypoint'] == ['/usr/local/bin/durable-workflow-server']
nonce = secrets.token_hex(16)
name = 'sdk-rust-417-logging-' + nonce[:12]
labels = {'owner': 'sdk-rust', 'task': 'logger227', 'qualification_nonce': nonce}
label_args = [argument for key, value in labels.items() for argument in ('--label', key + '=' + value)]
token = 'fixture-' + secrets.token_hex(24)
key = 'base64:' + base64.b64encode(secrets.token_bytes(32)).decode()
container_id = network_id = None
process = None
result = {'outcome': 'fail', 'build_receipt_sha256': RECEIPT,
'binary_sha256': BINARY, 'server_manifest': IMAGE, 'server_source': REVISION,
'started_at': time.time(), 'limits': {'consumer_cpus': 2, 'consumer_as': 2147483648,
'consumer_cpu_seconds': 60, 'consumer_wall_seconds': 180}}
def owned(kind, identity):
value = json.loads(call(['docker', kind, 'inspect', identity]).stdout)[0]
actual = value['Config']['Labels'] if kind == 'container' else value['Labels']
assert value['Id'] == identity and all(actual.get(k) == v for k, v in labels.items())
return value
def full_id(raw):
identity = raw.decode('ascii').strip()
assert re.fullmatch('[0-9a-f]{64}', identity), 'uncertain create reply'
return identity
def reconcile_created(kind, identity):
if identity is not None:
assert re.fullmatch('[0-9a-f]{64}', identity)
return identity
filters = [arg for key, val in labels.items() for arg in ('--filter', 'label=' + key + '=' + val)]
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
candidates = call(query + filters).stdout.split()
assert len(candidates) <= 1
if candidates:
recovered = full_id(candidates[0])
owned(kind, recovered)
return recovered
return None
def remove_resource(kind, identity):
value = owned(kind, identity)
call(['docker', 'rm', '-f', '-v', identity] if kind == 'container'
else ['docker', 'network', 'rm', identity])
observed = call(['docker', kind, 'inspect', identity], check=False)
missing = ('no such container: ' + identity if kind == 'container'
else 'network ' + identity + ' not found').encode()
assert observed.returncode != 0 and json.loads(observed.stdout) == []
assert missing in observed.stderr.lower()
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
assert call(query + ['--filter', 'id=' + identity]).stdout.strip() == b''
return value
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args):
raise AssertionError('redirect refused')
def consumer_limits():
os.sched_setaffinity(0, sorted(os.sched_getaffinity(0))[:2])
resource.setrlimit(resource.RLIMIT_AS, (2 * 1024**3, 2 * 1024**3))
resource.setrlimit(resource.RLIMIT_CPU, (60, 60))
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
def validate_network(value, runtime=None):
assert value['Driver'] == 'bridge' and value['Scope'] == 'local'
assert value['Internal'] is False and value['Ingress'] is False and value['Attachable'] is False
assert value['EnableIPv6'] is False
assert value['Options'] == {
'com.docker.network.bridge.enable_ip_masquerade': 'false',
'com.docker.network.bridge.enable_icc': 'false'}
assert set(value.get('Containers') or {}) <= ({runtime} if runtime else set())
def validate_container(value, image, network, name, command, labels, tmpfs):
assert value['Image'] == image['Id']
config, host = value['Config'], value['HostConfig']
expected_env = dict(entry.split('=', 1) for entry in image['Config']['Env'])
expected_env.update(DB_CONNECTION='sqlite', DB_DATABASE='/app/database/runtime.sqlite',
DW_RUST_MAINTENANCE_LOOP='1')
assert len(config['Env']) == len(expected_env)
assert dict(entry.split('=', 1) for entry in config['Env']) == expected_env
assert config['Image'] == IMAGE and config['Entrypoint'] == ['/bin/sh'] and config['Cmd'] == command
assert config['Hostname'] == name and config['User'] == '1000:1000'
assert config['WorkingDir'] == '/app' and config['StopSignal'] == 'SIGTERM'
assert config['Volumes'] == image['Config']['Volumes']
assert config['ExposedPorts'] == {'8080/tcp': {}}
assert config['Labels'] == dict(image['Config']['Labels'], **labels)
assert not config['Tty'] and not config['OpenStdin']
expected = {'ReadonlyRootfs': True, 'Init': True, 'Privileged': False,
'NanoCpus': 10**9, 'Memory': 1024**3, 'MemorySwap': 1024**3, 'PidsLimit': 256,
'CapAdd': None, 'CapDrop': ['ALL'], 'SecurityOpt': ['no-new-privileges'],
'NetworkMode': network, 'Binds': None, 'Tmpfs': tmpfs,
'PortBindings': {'8080/tcp': [{'HostIp': '127.0.0.1', 'HostPort': ''}]},
'PidMode': '', 'UTSMode': '', 'UsernsMode': '', 'IpcMode': 'private',
'Devices': [], 'DeviceRequests': None, 'VolumesFrom': None, 'ExtraHosts': None,
'AutoRemove': False, 'RestartPolicy': {'Name': 'no', 'MaximumRetryCount': 0}}
assert all(host.get(key) == val for key, val in expected.items())
assert 'OomKillDisable' in host and host['OomKillDisable'] in (False, None)
assert not host.get('Mounts')
assert all(m['Type'] == 'tmpfs' and m['Destination'] in tmpfs for m in value['Mounts'])
packet = json.loads(json.dumps({k: value[k] for k in ('Image', 'Config', 'HostConfig', 'Mounts')}))
# Docker29 changes this unset/false default during start. Both retain the
# kernel OOM killer; true is refused. Every other field remains exact.
packet['HostConfig']['OomKillDisable'] = False
return digest(json.dumps(packet, sort_keys=True, separators=(',', ':')).encode())
tmpfs = {'/tmp': 'mode=1777,size=64m',
'/app/database': 'uid=1000,gid=1000,mode=0700,size=64m',
'/app/storage': 'uid=1000,gid=1000,mode=0700,size=64m',
'/credentials': 'uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev'}
command = None
created_config = None
try:
engine()
image_identity()
network_id = full_id(call(['docker', 'network', 'create', '--driver', 'bridge',
'--opt', 'com.docker.network.bridge.enable_ip_masquerade=false',
'--opt', 'com.docker.network.bridge.enable_icc=false'] + label_args + [name]).stdout)
validate_network(owned('network', network_id))
deadline = str(int(time.time()) + 240)
command = runtime_command(supervisor_bytes, deadline)
engine()
image_identity()
container_id = full_id(call(['docker', 'create', '--pull=never', '--init', '--name', name,
'--hostname', name] + label_args + [
'--cpus', '1', '--memory', '1g', '--memory-swap', '1g', '--pids-limit', '256', '--read-only', '--user', '1000:1000',
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--network', network_id,
'--publish', '127.0.0.1::8080', '--tmpfs', '/tmp:mode=1777,size=64m',
'--tmpfs', '/app/database:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/app/storage:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/credentials:uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev',
'--env', 'DB_CONNECTION=sqlite', '--env', 'DB_DATABASE=/app/database/runtime.sqlite',
'--env', 'DW_RUST_MAINTENANCE_LOOP=1', '--entrypoint', '/bin/sh', IMAGE] + command).stdout)
before = owned('container', container_id)
output(root_fd, evidence['container-created.json'], 'container-created.json',
(json.dumps(before, indent=2) + '\n').encode())
result['container_id'], result['network_id'] = container_id, network_id
created_config = validate_container(before, image, network_id, name, command, labels, tmpfs)
validate_network(owned('network', network_id), container_id)
result['created_config_sha256'] = created_config
engine()
image_identity()
assert validate_container(owned('container', container_id), image, network_id,
name, command, labels, tmpfs) == created_config
call(['docker', 'start', container_id])
started = owned('container', container_id)
output(root_fd, evidence['container-started.json'], 'container-started.json',
(json.dumps(started, indent=2) + '\n').encode())
assert validate_container(started, image, network_id,
name, command, labels, tmpfs) == created_config
validate_network(owned('network', network_id), container_id)
call(['docker', 'exec', '-i', container_id, '/bin/sh', '-c',
'umask 077; IFS= read -r token && IFS= read -r key && '
'printf %s "$token" > /credentials/token && printf %s "$key" > /credentials/server-key && '
': > /credentials/ready.tmp && mv /credentials/ready.tmp /credentials/ready'],
input=(token + '\n' + key + '\n').encode())
live = owned('container', container_id)
ports = live['NetworkSettings']['Ports']['8080/tcp']
assert len(ports) == 1 and ports[0]['HostIp'] == '127.0.0.1'
port = int(ports[0]['HostPort'])
assert 0 < port < 65536
origin = 'http://127.0.0.1:' + str(port)
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
for attempt in range(60):
try:
request = urllib.request.Request(origin + '/api/cluster/info',
headers={'Authorization': 'Bearer ' + token, 'X-Namespace': 'default'})
with opener.open(request, timeout=1) as response:
cluster = json.load(response)
assert cluster['version'] == '3.10.0'
result['cluster_info'] = cluster
break
except (urllib.error.URLError, ConnectionError):
time.sleep(.25)
else:
raise AssertionError('runtime readiness bound expired')
args = ['/proc/self/fd/' + str(fd), '--ignored', '--exact',
'published_logging_emits_once_per_committed_step_across_cold_worker_processes',
'--nocapture', '--test-threads=1']
env = {'DURABLE_WORKFLOW_LOCAL_ISOLATED': '1', 'DURABLE_WORKFLOW_SERVER_URL': origin,
'DURABLE_WORKFLOW_AUTH_TOKEN': token, 'DURABLE_WORKFLOW_EXPECT_SERVER_VERSION': '3.10.0'}
process = subprocess.Popen(args, env=env, pass_fds=(fd,), start_new_session=True,
preexec_fn=consumer_limits, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate(timeout=180)
assert len(stdout) + len(stderr) <= 1024**2
assert all(secret.encode() not in stdout + stderr for secret in (token, key))
output(root_fd, evidence['logging.stdout'], 'logging.stdout', stdout)
output(root_fd, evidence['logging.stderr'], 'logging.stderr', stderr)
result['parent_pid'], result['exit_code'] = process.pid, process.returncode
assert process.returncode == 0, 'logging parent failed'
assert b'PASS: four cold worker processes' in stdout
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
engine()
image_identity()
returned = owned('container', container_id)
output(root_fd, evidence['container-returned.json'], 'container-returned.json',
(json.dumps(returned, indent=2) + '\n').encode())
assert validate_container(returned, image, network_id,
name, command, labels, tmpfs) == created_config
validate_network(owned('network', network_id), container_id)
result['outcome'] = 'pass'
except BaseException as error:
result['error'] = type(error).__name__
raise
finally:
if process is not None:
try:
os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:
pass
process.wait(timeout=10)
os.close(fd)
errors = []
# Recover only this exact nonce/owner if an uncertain create returned no ID.
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity is None:
try:
recovered = reconcile_created(kind, identity)
if kind == 'container':
container_id = recovered
else:
network_id = recovered
except Exception as error:
errors.append(type(error).__name__)
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity:
try:
value = remove_resource(kind, identity)
if kind == 'container':
result['runtime_oom'] = value['State']['OOMKilled']
if result['runtime_oom']:
result['outcome'] = 'fail'
except Exception as error:
errors.append(type(error).__name__)
result['cleanup'] = {'pass': not errors, 'errors': errors}
if errors:
result['outcome'] = 'fail'
result['finished_at'] = time.time()
named_root = ROOT.stat(follow_symlinks=False)
assert (named_root.st_dev, named_root.st_ino) == (root_info.st_dev, root_info.st_ino)
output(root_fd, evidence['logging-result.json'], 'logging-result.json',
(json.dumps(result, indent=2) + '\n').encode())
for descriptor in evidence.values():
os.close(descriptor)
os.close(config_fd)
os.close(root_fd)
assert not errors, errors
print(json.dumps(result)) |
|
Full source controls SHA256 import ast
import copy
import hashlib
import os
import pathlib
import re
import stat
import subprocess
import sys
import tempfile
import time
import unittest
from unittest import mock
SOURCE = pathlib.Path(sys.argv[1])
SUPERVISOR = pathlib.Path(sys.argv[2])
sys.argv = sys.argv[:1]
module = ast.parse(SOURCE.read_text())
keep = {'digest', 'directory', 'read_at', 'exclusive', 'output', 'runtime_command', 'docker_command', 'call', 'validate_network', 'validate_container', 'full_id', 'reconcile_created', 'remove_resource', 'owned'}
ns = {'pathlib': pathlib, 'os': os, 'stat': stat, 'hashlib': hashlib, 'subprocess': subprocess,
'json': __import__('json'), 're': re, 'CLOSED_ENV': {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'},
'IMAGE': 'synthetic-image'}
exec(compile(ast.Module(body=[node for node in module.body if isinstance(node, ast.FunctionDef) and node.name in keep], type_ignores=[]), str(SOURCE), 'exec'), ns)
class Controls(unittest.TestCase):
def test_supervisor_replacement_discriminates_predecessor(self):
script = SUPERVISOR.read_bytes()
self.assertEqual(hashlib.sha256(script).hexdigest(), '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b')
with tempfile.TemporaryDirectory() as tmp:
path = pathlib.Path(tmp) / 'supervisor'
path.write_bytes(script)
captured = path.read_bytes()
command = ns['runtime_command'](captured, int(time.time()) + 10)
command[-2:] = ['none', '/bin/echo', 'ORIGINAL']
path.write_text('printf SUBSTITUTED')
predecessor = subprocess.check_output(['/bin/sh', str(path), '10', '10', 'none', '/bin/echo', 'ORIGINAL'])
self.assertEqual(predecessor, b'SUBSTITUTED')
self.assertEqual(subprocess.check_output(['/bin/sh'] + command), b'ORIGINAL\n')
self.assertNotIn(str(path), command)
def test_exclusive_output_refuses_symlink(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp)
marker = root / 'marker'; marker.write_bytes(b'unchanged')
(root / 'logging.stdout').symlink_to(marker)
(root / 'logging.stdout').write_bytes(b'PREDECESSOR')
self.assertEqual(marker.read_bytes(), b'PREDECESSOR')
marker.write_bytes(b'unchanged')
fd = ns['directory'](root)
try:
with self.assertRaises(FileExistsError): ns['exclusive'](fd, 'logging.stdout')
self.assertEqual(marker.read_bytes(), b'unchanged')
finally: os.close(fd)
def test_output_replacement_refuses_before_foreign_write(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp); fd = ns['directory'](root)
out = ns['exclusive'](fd, 'logging.stdout')
try:
self.assertEqual(stat.S_IMODE(os.fstat(out).st_mode), 0o600)
(root / 'logging.stdout').rename(root / 'held')
marker = root / 'marker'; marker.write_bytes(b'unchanged')
(root / 'logging.stdout').symlink_to(marker)
with self.assertRaises(AssertionError): ns['output'](fd, out, 'logging.stdout', b'bad')
self.assertEqual(marker.read_bytes(), b'unchanged')
finally: os.close(out); os.close(fd)
def test_input_and_root_links_refused(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp); (root / 'alias').symlink_to(root, target_is_directory=True)
with self.assertRaises(OSError): ns['directory'](root / 'alias')
fd = ns['directory'](root)
try:
(root / 'value').write_bytes(b'expected'); (root / 'link').symlink_to(root / 'value')
with self.assertRaises(OSError): ns['read_at'](fd, 'link')
self.assertEqual(ns['read_at'](fd, 'value'), b'expected')
finally: os.close(fd)
def test_effectful_tool_and_environment_are_closed(self):
configpath = '/proc/' + str(os.getpid()) + '/fdinfo'
configfd = os.open(configpath, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
ns.update(config_fd=configfd, config_path=configpath, config_info=os.fstat(configfd))
captured = []
def fake(*args, **kwargs):
# Runs after call validation, just before the consumer would open config.
with self.assertRaises(OSError):
opened = os.open('config.json', os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600, dir_fd=configfd)
os.close(opened)
self.assertFalse(os.path.lexists(pathlib.Path(configpath) / 'config.json'))
captured.append((args, kwargs)); return object()
try:
with mock.patch.dict(os.environ, {'PATH': '/synthetic-untrusted', 'DOCKER_HOST': 'tcp://wrong', 'DOCKER_CONFIG': '/wrong', 'DOCKER_CONTEXT': 'wrong'}):
with mock.patch.object(subprocess, 'run', side_effect=fake): ns['call'](['docker', 'create', '--pull=never'])
args, kwargs = captured[0]
self.assertEqual(args[0][:3], ['/usr/bin/docker', '--host', 'unix:///run/docker.sock'])
self.assertEqual(kwargs['env'], ns['CLOSED_ENV'])
self.assertEqual(kwargs['pass_fds'], (configfd,))
self.assertEqual(kwargs['cwd'], '/')
self.assertNotIn('DOCKER_HOST', kwargs['env'])
finally: os.close(configfd)
def test_predecessor_config_changes_between_check_and_open(self):
with tempfile.TemporaryDirectory() as tmp:
path = pathlib.Path(tmp) / 'config.json'; path.write_text('{}\n')
before = path.stat()
self.assertEqual(path.read_text(), '{}\n')
# The old validation has completed; a writer changes the same inode.
path.write_text('{"credsStore":"synthetic"}')
self.assertEqual(path.stat().st_ino, before.st_ino)
self.assertEqual(path.read_text(), '{"credsStore":"synthetic"}')
def test_uncertain_network_and_container_replies_recover_full_id(self):
from types import SimpleNamespace
for kind in ('network', 'container'):
for reply in (b'', b'not-an-id', b'A' * 64, b'\xff'):
with self.subTest(kind=kind, reply=reply):
identity = 'a' * 64
labels = {'owner':'sdk-rust','task':'logger227','qualification_nonce':'synthetic-nonce'}
present = {identity}; operations = []
def fake(args, **kwargs):
operations.append(args)
if 'inspect' in args:
selected = args[-1]
if selected not in present:
message = ('No such container: '+selected if kind=='container' else 'network '+selected+' not found').encode()
return SimpleNamespace(returncode=1, stderr=message, stdout=b'[]\n')
value={'Id':selected,'Config':{'Labels':labels},'Labels':labels,'State':{'OOMKilled':False}}
return SimpleNamespace(returncode=0, stderr=b'', stdout=ns['json'].dumps([value]).encode())
if 'rm' in args:
self.assertEqual(args[-1], identity); present.remove(identity)
return SimpleNamespace(returncode=0, stderr=b'', stdout=identity.encode())
if 'id='+identity in args:
return SimpleNamespace(returncode=0, stderr=b'', stdout=(identity.encode() if present else b''))
for key,val in labels.items():self.assertIn('label='+key+'='+val, args)
self.assertIn('--no-trunc', args)
return SimpleNamespace(returncode=0, stderr=b'', stdout=(identity+'\n').encode())
old_identity = reply.decode('ascii', errors='replace').strip()
self.assertIsNotNone(old_identity) # Old is-None recovery skips every reply.
granted = None
with self.assertRaises((AssertionError,UnicodeError)):
granted = ns['full_id'](reply)
self.assertIsNone(granted)
with mock.patch.dict(ns, {'labels':labels,'call':fake}):
recovered=ns['reconcile_created'](kind,granted)
self.assertEqual(recovered,identity)
ns['remove_resource'](kind,recovered)
self.assertEqual(present,set())
self.assertIn('id='+identity,operations[-1])
def test_configuration_mutations_are_refused(self):
image = {'Id': 'synthetic-id', 'Config': {'Env': ['PATH=/usr/bin'], 'Labels': {}, 'Volumes': {'/app/database': {}, '/app/storage': {}}}}
command = ['-c', 'captured']; tmpfs = {'/tmp': 'size=64m'}
config = {'Env': ['PATH=/usr/bin', 'DB_CONNECTION=sqlite', 'DB_DATABASE=/app/database/runtime.sqlite', 'DW_RUST_MAINTENANCE_LOOP=1'],
'Image':'synthetic-image','Entrypoint':['/bin/sh'],'Cmd':command,'Hostname':'owned','User':'1000:1000','WorkingDir':'/app','StopSignal':'SIGTERM',
'Volumes': image['Config']['Volumes'],'ExposedPorts':{'8080/tcp':{}},'Labels':{'owner':'sdk-rust'},'Tty':False,'OpenStdin':False}
host = {'ReadonlyRootfs':True,'Init':True,'Privileged':False,'NanoCpus':10**9,'Memory':1024**3,'MemorySwap':1024**3,'PidsLimit':256,
'CapAdd':None,'CapDrop':['ALL'],'SecurityOpt':['no-new-privileges'],'NetworkMode':'network-id','Binds':None,'Tmpfs':tmpfs,
'PortBindings':{'8080/tcp':[{'HostIp':'127.0.0.1','HostPort':''}]},'PidMode':'','UTSMode':'','UsernsMode':'','IpcMode':'private',
'Devices':[],'DeviceRequests':None,'VolumesFrom':None,'ExtraHosts':None,'AutoRemove':False,'OomKillDisable':False,'RestartPolicy':{'Name':'no','MaximumRetryCount':0}}
value={'Image':'synthetic-id','Config':config,'HostConfig':host,'Mounts':[]}
check=lambda v: ns['validate_container'](v,image,'network-id','owned',command,{'owner':'sdk-rust'},tmpfs)
check(value)
started=copy.deepcopy(value);started['HostConfig']['OomKillDisable']=None
self.assertEqual(check(value),check(started))
mutations=[('Image',None,'wrong'),('Config','Cmd',['wrong']),('Config','Env',config['Env']+['INJECTED=yes']),('Config','Labels',{}),
('HostConfig','Privileged',True),('HostConfig','NanoCpus',0),('HostConfig','Memory',0),('HostConfig','ReadonlyRootfs',False),
('HostConfig','Binds',['synthetic:/app']),('HostConfig','NetworkMode','host'),('HostConfig','SecurityOpt',[]),('HostConfig','OomKillDisable',True),('Mounts',None,[{'Type':'bind','Destination':'/app'}])]
for group,key,new in mutations:
with self.subTest(field=(group,key)):
changed=copy.deepcopy(value)
if key is None:changed[group]=new
else:changed[group][key]=new
with self.assertRaises(AssertionError):check(changed)
def test_network_profile_refuses_wrong_routing_or_attachment(self):
value={'Driver':'bridge','Scope':'local','Internal':False,'Ingress':False,'Attachable':False,'EnableIPv6':False,
'Options':{'com.docker.network.bridge.enable_ip_masquerade':'false','com.docker.network.bridge.enable_icc':'false'},'Containers':{}}
ns['validate_network'](value)
value['Containers']={'owned-runtime':{}}
ns['validate_network'](value,'owned-runtime')
for key,bad in [('Internal',True),('Driver','host'),('Attachable',True),('Containers',{'foreign':{}}),('Options',{})]:
with self.subTest(field=key):
changed=copy.deepcopy(value);changed[key]=bad
with self.assertRaises(AssertionError):ns['validate_network'](changed,'owned-runtime')
unittest.main() |
|
Security review of frozen network-profile successor Independent checks:
This is acceptable only for this manual exact-package observation because the sealed host consumer requires loopback and the runtime receives no selected external request path or non-synthetic credential. It is not approval of this bridge as a reusable ordinary-CI profile. Both prior launcher results remain NONPASS. Authorize one unchanged-input attempt using the existing receipt/parent/package/test/build identities and the reviewed bootstrap. No tag, upload, package, reusable runner or broader Server/SDK acceptance is inferred. |
|
The third92dd attempt remains runner-blocked/NONPASS after owned network creation only. Its strict Options equality refused the daemon-supplied The complete metadata preflight now runs the actual profile validators against the exact cached native image while overriding its command to fixed sleep20, so no Server/SDK code or credential is involved. It passed exact network validation and all three create/start/return container projections; full0600 snapshots are retained. Inert container Frozen corrected controller Literal bootstrap: /usr/bin/python3 -I -c 'import hashlib,pathlib,sys; p=pathlib.Path(sys.argv[1]); b=p.read_bytes(); assert hashlib.sha256(b).hexdigest()=="04f9c0391e1670e67e757e0c16bca1c204ed557a345a483ec43c398c77a7c841"; sys.argv=sys.argv[1:]; exec(compile(b,str(p),"exec"),{"__name__":"__main__"})' <controller.py> <prepared-consumer-r4-root> <accepted-source-checkout>"""One fixed candidate observation; public review packet contains these bytes."""
import base64
import fcntl
import hashlib
import json
import os
import pathlib
import resource
import re
import secrets
import signal
import stat
import subprocess
import sys
import time
import urllib.error
import urllib.request
ROOT = pathlib.Path(sys.argv[1]).absolute()
SOURCE = pathlib.Path(sys.argv[2]).absolute()
IMAGE = 'ghcr.io/durable-workflow/server@sha256:9d64e9aeee84b46d21715826a3e7e5a96eb8d4ce7fccb126b88b15596ab14973'
REVISION = 'b6e04ce7e679464e91f6ceae83310d3bb3204092'
RECEIPT = '6f197812e8218fc44d513bfa1040b91b19fe168367c70e53e16882b0db13fe79'
BINARY = '89ae4f0fdea91e503d8b7e80426e7160259e324520341b2f325d7aed5edfb8b1'
TEST = '6d7b08d138fc13f9b513ce80c51a40fbec85beeb015e3a631598e7f8cdce4398'
def digest(data):
return hashlib.sha256(data).hexdigest()
def directory(path):
assert path.is_absolute() and '..' not in path.parts
current = os.open('/', os.O_RDONLY | os.O_DIRECTORY)
try:
for part in path.parts[1:]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=current)
os.close(current)
current = following
return current
except BaseException:
os.close(current)
raise
def read_at(root, relative):
parts = pathlib.PurePosixPath(relative).parts
assert parts and not relative.startswith('/') and '..' not in parts
parent = os.dup(root)
try:
for part in parts[:-1]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=parent)
os.close(parent)
parent = following
fd = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=parent)
try:
info = os.fstat(fd)
assert stat.S_ISREG(info.st_mode) and info.st_nlink == 1 and info.st_uid == os.getuid()
assert info.st_size <= 64 * 1024**2
value = os.pread(fd, info.st_size + 1, 0)
after = os.fstat(fd)
fields = ('st_dev', 'st_ino', 'st_size', 'st_uid', 'st_gid', 'st_mode',
'st_nlink', 'st_mtime_ns', 'st_ctime_ns')
assert len(value) == info.st_size
assert all(getattr(info, field) == getattr(after, field) for field in fields)
return value
finally:
os.close(fd)
finally:
os.close(parent)
def exclusive(root, name):
assert '/' not in name and name not in ('', '.', '..')
return os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW,
0o600, dir_fd=root)
def output(root, fd, name, value):
before = os.fstat(fd)
named = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (named.st_dev, named.st_ino) == (before.st_dev, before.st_ino)
assert stat.S_ISREG(named.st_mode) and stat.S_IMODE(named.st_mode) == 0o600
assert named.st_uid == os.getuid() and named.st_nlink == 1
with os.fdopen(os.dup(fd), 'wb') as handle:
handle.write(value)
handle.flush()
after = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (after.st_dev, after.st_ino, after.st_nlink) == (before.st_dev, before.st_ino, 1)
root_fd = directory(ROOT)
root_info = os.fstat(root_fd)
assert root_info.st_uid == os.getuid() and stat.S_IMODE(root_info.st_mode) == 0o700
receipt_bytes = read_at(root_fd, 'build-receipt.json')
assert digest(receipt_bytes) == RECEIPT
receipt = json.loads(receipt_bytes)
assert receipt['executable_sha256'] == BINARY
assert digest(read_at(root_fd, 'fixture/tests/workflow_logging_server.rs')) == TEST
assert digest(read_at(root_fd, 'fixture/Cargo.lock')) == receipt['lock_sha256']
assert digest(read_at(root_fd, 'fixture/Cargo.toml')) == receipt['manifest_sha256']
assert digest(read_at(root_fd, 'fixture/logging-build.jsonl')) == receipt['build_messages_sha256']
binary_bytes = read_at(root_fd, receipt['executable_relative'])
assert len(binary_bytes) == receipt['executable_bytes']
assert digest(binary_bytes) == BINARY
fd = os.memfd_create('reviewed-logging-parent', os.MFD_ALLOW_SEALING)
with os.fdopen(os.dup(fd), 'wb') as image_file:
image_file.write(binary_bytes)
os.fchmod(fd, 0o500)
seals = fcntl.F_SEAL_WRITE | fcntl.F_SEAL_GROW | fcntl.F_SEAL_SHRINK | fcntl.F_SEAL_SEAL
fcntl.fcntl(fd, fcntl.F_ADD_SEALS, seals)
assert fcntl.fcntl(fd, fcntl.F_GET_SEALS) == seals
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
supervisor = SOURCE / 'scripts/acceptance/installed-native/cell-supervisor.sh'
source_fd = directory(SOURCE)
supervisor_bytes = read_at(source_fd, 'scripts/acceptance/installed-native/cell-supervisor.sh')
os.close(source_fd)
assert digest(supervisor_bytes) == '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b'
def runtime_command(script, deadline):
script = script.decode()
original = ' /bin/sh "$0" --command "$@"'
assert script.count(original) == 1
wrapper = 'supervisor=$1\nshift\n' + script.replace(original,
' /bin/sh -c "$supervisor" supervisor --command "$@"')
return ['-c', wrapper, 'supervisor', script, str(deadline), '10', 'both',
'/usr/local/bin/durable-workflow-server']
# procfs fdinfo admits only kernel-created decimal descriptor names. A same-UID
# writer cannot create config.json, contexts or plugin paths in this namespace.
config_path = '/proc/' + str(os.getpid()) + '/fdinfo'
config_fd = os.open(config_path, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
config_info = os.fstat(config_fd)
evidence = {name: exclusive(root_fd, name) for name in
('logging.stdout', 'logging.stderr', 'logging-result.json',
'container-created.json', 'container-started.json', 'container-returned.json',
'network-created.json', 'network-returned.json')}
CLOSED_ENV = {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'}
def docker_command(args, config):
assert args[0] == 'docker'
return ['/usr/bin/docker', '--host', 'unix:///run/docker.sock', '--config',
'/proc/self/fd/' + str(config)] + args[1:]
def call(args, **kwargs):
tool = os.stat('/usr/bin/docker', follow_symlinks=False)
assert stat.S_ISREG(tool.st_mode) and tool.st_uid == 0 and tool.st_nlink == 1
assert stat.S_IMODE(tool.st_mode) == 0o755
assert digest(pathlib.Path('/usr/bin/docker').read_bytes()) == '40cdaf7fd0f21089dd9e15b0c3a7dd7f2399027f010e366dac6304ae0615954a'
assert all(name.isdecimal() for name in os.listdir(config_fd))
config_named = os.stat(config_path, follow_symlinks=False)
config_open = os.fstat(config_fd)
assert (config_named.st_dev, config_named.st_ino) == (config_info.st_dev, config_info.st_ino)
assert (config_open.st_dev, config_open.st_ino) == (config_info.st_dev, config_info.st_ino)
kwargs.setdefault('check', True)
return subprocess.run(docker_command(args, config_fd), capture_output=True, timeout=30,
cwd='/', env=CLOSED_ENV, pass_fds=(config_fd,), **kwargs)
socket_info = os.stat('/run/docker.sock', follow_symlinks=False)
assert stat.S_ISSOCK(socket_info.st_mode) and socket_info.st_uid == 0
def engine():
current = os.stat('/run/docker.sock', follow_symlinks=False)
assert (current.st_dev, current.st_ino, current.st_uid, current.st_gid, current.st_mode) == (
socket_info.st_dev, socket_info.st_ino, socket_info.st_uid, socket_info.st_gid, socket_info.st_mode)
identity = call(['docker', 'info', '--format', '{{.ID}}']).stdout.strip()
assert digest(identity) == '0a179ff32531e41cfc2d465b1d46afc1df91c0975e9627969f75c67e00b0e892'
def image_identity():
image = json.loads(call(['docker', 'image', 'inspect', IMAGE]).stdout)[0]
assert image['Id'] == IMAGE.split('@')[1]
assert image['RepoDigests'] == [IMAGE] and image['Descriptor']['digest'] == IMAGE.split('@')[1]
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert digest(json.dumps(image['Config'], sort_keys=True, separators=(',', ':')).encode()) == 'c88782b528aee2a1b7804cd62cb95afac9df8c5b2f89c471924c6c1085c63b62'
return image
engine()
image = image_identity()
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert image['Config']['Labels']['org.opencontainers.image.revision'] == REVISION
assert image['Config']['Labels']['dev.durable-workflow.release.tag'] == '3.10.0'
assert image['Config']['Entrypoint'] == ['/usr/local/bin/durable-workflow-server']
nonce = secrets.token_hex(16)
name = 'sdk-rust-417-logging-' + nonce[:12]
labels = {'owner': 'sdk-rust', 'task': 'logger227', 'qualification_nonce': nonce}
label_args = [argument for key, value in labels.items() for argument in ('--label', key + '=' + value)]
token = 'fixture-' + secrets.token_hex(24)
key = 'base64:' + base64.b64encode(secrets.token_bytes(32)).decode()
container_id = network_id = None
process = None
result = {'outcome': 'fail', 'build_receipt_sha256': RECEIPT,
'binary_sha256': BINARY, 'server_manifest': IMAGE, 'server_source': REVISION,
'started_at': time.time(), 'limits': {'consumer_cpus': 2, 'consumer_as': 2147483648,
'consumer_cpu_seconds': 60, 'consumer_wall_seconds': 180}}
def owned(kind, identity):
value = json.loads(call(['docker', kind, 'inspect', identity]).stdout)[0]
actual = value['Config']['Labels'] if kind == 'container' else value['Labels']
assert value['Id'] == identity and all(actual.get(k) == v for k, v in labels.items())
return value
def full_id(raw):
identity = raw.decode('ascii').strip()
assert re.fullmatch('[0-9a-f]{64}', identity), 'uncertain create reply'
return identity
def reconcile_created(kind, identity):
if identity is not None:
assert re.fullmatch('[0-9a-f]{64}', identity)
return identity
filters = [arg for key, val in labels.items() for arg in ('--filter', 'label=' + key + '=' + val)]
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
candidates = call(query + filters).stdout.split()
assert len(candidates) <= 1
if candidates:
recovered = full_id(candidates[0])
owned(kind, recovered)
return recovered
return None
def remove_resource(kind, identity):
value = owned(kind, identity)
call(['docker', 'rm', '-f', '-v', identity] if kind == 'container'
else ['docker', 'network', 'rm', identity])
observed = call(['docker', kind, 'inspect', identity], check=False)
missing = ('no such container: ' + identity if kind == 'container'
else 'network ' + identity + ' not found').encode()
assert observed.returncode != 0 and json.loads(observed.stdout) == []
assert missing in observed.stderr.lower()
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
assert call(query + ['--filter', 'id=' + identity]).stdout.strip() == b''
return value
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args):
raise AssertionError('redirect refused')
def consumer_limits():
os.sched_setaffinity(0, sorted(os.sched_getaffinity(0))[:2])
resource.setrlimit(resource.RLIMIT_AS, (2 * 1024**3, 2 * 1024**3))
resource.setrlimit(resource.RLIMIT_CPU, (60, 60))
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
def validate_network(value, runtime=None):
assert value['Driver'] == 'bridge' and value['Scope'] == 'local'
assert value['Internal'] is False and value['Ingress'] is False and value['Attachable'] is False
assert value['EnableIPv6'] is False
assert value['Options'] == {
'com.docker.network.bridge.enable_ip_masquerade': 'false',
'com.docker.network.bridge.enable_icc': 'false',
'com.docker.network.bridge.host_binding_ipv4': '127.0.0.1'}
assert set(value.get('Containers') or {}) <= ({runtime} if runtime else set())
def validate_container(value, image, network, name, command, labels, tmpfs):
assert value['Image'] == image['Id']
config, host = value['Config'], value['HostConfig']
expected_env = dict(entry.split('=', 1) for entry in image['Config']['Env'])
expected_env.update(DB_CONNECTION='sqlite', DB_DATABASE='/app/database/runtime.sqlite',
DW_RUST_MAINTENANCE_LOOP='1')
assert len(config['Env']) == len(expected_env)
assert dict(entry.split('=', 1) for entry in config['Env']) == expected_env
assert config['Image'] == IMAGE and config['Entrypoint'] == ['/bin/sh'] and config['Cmd'] == command
assert config['Hostname'] == name and config['User'] == '1000:1000'
assert config['WorkingDir'] == '/app' and config['StopSignal'] == 'SIGTERM'
assert config['Volumes'] == image['Config']['Volumes']
assert config['ExposedPorts'] == {'8080/tcp': {}}
assert config['Labels'] == dict(image['Config']['Labels'], **labels)
assert not config['Tty'] and not config['OpenStdin']
expected = {'ReadonlyRootfs': True, 'Init': True, 'Privileged': False,
'NanoCpus': 10**9, 'Memory': 1024**3, 'MemorySwap': 1024**3, 'PidsLimit': 256,
'CapAdd': None, 'CapDrop': ['ALL'], 'SecurityOpt': ['no-new-privileges'],
'NetworkMode': network, 'Binds': None, 'Tmpfs': tmpfs,
'PortBindings': {'8080/tcp': [{'HostIp': '127.0.0.1', 'HostPort': ''}]},
'PidMode': '', 'UTSMode': '', 'UsernsMode': '', 'IpcMode': 'private',
'Devices': [], 'DeviceRequests': None, 'VolumesFrom': None, 'ExtraHosts': None,
'AutoRemove': False, 'RestartPolicy': {'Name': 'no', 'MaximumRetryCount': 0}}
assert all(host.get(key) == val for key, val in expected.items())
assert 'OomKillDisable' in host and host['OomKillDisable'] in (False, None)
assert not host.get('Mounts')
assert all(m['Type'] == 'tmpfs' and m['Destination'] in tmpfs for m in value['Mounts'])
packet = json.loads(json.dumps({k: value[k] for k in ('Image', 'Config', 'HostConfig', 'Mounts')}))
# Docker29 changes this unset/false default during start. Both retain the
# kernel OOM killer; true is refused. Every other field remains exact.
packet['HostConfig']['OomKillDisable'] = False
return digest(json.dumps(packet, sort_keys=True, separators=(',', ':')).encode())
tmpfs = {'/tmp': 'mode=1777,size=64m',
'/app/database': 'uid=1000,gid=1000,mode=0700,size=64m',
'/app/storage': 'uid=1000,gid=1000,mode=0700,size=64m',
'/credentials': 'uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev'}
command = None
created_config = None
try:
engine()
image_identity()
network_id = full_id(call(['docker', 'network', 'create', '--driver', 'bridge',
'--opt', 'com.docker.network.bridge.enable_ip_masquerade=false',
'--opt', 'com.docker.network.bridge.enable_icc=false',
'--opt', 'com.docker.network.bridge.host_binding_ipv4=127.0.0.1'] + label_args + [name]).stdout)
result['network_id'] = network_id
created_network = owned('network', network_id)
output(root_fd, evidence['network-created.json'], 'network-created.json',
(json.dumps(created_network, indent=2) + '\n').encode())
validate_network(created_network)
deadline = str(int(time.time()) + 240)
command = runtime_command(supervisor_bytes, deadline)
engine()
image_identity()
container_id = full_id(call(['docker', 'create', '--pull=never', '--init', '--name', name,
'--hostname', name] + label_args + [
'--cpus', '1', '--memory', '1g', '--memory-swap', '1g', '--pids-limit', '256', '--read-only', '--user', '1000:1000',
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--network', network_id,
'--publish', '127.0.0.1::8080', '--tmpfs', '/tmp:mode=1777,size=64m',
'--tmpfs', '/app/database:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/app/storage:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/credentials:uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev',
'--env', 'DB_CONNECTION=sqlite', '--env', 'DB_DATABASE=/app/database/runtime.sqlite',
'--env', 'DW_RUST_MAINTENANCE_LOOP=1', '--entrypoint', '/bin/sh', IMAGE] + command).stdout)
result['container_id'] = container_id
before = owned('container', container_id)
output(root_fd, evidence['container-created.json'], 'container-created.json',
(json.dumps(before, indent=2) + '\n').encode())
result['container_id'], result['network_id'] = container_id, network_id
created_config = validate_container(before, image, network_id, name, command, labels, tmpfs)
validate_network(owned('network', network_id), container_id)
result['created_config_sha256'] = created_config
engine()
image_identity()
assert validate_container(owned('container', container_id), image, network_id,
name, command, labels, tmpfs) == created_config
call(['docker', 'start', container_id])
started = owned('container', container_id)
output(root_fd, evidence['container-started.json'], 'container-started.json',
(json.dumps(started, indent=2) + '\n').encode())
assert validate_container(started, image, network_id,
name, command, labels, tmpfs) == created_config
validate_network(owned('network', network_id), container_id)
call(['docker', 'exec', '-i', container_id, '/bin/sh', '-c',
'umask 077; IFS= read -r token && IFS= read -r key && '
'printf %s "$token" > /credentials/token && printf %s "$key" > /credentials/server-key && '
': > /credentials/ready.tmp && mv /credentials/ready.tmp /credentials/ready'],
input=(token + '\n' + key + '\n').encode())
live = owned('container', container_id)
ports = live['NetworkSettings']['Ports']['8080/tcp']
assert len(ports) == 1 and ports[0]['HostIp'] == '127.0.0.1'
port = int(ports[0]['HostPort'])
assert 0 < port < 65536
origin = 'http://127.0.0.1:' + str(port)
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
for attempt in range(60):
try:
request = urllib.request.Request(origin + '/api/cluster/info',
headers={'Authorization': 'Bearer ' + token, 'X-Namespace': 'default'})
with opener.open(request, timeout=1) as response:
cluster = json.load(response)
assert cluster['version'] == '3.10.0'
result['cluster_info'] = cluster
break
except (urllib.error.URLError, ConnectionError):
time.sleep(.25)
else:
raise AssertionError('runtime readiness bound expired')
args = ['/proc/self/fd/' + str(fd), '--ignored', '--exact',
'published_logging_emits_once_per_committed_step_across_cold_worker_processes',
'--nocapture', '--test-threads=1']
env = {'DURABLE_WORKFLOW_LOCAL_ISOLATED': '1', 'DURABLE_WORKFLOW_SERVER_URL': origin,
'DURABLE_WORKFLOW_AUTH_TOKEN': token, 'DURABLE_WORKFLOW_EXPECT_SERVER_VERSION': '3.10.0'}
process = subprocess.Popen(args, env=env, pass_fds=(fd,), start_new_session=True,
preexec_fn=consumer_limits, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate(timeout=180)
assert len(stdout) + len(stderr) <= 1024**2
assert all(secret.encode() not in stdout + stderr for secret in (token, key))
output(root_fd, evidence['logging.stdout'], 'logging.stdout', stdout)
output(root_fd, evidence['logging.stderr'], 'logging.stderr', stderr)
result['parent_pid'], result['exit_code'] = process.pid, process.returncode
assert process.returncode == 0, 'logging parent failed'
assert b'PASS: four cold worker processes' in stdout
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
engine()
image_identity()
returned = owned('container', container_id)
output(root_fd, evidence['container-returned.json'], 'container-returned.json',
(json.dumps(returned, indent=2) + '\n').encode())
assert validate_container(returned, image, network_id,
name, command, labels, tmpfs) == created_config
final_network = owned('network', network_id)
output(root_fd, evidence['network-returned.json'], 'network-returned.json',
(json.dumps(final_network, indent=2) + '\n').encode())
validate_network(final_network, container_id)
result['outcome'] = 'pass'
except BaseException as error:
result['error'] = type(error).__name__
raise
finally:
if process is not None:
try:
os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:
pass
process.wait(timeout=10)
os.close(fd)
errors = []
# Recover only this exact nonce/owner if an uncertain create returned no ID.
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity is None:
try:
recovered = reconcile_created(kind, identity)
if kind == 'container':
container_id = recovered
else:
network_id = recovered
except Exception as error:
errors.append(type(error).__name__)
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity:
try:
value = remove_resource(kind, identity)
if kind == 'container':
result['runtime_oom'] = value['State']['OOMKilled']
if result['runtime_oom']:
result['outcome'] = 'fail'
except Exception as error:
errors.append(type(error).__name__)
result['cleanup'] = {'pass': not errors, 'errors': errors}
if errors:
result['outcome'] = 'fail'
result['finished_at'] = time.time()
named_root = ROOT.stat(follow_symlinks=False)
assert (named_root.st_dev, named_root.st_ino) == (root_info.st_dev, root_info.st_ino)
output(root_fd, evidence['logging-result.json'], 'logging-result.json',
(json.dumps(result, indent=2) + '\n').encode())
for descriptor in evidence.values():
os.close(descriptor)
os.close(config_fd)
os.close(root_fd)
assert not errors, errors
print(json.dumps(result)) |
|
Complete frozen source controls SHA256 import ast
import copy
import hashlib
import os
import pathlib
import re
import stat
import subprocess
import sys
import tempfile
import time
import unittest
from unittest import mock
SOURCE = pathlib.Path(sys.argv[1])
SUPERVISOR = pathlib.Path(sys.argv[2])
sys.argv = sys.argv[:1]
module = ast.parse(SOURCE.read_text())
keep = {'digest', 'directory', 'read_at', 'exclusive', 'output', 'runtime_command', 'docker_command', 'call', 'validate_network', 'validate_container', 'full_id', 'reconcile_created', 'remove_resource', 'owned'}
ns = {'pathlib': pathlib, 'os': os, 'stat': stat, 'hashlib': hashlib, 'subprocess': subprocess,
'json': __import__('json'), 're': re, 'CLOSED_ENV': {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'},
'IMAGE': 'synthetic-image'}
exec(compile(ast.Module(body=[node for node in module.body if isinstance(node, ast.FunctionDef) and node.name in keep], type_ignores=[]), str(SOURCE), 'exec'), ns)
class Controls(unittest.TestCase):
def test_supervisor_replacement_discriminates_predecessor(self):
script = SUPERVISOR.read_bytes()
self.assertEqual(hashlib.sha256(script).hexdigest(), '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b')
with tempfile.TemporaryDirectory() as tmp:
path = pathlib.Path(tmp) / 'supervisor'
path.write_bytes(script)
captured = path.read_bytes()
command = ns['runtime_command'](captured, int(time.time()) + 10)
command[-2:] = ['none', '/bin/echo', 'ORIGINAL']
path.write_text('printf SUBSTITUTED')
predecessor = subprocess.check_output(['/bin/sh', str(path), '10', '10', 'none', '/bin/echo', 'ORIGINAL'])
self.assertEqual(predecessor, b'SUBSTITUTED')
self.assertEqual(subprocess.check_output(['/bin/sh'] + command), b'ORIGINAL\n')
self.assertNotIn(str(path), command)
def test_exclusive_output_refuses_symlink(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp)
marker = root / 'marker'; marker.write_bytes(b'unchanged')
(root / 'logging.stdout').symlink_to(marker)
(root / 'logging.stdout').write_bytes(b'PREDECESSOR')
self.assertEqual(marker.read_bytes(), b'PREDECESSOR')
marker.write_bytes(b'unchanged')
fd = ns['directory'](root)
try:
with self.assertRaises(FileExistsError): ns['exclusive'](fd, 'logging.stdout')
self.assertEqual(marker.read_bytes(), b'unchanged')
finally: os.close(fd)
def test_output_replacement_refuses_before_foreign_write(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp); fd = ns['directory'](root)
out = ns['exclusive'](fd, 'logging.stdout')
try:
self.assertEqual(stat.S_IMODE(os.fstat(out).st_mode), 0o600)
(root / 'logging.stdout').rename(root / 'held')
marker = root / 'marker'; marker.write_bytes(b'unchanged')
(root / 'logging.stdout').symlink_to(marker)
with self.assertRaises(AssertionError): ns['output'](fd, out, 'logging.stdout', b'bad')
self.assertEqual(marker.read_bytes(), b'unchanged')
finally: os.close(out); os.close(fd)
def test_input_and_root_links_refused(self):
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp); (root / 'alias').symlink_to(root, target_is_directory=True)
with self.assertRaises(OSError): ns['directory'](root / 'alias')
fd = ns['directory'](root)
try:
(root / 'value').write_bytes(b'expected'); (root / 'link').symlink_to(root / 'value')
with self.assertRaises(OSError): ns['read_at'](fd, 'link')
self.assertEqual(ns['read_at'](fd, 'value'), b'expected')
finally: os.close(fd)
def test_effectful_tool_and_environment_are_closed(self):
configpath = '/proc/' + str(os.getpid()) + '/fdinfo'
configfd = os.open(configpath, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
ns.update(config_fd=configfd, config_path=configpath, config_info=os.fstat(configfd))
captured = []
def fake(*args, **kwargs):
# Runs after call validation, just before the consumer would open config.
with self.assertRaises(OSError):
opened = os.open('config.json', os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600, dir_fd=configfd)
os.close(opened)
self.assertFalse(os.path.lexists(pathlib.Path(configpath) / 'config.json'))
captured.append((args, kwargs)); return object()
try:
with mock.patch.dict(os.environ, {'PATH': '/synthetic-untrusted', 'DOCKER_HOST': 'tcp://wrong', 'DOCKER_CONFIG': '/wrong', 'DOCKER_CONTEXT': 'wrong'}):
with mock.patch.object(subprocess, 'run', side_effect=fake): ns['call'](['docker', 'create', '--pull=never'])
args, kwargs = captured[0]
self.assertEqual(args[0][:3], ['/usr/bin/docker', '--host', 'unix:///run/docker.sock'])
self.assertEqual(kwargs['env'], ns['CLOSED_ENV'])
self.assertEqual(kwargs['pass_fds'], (configfd,))
self.assertEqual(kwargs['cwd'], '/')
self.assertNotIn('DOCKER_HOST', kwargs['env'])
finally: os.close(configfd)
def test_predecessor_config_changes_between_check_and_open(self):
with tempfile.TemporaryDirectory() as tmp:
path = pathlib.Path(tmp) / 'config.json'; path.write_text('{}\n')
before = path.stat()
self.assertEqual(path.read_text(), '{}\n')
# The old validation has completed; a writer changes the same inode.
path.write_text('{"credsStore":"synthetic"}')
self.assertEqual(path.stat().st_ino, before.st_ino)
self.assertEqual(path.read_text(), '{"credsStore":"synthetic"}')
def test_uncertain_network_and_container_replies_recover_full_id(self):
from types import SimpleNamespace
for kind in ('network', 'container'):
for reply in (b'', b'not-an-id', b'A' * 64, b'\xff'):
with self.subTest(kind=kind, reply=reply):
identity = 'a' * 64
labels = {'owner':'sdk-rust','task':'logger227','qualification_nonce':'synthetic-nonce'}
present = {identity}; operations = []
def fake(args, **kwargs):
operations.append(args)
if 'inspect' in args:
selected = args[-1]
if selected not in present:
message = ('No such container: '+selected if kind=='container' else 'network '+selected+' not found').encode()
return SimpleNamespace(returncode=1, stderr=message, stdout=b'[]\n')
value={'Id':selected,'Config':{'Labels':labels},'Labels':labels,'State':{'OOMKilled':False}}
return SimpleNamespace(returncode=0, stderr=b'', stdout=ns['json'].dumps([value]).encode())
if 'rm' in args:
self.assertEqual(args[-1], identity); present.remove(identity)
return SimpleNamespace(returncode=0, stderr=b'', stdout=identity.encode())
if 'id='+identity in args:
return SimpleNamespace(returncode=0, stderr=b'', stdout=(identity.encode() if present else b''))
for key,val in labels.items():self.assertIn('label='+key+'='+val, args)
self.assertIn('--no-trunc', args)
return SimpleNamespace(returncode=0, stderr=b'', stdout=(identity+'\n').encode())
old_identity = reply.decode('ascii', errors='replace').strip()
self.assertIsNotNone(old_identity) # Old is-None recovery skips every reply.
granted = None
with self.assertRaises((AssertionError,UnicodeError)):
granted = ns['full_id'](reply)
self.assertIsNone(granted)
with mock.patch.dict(ns, {'labels':labels,'call':fake}):
recovered=ns['reconcile_created'](kind,granted)
self.assertEqual(recovered,identity)
ns['remove_resource'](kind,recovered)
self.assertEqual(present,set())
self.assertIn('id='+identity,operations[-1])
def test_configuration_mutations_are_refused(self):
image = {'Id': 'synthetic-id', 'Config': {'Env': ['PATH=/usr/bin'], 'Labels': {}, 'Volumes': {'/app/database': {}, '/app/storage': {}}}}
command = ['-c', 'captured']; tmpfs = {'/tmp': 'size=64m'}
config = {'Env': ['PATH=/usr/bin', 'DB_CONNECTION=sqlite', 'DB_DATABASE=/app/database/runtime.sqlite', 'DW_RUST_MAINTENANCE_LOOP=1'],
'Image':'synthetic-image','Entrypoint':['/bin/sh'],'Cmd':command,'Hostname':'owned','User':'1000:1000','WorkingDir':'/app','StopSignal':'SIGTERM',
'Volumes': image['Config']['Volumes'],'ExposedPorts':{'8080/tcp':{}},'Labels':{'owner':'sdk-rust'},'Tty':False,'OpenStdin':False}
host = {'ReadonlyRootfs':True,'Init':True,'Privileged':False,'NanoCpus':10**9,'Memory':1024**3,'MemorySwap':1024**3,'PidsLimit':256,
'CapAdd':None,'CapDrop':['ALL'],'SecurityOpt':['no-new-privileges'],'NetworkMode':'network-id','Binds':None,'Tmpfs':tmpfs,
'PortBindings':{'8080/tcp':[{'HostIp':'127.0.0.1','HostPort':''}]},'PidMode':'','UTSMode':'','UsernsMode':'','IpcMode':'private',
'Devices':[],'DeviceRequests':None,'VolumesFrom':None,'ExtraHosts':None,'AutoRemove':False,'OomKillDisable':False,'RestartPolicy':{'Name':'no','MaximumRetryCount':0}}
value={'Image':'synthetic-id','Config':config,'HostConfig':host,'Mounts':[]}
check=lambda v: ns['validate_container'](v,image,'network-id','owned',command,{'owner':'sdk-rust'},tmpfs)
check(value)
started=copy.deepcopy(value);started['HostConfig']['OomKillDisable']=None
self.assertEqual(check(value),check(started))
mutations=[('Image',None,'wrong'),('Config','Cmd',['wrong']),('Config','Env',config['Env']+['INJECTED=yes']),('Config','Labels',{}),
('HostConfig','Privileged',True),('HostConfig','NanoCpus',0),('HostConfig','Memory',0),('HostConfig','ReadonlyRootfs',False),
('HostConfig','Binds',['synthetic:/app']),('HostConfig','NetworkMode','host'),('HostConfig','SecurityOpt',[]),('HostConfig','OomKillDisable',True),('Mounts',None,[{'Type':'bind','Destination':'/app'}])]
for group,key,new in mutations:
with self.subTest(field=(group,key)):
changed=copy.deepcopy(value)
if key is None:changed[group]=new
else:changed[group][key]=new
with self.assertRaises(AssertionError):check(changed)
def test_network_profile_refuses_wrong_routing_or_attachment(self):
value={'Driver':'bridge','Scope':'local','Internal':False,'Ingress':False,'Attachable':False,'EnableIPv6':False,
'Options':{'com.docker.network.bridge.enable_ip_masquerade':'false','com.docker.network.bridge.enable_icc':'false','com.docker.network.bridge.host_binding_ipv4':'127.0.0.1'},'Containers':{}}
ns['validate_network'](value)
value['Containers']={'owned-runtime':{}}
ns['validate_network'](value,'owned-runtime')
for key,bad in [('Internal',True),('Driver','host'),('Attachable',True),('Containers',{'foreign':{}}),('Options',{})]:
with self.subTest(field=key):
changed=copy.deepcopy(value);changed[key]=bad
with self.assertRaises(AssertionError):ns['validate_network'](changed,'owned-runtime')
unittest.main() |
|
Security source/runner disposition for the requested r4 attempt: PASS for one bounded attempt only on the exact frozen controller Independent checks:
This does not convert the first three attempts into passes and does not authorize a tag, upload, reusable launcher, or any unchanged retry. Preserve all three prior NONPASS receipts. |
|
The one04f9 candidate logging observation reached the actual SDK parent and cluster3.10.0, but the first cold child exited101. The parent exited101 at the existing Runtime Next action is a narrow test-only diagnostics correction: retain bounded owned-child stderr on failure and add a synthetic pre-client failure control. Package/library bytes stay fixed. The new reviewed test will then be built against the same exact package and returned with its new parent/build identities before another bounded runtime. No unchanged repeat, tag or upload is selected. All earlier launcher NONPASS receipts remain. |
|
Security disposition of the r4 result: NONPASS, correctly preserved. Reaching the real SDK parent and Server 3.10.0 does not qualify logging when the first cold child exits 101 and the current fixture discards that child's stderr; no logger, authentication, or SDK failure category can be inferred from the retained parent assertion alone. Independent read-only cleanup verification on the execution engine confirms exact full-ID absence for container Do not retry unchanged. A future attempt requires the stated bounded child-stderr diagnostic, a predecessor/synthetic pre-client failure control, and new exact test/build/parent identities returned for source/runner review. Package/library bytes may remain fixed, but no tag, upload, logging acceptance, or #980 result follows from r4. |
|
Bounded diagnostic source #270 is frozen at 8b006e1; its three ordinary controls pass against the exact candidate package, with two actual SDK flows ignored. Restoring only the previous run_child body makes the new child-diagnostic control fail. The optional source-control noexec fixture refusal remains recorded separately. New build receipt: {
"version": "4.17.0",
"package_commit": "52208134296009bbae1af316c8efac89d3465990",
"crate_sha256": "6de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3",
"test_source_commit": "8b006e1de9745665d52fa7712912e4ccc4794592",
"test_sha256": "c53a9e0419216a2f61df3a260f5c63189390a30a2678c57021ae02f53ce49899",
"manifest_sha256": "8b8fcaa21cf434d51d27215243ab71de04f1e71468609101b0476258239afac1",
"lock_sha256": "f01b9abab4a84c2c72da012c0131ff8dd77fd9d588c540ccb3d00b6eb8dd177d",
"build_messages_sha256": "dc41c54e1b553400a0a7160cbf1c12243bdbd2ce2ea0bbfde0d58a2ab7fd3dee",
"executable_relative": "fixture/target/debug/deps/workflow_logging_server-d0e3880b66002e1b",
"executable_sha256": "13bd9dd00a258144dc01feeeac0ad92a1ab6ae1388113b9c6445f79081e9d559",
"executable_bytes": 22392864,
"crate_file_count": 118,
"crate_members_equal": true,
"rust_image": "rust@sha256:300ec56abce8cc9448ddea2172747d048ed902a3090e6b57babb2bf19f754081",
"cargo_version": "1.86.0",
"build_network": "none"
}Receipt SHA256 Manual diagnostic controller SHA256 Literal bootstrap: /usr/bin/python3 -I -c 'import hashlib,pathlib,sys; p=pathlib.Path(sys.argv[1]); b=p.read_bytes(); assert hashlib.sha256(b).hexdigest()=="e9437c7223ec2f6244bf8981db57c514e723f6c98976cd1f44e5d31fbe82a82f"; sys.argv=sys.argv[1:]; exec(compile(b,str(p),"exec"),{"__name__":"__main__"})' <diagnostic-controller.py> <prepared-diagnostic-consumer-root> <accepted-source-checkout>"""One fixed candidate observation; public review packet contains these bytes."""
import base64
import fcntl
import hashlib
import json
import os
import pathlib
import resource
import re
import secrets
import signal
import stat
import subprocess
import sys
import time
import urllib.error
import urllib.request
ROOT = pathlib.Path(sys.argv[1]).absolute()
SOURCE = pathlib.Path(sys.argv[2]).absolute()
IMAGE = 'ghcr.io/durable-workflow/server@sha256:9d64e9aeee84b46d21715826a3e7e5a96eb8d4ce7fccb126b88b15596ab14973'
REVISION = 'b6e04ce7e679464e91f6ceae83310d3bb3204092'
RECEIPT = 'b7e63903bf16162bd6c14f67ed242291b244828b5f32bc94c6cf40e1992da912'
BINARY = '13bd9dd00a258144dc01feeeac0ad92a1ab6ae1388113b9c6445f79081e9d559'
TEST = 'c53a9e0419216a2f61df3a260f5c63189390a30a2678c57021ae02f53ce49899'
def digest(data):
return hashlib.sha256(data).hexdigest()
def directory(path):
assert path.is_absolute() and '..' not in path.parts
current = os.open('/', os.O_RDONLY | os.O_DIRECTORY)
try:
for part in path.parts[1:]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=current)
os.close(current)
current = following
return current
except BaseException:
os.close(current)
raise
def read_at(root, relative):
parts = pathlib.PurePosixPath(relative).parts
assert parts and not relative.startswith('/') and '..' not in parts
parent = os.dup(root)
try:
for part in parts[:-1]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=parent)
os.close(parent)
parent = following
fd = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=parent)
try:
info = os.fstat(fd)
assert stat.S_ISREG(info.st_mode) and info.st_nlink == 1 and info.st_uid == os.getuid()
assert info.st_size <= 64 * 1024**2
value = os.pread(fd, info.st_size + 1, 0)
after = os.fstat(fd)
fields = ('st_dev', 'st_ino', 'st_size', 'st_uid', 'st_gid', 'st_mode',
'st_nlink', 'st_mtime_ns', 'st_ctime_ns')
assert len(value) == info.st_size
assert all(getattr(info, field) == getattr(after, field) for field in fields)
return value
finally:
os.close(fd)
finally:
os.close(parent)
def exclusive(root, name):
assert '/' not in name and name not in ('', '.', '..')
return os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW,
0o600, dir_fd=root)
def output(root, fd, name, value):
before = os.fstat(fd)
named = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (named.st_dev, named.st_ino) == (before.st_dev, before.st_ino)
assert stat.S_ISREG(named.st_mode) and stat.S_IMODE(named.st_mode) == 0o600
assert named.st_uid == os.getuid() and named.st_nlink == 1
with os.fdopen(os.dup(fd), 'wb') as handle:
handle.write(value)
handle.flush()
after = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (after.st_dev, after.st_ino, after.st_nlink) == (before.st_dev, before.st_ino, 1)
root_fd = directory(ROOT)
root_info = os.fstat(root_fd)
assert root_info.st_uid == os.getuid() and stat.S_IMODE(root_info.st_mode) == 0o700
receipt_bytes = read_at(root_fd, 'build-receipt.json')
assert digest(receipt_bytes) == RECEIPT
receipt = json.loads(receipt_bytes)
assert receipt['executable_sha256'] == BINARY
assert digest(read_at(root_fd, 'fixture/tests/workflow_logging_server.rs')) == TEST
assert digest(read_at(root_fd, 'fixture/Cargo.lock')) == receipt['lock_sha256']
assert digest(read_at(root_fd, 'fixture/Cargo.toml')) == receipt['manifest_sha256']
assert digest(read_at(root_fd, 'fixture/logging-build.jsonl')) == receipt['build_messages_sha256']
binary_bytes = read_at(root_fd, receipt['executable_relative'])
assert len(binary_bytes) == receipt['executable_bytes']
assert digest(binary_bytes) == BINARY
fd = os.memfd_create('reviewed-logging-parent', os.MFD_ALLOW_SEALING)
with os.fdopen(os.dup(fd), 'wb') as image_file:
image_file.write(binary_bytes)
os.fchmod(fd, 0o500)
seals = fcntl.F_SEAL_WRITE | fcntl.F_SEAL_GROW | fcntl.F_SEAL_SHRINK | fcntl.F_SEAL_SEAL
fcntl.fcntl(fd, fcntl.F_ADD_SEALS, seals)
assert fcntl.fcntl(fd, fcntl.F_GET_SEALS) == seals
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
supervisor = SOURCE / 'scripts/acceptance/installed-native/cell-supervisor.sh'
source_fd = directory(SOURCE)
supervisor_bytes = read_at(source_fd, 'scripts/acceptance/installed-native/cell-supervisor.sh')
os.close(source_fd)
assert digest(supervisor_bytes) == '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b'
def runtime_command(script, deadline):
script = script.decode()
original = ' /bin/sh "$0" --command "$@"'
assert script.count(original) == 1
wrapper = 'supervisor=$1\nshift\n' + script.replace(original,
' /bin/sh -c "$supervisor" supervisor --command "$@"')
return ['-c', wrapper, 'supervisor', script, str(deadline), '10', 'both',
'/usr/local/bin/durable-workflow-server']
# procfs fdinfo admits only kernel-created decimal descriptor names. A same-UID
# writer cannot create config.json, contexts or plugin paths in this namespace.
config_path = '/proc/' + str(os.getpid()) + '/fdinfo'
config_fd = os.open(config_path, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
config_info = os.fstat(config_fd)
evidence = {name: exclusive(root_fd, name) for name in
('logging.stdout', 'logging.stderr', 'logging-result.json',
'container-created.json', 'container-started.json', 'container-returned.json',
'network-created.json', 'network-returned.json')}
CLOSED_ENV = {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'}
def docker_command(args, config):
assert args[0] == 'docker'
return ['/usr/bin/docker', '--host', 'unix:///run/docker.sock', '--config',
'/proc/self/fd/' + str(config)] + args[1:]
def call(args, **kwargs):
tool = os.stat('/usr/bin/docker', follow_symlinks=False)
assert stat.S_ISREG(tool.st_mode) and tool.st_uid == 0 and tool.st_nlink == 1
assert stat.S_IMODE(tool.st_mode) == 0o755
assert digest(pathlib.Path('/usr/bin/docker').read_bytes()) == '40cdaf7fd0f21089dd9e15b0c3a7dd7f2399027f010e366dac6304ae0615954a'
assert all(name.isdecimal() for name in os.listdir(config_fd))
config_named = os.stat(config_path, follow_symlinks=False)
config_open = os.fstat(config_fd)
assert (config_named.st_dev, config_named.st_ino) == (config_info.st_dev, config_info.st_ino)
assert (config_open.st_dev, config_open.st_ino) == (config_info.st_dev, config_info.st_ino)
kwargs.setdefault('check', True)
return subprocess.run(docker_command(args, config_fd), capture_output=True, timeout=30,
cwd='/', env=CLOSED_ENV, pass_fds=(config_fd,), **kwargs)
socket_info = os.stat('/run/docker.sock', follow_symlinks=False)
assert stat.S_ISSOCK(socket_info.st_mode) and socket_info.st_uid == 0
def engine():
current = os.stat('/run/docker.sock', follow_symlinks=False)
assert (current.st_dev, current.st_ino, current.st_uid, current.st_gid, current.st_mode) == (
socket_info.st_dev, socket_info.st_ino, socket_info.st_uid, socket_info.st_gid, socket_info.st_mode)
identity = call(['docker', 'info', '--format', '{{.ID}}']).stdout.strip()
assert digest(identity) == '0a179ff32531e41cfc2d465b1d46afc1df91c0975e9627969f75c67e00b0e892'
def image_identity():
image = json.loads(call(['docker', 'image', 'inspect', IMAGE]).stdout)[0]
assert image['Id'] == IMAGE.split('@')[1]
assert image['RepoDigests'] == [IMAGE] and image['Descriptor']['digest'] == IMAGE.split('@')[1]
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert digest(json.dumps(image['Config'], sort_keys=True, separators=(',', ':')).encode()) == 'c88782b528aee2a1b7804cd62cb95afac9df8c5b2f89c471924c6c1085c63b62'
return image
engine()
image = image_identity()
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert image['Config']['Labels']['org.opencontainers.image.revision'] == REVISION
assert image['Config']['Labels']['dev.durable-workflow.release.tag'] == '3.10.0'
assert image['Config']['Entrypoint'] == ['/usr/local/bin/durable-workflow-server']
nonce = secrets.token_hex(16)
name = 'sdk-rust-417-logging-' + nonce[:12]
labels = {'owner': 'sdk-rust', 'task': 'logger227', 'qualification_nonce': nonce}
label_args = [argument for key, value in labels.items() for argument in ('--label', key + '=' + value)]
token = 'fixture-' + secrets.token_hex(24)
key = 'base64:' + base64.b64encode(secrets.token_bytes(32)).decode()
container_id = network_id = None
process = None
result = {'outcome': 'fail', 'build_receipt_sha256': RECEIPT,
'binary_sha256': BINARY, 'server_manifest': IMAGE, 'server_source': REVISION,
'started_at': time.time(), 'limits': {'consumer_cpus': 2, 'consumer_as': 2147483648,
'consumer_cpu_seconds': 60, 'consumer_wall_seconds': 180}}
def owned(kind, identity):
value = json.loads(call(['docker', kind, 'inspect', identity]).stdout)[0]
actual = value['Config']['Labels'] if kind == 'container' else value['Labels']
assert value['Id'] == identity and all(actual.get(k) == v for k, v in labels.items())
return value
def full_id(raw):
identity = raw.decode('ascii').strip()
assert re.fullmatch('[0-9a-f]{64}', identity), 'uncertain create reply'
return identity
def reconcile_created(kind, identity):
if identity is not None:
assert re.fullmatch('[0-9a-f]{64}', identity)
return identity
filters = [arg for key, val in labels.items() for arg in ('--filter', 'label=' + key + '=' + val)]
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
candidates = call(query + filters).stdout.split()
assert len(candidates) <= 1
if candidates:
recovered = full_id(candidates[0])
owned(kind, recovered)
return recovered
return None
def remove_resource(kind, identity):
value = owned(kind, identity)
call(['docker', 'rm', '-f', '-v', identity] if kind == 'container'
else ['docker', 'network', 'rm', identity])
observed = call(['docker', kind, 'inspect', identity], check=False)
missing = ('no such container: ' + identity if kind == 'container'
else 'network ' + identity + ' not found').encode()
assert observed.returncode != 0 and json.loads(observed.stdout) == []
assert missing in observed.stderr.lower()
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
assert call(query + ['--filter', 'id=' + identity]).stdout.strip() == b''
return value
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args):
raise AssertionError('redirect refused')
def consumer_limits():
os.sched_setaffinity(0, sorted(os.sched_getaffinity(0))[:2])
resource.setrlimit(resource.RLIMIT_AS, (2 * 1024**3, 2 * 1024**3))
resource.setrlimit(resource.RLIMIT_CPU, (60, 60))
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
def validate_network(value, runtime=None):
assert value['Driver'] == 'bridge' and value['Scope'] == 'local'
assert value['Internal'] is False and value['Ingress'] is False and value['Attachable'] is False
assert value['EnableIPv6'] is False
assert value['Options'] == {
'com.docker.network.bridge.enable_ip_masquerade': 'false',
'com.docker.network.bridge.enable_icc': 'false',
'com.docker.network.bridge.host_binding_ipv4': '127.0.0.1'}
assert set(value.get('Containers') or {}) <= ({runtime} if runtime else set())
def validate_container(value, image, network, name, command, labels, tmpfs):
assert value['Image'] == image['Id']
config, host = value['Config'], value['HostConfig']
expected_env = dict(entry.split('=', 1) for entry in image['Config']['Env'])
expected_env.update(DB_CONNECTION='sqlite', DB_DATABASE='/app/database/runtime.sqlite',
DW_RUST_MAINTENANCE_LOOP='1')
assert len(config['Env']) == len(expected_env)
assert dict(entry.split('=', 1) for entry in config['Env']) == expected_env
assert config['Image'] == IMAGE and config['Entrypoint'] == ['/bin/sh'] and config['Cmd'] == command
assert config['Hostname'] == name and config['User'] == '1000:1000'
assert config['WorkingDir'] == '/app' and config['StopSignal'] == 'SIGTERM'
assert config['Volumes'] == image['Config']['Volumes']
assert config['ExposedPorts'] == {'8080/tcp': {}}
assert config['Labels'] == dict(image['Config']['Labels'], **labels)
assert not config['Tty'] and not config['OpenStdin']
expected = {'ReadonlyRootfs': True, 'Init': True, 'Privileged': False,
'NanoCpus': 10**9, 'Memory': 1024**3, 'MemorySwap': 1024**3, 'PidsLimit': 256,
'CapAdd': None, 'CapDrop': ['ALL'], 'SecurityOpt': ['no-new-privileges'],
'NetworkMode': network, 'Binds': None, 'Tmpfs': tmpfs,
'PortBindings': {'8080/tcp': [{'HostIp': '127.0.0.1', 'HostPort': ''}]},
'PidMode': '', 'UTSMode': '', 'UsernsMode': '', 'IpcMode': 'private',
'Devices': [], 'DeviceRequests': None, 'VolumesFrom': None, 'ExtraHosts': None,
'AutoRemove': False, 'RestartPolicy': {'Name': 'no', 'MaximumRetryCount': 0}}
assert all(host.get(key) == val for key, val in expected.items())
assert 'OomKillDisable' in host and host['OomKillDisable'] in (False, None)
assert not host.get('Mounts')
assert all(m['Type'] == 'tmpfs' and m['Destination'] in tmpfs for m in value['Mounts'])
packet = json.loads(json.dumps({k: value[k] for k in ('Image', 'Config', 'HostConfig', 'Mounts')}))
# Docker29 changes this unset/false default during start. Both retain the
# kernel OOM killer; true is refused. Every other field remains exact.
packet['HostConfig']['OomKillDisable'] = False
return digest(json.dumps(packet, sort_keys=True, separators=(',', ':')).encode())
tmpfs = {'/tmp': 'mode=1777,size=64m',
'/app/database': 'uid=1000,gid=1000,mode=0700,size=64m',
'/app/storage': 'uid=1000,gid=1000,mode=0700,size=64m',
'/credentials': 'uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev'}
command = None
created_config = None
try:
engine()
image_identity()
network_id = full_id(call(['docker', 'network', 'create', '--driver', 'bridge',
'--opt', 'com.docker.network.bridge.enable_ip_masquerade=false',
'--opt', 'com.docker.network.bridge.enable_icc=false',
'--opt', 'com.docker.network.bridge.host_binding_ipv4=127.0.0.1'] + label_args + [name]).stdout)
result['network_id'] = network_id
created_network = owned('network', network_id)
output(root_fd, evidence['network-created.json'], 'network-created.json',
(json.dumps(created_network, indent=2) + '\n').encode())
validate_network(created_network)
deadline = str(int(time.time()) + 240)
command = runtime_command(supervisor_bytes, deadline)
engine()
image_identity()
container_id = full_id(call(['docker', 'create', '--pull=never', '--init', '--name', name,
'--hostname', name] + label_args + [
'--cpus', '1', '--memory', '1g', '--memory-swap', '1g', '--pids-limit', '256', '--read-only', '--user', '1000:1000',
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--network', network_id,
'--publish', '127.0.0.1::8080', '--tmpfs', '/tmp:mode=1777,size=64m',
'--tmpfs', '/app/database:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/app/storage:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/credentials:uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev',
'--env', 'DB_CONNECTION=sqlite', '--env', 'DB_DATABASE=/app/database/runtime.sqlite',
'--env', 'DW_RUST_MAINTENANCE_LOOP=1', '--entrypoint', '/bin/sh', IMAGE] + command).stdout)
result['container_id'] = container_id
before = owned('container', container_id)
output(root_fd, evidence['container-created.json'], 'container-created.json',
(json.dumps(before, indent=2) + '\n').encode())
result['container_id'], result['network_id'] = container_id, network_id
created_config = validate_container(before, image, network_id, name, command, labels, tmpfs)
validate_network(owned('network', network_id), container_id)
result['created_config_sha256'] = created_config
engine()
image_identity()
assert validate_container(owned('container', container_id), image, network_id,
name, command, labels, tmpfs) == created_config
call(['docker', 'start', container_id])
started = owned('container', container_id)
output(root_fd, evidence['container-started.json'], 'container-started.json',
(json.dumps(started, indent=2) + '\n').encode())
assert validate_container(started, image, network_id,
name, command, labels, tmpfs) == created_config
validate_network(owned('network', network_id), container_id)
call(['docker', 'exec', '-i', container_id, '/bin/sh', '-c',
'umask 077; IFS= read -r token && IFS= read -r key && '
'printf %s "$token" > /credentials/token && printf %s "$key" > /credentials/server-key && '
': > /credentials/ready.tmp && mv /credentials/ready.tmp /credentials/ready'],
input=(token + '\n' + key + '\n').encode())
live = owned('container', container_id)
ports = live['NetworkSettings']['Ports']['8080/tcp']
assert len(ports) == 1 and ports[0]['HostIp'] == '127.0.0.1'
port = int(ports[0]['HostPort'])
assert 0 < port < 65536
origin = 'http://127.0.0.1:' + str(port)
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
for attempt in range(60):
try:
request = urllib.request.Request(origin + '/api/cluster/info',
headers={'Authorization': 'Bearer ' + token, 'X-Namespace': 'default'})
with opener.open(request, timeout=1) as response:
cluster = json.load(response)
assert cluster['version'] == '3.10.0'
result['cluster_info'] = cluster
break
except (urllib.error.URLError, ConnectionError):
time.sleep(.25)
else:
raise AssertionError('runtime readiness bound expired')
args = ['/proc/self/fd/' + str(fd), '--ignored', '--exact',
'published_logging_emits_once_per_committed_step_across_cold_worker_processes',
'--nocapture', '--test-threads=1']
env = {'DURABLE_WORKFLOW_LOCAL_ISOLATED': '1', 'DURABLE_WORKFLOW_SERVER_URL': origin,
'DURABLE_WORKFLOW_AUTH_TOKEN': token, 'DURABLE_WORKFLOW_EXPECT_SERVER_VERSION': '3.10.0'}
process = subprocess.Popen(args, env=env, pass_fds=(fd,), start_new_session=True,
preexec_fn=consumer_limits, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate(timeout=180)
assert len(stdout) + len(stderr) <= 1024**2
assert all(secret.encode() not in stdout + stderr for secret in (token, key))
output(root_fd, evidence['logging.stdout'], 'logging.stdout', stdout)
output(root_fd, evidence['logging.stderr'], 'logging.stderr', stderr)
result['parent_pid'], result['exit_code'] = process.pid, process.returncode
assert process.returncode == 0, 'logging parent failed'
assert b'PASS: four cold worker processes' in stdout
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
engine()
image_identity()
returned = owned('container', container_id)
output(root_fd, evidence['container-returned.json'], 'container-returned.json',
(json.dumps(returned, indent=2) + '\n').encode())
assert validate_container(returned, image, network_id,
name, command, labels, tmpfs) == created_config
final_network = owned('network', network_id)
output(root_fd, evidence['network-returned.json'], 'network-returned.json',
(json.dumps(final_network, indent=2) + '\n').encode())
validate_network(final_network, container_id)
result['outcome'] = 'pass'
except BaseException as error:
result['error'] = type(error).__name__
raise
finally:
if process is not None:
try:
os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:
pass
process.wait(timeout=10)
os.close(fd)
errors = []
# Recover only this exact nonce/owner if an uncertain create returned no ID.
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity is None:
try:
recovered = reconcile_created(kind, identity)
if kind == 'container':
container_id = recovered
else:
network_id = recovered
except Exception as error:
errors.append(type(error).__name__)
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity:
try:
value = remove_resource(kind, identity)
if kind == 'container':
result['runtime_oom'] = value['State']['OOMKilled']
if result['runtime_oom']:
result['outcome'] = 'fail'
except Exception as error:
errors.append(type(error).__name__)
result['cleanup'] = {'pass': not errors, 'errors': errors}
if errors:
result['outcome'] = 'fail'
result['finished_at'] = time.time()
named_root = ROOT.stat(follow_symlinks=False)
assert (named_root.st_dev, named_root.st_ino) == (root_info.st_dev, root_info.st_ino)
output(root_fd, evidence['logging-result.json'], 'logging-result.json',
(json.dumps(result, indent=2) + '\n').encode())
for descriptor in evidence.values():
os.close(descriptor)
os.close(config_fd)
os.close(root_fd)
assert not errors, errors
print(json.dumps(result)) |
|
Security data/controller binding PASS for one exact diagnostic observation only. Frozen identities independently checked:
I rehashed the complete public controller and receipt, the retained receipt/parent/test/manifest/lock/build-message bytes, and compared the retained test file byte-for-byte with the exact Git blob. The receipt binds package source This permits one diagnostic runtime only after the remaining #270 current-head check is terminal green, using the unchanged reviewed supervisor and nine-control envelope. Preserve all four earlier launcher/runtime outcomes as NONPASS. Retain the bounded child stderr privately and publish only a sanitized classification; recheck the exact parent/receipt/package/test identities, OOM state and full container/network ID absence. This is not a logger PASS, package approval, #980 result, tag, upload or registry approval. |
|
The exact e943 diagnostic observation is runner-blocked/NONPASS. Bounded child stderr identifies the first poll's concrete response: HTTP409, reason worker_not_registered. The parent registers its setup worker ID; the child constructs a new phase-specific ID and called run_once without registering that ID. The Server's registration fence worked. This demonstrates a fixture setup omission, not a logger failure or a need for another credential. It does not relabel the earlier unclassified child result. Parent exit101/PID2357385; runtime #271 makes the narrow test-only correction: register each fresh child before polling. It preserves the same workflow definition, four process boundaries, original identity/history, one new observation and exact result assertions. Its ordinary controls pass3/2ignored on the same4.17 archive, and new source/build/parent/controller identities will be counter-reviewed before another bounded observation. Five preceding outcomes remain NONPASS; no tag/upload or logger PASS exists. |
|
The diagnostic e943 run demonstrated the fixture's missing per-child registration: HTTP409 worker_not_registered. #271 exact 7b6a351 registers each fresh child before polling and changes no workflow definition, replay/log/history/result assertions or SDK/library/package bytes. Its ordinary controls pass3/2ignored against the same4.17 crate. An initial local missing-bind preparation refusal is preserved; no test container was created in that setup attempt. New bound build receipt SHA256 {
"version": "4.17.0",
"package_commit": "52208134296009bbae1af316c8efac89d3465990",
"crate_sha256": "6de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3",
"test_source_commit": "7b6a3514dd9f7c6454a1b753a5b5247cab064722",
"test_sha256": "e66d177c6a1ffc486623169d1505766447c18c3c4650a2023a60f8bb9f9d11f0",
"manifest_sha256": "8b8fcaa21cf434d51d27215243ab71de04f1e71468609101b0476258239afac1",
"lock_sha256": "f01b9abab4a84c2c72da012c0131ff8dd77fd9d588c540ccb3d00b6eb8dd177d",
"build_messages_sha256": "28b558a6f042bee3f20dedd36e9ab79b6aad70e88722195160d30afc4c86ef0a",
"executable_relative": "fixture/target/debug/deps/workflow_logging_server-d0e3880b66002e1b",
"executable_sha256": "217aaf912fb90ed8e6be5dc35ee9ade5144effb36f5d0b833179c484ad0428a8",
"executable_bytes": 22396960,
"crate_file_count": 118,
"crate_members_equal": true,
"rust_image": "rust@sha256:300ec56abce8cc9448ddea2172747d048ed902a3090e6b57babb2bf19f754081",
"cargo_version": "1.86.0",
"build_network": "none"
}New controller /usr/bin/python3 -I -c 'import hashlib,pathlib,sys; p=pathlib.Path(sys.argv[1]); b=p.read_bytes(); assert hashlib.sha256(b).hexdigest()=="2e2c2e486683b94abaf00c6cdb0ce589ca905f71033e0098b2da9bc0b32098b5"; sys.argv=sys.argv[1:]; exec(compile(b,str(p),"exec"),{"__name__":"__main__"})' <registered-controller.py> <prepared-registration-consumer-root> <accepted-source-checkout>"""One fixed candidate observation; public review packet contains these bytes."""
import base64
import fcntl
import hashlib
import json
import os
import pathlib
import resource
import re
import secrets
import signal
import stat
import subprocess
import sys
import time
import urllib.error
import urllib.request
ROOT = pathlib.Path(sys.argv[1]).absolute()
SOURCE = pathlib.Path(sys.argv[2]).absolute()
IMAGE = 'ghcr.io/durable-workflow/server@sha256:9d64e9aeee84b46d21715826a3e7e5a96eb8d4ce7fccb126b88b15596ab14973'
REVISION = 'b6e04ce7e679464e91f6ceae83310d3bb3204092'
RECEIPT = '4ac6427eeab05380cbfa3ce16da382c8e773622fb06ae6fcd4f95e540f26a8e7'
BINARY = '217aaf912fb90ed8e6be5dc35ee9ade5144effb36f5d0b833179c484ad0428a8'
TEST = 'e66d177c6a1ffc486623169d1505766447c18c3c4650a2023a60f8bb9f9d11f0'
def digest(data):
return hashlib.sha256(data).hexdigest()
def directory(path):
assert path.is_absolute() and '..' not in path.parts
current = os.open('/', os.O_RDONLY | os.O_DIRECTORY)
try:
for part in path.parts[1:]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=current)
os.close(current)
current = following
return current
except BaseException:
os.close(current)
raise
def read_at(root, relative):
parts = pathlib.PurePosixPath(relative).parts
assert parts and not relative.startswith('/') and '..' not in parts
parent = os.dup(root)
try:
for part in parts[:-1]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=parent)
os.close(parent)
parent = following
fd = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=parent)
try:
info = os.fstat(fd)
assert stat.S_ISREG(info.st_mode) and info.st_nlink == 1 and info.st_uid == os.getuid()
assert info.st_size <= 64 * 1024**2
value = os.pread(fd, info.st_size + 1, 0)
after = os.fstat(fd)
fields = ('st_dev', 'st_ino', 'st_size', 'st_uid', 'st_gid', 'st_mode',
'st_nlink', 'st_mtime_ns', 'st_ctime_ns')
assert len(value) == info.st_size
assert all(getattr(info, field) == getattr(after, field) for field in fields)
return value
finally:
os.close(fd)
finally:
os.close(parent)
def exclusive(root, name):
assert '/' not in name and name not in ('', '.', '..')
return os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW,
0o600, dir_fd=root)
def output(root, fd, name, value):
before = os.fstat(fd)
named = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (named.st_dev, named.st_ino) == (before.st_dev, before.st_ino)
assert stat.S_ISREG(named.st_mode) and stat.S_IMODE(named.st_mode) == 0o600
assert named.st_uid == os.getuid() and named.st_nlink == 1
with os.fdopen(os.dup(fd), 'wb') as handle:
handle.write(value)
handle.flush()
after = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (after.st_dev, after.st_ino, after.st_nlink) == (before.st_dev, before.st_ino, 1)
root_fd = directory(ROOT)
root_info = os.fstat(root_fd)
assert root_info.st_uid == os.getuid() and stat.S_IMODE(root_info.st_mode) == 0o700
receipt_bytes = read_at(root_fd, 'build-receipt.json')
assert digest(receipt_bytes) == RECEIPT
receipt = json.loads(receipt_bytes)
assert receipt['executable_sha256'] == BINARY
assert digest(read_at(root_fd, 'fixture/tests/workflow_logging_server.rs')) == TEST
assert digest(read_at(root_fd, 'fixture/Cargo.lock')) == receipt['lock_sha256']
assert digest(read_at(root_fd, 'fixture/Cargo.toml')) == receipt['manifest_sha256']
assert digest(read_at(root_fd, 'fixture/logging-build.jsonl')) == receipt['build_messages_sha256']
binary_bytes = read_at(root_fd, receipt['executable_relative'])
assert len(binary_bytes) == receipt['executable_bytes']
assert digest(binary_bytes) == BINARY
fd = os.memfd_create('reviewed-logging-parent', os.MFD_ALLOW_SEALING)
with os.fdopen(os.dup(fd), 'wb') as image_file:
image_file.write(binary_bytes)
os.fchmod(fd, 0o500)
seals = fcntl.F_SEAL_WRITE | fcntl.F_SEAL_GROW | fcntl.F_SEAL_SHRINK | fcntl.F_SEAL_SEAL
fcntl.fcntl(fd, fcntl.F_ADD_SEALS, seals)
assert fcntl.fcntl(fd, fcntl.F_GET_SEALS) == seals
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
supervisor = SOURCE / 'scripts/acceptance/installed-native/cell-supervisor.sh'
source_fd = directory(SOURCE)
supervisor_bytes = read_at(source_fd, 'scripts/acceptance/installed-native/cell-supervisor.sh')
os.close(source_fd)
assert digest(supervisor_bytes) == '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b'
def runtime_command(script, deadline):
script = script.decode()
original = ' /bin/sh "$0" --command "$@"'
assert script.count(original) == 1
wrapper = 'supervisor=$1\nshift\n' + script.replace(original,
' /bin/sh -c "$supervisor" supervisor --command "$@"')
return ['-c', wrapper, 'supervisor', script, str(deadline), '10', 'both',
'/usr/local/bin/durable-workflow-server']
# procfs fdinfo admits only kernel-created decimal descriptor names. A same-UID
# writer cannot create config.json, contexts or plugin paths in this namespace.
config_path = '/proc/' + str(os.getpid()) + '/fdinfo'
config_fd = os.open(config_path, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
config_info = os.fstat(config_fd)
evidence = {name: exclusive(root_fd, name) for name in
('logging.stdout', 'logging.stderr', 'logging-result.json',
'container-created.json', 'container-started.json', 'container-returned.json',
'network-created.json', 'network-returned.json')}
CLOSED_ENV = {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'}
def docker_command(args, config):
assert args[0] == 'docker'
return ['/usr/bin/docker', '--host', 'unix:///run/docker.sock', '--config',
'/proc/self/fd/' + str(config)] + args[1:]
def call(args, **kwargs):
tool = os.stat('/usr/bin/docker', follow_symlinks=False)
assert stat.S_ISREG(tool.st_mode) and tool.st_uid == 0 and tool.st_nlink == 1
assert stat.S_IMODE(tool.st_mode) == 0o755
assert digest(pathlib.Path('/usr/bin/docker').read_bytes()) == '40cdaf7fd0f21089dd9e15b0c3a7dd7f2399027f010e366dac6304ae0615954a'
assert all(name.isdecimal() for name in os.listdir(config_fd))
config_named = os.stat(config_path, follow_symlinks=False)
config_open = os.fstat(config_fd)
assert (config_named.st_dev, config_named.st_ino) == (config_info.st_dev, config_info.st_ino)
assert (config_open.st_dev, config_open.st_ino) == (config_info.st_dev, config_info.st_ino)
kwargs.setdefault('check', True)
return subprocess.run(docker_command(args, config_fd), capture_output=True, timeout=30,
cwd='/', env=CLOSED_ENV, pass_fds=(config_fd,), **kwargs)
socket_info = os.stat('/run/docker.sock', follow_symlinks=False)
assert stat.S_ISSOCK(socket_info.st_mode) and socket_info.st_uid == 0
def engine():
current = os.stat('/run/docker.sock', follow_symlinks=False)
assert (current.st_dev, current.st_ino, current.st_uid, current.st_gid, current.st_mode) == (
socket_info.st_dev, socket_info.st_ino, socket_info.st_uid, socket_info.st_gid, socket_info.st_mode)
identity = call(['docker', 'info', '--format', '{{.ID}}']).stdout.strip()
assert digest(identity) == '0a179ff32531e41cfc2d465b1d46afc1df91c0975e9627969f75c67e00b0e892'
def image_identity():
image = json.loads(call(['docker', 'image', 'inspect', IMAGE]).stdout)[0]
assert image['Id'] == IMAGE.split('@')[1]
assert image['RepoDigests'] == [IMAGE] and image['Descriptor']['digest'] == IMAGE.split('@')[1]
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert digest(json.dumps(image['Config'], sort_keys=True, separators=(',', ':')).encode()) == 'c88782b528aee2a1b7804cd62cb95afac9df8c5b2f89c471924c6c1085c63b62'
return image
engine()
image = image_identity()
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert image['Config']['Labels']['org.opencontainers.image.revision'] == REVISION
assert image['Config']['Labels']['dev.durable-workflow.release.tag'] == '3.10.0'
assert image['Config']['Entrypoint'] == ['/usr/local/bin/durable-workflow-server']
nonce = secrets.token_hex(16)
name = 'sdk-rust-417-logging-' + nonce[:12]
labels = {'owner': 'sdk-rust', 'task': 'logger227', 'qualification_nonce': nonce}
label_args = [argument for key, value in labels.items() for argument in ('--label', key + '=' + value)]
token = 'fixture-' + secrets.token_hex(24)
key = 'base64:' + base64.b64encode(secrets.token_bytes(32)).decode()
container_id = network_id = None
process = None
result = {'outcome': 'fail', 'build_receipt_sha256': RECEIPT,
'binary_sha256': BINARY, 'server_manifest': IMAGE, 'server_source': REVISION,
'started_at': time.time(), 'limits': {'consumer_cpus': 2, 'consumer_as': 2147483648,
'consumer_cpu_seconds': 60, 'consumer_wall_seconds': 180}}
def owned(kind, identity):
value = json.loads(call(['docker', kind, 'inspect', identity]).stdout)[0]
actual = value['Config']['Labels'] if kind == 'container' else value['Labels']
assert value['Id'] == identity and all(actual.get(k) == v for k, v in labels.items())
return value
def full_id(raw):
identity = raw.decode('ascii').strip()
assert re.fullmatch('[0-9a-f]{64}', identity), 'uncertain create reply'
return identity
def reconcile_created(kind, identity):
if identity is not None:
assert re.fullmatch('[0-9a-f]{64}', identity)
return identity
filters = [arg for key, val in labels.items() for arg in ('--filter', 'label=' + key + '=' + val)]
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
candidates = call(query + filters).stdout.split()
assert len(candidates) <= 1
if candidates:
recovered = full_id(candidates[0])
owned(kind, recovered)
return recovered
return None
def remove_resource(kind, identity):
value = owned(kind, identity)
call(['docker', 'rm', '-f', '-v', identity] if kind == 'container'
else ['docker', 'network', 'rm', identity])
observed = call(['docker', kind, 'inspect', identity], check=False)
missing = ('no such container: ' + identity if kind == 'container'
else 'network ' + identity + ' not found').encode()
assert observed.returncode != 0 and json.loads(observed.stdout) == []
assert missing in observed.stderr.lower()
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
assert call(query + ['--filter', 'id=' + identity]).stdout.strip() == b''
return value
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args):
raise AssertionError('redirect refused')
def consumer_limits():
os.sched_setaffinity(0, sorted(os.sched_getaffinity(0))[:2])
resource.setrlimit(resource.RLIMIT_AS, (2 * 1024**3, 2 * 1024**3))
resource.setrlimit(resource.RLIMIT_CPU, (60, 60))
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
def validate_network(value, runtime=None):
assert value['Driver'] == 'bridge' and value['Scope'] == 'local'
assert value['Internal'] is False and value['Ingress'] is False and value['Attachable'] is False
assert value['EnableIPv6'] is False
assert value['Options'] == {
'com.docker.network.bridge.enable_ip_masquerade': 'false',
'com.docker.network.bridge.enable_icc': 'false',
'com.docker.network.bridge.host_binding_ipv4': '127.0.0.1'}
assert set(value.get('Containers') or {}) <= ({runtime} if runtime else set())
def validate_container(value, image, network, name, command, labels, tmpfs):
assert value['Image'] == image['Id']
config, host = value['Config'], value['HostConfig']
expected_env = dict(entry.split('=', 1) for entry in image['Config']['Env'])
expected_env.update(DB_CONNECTION='sqlite', DB_DATABASE='/app/database/runtime.sqlite',
DW_RUST_MAINTENANCE_LOOP='1')
assert len(config['Env']) == len(expected_env)
assert dict(entry.split('=', 1) for entry in config['Env']) == expected_env
assert config['Image'] == IMAGE and config['Entrypoint'] == ['/bin/sh'] and config['Cmd'] == command
assert config['Hostname'] == name and config['User'] == '1000:1000'
assert config['WorkingDir'] == '/app' and config['StopSignal'] == 'SIGTERM'
assert config['Volumes'] == image['Config']['Volumes']
assert config['ExposedPorts'] == {'8080/tcp': {}}
assert config['Labels'] == dict(image['Config']['Labels'], **labels)
assert not config['Tty'] and not config['OpenStdin']
expected = {'ReadonlyRootfs': True, 'Init': True, 'Privileged': False,
'NanoCpus': 10**9, 'Memory': 1024**3, 'MemorySwap': 1024**3, 'PidsLimit': 256,
'CapAdd': None, 'CapDrop': ['ALL'], 'SecurityOpt': ['no-new-privileges'],
'NetworkMode': network, 'Binds': None, 'Tmpfs': tmpfs,
'PortBindings': {'8080/tcp': [{'HostIp': '127.0.0.1', 'HostPort': ''}]},
'PidMode': '', 'UTSMode': '', 'UsernsMode': '', 'IpcMode': 'private',
'Devices': [], 'DeviceRequests': None, 'VolumesFrom': None, 'ExtraHosts': None,
'AutoRemove': False, 'RestartPolicy': {'Name': 'no', 'MaximumRetryCount': 0}}
assert all(host.get(key) == val for key, val in expected.items())
assert 'OomKillDisable' in host and host['OomKillDisable'] in (False, None)
assert not host.get('Mounts')
assert all(m['Type'] == 'tmpfs' and m['Destination'] in tmpfs for m in value['Mounts'])
packet = json.loads(json.dumps({k: value[k] for k in ('Image', 'Config', 'HostConfig', 'Mounts')}))
# Docker29 changes this unset/false default during start. Both retain the
# kernel OOM killer; true is refused. Every other field remains exact.
packet['HostConfig']['OomKillDisable'] = False
return digest(json.dumps(packet, sort_keys=True, separators=(',', ':')).encode())
tmpfs = {'/tmp': 'mode=1777,size=64m',
'/app/database': 'uid=1000,gid=1000,mode=0700,size=64m',
'/app/storage': 'uid=1000,gid=1000,mode=0700,size=64m',
'/credentials': 'uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev'}
command = None
created_config = None
try:
engine()
image_identity()
network_id = full_id(call(['docker', 'network', 'create', '--driver', 'bridge',
'--opt', 'com.docker.network.bridge.enable_ip_masquerade=false',
'--opt', 'com.docker.network.bridge.enable_icc=false',
'--opt', 'com.docker.network.bridge.host_binding_ipv4=127.0.0.1'] + label_args + [name]).stdout)
result['network_id'] = network_id
created_network = owned('network', network_id)
output(root_fd, evidence['network-created.json'], 'network-created.json',
(json.dumps(created_network, indent=2) + '\n').encode())
validate_network(created_network)
deadline = str(int(time.time()) + 240)
command = runtime_command(supervisor_bytes, deadline)
engine()
image_identity()
container_id = full_id(call(['docker', 'create', '--pull=never', '--init', '--name', name,
'--hostname', name] + label_args + [
'--cpus', '1', '--memory', '1g', '--memory-swap', '1g', '--pids-limit', '256', '--read-only', '--user', '1000:1000',
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--network', network_id,
'--publish', '127.0.0.1::8080', '--tmpfs', '/tmp:mode=1777,size=64m',
'--tmpfs', '/app/database:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/app/storage:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/credentials:uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev',
'--env', 'DB_CONNECTION=sqlite', '--env', 'DB_DATABASE=/app/database/runtime.sqlite',
'--env', 'DW_RUST_MAINTENANCE_LOOP=1', '--entrypoint', '/bin/sh', IMAGE] + command).stdout)
result['container_id'] = container_id
before = owned('container', container_id)
output(root_fd, evidence['container-created.json'], 'container-created.json',
(json.dumps(before, indent=2) + '\n').encode())
result['container_id'], result['network_id'] = container_id, network_id
created_config = validate_container(before, image, network_id, name, command, labels, tmpfs)
validate_network(owned('network', network_id), container_id)
result['created_config_sha256'] = created_config
engine()
image_identity()
assert validate_container(owned('container', container_id), image, network_id,
name, command, labels, tmpfs) == created_config
call(['docker', 'start', container_id])
started = owned('container', container_id)
output(root_fd, evidence['container-started.json'], 'container-started.json',
(json.dumps(started, indent=2) + '\n').encode())
assert validate_container(started, image, network_id,
name, command, labels, tmpfs) == created_config
validate_network(owned('network', network_id), container_id)
call(['docker', 'exec', '-i', container_id, '/bin/sh', '-c',
'umask 077; IFS= read -r token && IFS= read -r key && '
'printf %s "$token" > /credentials/token && printf %s "$key" > /credentials/server-key && '
': > /credentials/ready.tmp && mv /credentials/ready.tmp /credentials/ready'],
input=(token + '\n' + key + '\n').encode())
live = owned('container', container_id)
ports = live['NetworkSettings']['Ports']['8080/tcp']
assert len(ports) == 1 and ports[0]['HostIp'] == '127.0.0.1'
port = int(ports[0]['HostPort'])
assert 0 < port < 65536
origin = 'http://127.0.0.1:' + str(port)
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
for attempt in range(60):
try:
request = urllib.request.Request(origin + '/api/cluster/info',
headers={'Authorization': 'Bearer ' + token, 'X-Namespace': 'default'})
with opener.open(request, timeout=1) as response:
cluster = json.load(response)
assert cluster['version'] == '3.10.0'
result['cluster_info'] = cluster
break
except (urllib.error.URLError, ConnectionError):
time.sleep(.25)
else:
raise AssertionError('runtime readiness bound expired')
args = ['/proc/self/fd/' + str(fd), '--ignored', '--exact',
'published_logging_emits_once_per_committed_step_across_cold_worker_processes',
'--nocapture', '--test-threads=1']
env = {'DURABLE_WORKFLOW_LOCAL_ISOLATED': '1', 'DURABLE_WORKFLOW_SERVER_URL': origin,
'DURABLE_WORKFLOW_AUTH_TOKEN': token, 'DURABLE_WORKFLOW_EXPECT_SERVER_VERSION': '3.10.0'}
process = subprocess.Popen(args, env=env, pass_fds=(fd,), start_new_session=True,
preexec_fn=consumer_limits, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate(timeout=180)
assert len(stdout) + len(stderr) <= 1024**2
assert all(secret.encode() not in stdout + stderr for secret in (token, key))
output(root_fd, evidence['logging.stdout'], 'logging.stdout', stdout)
output(root_fd, evidence['logging.stderr'], 'logging.stderr', stderr)
result['parent_pid'], result['exit_code'] = process.pid, process.returncode
assert process.returncode == 0, 'logging parent failed'
assert b'PASS: four cold worker processes' in stdout
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
engine()
image_identity()
returned = owned('container', container_id)
output(root_fd, evidence['container-returned.json'], 'container-returned.json',
(json.dumps(returned, indent=2) + '\n').encode())
assert validate_container(returned, image, network_id,
name, command, labels, tmpfs) == created_config
final_network = owned('network', network_id)
output(root_fd, evidence['network-returned.json'], 'network-returned.json',
(json.dumps(final_network, indent=2) + '\n').encode())
validate_network(final_network, container_id)
result['outcome'] = 'pass'
except BaseException as error:
result['error'] = type(error).__name__
raise
finally:
if process is not None:
try:
os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:
pass
process.wait(timeout=10)
os.close(fd)
errors = []
# Recover only this exact nonce/owner if an uncertain create returned no ID.
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity is None:
try:
recovered = reconcile_created(kind, identity)
if kind == 'container':
container_id = recovered
else:
network_id = recovered
except Exception as error:
errors.append(type(error).__name__)
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity:
try:
value = remove_resource(kind, identity)
if kind == 'container':
result['runtime_oom'] = value['State']['OOMKilled']
if result['runtime_oom']:
result['outcome'] = 'fail'
except Exception as error:
errors.append(type(error).__name__)
result['cleanup'] = {'pass': not errors, 'errors': errors}
if errors:
result['outcome'] = 'fail'
result['finished_at'] = time.time()
named_root = ROOT.stat(follow_symlinks=False)
assert (named_root.st_dev, named_root.st_ino) == (root_info.st_dev, root_info.st_ino)
output(root_fd, evidence['logging-result.json'], 'logging-result.json',
(json.dumps(result, indent=2) + '\n').encode())
for descriptor in evidence.values():
os.close(descriptor)
os.close(config_fd)
os.close(root_fd)
assert not errors, errors
print(json.dumps(result)) |
|
The one reviewed registered-worker candidate observation passes. The exact parent test executed four distinct cold worker processes, required one new message per committed region, original default namespace/workflow/run identity, public committed-history counts through three signals, and final result {steps:3}. Every assertion passed (1 selected test/exit0); other tests were filtered. This is the fixed candidate-package scenario only, not registry-installed acceptance or a reusable runner. Independent terminal rechecks match the three canonical container projections, explicit network profile, parent/package bytes, private0600 observations and full-ID container/network absence. Runtime OOM=false; stderr is empty. All five preceding NONPASS outcomes remain preserved. Request exact terminal counterreview and final record/source/base review before approval merge/publication gates. {
"outcome": "pass",
"source": "7b6a3514dd9f7c6454a1b753a5b5247cab064722",
"controller_sha256": "2e2c2e486683b94abaf00c6cdb0ce589ca905f71033e0098b2da9bc0b32098b5",
"package_commit": "52208134296009bbae1af316c8efac89d3465990",
"crate_sha256": "6de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3",
"build_receipt_sha256": "4ac6427eeab05380cbfa3ce16da382c8e773622fb06ae6fcd4f95e540f26a8e7",
"parent_sha256": "217aaf912fb90ed8e6be5dc35ee9ade5144effb36f5d0b833179c484ad0428a8",
"test_sha256": "e66d177c6a1ffc486623169d1505766447c18c3c4650a2023a60f8bb9f9d11f0",
"server_manifest": "ghcr.io/durable-workflow/server@sha256:9d64e9aeee84b46d21715826a3e7e5a96eb8d4ce7fccb126b88b15596ab14973",
"server_source": "b6e04ce7e679464e91f6ceae83310d3bb3204092",
"cluster_version": "3.10.0",
"parent_pid": 2402505,
"exit_code": 0,
"runtime_oom": false,
"started_at": "2026-11-13T23:56:40.528296+00:00",
"finished_at": "2026-11-13T23:56:49.555747+00:00",
"configuration_projection_sha256": "2bd21c42d4dc065dcab62c469fa882bc179d7aa02aefc76dd68c24a964104600",
"independent_absence": {
"container": {
"id": "e14cde963c5593ebc60b5e2deca4b1dda86b9d005b14613b82fdfe9d81306878",
"inspect_empty": true,
"successful_id_filter_empty": true
},
"network": {
"id": "e219430d3d3740fd502633da0822dc5b178220c9aa720759f4d50a0d87b3ca78",
"inspect_empty": true,
"successful_id_filter_empty": true
}
},
"files": {
"logging-result.json": {
"bytes": 64336,
"sha256": "4718e05bfc4b81acd52644cd2ca92da34bd890c31a7660037eba70425cdcc9c2",
"mode": "0o600"
},
"logging.stdout": {
"bytes": 332,
"sha256": "86f062a91f582c42d756d5eb5b81a7d30d256a25031c71ccbeebb5e34130472b",
"mode": "0o600"
},
"logging.stderr": {
"bytes": 0,
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"mode": "0o600"
},
"container-created.json": {
"bytes": 14046,
"sha256": "4d2e2158ed695474575b8b17f10b6ec86ad54345ac9c42951364598637e6efe8",
"mode": "0o600"
},
"container-started.json": {
"bytes": 14833,
"sha256": "862adbb60485284e8194b89884c2f643d4a0a08c283a2530905a791eed7e603a",
"mode": "0o600"
},
"container-returned.json": {
"bytes": 14833,
"sha256": "862adbb60485284e8194b89884c2f643d4a0a08c283a2530905a791eed7e603a",
"mode": "0o600"
},
"network-created.json": {
"bytes": 1094,
"sha256": "db5aa0c1af118c2f85f59adbbbed811307fb49264bd0d56f55effe73f1a3960f",
"mode": "0o600"
},
"network-returned.json": {
"bytes": 1419,
"sha256": "605d631ca93983700078f326a3e8106520f6dfd26bcb403c007601945259d31c",
"mode": "0o600"
}
}
}Temporary diagnostics retain seven days. No tag or upload has occurred; main checks, reviewed approval, protected publication, registry-byte equality, a registry-installed logging repeat and downstream docs remain required. |
|
|
Security exact terminal counter-review: PASS, scoped to the one candidate-package logging observation and the current approval-record/source/base rebind.
All five earlier NONPASS observations remain historical. This PASS does not establish registry-installed byte equality/repeat, authorize a tag or upload, or replace protected publication and downstream gates. Keep the draft/current-head CI and those remaining gates intact. |
|
Protected publication is complete for 4.17.0. Release run 43532646142 passed all four gate/publish/registry-verify/Release jobs using maintained main Independent crates.io API and static archive readback match approved SHA-256 The accepted candidate logging receipt remains separate. A fresh normal-registry installed repeat, independent terminal review and published API/root Docs readback are next; no registry logging or shared #227 closure is inferred from publication alone. All five preceding candidate launcher/fixture NONPASS outcomes remain preserved. |
|
Security independent 4.17.0 publication readback: PASS for immutable publication identity and public metadata.
This closes publication identity only. The fresh normal-registry installed native lifecycle/deadline result, registry-installed four-process logging repeat, independent evidence review, public API/root Docs readback, and any shared logger closure remain separate gates. No result from the candidate-package observation is relabeled as registry-installed proof. |
|
Fresh normal-registry lifecycle/deadline repeat passes on published SDK 4.17.0 / qualified native 3.10.0, linux/amd64. The consumer was freshly resolved and downloaded from crates.io, without a patch or directory-source override; lock/API/cache SHA-256 agree at The separately prepared logging consumer retains that fresh registry cache/source and exact accepted qualifier No registry logging runtime has launched. Request exact source/data review for one bounded registry logging observation under the already reviewed sealed-host manual profile. The controller differs from accepted Build receipt SHA-256: {
"version": "4.17.0",
"installation": "crates.io registry without source override",
"package_commit": "52208134296009bbae1af316c8efac89d3465990",
"crate_sha256": "6de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3",
"test_source_commit": "7b6a3514dd9f7c6454a1b753a5b5247cab064722",
"test_sha256": "e66d177c6a1ffc486623169d1505766447c18c3c4650a2023a60f8bb9f9d11f0",
"manifest_sha256": "8b8fcaa21cf434d51d27215243ab71de04f1e71468609101b0476258239afac1",
"lock_sha256": "f01b9abab4a84c2c72da012c0131ff8dd77fd9d588c540ccb3d00b6eb8dd177d",
"build_messages_sha256": "c0ee3371b4dc6a48e2aa05b8cb7b2f4bec1d9d7179d1fce60ad9939bcfdecab8",
"executable_relative": "fixture/target/debug/deps/workflow_logging_server-d0e3880b66002e1b",
"executable_sha256": "a7c46d96d944e112685363b6940f275feab1dfeab10efe8ecf234b8f44b9b972",
"executable_bytes": 22433824,
"crate_file_count": 118,
"crate_members_equal": true,
"rust_image": "rust@sha256:300ec56abce8cc9448ddea2172747d048ed902a3090e6b57babb2bf19f754081",
"cargo_version": "1.86.0",
"build_network": "none",
"cargo_source_override": false,
"baseline_summary_sha256": "ec4eca5d2d7352d70e5ff27de030837ef14379e30d546befa736b736a3f4c942"
}Controller SHA-256: Literal reviewed launch (placeholders identify privately prepared paths; no path is public authority): /usr/bin/python3 -I -c 'import hashlib,pathlib,sys; p=pathlib.Path(sys.argv[1]); b=p.read_bytes(); assert hashlib.sha256(b).hexdigest()=="0dcb468f55dc205b8a9860ccb5e7c6f6ebdc91d66ad7fca983558690e95c6575"; sys.argv=sys.argv[1:]; exec(compile(b,str(p),"exec"),{"__name__":"__main__"})' <registry-controller.py> <prepared-registry-consumer-root> <accepted-source-checkout>"""One fixed candidate observation; public review packet contains these bytes."""
import base64
import fcntl
import hashlib
import json
import os
import pathlib
import resource
import re
import secrets
import signal
import stat
import subprocess
import sys
import time
import urllib.error
import urllib.request
ROOT = pathlib.Path(sys.argv[1]).absolute()
SOURCE = pathlib.Path(sys.argv[2]).absolute()
IMAGE = 'ghcr.io/durable-workflow/server@sha256:9d64e9aeee84b46d21715826a3e7e5a96eb8d4ce7fccb126b88b15596ab14973'
REVISION = 'b6e04ce7e679464e91f6ceae83310d3bb3204092'
RECEIPT = '2fbaaa9a100184f9e0f27087ecb3562e6ea84d35e5f23b052a23591150d66217'
BINARY = 'a7c46d96d944e112685363b6940f275feab1dfeab10efe8ecf234b8f44b9b972'
TEST = 'e66d177c6a1ffc486623169d1505766447c18c3c4650a2023a60f8bb9f9d11f0'
def digest(data):
return hashlib.sha256(data).hexdigest()
def directory(path):
assert path.is_absolute() and '..' not in path.parts
current = os.open('/', os.O_RDONLY | os.O_DIRECTORY)
try:
for part in path.parts[1:]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=current)
os.close(current)
current = following
return current
except BaseException:
os.close(current)
raise
def read_at(root, relative):
parts = pathlib.PurePosixPath(relative).parts
assert parts and not relative.startswith('/') and '..' not in parts
parent = os.dup(root)
try:
for part in parts[:-1]:
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=parent)
os.close(parent)
parent = following
fd = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=parent)
try:
info = os.fstat(fd)
assert stat.S_ISREG(info.st_mode) and info.st_nlink == 1 and info.st_uid == os.getuid()
assert info.st_size <= 64 * 1024**2
value = os.pread(fd, info.st_size + 1, 0)
after = os.fstat(fd)
fields = ('st_dev', 'st_ino', 'st_size', 'st_uid', 'st_gid', 'st_mode',
'st_nlink', 'st_mtime_ns', 'st_ctime_ns')
assert len(value) == info.st_size
assert all(getattr(info, field) == getattr(after, field) for field in fields)
return value
finally:
os.close(fd)
finally:
os.close(parent)
def exclusive(root, name):
assert '/' not in name and name not in ('', '.', '..')
return os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW,
0o600, dir_fd=root)
def output(root, fd, name, value):
before = os.fstat(fd)
named = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (named.st_dev, named.st_ino) == (before.st_dev, before.st_ino)
assert stat.S_ISREG(named.st_mode) and stat.S_IMODE(named.st_mode) == 0o600
assert named.st_uid == os.getuid() and named.st_nlink == 1
with os.fdopen(os.dup(fd), 'wb') as handle:
handle.write(value)
handle.flush()
after = os.stat(name, dir_fd=root, follow_symlinks=False)
assert (after.st_dev, after.st_ino, after.st_nlink) == (before.st_dev, before.st_ino, 1)
root_fd = directory(ROOT)
root_info = os.fstat(root_fd)
assert root_info.st_uid == os.getuid() and stat.S_IMODE(root_info.st_mode) == 0o700
receipt_bytes = read_at(root_fd, 'build-receipt.json')
assert digest(receipt_bytes) == RECEIPT
receipt = json.loads(receipt_bytes)
assert receipt['executable_sha256'] == BINARY
assert digest(read_at(root_fd, 'fixture/tests/workflow_logging_server.rs')) == TEST
assert digest(read_at(root_fd, 'fixture/Cargo.lock')) == receipt['lock_sha256']
assert digest(read_at(root_fd, 'fixture/Cargo.toml')) == receipt['manifest_sha256']
assert digest(read_at(root_fd, 'fixture/logging-build.jsonl')) == receipt['build_messages_sha256']
binary_bytes = read_at(root_fd, receipt['executable_relative'])
assert len(binary_bytes) == receipt['executable_bytes']
assert digest(binary_bytes) == BINARY
fd = os.memfd_create('reviewed-logging-parent', os.MFD_ALLOW_SEALING)
with os.fdopen(os.dup(fd), 'wb') as image_file:
image_file.write(binary_bytes)
os.fchmod(fd, 0o500)
seals = fcntl.F_SEAL_WRITE | fcntl.F_SEAL_GROW | fcntl.F_SEAL_SHRINK | fcntl.F_SEAL_SEAL
fcntl.fcntl(fd, fcntl.F_ADD_SEALS, seals)
assert fcntl.fcntl(fd, fcntl.F_GET_SEALS) == seals
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
supervisor = SOURCE / 'scripts/acceptance/installed-native/cell-supervisor.sh'
source_fd = directory(SOURCE)
supervisor_bytes = read_at(source_fd, 'scripts/acceptance/installed-native/cell-supervisor.sh')
os.close(source_fd)
assert digest(supervisor_bytes) == '25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b'
def runtime_command(script, deadline):
script = script.decode()
original = ' /bin/sh "$0" --command "$@"'
assert script.count(original) == 1
wrapper = 'supervisor=$1\nshift\n' + script.replace(original,
' /bin/sh -c "$supervisor" supervisor --command "$@"')
return ['-c', wrapper, 'supervisor', script, str(deadline), '10', 'both',
'/usr/local/bin/durable-workflow-server']
# procfs fdinfo admits only kernel-created decimal descriptor names. A same-UID
# writer cannot create config.json, contexts or plugin paths in this namespace.
config_path = '/proc/' + str(os.getpid()) + '/fdinfo'
config_fd = os.open(config_path, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
config_info = os.fstat(config_fd)
evidence = {name: exclusive(root_fd, name) for name in
('logging.stdout', 'logging.stderr', 'logging-result.json',
'container-created.json', 'container-started.json', 'container-returned.json',
'network-created.json', 'network-returned.json')}
CLOSED_ENV = {'PATH': '/usr/bin:/bin', 'HOME': '/nonexistent', 'LANG': 'C', 'LC_ALL': 'C'}
def docker_command(args, config):
assert args[0] == 'docker'
return ['/usr/bin/docker', '--host', 'unix:///run/docker.sock', '--config',
'/proc/self/fd/' + str(config)] + args[1:]
def call(args, **kwargs):
tool = os.stat('/usr/bin/docker', follow_symlinks=False)
assert stat.S_ISREG(tool.st_mode) and tool.st_uid == 0 and tool.st_nlink == 1
assert stat.S_IMODE(tool.st_mode) == 0o755
assert digest(pathlib.Path('/usr/bin/docker').read_bytes()) == '40cdaf7fd0f21089dd9e15b0c3a7dd7f2399027f010e366dac6304ae0615954a'
assert all(name.isdecimal() for name in os.listdir(config_fd))
config_named = os.stat(config_path, follow_symlinks=False)
config_open = os.fstat(config_fd)
assert (config_named.st_dev, config_named.st_ino) == (config_info.st_dev, config_info.st_ino)
assert (config_open.st_dev, config_open.st_ino) == (config_info.st_dev, config_info.st_ino)
kwargs.setdefault('check', True)
return subprocess.run(docker_command(args, config_fd), capture_output=True, timeout=30,
cwd='/', env=CLOSED_ENV, pass_fds=(config_fd,), **kwargs)
socket_info = os.stat('/run/docker.sock', follow_symlinks=False)
assert stat.S_ISSOCK(socket_info.st_mode) and socket_info.st_uid == 0
def engine():
current = os.stat('/run/docker.sock', follow_symlinks=False)
assert (current.st_dev, current.st_ino, current.st_uid, current.st_gid, current.st_mode) == (
socket_info.st_dev, socket_info.st_ino, socket_info.st_uid, socket_info.st_gid, socket_info.st_mode)
identity = call(['docker', 'info', '--format', '{{.ID}}']).stdout.strip()
assert digest(identity) == '0a179ff32531e41cfc2d465b1d46afc1df91c0975e9627969f75c67e00b0e892'
def image_identity():
image = json.loads(call(['docker', 'image', 'inspect', IMAGE]).stdout)[0]
assert image['Id'] == IMAGE.split('@')[1]
assert image['RepoDigests'] == [IMAGE] and image['Descriptor']['digest'] == IMAGE.split('@')[1]
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert digest(json.dumps(image['Config'], sort_keys=True, separators=(',', ':')).encode()) == 'c88782b528aee2a1b7804cd62cb95afac9df8c5b2f89c471924c6c1085c63b62'
return image
engine()
image = image_identity()
assert image['Os'] == 'linux' and image['Architecture'] == 'amd64'
assert image['Config']['Labels']['org.opencontainers.image.revision'] == REVISION
assert image['Config']['Labels']['dev.durable-workflow.release.tag'] == '3.10.0'
assert image['Config']['Entrypoint'] == ['/usr/local/bin/durable-workflow-server']
nonce = secrets.token_hex(16)
name = 'sdk-rust-417-logging-' + nonce[:12]
labels = {'owner': 'sdk-rust', 'task': 'logger227', 'qualification_nonce': nonce}
label_args = [argument for key, value in labels.items() for argument in ('--label', key + '=' + value)]
token = 'fixture-' + secrets.token_hex(24)
key = 'base64:' + base64.b64encode(secrets.token_bytes(32)).decode()
container_id = network_id = None
process = None
result = {'outcome': 'fail', 'build_receipt_sha256': RECEIPT,
'binary_sha256': BINARY, 'server_manifest': IMAGE, 'server_source': REVISION,
'started_at': time.time(), 'limits': {'consumer_cpus': 2, 'consumer_as': 2147483648,
'consumer_cpu_seconds': 60, 'consumer_wall_seconds': 180}}
def owned(kind, identity):
value = json.loads(call(['docker', kind, 'inspect', identity]).stdout)[0]
actual = value['Config']['Labels'] if kind == 'container' else value['Labels']
assert value['Id'] == identity and all(actual.get(k) == v for k, v in labels.items())
return value
def full_id(raw):
identity = raw.decode('ascii').strip()
assert re.fullmatch('[0-9a-f]{64}', identity), 'uncertain create reply'
return identity
def reconcile_created(kind, identity):
if identity is not None:
assert re.fullmatch('[0-9a-f]{64}', identity)
return identity
filters = [arg for key, val in labels.items() for arg in ('--filter', 'label=' + key + '=' + val)]
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
candidates = call(query + filters).stdout.split()
assert len(candidates) <= 1
if candidates:
recovered = full_id(candidates[0])
owned(kind, recovered)
return recovered
return None
def remove_resource(kind, identity):
value = owned(kind, identity)
call(['docker', 'rm', '-f', '-v', identity] if kind == 'container'
else ['docker', 'network', 'rm', identity])
observed = call(['docker', kind, 'inspect', identity], check=False)
missing = ('no such container: ' + identity if kind == 'container'
else 'network ' + identity + ' not found').encode()
assert observed.returncode != 0 and json.loads(observed.stdout) == []
assert missing in observed.stderr.lower()
query = ['docker', 'ps', '-aq', '--no-trunc'] if kind == 'container' else ['docker', 'network', 'ls', '-q', '--no-trunc']
assert call(query + ['--filter', 'id=' + identity]).stdout.strip() == b''
return value
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args):
raise AssertionError('redirect refused')
def consumer_limits():
os.sched_setaffinity(0, sorted(os.sched_getaffinity(0))[:2])
resource.setrlimit(resource.RLIMIT_AS, (2 * 1024**3, 2 * 1024**3))
resource.setrlimit(resource.RLIMIT_CPU, (60, 60))
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
def validate_network(value, runtime=None):
assert value['Driver'] == 'bridge' and value['Scope'] == 'local'
assert value['Internal'] is False and value['Ingress'] is False and value['Attachable'] is False
assert value['EnableIPv6'] is False
assert value['Options'] == {
'com.docker.network.bridge.enable_ip_masquerade': 'false',
'com.docker.network.bridge.enable_icc': 'false',
'com.docker.network.bridge.host_binding_ipv4': '127.0.0.1'}
assert set(value.get('Containers') or {}) <= ({runtime} if runtime else set())
def validate_container(value, image, network, name, command, labels, tmpfs):
assert value['Image'] == image['Id']
config, host = value['Config'], value['HostConfig']
expected_env = dict(entry.split('=', 1) for entry in image['Config']['Env'])
expected_env.update(DB_CONNECTION='sqlite', DB_DATABASE='/app/database/runtime.sqlite',
DW_RUST_MAINTENANCE_LOOP='1')
assert len(config['Env']) == len(expected_env)
assert dict(entry.split('=', 1) for entry in config['Env']) == expected_env
assert config['Image'] == IMAGE and config['Entrypoint'] == ['/bin/sh'] and config['Cmd'] == command
assert config['Hostname'] == name and config['User'] == '1000:1000'
assert config['WorkingDir'] == '/app' and config['StopSignal'] == 'SIGTERM'
assert config['Volumes'] == image['Config']['Volumes']
assert config['ExposedPorts'] == {'8080/tcp': {}}
assert config['Labels'] == dict(image['Config']['Labels'], **labels)
assert not config['Tty'] and not config['OpenStdin']
expected = {'ReadonlyRootfs': True, 'Init': True, 'Privileged': False,
'NanoCpus': 10**9, 'Memory': 1024**3, 'MemorySwap': 1024**3, 'PidsLimit': 256,
'CapAdd': None, 'CapDrop': ['ALL'], 'SecurityOpt': ['no-new-privileges'],
'NetworkMode': network, 'Binds': None, 'Tmpfs': tmpfs,
'PortBindings': {'8080/tcp': [{'HostIp': '127.0.0.1', 'HostPort': ''}]},
'PidMode': '', 'UTSMode': '', 'UsernsMode': '', 'IpcMode': 'private',
'Devices': [], 'DeviceRequests': None, 'VolumesFrom': None, 'ExtraHosts': None,
'AutoRemove': False, 'RestartPolicy': {'Name': 'no', 'MaximumRetryCount': 0}}
assert all(host.get(key) == val for key, val in expected.items())
assert 'OomKillDisable' in host and host['OomKillDisable'] in (False, None)
assert not host.get('Mounts')
assert all(m['Type'] == 'tmpfs' and m['Destination'] in tmpfs for m in value['Mounts'])
packet = json.loads(json.dumps({k: value[k] for k in ('Image', 'Config', 'HostConfig', 'Mounts')}))
# Docker29 changes this unset/false default during start. Both retain the
# kernel OOM killer; true is refused. Every other field remains exact.
packet['HostConfig']['OomKillDisable'] = False
return digest(json.dumps(packet, sort_keys=True, separators=(',', ':')).encode())
tmpfs = {'/tmp': 'mode=1777,size=64m',
'/app/database': 'uid=1000,gid=1000,mode=0700,size=64m',
'/app/storage': 'uid=1000,gid=1000,mode=0700,size=64m',
'/credentials': 'uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev'}
command = None
created_config = None
try:
engine()
image_identity()
network_id = full_id(call(['docker', 'network', 'create', '--driver', 'bridge',
'--opt', 'com.docker.network.bridge.enable_ip_masquerade=false',
'--opt', 'com.docker.network.bridge.enable_icc=false',
'--opt', 'com.docker.network.bridge.host_binding_ipv4=127.0.0.1'] + label_args + [name]).stdout)
result['network_id'] = network_id
created_network = owned('network', network_id)
output(root_fd, evidence['network-created.json'], 'network-created.json',
(json.dumps(created_network, indent=2) + '\n').encode())
validate_network(created_network)
deadline = str(int(time.time()) + 240)
command = runtime_command(supervisor_bytes, deadline)
engine()
image_identity()
container_id = full_id(call(['docker', 'create', '--pull=never', '--init', '--name', name,
'--hostname', name] + label_args + [
'--cpus', '1', '--memory', '1g', '--memory-swap', '1g', '--pids-limit', '256', '--read-only', '--user', '1000:1000',
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--network', network_id,
'--publish', '127.0.0.1::8080', '--tmpfs', '/tmp:mode=1777,size=64m',
'--tmpfs', '/app/database:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/app/storage:uid=1000,gid=1000,mode=0700,size=64m',
'--tmpfs', '/credentials:uid=1000,gid=1000,mode=0700,size=64k,noexec,nosuid,nodev',
'--env', 'DB_CONNECTION=sqlite', '--env', 'DB_DATABASE=/app/database/runtime.sqlite',
'--env', 'DW_RUST_MAINTENANCE_LOOP=1', '--entrypoint', '/bin/sh', IMAGE] + command).stdout)
result['container_id'] = container_id
before = owned('container', container_id)
output(root_fd, evidence['container-created.json'], 'container-created.json',
(json.dumps(before, indent=2) + '\n').encode())
result['container_id'], result['network_id'] = container_id, network_id
created_config = validate_container(before, image, network_id, name, command, labels, tmpfs)
validate_network(owned('network', network_id), container_id)
result['created_config_sha256'] = created_config
engine()
image_identity()
assert validate_container(owned('container', container_id), image, network_id,
name, command, labels, tmpfs) == created_config
call(['docker', 'start', container_id])
started = owned('container', container_id)
output(root_fd, evidence['container-started.json'], 'container-started.json',
(json.dumps(started, indent=2) + '\n').encode())
assert validate_container(started, image, network_id,
name, command, labels, tmpfs) == created_config
validate_network(owned('network', network_id), container_id)
call(['docker', 'exec', '-i', container_id, '/bin/sh', '-c',
'umask 077; IFS= read -r token && IFS= read -r key && '
'printf %s "$token" > /credentials/token && printf %s "$key" > /credentials/server-key && '
': > /credentials/ready.tmp && mv /credentials/ready.tmp /credentials/ready'],
input=(token + '\n' + key + '\n').encode())
live = owned('container', container_id)
ports = live['NetworkSettings']['Ports']['8080/tcp']
assert len(ports) == 1 and ports[0]['HostIp'] == '127.0.0.1'
port = int(ports[0]['HostPort'])
assert 0 < port < 65536
origin = 'http://127.0.0.1:' + str(port)
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
for attempt in range(60):
try:
request = urllib.request.Request(origin + '/api/cluster/info',
headers={'Authorization': 'Bearer ' + token, 'X-Namespace': 'default'})
with opener.open(request, timeout=1) as response:
cluster = json.load(response)
assert cluster['version'] == '3.10.0'
result['cluster_info'] = cluster
break
except (urllib.error.URLError, ConnectionError):
time.sleep(.25)
else:
raise AssertionError('runtime readiness bound expired')
args = ['/proc/self/fd/' + str(fd), '--ignored', '--exact',
'published_logging_emits_once_per_committed_step_across_cold_worker_processes',
'--nocapture', '--test-threads=1']
env = {'DURABLE_WORKFLOW_LOCAL_ISOLATED': '1', 'DURABLE_WORKFLOW_SERVER_URL': origin,
'DURABLE_WORKFLOW_AUTH_TOKEN': token, 'DURABLE_WORKFLOW_EXPECT_SERVER_VERSION': '3.10.0'}
process = subprocess.Popen(args, env=env, pass_fds=(fd,), start_new_session=True,
preexec_fn=consumer_limits, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate(timeout=180)
assert len(stdout) + len(stderr) <= 1024**2
assert all(secret.encode() not in stdout + stderr for secret in (token, key))
output(root_fd, evidence['logging.stdout'], 'logging.stdout', stdout)
output(root_fd, evidence['logging.stderr'], 'logging.stderr', stderr)
result['parent_pid'], result['exit_code'] = process.pid, process.returncode
assert process.returncode == 0, 'logging parent failed'
assert b'PASS: four cold worker processes' in stdout
assert digest(os.pread(fd, len(binary_bytes) + 1, 0)) == BINARY
engine()
image_identity()
returned = owned('container', container_id)
output(root_fd, evidence['container-returned.json'], 'container-returned.json',
(json.dumps(returned, indent=2) + '\n').encode())
assert validate_container(returned, image, network_id,
name, command, labels, tmpfs) == created_config
final_network = owned('network', network_id)
output(root_fd, evidence['network-returned.json'], 'network-returned.json',
(json.dumps(final_network, indent=2) + '\n').encode())
validate_network(final_network, container_id)
result['outcome'] = 'pass'
except BaseException as error:
result['error'] = type(error).__name__
raise
finally:
if process is not None:
try:
os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:
pass
process.wait(timeout=10)
os.close(fd)
errors = []
# Recover only this exact nonce/owner if an uncertain create returned no ID.
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity is None:
try:
recovered = reconcile_created(kind, identity)
if kind == 'container':
container_id = recovered
else:
network_id = recovered
except Exception as error:
errors.append(type(error).__name__)
for kind, identity in [('container', container_id), ('network', network_id)]:
if identity:
try:
value = remove_resource(kind, identity)
if kind == 'container':
result['runtime_oom'] = value['State']['OOMKilled']
if result['runtime_oom']:
result['outcome'] = 'fail'
except Exception as error:
errors.append(type(error).__name__)
result['cleanup'] = {'pass': not errors, 'errors': errors}
if errors:
result['outcome'] = 'fail'
result['finished_at'] = time.time()
named_root = ROOT.stat(follow_symlinks=False)
assert (named_root.st_dev, named_root.st_ino) == (root_info.st_dev, root_info.st_ino)
output(root_fd, evidence['logging-result.json'], 'logging-result.json',
(json.dumps(result, indent=2) + '\n').encode())
for descriptor in evidence.values():
os.close(descriptor)
os.close(config_fd)
os.close(root_fd)
assert not errors, errors
print(json.dumps(result)) |
|
Security exact source/data review of the proposed registry-installed logging observation: PASS for one bounded observation with controller Independent checks:
Use the published literal hash-binding invocation and the exact prepared root/controller/source checkout. This permits one observation only; any source, receipt, binary, root, Server, engine, configuration, result, or cleanup drift requires a new review. Retain the full private 0600 result/config/stdout/stderr packet and independently prove the exact container and network absent. The candidate-package PASS remains separate and all five earlier NONPASS outcomes remain historical. This is not a terminal registry logging verdict and does not itself close the logger feature, Docs, package, or shared issue. Return the exact observation and cleanup receipt for independent counter-review. |
|
The single reviewed normal-registry 4.17.0 / native3.10.0 linux/amd64 logging observation passed. Parent exit0; selected acceptance1 PASS /4 filtered in6.55s; no OOM. The unchanged accepted test asserts four distinct child PIDs, one observation for each new committed region, original namespace/workflow/run identity, public-history gates, three applied signals and exact final The owned runtime and network are independently absent by exact full-ID missing response, structured inspect Request independent terminal evidence counter-review on this exact retained packet. No shared cross-SDK #227 closure is inferred. Artifact hashes, identities and absence evidence: {
"outcome": "pass",
"runtime_outcome": "pass",
"parent_pid": 2509850,
"exit_code": 0,
"runtime_oom": false,
"receipt_sha256": "2fbaaa9a100184f9e0f27087ecb3562e6ea84d35e5f23b052a23591150d66217",
"binary_sha256": "a7c46d96d944e112685363b6940f275feab1dfeab10efe8ecf234b8f44b9b972",
"config_projections": [
"e3153c580bd0449d998e924395e754dc59da31bc0b606bb6de92eaf88c200f38",
"e3153c580bd0449d998e924395e754dc59da31bc0b606bb6de92eaf88c200f38",
"e3153c580bd0449d998e924395e754dc59da31bc0b606bb6de92eaf88c200f38"
],
"absence": {
"container": {
"full_id": "b8f97689be49e833675aa14f2ea00522a8b5f12233e2c4730647be655ce4bd86",
"inspect_missing": true,
"structured_inspect": [],
"full_id_filter_empty": true,
"owner_task_nonce_filter_empty": true
},
"network": {
"full_id": "757f8b2c21b7ea15db22d5b7bf074325492cf22565374cc9c59bc11b0af78836",
"inspect_missing": true,
"structured_inspect": [],
"full_id_filter_empty": true,
"owner_task_nonce_filter_empty": true
}
},
"artifacts": {
"logging.stdout": {
"bytes": 332,
"sha256": "5f074e10b7ebeca5671fe2406fb9b25a6250ed04399756a640b3bf8fc18f87b5",
"mode": "0600",
"single_link": true
},
"logging.stderr": {
"bytes": 0,
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"mode": "0600",
"single_link": true
},
"logging-result.json": {
"bytes": 64334,
"sha256": "e9b7d8f9a35af747687c09c0446eee0aed034608178b3d76128243609af0e1a1",
"mode": "0600",
"single_link": true
},
"container-created.json": {
"bytes": 14047,
"sha256": "3294bb251b67a00fdd9f2ee73cd5f3679147fd096af21e2af7189aac83c75927",
"mode": "0600",
"single_link": true
},
"container-started.json": {
"bytes": 14834,
"sha256": "2b3a5d957b9575b20b7eba1a75d2b9089c730a629320a993d126c330fc3fb9f1",
"mode": "0600",
"single_link": true
},
"container-returned.json": {
"bytes": 14834,
"sha256": "2b3a5d957b9575b20b7eba1a75d2b9089c730a629320a993d126c330fc3fb9f1",
"mode": "0600",
"single_link": true
},
"network-created.json": {
"bytes": 1094,
"sha256": "ad37b1c9c04d3ff273c150aa469699ebe37e5f7b9d34e8f3290cb222fe5d46b7",
"mode": "0600",
"single_link": true
},
"network-returned.json": {
"bytes": 1419,
"sha256": "4c9dd88ca506b668120f94fa245c9dcd7fd93098e43ac38f68ebbc70e6e6ecef",
"mode": "0600",
"single_link": true
}
}
}Sanitized test stdout: Published API documentation also refreshed successfully through 43533751449. Public Root Docs owner is preparing the eight-locale Rust guide/constraints and selector adoption; final terminal review and that public guide readback remain before Rust's full shared227 delivery is recorded. |
|
Security exact terminal counter-review: PASS for the one normal-registry 4.17.0 logging observation. Independent checks:
All five earlier candidate launcher and fixture outcomes remain NONPASS and are not replaced. This closes the published registry-installed Rust logging observation and its exact cleanup only. The eight-locale guide and selector adoption, other SDKs, shared 227 closure, and any new package or release remain separate. |
|
The Rust Docs guide/constraints/selector slice is delivered: final receipt. Docs #542 merged as Fresh registry metadata and Rust API identity/anchors reproduce 4.17.0/source |



Approve the exact 4.17.0 package from source
52208134296009bbae1af316c8efac89d3465990, archive SHA-2566de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3, Cargo1.86 and118 canonical members. The two committed files are the unchanged generated lifecycle/deadline approval and summary. Both cells passed on qualified native3.10.0/linux-amd64, including public history, same-worker continuation and cleanup; independent record review.Candidate-package four-process logging passed and received terminal/source/base counter-review. Accepted main
db81b918b4d0e9a021514c7dc42586b0efaf9926exactly equals the reviewed tree, all five main workflows passed, and the remote branch is absent. Protected release43532646142 published the identical approved bytes; independent publication readback verifies immutable tag4.17.0→522, registry/archive/VCS and stable Latest Release.The fresh normal-registry lifecycle/deadline and four-cold-worker logging repeat also passes, with independent terminal counter-review. The consumer has no source patch/override; all118 installed members match the published crate. Each new committed region emits exactly one observation with original run identity; three signal deliveries and final result match. Resource/configuration/output/package identity and complete cleanup checks pass, no OOM. Published API docs and public build/API readback select this same4.17 artifact. Root eight-locale guide/constraints/selector follow-through remains on durable-workflow/.github#227 with its Docs owner.
All five preceding launcher/fixture NONPASS outcomes remain recorded, separate from the two passing package observations. The qualifier corrections changed no library/package bytes. Scope is this Rust logging delivery; uncommitted attempts may repeat process logs, and other bindings, #980 and reusable-driver approval remain separate.