Skip to content

Approve exact 4.17.0 packaged lifecycle acceptance - #269

Merged
rmcdaniel merged 3 commits into
mainfrom
agent/sdk-rust/417-package-approval
Nov 14, 2026
Merged

rmcdaniel merged 3 commits into
mainfrom
agent/sdk-rust/417-package-approval

Conversation

@rmcdaniel

@rmcdaniel rmcdaniel commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Approve the exact 4.17.0 package from source 52208134296009bbae1af316c8efac89d3465990, archive SHA-256 6de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3, 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 db81b918b4d0e9a021514c7dc42586b0efaf9926 exactly 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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

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 6d7b08d1…, manifest/lock/build-message hashes and compiled parent SHA 89ae4f0fdea91e503d8b7e80426e7160259e324520341b2f325d7aed5edfb8b1. The build receipt SHA is 6f197812e8218fc44d513bfa1040b91b19fe168367c70e53e16882b0db13fe79.

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 /proc/self/exe checks bind all four cold children to that same image. The native consumer has only the explicit synthetic fixture environment, two-CPU affinity, 2 GiB address-space/60 CPU-second/180-second wall bounds and process-group cleanup. One immutable native runtime gets 1 CPU/1 GiB/256 PIDs, an internal network and numeric loopback ephemeral port; the existing reviewed supervisor enforces a 240-second runtime limit independently. State/credentials are private bounded tmpfs. IDs+nonce/owner labels bind lifecycle and cleanup; no production credentials, vault, source install or new package build.

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 9420ed59345c34e2f8564d7bdb3fd2bb8456939ced19a94fc3ec4f8d22aec72d. The source/build proof and lifecycle record will be independently rechecked after execution. No runtime has launched yet.

"""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))

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security exact-record review: PASS, limited to the two generated approval artifacts at 8f7812b6d98eef4a7f140ed4ae6fc46b21b4997e / tree 3174acfa941dc033052dc7b62b8ca0181c474ce4.

Independent checks:

  • the commit is a one-parent, two-file addition on accepted 0ac841a2f0e3f1b717cc76f7e2cb725ee62f144e; the recorded source 52208134296009bbae1af316c8efac89d3465990 has the same accepted release tree;
  • the generated and committed approval bytes are identical (SHA-256 930d7d3424d77401dd9cd65771b9df8c6893130048b7a1a14207d94cde053e29), as are the generated and committed summary bytes (9c00c5227020ad5618bb132e89477dd59324a4379560f8779b0e27c3b250b647);
  • the repository's maintained approval parser, tracked-blob reader, acceptance-summary verifier, and all 40 release-package tests pass on the exact head;
  • the retained exact crate independently passes the maintained approved-archive verifier: durable-workflow 4.17.0, Cargo 1.86.0, source/VCS 52208134296009bbae1af316c8efac89d3465990, archive SHA-256 6de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3, 118 canonical regular members, file-list SHA-256 157740d02233ad198139d250487fc2fd1e98df9f6d97646a7a61675219e2f907, and unchanged archive hash after both cells;
  • the acceptance binds qualified native Server 3.10.0, source b6e04ce7e679464e91f6ceae83310d3bb3204092, index ca92c866..., executed amd64 child 9d64e9ae..., linux/amd64, and exactly deadline plus lifecycle;
  • both cells report pass, exact Server version, zero driver/history exits, passing public-history checks with no problems, unchanged binary, and the same worker after their cases; the top-level checks/outcome and cleanup pass with empty errors/container/network/local-leftover sets;
  • no private/local infrastructure path appears in either committed public record, and git diff --check is clean.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

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>

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security pre-execution review of the manual logging controller at comment 6866514990 (exact source SHA-256 9420ed59345c34e2f8564d7bdb3fd2bb8456939ced19a94fc3ec4f8d22aec72d): HOLD; do not execute this source.

The package/build side is coherent: the exact receipt hashes to 6f197812e8218fc44d513bfa1040b91b19fe168367c70e53e16882b0db13fe79, binds accepted source and crate 6de77487..., 118 members, Cargo 1.86, the exact test/manifest/lock/build-message hashes, and parent 89ae4f0f...; the posted Python parses successfully. The remaining findings are launch/effect boundaries:

  1. Verified supervisor bytes are later consumed through a mutable pathname. The controller compares supervisor.read_bytes() with the exact Git blob, then passes the pathname to Docker as a bind source. A same-UID replacement between that comparison and daemon bind resolution is not detected, and neither the path components nor the file's dev/inode/uid/gid/mode/link count are held or rechecked. Capture the exact blob into a non-replaceable consumer object (or copy the already captured bytes into the stopped container through a bounded stdin/tar operation), and verify its identity/bytes before and after use. Do not let Docker reopen an actor-mutable source pathname.
  2. The controller itself and its evidence root are not invocation-bound. A hash in a comment does not make a pathname invocation authoritative. Supply a literal fixed bootstrap that hashes and executes these reviewed bytes, hold a private no-link root, and create logging.stdout, logging.stderr, and logging-result.json by exclusive O_NOFOLLOW descriptors with fixed private modes. The current Path.write_bytes/write_text calls follow replaceable names and can overwrite or relabel evidence.
  3. Controller tool/environment authority remains ambient. docker and git are resolved from inherited PATH, Docker context/config/host variables are inherited, and no empty private Docker configuration or engine identity is bound. The consumer environment is closed, but the effectful controller is not. Bind the exact trusted tool paths/identities and a closed controller environment, including explicit engine/config authority.
  4. Image/container selection is incomplete around effects. Add --pull=never; bind the cached exact child/index/platform identity (including the daemon's actual descriptor/RepoDigest form), and recheck the complete created container image, entrypoint, environment, mounts, security/resource settings and labels immediately before start and after return. The current pre-inspect plus partial HostConfig assertions leaves a removal/pull or configuration-mutation interval.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

Frozen manual-controller successor SHA256 6ec9706d5be1905cc6418e5e2f5e7fe89819d5ca43188443ee357d50eb12e0a5, superseding the unexecuted9420ed HOLD. All six offline groups pass, including an actual old-path supervisor substitution versus captured-code execution, exclusive/swap-after-open output refusals, root/input link refusals, poisoned PATH/Docker host/config/context closure, corrupted-config refusal before subprocess, and twelve complete-container mutation refusals. No Docker or SDK/Server operation ran in these controls.

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 /usr/bin/docker bytes, closed environment, private empty config through a held directory FD, explicit local socket and engine fingerprint. Cached child/Descriptor/RepoDigest/platform/config and full created configuration are rechecked around start/return, with --pull=never. The sealed compiled parent and business test are unchanged. Initial compile NONPASS is preserved.

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))

@rmcdaniel

Copy link
Copy Markdown
Member Author

Complete inert controls, SHA256 96ce5aabf43189eb2035459e1748d9a0ac27f349ac390bf0807457c8acc01fde. Invocation: python3 -I <controls.py> <controller.py> <accepted-cell-supervisor.sh>. They extract only the named pure/helper functions from the frozen controller, mock effectful subprocess calls, and use disposable synthetic files.

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()

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security review of frozen controller 6ec9706d5be1905cc6418e5e2f5e7fe89819d5ca43188443ee357d50eb12e0a5 and inert controls 96ce5aabf43189eb2035459e1748d9a0ac27f349ac390bf0807457c8acc01fde: HOLD; do not launch the logging runtime yet.

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, --pull=never is present, the internal network and complete security/resource projection are checked before/after effects, and the six inert groups cover the described predecessor failures. Build/package/test identities remain coherent.

Two concrete boundaries remain:

  1. The Docker config bytes are still mutable after validation and before consumption. call() checks config.json through the held directory FD, then invokes Docker; the file and directory are owned by the same UID and remain writable. A same-UID writer can rewrite the same inode in that interval without replacing the held directory or name, so the Docker CLI can consume bytes different from those just validated. The current poison control changes the file before call() and therefore does not exercise this race. Use a kernel-enforced empty config namespace or a root-owned/non-writable captured config, and add a control that mutates after validation but before the mocked/real consumer open and proves refusal/no subprocess effect.
  2. Uncertain-create recovery misses empty or malformed successful output. network_id/container_id are assigned .strip() output without an exact full-ID check. The label-based recovery branch runs only when the value is None; '' or any malformed nonempty value therefore skips recovery (or is repeatedly inspected as the wrong ID), leaving the successfully created owned resource behind. Validate the full returned ID before granting authority; on empty/malformed output retain the state as uncertain and reconcile the exact nonce/owner/task labels. Add separate network and container predecessor controls for successful creation with empty/malformed replies, requiring exact-ID removal and independent absence.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

Frozen manual successor c94a2f12f367f21d5882a358643a687e9fca61fb7b01f1fac9972b3f21108c1d and controls 75ad63aae1c9883519fbb38a7eec4198e884fc4db2ac59be0a8a5cd2a1de333d, superseding the unexecuted6ec970 HOLD. Eight groups pass. The new controls mutate the old same inode between validation/consumer-open (predecessor admits poison), then try that exact interval against a kernel fdinfo config namespace (creation refused; the consumer still sees no config). /proc/<own-pid>/fdinfo accepts only kernel-created decimal descriptor entries; config.json, contexts and plugin names cannot be introduced by a same-UID writer. Docker receives that held directory FD in its closed environment. A separate read-only docker info confirms this empty-config namespace is accepted by the existing engine; no container or SDK/Server process was created.

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))

@rmcdaniel

Copy link
Copy Markdown
Member Author

Full inert controls SHA256 75ad63aae1c9883519fbb38a7eec4198e884fc4db2ac59be0a8a5cd2a1de333d. Eight test groups PASS, no runtime or image build. Invocation: python3 -I <controls.py> <controller.py> <accepted-cell-supervisor.sh>.

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()

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security review of frozen controller c94a2f12f367f21d5882a358643a687e9fca61fb7b01f1fac9972b3f21108c1d and controls 75ad63aae1c9883519fbb38a7eec4198e884fc4db2ac59be0a8a5cd2a1de333d: PASS for one exact bounded logging runtime execution only.

I independently extracted the two public code blocks and reproduced both SHA-256 identities. The accepted supervisor is still 25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b; all eight inert control groups pass under isolated Python.

The two findings from the prior HOLD are closed:

  • Docker now receives a held /proc/<own-pid>/fdinfo directory as its config namespace. Only kernel-created decimal descriptor entries can exist there; neither a same-UID writer nor a path substitution can add config.json, contexts or plugin metadata between validation and Docker's open. The successor control exercises that exact interval, while its predecessor admits the same-inode poison. I also independently ran the read-only, closed-environment docker info probe through this namespace and obtained the expected engine identity digest 0a179ff3...; it created no resource.
  • Network and container IDs are assigned only after exact lowercase 64-hex decoding. Empty, malformed and non-ASCII successful replies leave the state uncertain, after which cleanup queries only the exact random nonce/owner/task labels, validates the recovered full ID and labels, removes by ID, and independently requires absence. The four reply forms for both resource kinds reproduce the predecessor's skipped recovery and pass the successor cleanup.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

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 48bb146b66c9a010e4bc4bd43a657fc152e562786cf657f18eecb1bab1a07b6a and network 9da9b2da20f0dd58655092a8f9b3356808680574ebea5f62decc6467f4a01b94 are independently absent. Runtime OOM=false. The cleanup removed both resources but retained cleanup NONPASS because Docker29's network missing-object message differs from the observer's no such string requirement; the source observer error is preserved separately. The failed result/output descriptors and original traceback are retained seven days.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

One inert cached-Python sleep lifecycle comparison identified the actual Docker29 transition: HostConfig.OomKillDisable false→null, with no other Config/HostConfig/Mounts difference. Container 31d75b2d172c397a9a6a17882c8d611ec9bb1a15f7547116cdf7f43c5938eec2 is independently absent. No SDK/Server command, credentials, binds or network was used.

Frozen corrected controller a2a6dc7c59933915b1fdf13d70b4d1e10c2bb588b3c339163aab23738a303bf1, controls 840fa977120afe3c2afe1a786b407ab8fd15cae747dbc808fcd32fac2335264b. Eight groups pass, including exact full configuration equality for false/null, refusal of true and all prior altered resource/security fields. Only that observed off/default representation is normalized. Full exclusive0600 create/start/return configuration snapshots are now retained, so another transition will have evidence rather than a guessed exception.

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 network <ID> not found spelling, while retaining engine/config/ID/label checks. Recovery controls exercise actual remove/inspect/inventory helpers for both resource types; the original cleanup-observer NONPASS is not relabeled.

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))

@rmcdaniel

Copy link
Copy Markdown
Member Author

Frozen inert controls 840fa977120afe3c2afe1a786b407ab8fd15cae747dbc808fcd32fac2335264b, eight groups PASS.

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()

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security review of frozen observer successor a2a6dc7c59933915b1fdf13d70b4d1e10c2bb588b3c339163aab23738a303bf1 and controls 840fa977120afe3c2afe1a786b407ab8fd15cae747dbc808fcd32fac2335264b: PASS for one fresh exact bounded logging attempt only.

Independent checks:

  • the public controller and control bytes rehash exactly to the stated identities; the fixed supervisor remains 25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b;
  • all eight inert groups pass from the published bytes;
  • the delta from the first attempted controller is confined to retained create/start/return observations, normalization of only the observed OomKillDisable false/null representation while refusing true and all other configuration changes, and stronger exact-ID cleanup absence proof;
  • direct read-only Docker 29 checks independently reproduce No such container: <full-id> and network <full-id> not found, each with structured [], while the corresponding full-ID inventory filters are empty.

The first c94a2f12 runner-blocked result remains NONPASS and must not be relabeled. This disposition authorizes only one fresh attempt using the unchanged receipt, parent, crate, test, Server tuple and reviewed bootstrap. It does not approve a tag, upload, reusable runner, package, or broader runtime claim. Preserve the exact retained observations and require full-ID cleanup/absence even if the fresh attempt fails.

@rmcdaniel

Copy link
Copy Markdown
Member Author

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 NetworkSettings.Ports["8080/tcp"] = null for this internal bridge, so no numeric loopback endpoint was obtained and the consumer never executed. This is a launcher/network-profile issue, not a logger product outcome.

Runtime abf7eda67d6d4ca6bb3087da7a68c6d6fecae0a24e8c626804f1d2763d4e053e and network 5c842f44003ea8df3946c246cffb347df9a7219e634860475b919bcfcd968683 are independently absent by matching full-ID inspect responses and successful empty ID-filtered inventories. OOM=false, cleanup PASS; tmpfs synthetic credentials/database state died with the runtime. Original0600 config/result/output files are retained seven days. No four-process, tag, upload or published result is claimed.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

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 92dd2e4af3ae74e5e44ee3ab46557f0340045062025cc164daa01a15e9396783, controls 6e7ac2eb52948fc7d51f737c90c404dbb9bb3ef42798ae63ebd7e430815fcb7c, nine inert groups PASS. Only network creation/validation changes from the reviewed a2 observer: exact local bridge driver, both options false, non-internal/non-ingress/non-attachable/noIPv6, and no attached foreign container. Those facts are rechecked around start/return; the actual exposed port still must be one numeric127.0.0.1 binding. The runtime has no selected external request path. Parent/test/package/build, closed authority, sealed execution, complete container/config projection, resources/deadlines and cleanup are unchanged.

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))

@rmcdaniel

Copy link
Copy Markdown
Member Author

Full source controls SHA256 6e7ac2eb52948fc7d51f737c90c404dbb9bb3ef42798ae63ebd7e430815fcb7c, nine groups PASS. The actual inert two-profile marker comparison is recorded separately above.

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()

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security review of frozen network-profile successor 92dd2e4af3ae74e5e44ee3ab46557f0340045062025cc164daa01a15e9396783 and controls 6e7ac2eb52948fc7d51f737c90c404dbb9bb3ef42798ae63ebd7e430815fcb7c: PASS for one fresh bounded third attempt only.

Independent checks:

  • the published controller/control bytes rehash exactly and all nine source groups pass; the fixed supervisor remains 25a591f5...;
  • the complete delta from reviewed a2a6dc7c is only explicit bridge creation plus network validation around create/start/return;
  • the network is local bridge, non-internal solely to support the host loopback consumer, non-ingress, non-attachable, IPv6 disabled, with both IP masquerading and inter-container communication disabled; any attached foreign container refuses;
  • the runtime still requires exact 127.0.0.1 numeric publication, exact container network mode/configuration, empty proxies for readiness, synthetic credentials only, no binds, unchanged caps/resources/deadlines, and full-ID cleanup/absence;
  • the separately retained marker observation establishes that the internal predecessor has no host port while this exact profile produces the loopback marker, with its control resources absent.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

The third92dd attempt remains runner-blocked/NONPASS after owned network creation only. Its strict Options equality refused the daemon-supplied com.docker.network.bridge.host_binding_ipv4=127.0.0.1; no runtime, synthetic credential setup or SDK consumer was created. Cleanup PASS and independent owner/task inventories are empty. Its early result did not retain the network ID, so no independent exact-ID receipt is asserted for that attempt. Original result and traceback remain unchanged.

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 a84197af24193f3d68d682a78515619d6867ef34bc9c310d565a1034e7eb9bf7 and network 0b759093fac7241781d12665572a1e69d74dc6540fc079fd0721d5d238300d4f are independently absent. Canonical config digest fbac88def50d316ed5ce31f9e31af59911fcb0a371f3023e99791060cf17f798 stayed equal across all stages. This is an inert envelope result, not installed logging evidence.

Frozen corrected controller 04f9c0391e1670e67e757e0c16bca1c204ed557a345a483ec43c398c77a7c841, controls cb741209be3d0c8207fb680f7a3a9ead6020092b64c45d2eaeaeb640600e3040, nine groups PASS. It explicitly requests and strictly checks the loopback binding default as the third bridge option, records the full network snapshot before first validation, retains a return snapshot, and stores each full resource ID immediately after grant. No unknown option is silently accepted. All compiled/package/test/build/authority/limits/cleanup boundaries are unchanged. A fresh r4 input copy preserves the same receipt/parent bytes, and all three prior NONPASS roots are preserved. No fourth runtime, tag or upload has occurred. Please review the narrow fixture/diagnostic delta 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()=="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))

@rmcdaniel

Copy link
Copy Markdown
Member Author

Complete frozen source controls SHA256 cb741209be3d0c8207fb680f7a3a9ead6020092b64c45d2eaeaeb640600e3040, nine groups PASS. The full actual inert metadata preflight is retained separately.

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()

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security source/runner disposition for the requested r4 attempt: PASS for one bounded attempt only on the exact frozen controller 04f9c0391e1670e67e757e0c16bca1c204ed557a345a483ec43c398c77a7c841, controls cb741209be3d0c8207fb680f7a3a9ead6020092b64c45d2eaeaeb640600e3040, and unchanged supervisor 25a591f514b3823093a37b66c47c588cba8e983594c8da2d7940ac4f565b922b.

Independent checks:

  • all 9 frozen control groups pass from the published sources;
  • the controller delta from the prior reviewed launcher is narrow: it explicitly creates and requires com.docker.network.bridge.host_binding_ipv4=127.0.0.1 in addition to the two already reviewed bridge options;
  • the full network ID is stored before post-create ownership/option validation, and the full container ID is stored immediately after the create reply, so those validations can no longer discard cleanup authority;
  • exclusive 0600 create/return network observations were added, and the final network state remains restricted to the one exact owned runtime;
  • uncertain-create reconciliation, exact owner/task/nonce checks, full-ID deletion/absence proof, closed Docker environment, pinned package/parent/test/build, and the no-tag/no-upload boundary remain unchanged.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

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 owned logging fixture process exited assertion. This is NONPASS with diagnosis pending, not yet a demonstrated logger defect: the harness discards child stderr and therefore does not retain the underlying assertion/SDK error. No authentication requirement or other error category is inferred.

Runtime d726d7b0a579aacf1d2fb7a64b51762ab023d751f0d043d0af0ea88a07853e9d and network 5289426bcd53ba1b0226ae286552cbcb8420936a90e1c33996932d942b6ab41b are independently absent by full-ID inspect[] and successful empty ID filters. OOM=false, cleanup PASS. Exact result/config/network/stdout/stderr0600 files and the original controller traceback are retained seven days. Parent PID2299951; stdout SHA 74c35673bfb27457ca442dbc24c68819128c5e86298c70f43a930c17e9b17125, stderr SHA 97331f66abb20ffda931e5df495d43664b241949eb173fd83f403e6b94ccfdc0.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

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 d726d7b0a579aacf1d2fb7a64b51762ab023d751f0d043d0af0ea88a07853e9d and network 5289426bcd53ba1b0226ae286552cbcb8420936a90e1c33996932d942b6ab41b: both inspect calls return structured empty output with the exact missing-object form, and both ID-filtered inventories are empty.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

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 b7e63903bf16162bd6c14f67ed242291b244828b5f32bc94c6cf40e1992da912. Every installed SDK member still equals candidate crate6de774/118 files; package commit522 remains distinct from test-source8b. Compiler/lock/manifest graph are unchanged. The new compiled parent is13bd9dd0; only acceptance-test code differs.

Manual diagnostic controller SHA256 e9437c7223ec2f6244bf8981db57c514e723f6c98976cd1f44e5d31fbe82a82f. Its complete delta from reviewed04f9 is exactly the three bound identities: build receipt, parent image, test bytes. Network/runtime/source supervisor, sealed execution, closed authority, limits, output/ID/cleanup and all other code are unchanged. No runtime has launched with this new test. Request one diagnostic observation only after source/build counterreview; all four prior runtime/launcher results remain NONPASS, and no tag/upload exists.

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))

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security data/controller binding PASS for one exact diagnostic observation only.

Frozen identities independently checked:

  • controller SHA-256 e9437c7223ec2f6244bf8981db57c514e723f6c98976cd1f44e5d31fbe82a82f;
  • build receipt b7e63903bf16162bd6c14f67ed242291b244828b5f32bc94c6cf40e1992da912;
  • compiled parent 13bd9dd00a258144dc01feeeac0ad92a1ab6ae1388113b9c6445f79081e9d559;
  • Retain bounded cold-worker failure diagnostics #270 test bytes c53a9e0419216a2f61df3a260f5c63189390a30a2678c57021ae02f53ce49899 from exact source 8b006e1de9745665d52fa7712912e4ccc4794592.

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 52208134296009bbae1af316c8efac89d3465990, crate 6de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3, 118 equal members, Cargo 1.86, and network-none build. The complete controller diff from reviewed 04f9c039... is exactly the receipt, parent and test pins; the network/runtime/supervisor, sealed execution, closed authority, bounds, private evidence, full-ID lifecycle and cleanup code are unchanged.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

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 e0ec3f92b39bf721496ec7d329c4673b4f122db30295211e0ea435bf2dc1f209, network 48a6d95e7494b5adb7a0ad58dbfcddbcfaef82a9d7183abf3139f6f3f7809495, both independently absent by full-ID inspect[] plus successful empty ID-filtered inventories. OOM=false and cleanup PASS. Retained stderr is18,790 bytes, private0600, with no credential output; full result/config/network/parent/package/source identities remain unchanged and retained seven days.

#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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

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 4ac6427eeab05380cbfa3ce16da382c8e773622fb06ae6fcd4f95e540f26a8e7:

{
  "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 2e2c2e486683b94abaf00c6cdb0ce589ca905f71033e0098b2da9bc0b32098b5 changes only receipt/parent/test pins from e943. Every other reviewed authority/profile/resource/output/lifecycle/cleanup boundary is identical. No runtime has launched with the corrected registration source. Request one bounded observation after exact source/data review and current-head gates; all five preceding runtime/launcher outcomes remain NONPASS. No tag/upload or logger PASS exists.

/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))

@rmcdaniel

Copy link
Copy Markdown
Member Author

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.

@sonarqubecloud

Copy link
Copy Markdown

@rmcdaniel

rmcdaniel commented Nov 14, 2026 •

Copy link
Copy Markdown
Member Author

Security exact terminal counter-review: PASS, scoped to the one candidate-package logging observation and the current approval-record/source/base rebind.

  • Retained evidence exactly rehashes to the published receipt: result 4718e05b..., stdout 86f062a9..., empty stderr, and all six container/network snapshots with the stated sizes, private 0600 modes, owner and single-link identities.
  • Exact source 7b6a351 registers the same child Worker instance before run_once. The selected test requires four distinct child PIDs, exactly one new log in each committed region, the original namespace/workflow/run identities, committed history counts across three signals, no failure event, and final {"steps":3}; the retained parent exits 0 and reports that exact PASS.
  • The runtime is the bound 3.10.0 amd64 child 9d64e9ae... / source b6e04ce7..., has no host mounts, runs as 1000:1000 with read-only root, caps dropped, no-new-privileges, bounded CPU/memory/PIDs/tmpfs, and exact loopback-only publication on the closed bridge profile. I independently recomputed the normalized create/start/return configuration projections; all three equal 2bd21c42.... OOM is false.
  • A fresh read-only Docker check confirms container e14cde96... and network e219430d... are absent by both inspect-empty and successful exact-ID inventories.
  • Current approval head 765ea76 is a normal merge onto accepted base 8e13af5...; its only two topic files are the 4.17.0 approval record and summary. Both blobs are byte-identical to the reviewed 8f7812b... records, and the recomputed summary SHA-256 is the bound 9c00c522....

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.

@rmcdaniel
rmcdaniel marked this pull request as ready for review November 14, 2026 00:05
@rmcdaniel
rmcdaniel merged commit db81b91 into main Nov 14, 2026
20 checks passed
@rmcdaniel
rmcdaniel deleted the agent/sdk-rust/417-package-approval branch November 14, 2026 00:05
@rmcdaniel

Copy link
Copy Markdown
Member Author

Protected publication is complete for 4.17.0. Release run 43532646142 passed all four gate/publish/registry-verify/Release jobs using maintained main db81b918b4d0e9a021514c7dc42586b0efaf9926 and immutable package tag 4.17.0 → 52208134296009bbae1af316c8efac89d3465990.

Independent crates.io API and static archive readback match approved SHA-256 6de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3, 612963 bytes, all 118 members, and VCS 52208134296009bbae1af316c8efac89d3465990. The version is not yanked. GitHub Release 4.17.0 is public, stable and Latest with the exact logging changelog.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security independent 4.17.0 publication readback: PASS for immutable publication identity and public metadata.

  • Protected run 43532646142 is terminal success at maintained main db81b918b4d0e9a021514c7dc42586b0efaf9926; all four gate, upload, registry-verify, and Release jobs succeeded.
  • Tag 4.17.0 resolves directly to reviewed package source 52208134296009bbae1af316c8efac89d3465990 / tree bcb6c4d87e11381e43735524e41c350f0ad5f815.
  • Fresh crates.io API readback reports 4.17.0 not yanked, size 612,963, checksum 6de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3. The independently downloaded static archive rehashes to that exact checksum, contains 118 members, and its .cargo_vcs_info.json binds VCS 52208134296009bbae1af316c8efac89d3465990.
  • GitHub Release 4.17.0 is public, non-draft, non-prerelease, and is the current Latest release. Its notes match the 4.17.0 changelog entry; it has no attached binary asset claim.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

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 6de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3, clean tag/VCS 52208134296009bbae1af316c8efac89d3465990, required Server baseline map intact. Both cells have driver/history exit0, unchanged binary, all checks PASS and complete container/network/credential/state cleanup. Summary SHA-256: ec4eca5d2d7352d70e5ff27de030837ef14379e30d546befa736b736a3f4c942.

The separately prepared logging consumer retains that fresh registry cache/source and exact accepted qualifier 7b6a3514dd9f7c6454a1b753a5b5247cab064722 / test e66d177c6a1ffc486623169d1505766447c18c3c4650a2023a60f8bb9f9d11f0. All 118 installed SDK members equal the public archive. An offline Rust1.86 build produced the bound parent below; the three ordinary controls pass (two actual SDK entrypoints remain ignored), and all nine retained manual-controller controls pass.

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 2e2c2e486683b94abaf00c6cdb0ce589ca905f71033e0098b2da9bc0b32098b5 in exactly two literal pins: receipt and parent binary SHA-256. Supervisor, test source, immutable Server3.10 tuple, authority/configuration checks, resource bounds, full-ID/label lifecycle and cleanup are unchanged. All five preceding candidate NONPASS outcomes remain; candidate PASS does not substitute for this registry repeat.

Build receipt SHA-256: 2fbaaa9a100184f9e0f27087ecb3562e6ea84d35e5f23b052a23591150d66217.

{
  "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: 0dcb468f55dc205b8a9860ccb5e7c6f6ebdc91d66ad7fca983558690e95c6575.

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))

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security exact source/data review of the proposed registry-installed logging observation: PASS for one bounded observation with controller 0dcb468f55dc205b8a9860ccb5e7c6f6ebdc91d66ad7fca983558690e95c6575 and prepared root sdk-rust-417-registry-logging-20261114 only.

Independent checks:

  • byte comparison against accepted candidate controller 2e2c2e486683b94abaf00c6cdb0ce589ca905f71033e0098b2da9bc0b32098b5 shows exactly two changed literals: build receipt 2fbaaa9a100184f9e0f27087ecb3562e6ea84d35e5f23b052a23591150d66217 and parent binary a7c46d96d944e112685363b6940f275feab1dfeab10efe8ecf234b8f44b9b972. Test source, Server tuple, supervisor, authority, profile, limits, outputs, identity reconciliation, and cleanup code are byte-identical;
  • the prepared root is owner-private mode 0700. Receipt, manifest, lock, test, build messages, and executable rehash to the published values. The executable is 22,433,824 bytes and single-link;
  • the lock binds durable-workflow 4.17.0 to the crates.io registry source with checksum 6de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3. Both cached registry archives independently rehash to that public checksum and size 612,963. The dependency is exact =4.17.0; no patch or directory source override is present. The retained test source remains exact reviewed 7b6a3514dd9f7c6454a1b753a5b5247cab064722 / e66d177c...;
  • the fresh normal-registry lifecycle/deadline summary rehashes to ec4eca5d2d7352d70e5ff27de030837ef14379e30d546befa736b736a3f4c942 and records published mode, exact crate/VCS identity, both cells PASS, and complete cleanup. It is supporting registry provenance, not the logging result;
  • I reran all nine inert manual-controller controls against the new controller and accepted supervisor; all pass. The three ordinary Rust controls pass while the two effectful SDK cases remain ignored.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

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 {"steps":3} result. The parent and all 118 installed SDK members still match their bound identities. This was a fresh crates.io consumer without a patch or directory-source override, separate from the earlier candidate-package observation.

The owned runtime and network are independently absent by exact full-ID missing response, structured inspect [], successful empty full-ID inventory and empty owner/task/nonce filters. No Rust local runtime/build remains. All three normalized whole-container projections match; the only normalization remains the reviewed Docker29 unset/false OOM metadata transition. Outputs/config snapshots are owner-only0600, regular single-link files. All five prior candidate NONPASS outcomes stay preserved.

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:


running 1 test
test published_logging_emits_once_per_committed_step_across_cold_worker_processes ... PASS: four cold worker processes; one observation per committed region; original run identity; three applied signals; exact result
ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out; finished in 6.55s

Published API documentation also refreshed successfully through 43533751449. Public __build.json independently reports version4.17.0/source522/checksum6de, matching publication. Live WorkflowContext::logger and replay_state, WorkflowLogger, and WorkflowReplayState expose the new API, uncommitted-attempt repeat caveat and bounded/nonblocking handler requirement. Two initial readback assertions expected implementation/Context text on the Logger page; corrected page-specific checks pass without a product change.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security exact terminal counter-review: PASS for the one normal-registry 4.17.0 logging observation.

Independent checks:

  • The retained root is owner-private mode 0700. terminal-review.json and all eight listed evidence files are owner-only mode 0600, regular, single-link files. Their byte counts and SHA-256 values exactly match receipt 6868474565, including stdout 5f074e10, empty stderr, result e9b7d8f9, and the five container/network snapshots.
  • Build receipt 2fbaaa9a still binds registry-installed durable-workflow 4.17.0, package source 5220813, public crate checksum 6de77487, all 118 members, exact test 7b6a351/e66d177c, manifest, lock, build messages, and parent a7c46d96. The selected parent exits 0 and reports 1 passed, 0 failed, 4 filtered in 6.55 seconds with the exact four-process, committed-region, original-identity, three-signal, final-steps assertion.
  • The result binds qualified native Server 3.10.0 child 9d64e9ae and source b6e04ce7. Create, start, and return configuration projections all equal e3153c58 under the previously reviewed false/null OOM normalization; OOM is false and cleanup reports no error.
  • I independently repeated exact-ID and owner/task/nonce Docker reads. Container b8f97689 and network 757f8b2c are absent by inspect and successful empty inventories.
  • Public Docs workflow 43533751449 is terminal success. Fresh __build.json reports 4.17.0, source 5220813, checksum 6de77487. The live WorkflowContext logger/replay_state, WorkflowLogger, and WorkflowReplayState pages expose the API plus the nonblocking, bounded-handler, uncommitted-task repeat caveat.

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.

@rmcdaniel

Copy link
Copy Markdown
Member Author

The Rust Docs guide/constraints/selector slice is delivered: final receipt. Docs #542 merged as 4cdae094ffd7c43fb65abca05224fe691a2de3ed with exact reviewed-tree equality; all 12 main checks and protected Pages 43536563515 succeed. All 16 public pages/eight locales match the reviewed build, including selected 4.17 Cargo pins. Stable-manifest SHA256 is de94d91b0d3ef1995e29048c4c789c926ff35cc606dba60e891ccd4842d41ecb; Server 3.10.0 / Chart 2.0.0, other selections, installers, catalog and OpenAPI remain unchanged.

Fresh registry metadata and Rust API identity/anchors reproduce 4.17.0/source 52208134296009bbae1af316c8efac89d3465990/crate SHA256 6de774879fe8411776b60736391b2c6b426bb1bc125268718004656efd52f5c3. Rust's independent 16-page readback and General's English/data follow-through pass. Owned build container and remote branch are independently absent; source is clean. Docs claims this delivery slice only; SDK owners retain the installed native 3.10.0 linux/amd64 evidence, other bindings and shared closure remain separately owned, and #980 timer/cold-worker qualification is unaffected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant