From 2af5db16f12d0851fd76935df876e73433fdc1cf Mon Sep 17 00:00:00 2001 From: Kevin Janssen Date: Sun, 15 Nov 2026 10:59:02 +0100 Subject: [PATCH] Prepare protected time broker provisioning with closed native quality gate --- deploy/server_time_broker_bootstrap.py | 761 +++++++++++++++++++++++++ docs/server-time-broker-bootstrap.md | 253 ++++++++ 2 files changed, 1014 insertions(+) create mode 100644 deploy/server_time_broker_bootstrap.py create mode 100644 docs/server-time-broker-bootstrap.md diff --git a/deploy/server_time_broker_bootstrap.py b/deploy/server_time_broker_bootstrap.py new file mode 100644 index 0000000..ba3b51b --- /dev/null +++ b/deploy/server_time_broker_bootstrap.py @@ -0,0 +1,761 @@ +#!/usr/bin/env python3 +"""Finite root-only time signer/bootstrap. Never starts/enables a service or signs time. + +Private seeds are generated only on the target and never returned. Each phase +is create-only; failures retain their original partial state for readback. +""" +import argparse +import grp +import hashlib +import http.client +import importlib.util +import json +import os +from pathlib import Path +import re +import resource +import socket +import ssl +import stat +import subprocess +import sys +import uuid + +PIN_SHA = 'fac85dd0399009af36f625232daa5b67ab7fda391dbf95229d4237c307b142ca' +PIN_CODE = Path('/var/lib/rmm-time-source-operators') / PIN_SHA / 'pin_bootstrap.py' +CASE_ID = '5b358997-3abc-43db-945f-f41855b4e3c0' +CASE = Path('/var/lib/rmm-time-source-bootstrap') / CASE_ID +ETC = Path('/etc/rmm-time-source') +SIGNER = ETC / 'signer.json' +PUBLIC = ETC / 'time-public-key.json' +BINARY = Path('/usr/local/libexec/rmm-time-broker') +UNIT = Path('/etc/systemd/system/rmm-time-broker.service') +GROUP = 'rmm-time-gateway' +BROKER_SHA = '5d8d786925c060eb042f0a592453f11970c32c4287fa4c9464f6f6a6e38cb201' +BROKER_BYTES = 1067136 +SERVER = Path('/opt/rust-discovery') +CERTIFICATES = tuple(SERVER / 'devstate' / kind / leaf for kind in ('pki', 'api-pki') for leaf in ('ca.pem', 'server.pem')) +PROFILE = 'rmm.server-time-broker.bootstrap.v1' +QUALITY_PHASE = 'probe-peer-acceptance-v1' +QUALITY_CONTROLLER_SHA = 'ca89eac44d6b1e8bbbb14cca58ecabb02fd05d59292b77f703997fad0c29e3c8' +QUALITY_RESULT_SHA = None # Root must bind an independently reviewed actual native PASS first. +GROUP_FAILURE_SHA = '4977876b935bed8903ce4c880a0d9c77c49cd2c7110551fbf854baeccbe64ea7' +GROUPADD_SHA = '468289aa24d8e9bacb1f21d315e59dc49febec5f120eb7a01b44fe6e98700ed0' +OLD_QUALITY_ORIGIN = { + 'original_group_acceptance_controller_sha256': 'd04989ccf6d3e7b379a1b02f5fd3ce2545a3563fbce1368f33102f58a36f2dcf', + 'original_group_acceptance_result_sha256': '96b714e2e43aa13073317c310b213863a02f26dbf2e6c975dc0801ef621eccd5', + 'original_group_acceptance_log_sha256': 'f80644630b09f50fdc731418dbe4f17fff32622910b3efd346a0369b75e985ef', + 'original_group_acceptance_receipt_sha256': '6923cc1893619f67ae8677b84f9cfea6d0edd554120e9139d843115e52aa7643', + 'original_dac_diagnostic_receipt_sha256': 'd999e5260cab3457a7a66603fdb0288615443628e5a28f31df9c1cecd3401ef5', +} +PEER_ORIGIN = { + 'peer_namespace_controller_sha256': '2f1dafece1e5cd1b9be11078edee5f67fbdaef013defa10c527367b42dce9265', + 'peer_namespace_result_sha256': 'cb1665cb14086d3ba79089a2eb9e01a532dd779bdcf577eafca0e343b5cc6a8b', + 'peer_namespace_local_profile_sha256': '27e3708a34988fb778cbc8cfd892e0f222b8caf927034e472f391aab65349394', + 'peer_namespace_receipt_sha256': '1dc76b5a9673f9e08e59f91f05d586cb9335ffd0a33e697d5170823a6f053619', + 'peer_namespace_read_receipt_sha256': '129584f296b53614e10a9e5eac2bab0a1e70b1c51f7fd70eb31bdf907ce767b3', + 'original_dac_acceptance_controller_sha256': '1b79a4ab8d587338e43330db0fc73ff2e199dc61f1172da7cc3fc93d3538d2ac', + 'original_dac_acceptance_result_sha256': '5f8e0634e44c7caeab2020af5f5dd0d6e83249265d0ebd67f938f0797b551fca', + 'original_dac_acceptance_log_sha256': 'f80644630b09f50fdc731418dbe4f17fff32622910b3efd346a0369b75e985ef', + 'original_dac_acceptance_receipt_sha256': '553bc8580deb0e78d780b43c569f3827715a54a7b8629c51c705cf4e9ded7c61', +} +PEER_MAIN_SHA = '214e509af9ab9b713e89b09bf6440c4b4248e97c64d4b0d884d2f869d406e1e2' +PEER_CODE = Path('/var/lib/rmm-time-source-operators') / PEER_ORIGIN['peer_namespace_controller_sha256'] / 'peer_namespace_bootstrap.py' +PKCS8 = bytes.fromhex('302e020100300506032b657004220420') +SPKI = bytes.fromhex('302a300506032b6570032100') +UNIT_RAW = b'''[Unit] +Description=RMM local time attestation broker (demand only) +ConditionPathExists=/etc/rmm-time-source/signer.json +ConditionPathExists=/etc/rmm-time-source/chrony-pin.json + +[Service] +Type=exec +User=root +Group=_chrony +SupplementaryGroups=rmm-time-gateway +ExecStart=/usr/local/libexec/rmm-time-broker +NoNewPrivileges=yes +CapabilityBoundingSet=CAP_SYS_PTRACE CAP_DAC_OVERRIDE +AmbientCapabilities= +RestrictAddressFamilies=AF_UNIX +IPAddressDeny=any +ProtectSystem=strict +ProtectHome=yes +PrivateDevices=yes +PrivateTmp=yes +SystemCallFilter=~@debug ptrace process_vm_readv process_vm_writev +ReadWritePaths=/run/rmm-time-source +UMask=0077 +LimitCORE=0 +Restart=no +''' + + +class Denied(RuntimeError): + pass + + +def require(value, reason): + if not value: + raise Denied(reason) + + +def encoded(value): + return (json.dumps(value, sort_keys=True, separators=(',', ':'), ensure_ascii=True) + '\n').encode('ascii') + + +def sha(raw): + return hashlib.sha256(raw).hexdigest() + + +def stamp(info): + return tuple(getattr(info, 'st_' + name) for name in + ('dev', 'ino', 'uid', 'gid', 'mode', 'nlink', 'size', 'mtime_ns', 'ctime_ns')) + + +def protected_code(): + current = Path('/') + for part in PIN_CODE.parent.parts[1:]: + current /= part + info = current.lstat() + require(stat.S_ISDIR(info.st_mode) and info.st_uid == 0 and info.st_mode & 0o022 == 0, + 'pin_controller_protected_ancestry') + fd = os.open(PIN_CODE, os.O_RDONLY | os.O_NOFOLLOW) + try: + info = os.fstat(fd) + require(stat.S_ISREG(info.st_mode) and info.st_uid == info.st_gid == 0 and + stat.S_IMODE(info.st_mode) == 0o600 and info.st_nlink == 1 and info.st_size <= 128 * 1024, + 'pin_controller_root_file') + raw = os.read(fd, 128 * 1024 + 1) + require(len(raw) == info.st_size and sha(raw) == PIN_SHA and stamp(os.fstat(fd)) == stamp(info) and + stamp(PIN_CODE.lstat()) == stamp(info), 'reviewed_pin_controller_bytes') + finally: + os.close(fd) + module = importlib.util.module_from_spec(importlib.util.spec_from_loader('rmm_reviewed_pin', loader=None)) + module.__file__ = str(PIN_CODE) + exec(compile(raw, str(PIN_CODE), 'exec'), module.__dict__) + return module, lambda: require(module.read_file(PIN_CODE, 128 * 1024) == (raw, module.identity(info)), + 'reviewed_pin_controller_unchanged') + + +def command(pin, path, args, data=None): + # Fixed public tools only. Private DER is stdin, never argv/environment/file. + parent = pin.directory(path.parent) + try: + info = path.lstat() + require(stat.S_ISREG(info.st_mode) and info.st_uid == 0 and info.st_mode & 0o022 == 0, + 'protected_fixed_tool') + digest = sha(pin.read_file(path, 4 * 1024 * 1024, stat.S_IMODE(info.st_mode))[0]) + require(path != Path('/usr/sbin/groupadd') or digest == GROUPADD_SHA, 'actual_reviewed_groupadd_provenance') + result = subprocess.run([str(path), *args], input=data, stdin=None if data is not None else subprocess.DEVNULL, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10, check=False, + env={'PATH': '/usr/sbin:/usr/bin:/sbin:/bin', 'LC_ALL': 'C'}) + require(len(result.stdout) <= 16384 and len(result.stderr) <= 16384 and stamp(path.lstat()) == stamp(info) and + sha(pin.read_file(path, 4 * 1024 * 1024, stat.S_IMODE(info.st_mode))[0]) == digest, + 'fixed_tool_identity_output_bound') + return result + finally: + os.close(parent) + + +def derive_public(pin, seed): + require(type(seed) is bytes and len(seed) == 32, 'host_seed_length') + result = command(pin, Path('/usr/bin/openssl'), ['pkey', '-inform', 'DER', '-pubout', '-outform', 'DER'], PKCS8 + seed) + require(result.returncode == 0 and result.stdout.startswith(SPKI) and len(result.stdout) == len(SPKI) + 32, + 'ed25519_public_derivation') + return result.stdout[len(SPKI):] + + +def certificate_key(pin, raw): + result = command(pin, Path('/usr/bin/openssl'), ['x509', '-inform', 'PEM', '-pubkey', '-noout'], raw) + require(result.returncode == 0, 'known_public_certificate_parse') + result = command(pin, Path('/usr/bin/openssl'), ['pkey', '-pubin', '-outform', 'DER'], result.stdout) + require(result.returncode == 0, 'known_public_certificate_spki') + return result.stdout[len(SPKI):] if result.stdout.startswith(SPKI) and len(result.stdout) == len(SPKI) + 32 else None + + +def public_material(pin, path, private=False): + certificate = path in CERTIFICATES + require(certificate != private, 'only_fixed_public_certificates_or_private_reader_token') + require(certificate or path == SERVER / 'devstate/operator-a.token', 'fixed_server_material_path') + root = pin.directory(SERVER / 'devstate' if certificate else path.parent) + parent = -1 + try: + if certificate: + parent = os.open(path.parent.name, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=root) + directory_proof = os.fstat(parent) + require(directory_proof.st_uid == directory_proof.st_gid == 10001 and + stat.S_IMODE(directory_proof.st_mode) == 0o700, 'known_server_public_pki_directory') + else: + parent = os.dup(root) + directory_proof = os.fstat(parent) + fd = os.open(path.name, os.O_RDONLY | os.O_NOFOLLOW, dir_fd=parent) + try: + info = os.fstat(fd) + owner = 10001 if certificate else 0 + require(stat.S_ISREG(info.st_mode) and info.st_uid == info.st_gid == owner and + info.st_nlink == 1 and stat.S_IMODE(info.st_mode) == 0o600 and info.st_size <= 16384, + 'actual_fixed_server_material_protection') + raw = os.read(fd, 16385) + require(len(raw) == info.st_size and len(raw) <= 16384 and stamp(os.fstat(fd)) == stamp(info) and + stamp(os.stat(path.name, dir_fd=parent, follow_symlinks=False)) == stamp(info) and + stamp(os.fstat(parent)) == stamp(directory_proof) and + stamp(os.stat(path.parent.name, dir_fd=root, follow_symlinks=False) if certificate else os.fstat(root)) == stamp(directory_proof), + 'actual_fixed_server_material_stable') + return raw + finally: + os.close(fd) + finally: + if parent >= 0: + os.close(parent) + os.close(root) + + +def forbidden_keys(pin, original): + original.fresh() # Independently verifies fixed API/GW image, UID and runtime before the public read. + ca = SERVER / 'devstate/pki/ca.pem' + ca_raw = public_material(pin, ca) + token = public_material(pin, SERVER / 'devstate/operator-a.token', True).decode('ascii').strip() + require(re.fullmatch('[A-Za-z0-9._~-]{16,8192}', token), 'private_reader_token_format') + context = ssl.create_default_context(cadata=ca_raw.decode('ascii')) + class Loopback(http.client.HTTPSConnection): + def connect(self): + self.sock = self._context.wrap_socket(socket.create_connection(('127.0.0.1', 18443), timeout=10), + server_hostname='rmm-dev.internal') + client = Loopback('rmm-dev.internal', 18443, timeout=10, context=context) + try: + client.request('GET', '/api/v1/job-signing-key', headers={'Authorization': 'Bearer ' + token}) + response = client.getresponse() + require(response.status == 200, 'actual_public_job_key_getter_denied') + raw = response.read(4097) + require(len(raw) <= 4096, 'public_job_key_response_bound') + job = pin.parsed(raw) + require(set(job) == {'schema_version', 'algorithm', 'key_id', 'public_key_hex'} and + type(job['schema_version']) is int and job['schema_version'] == 1 and job['algorithm'] == 'Ed25519' and + type(job['key_id']) is str and re.fullmatch('[A-Za-z0-9_-]{1,128}', job['key_id']) and + type(job['public_key_hex']) is str and re.fullmatch('[0-9a-f]{64}', job['public_key_hex']), 'actual_public_job_key_shape') + finally: + client.close() + del token + keys = {job['public_key_hex']} + certificates = [] + for path in CERTIFICATES: + raw = public_material(pin, path) + public = certificate_key(pin, raw) + certificates.append({'path': str(path), 'certificate_sha256': sha(raw), 'ed25519': public is not None}) + if public is not None: + keys.add(public.hex()) + # Root independently observed these exact role roots absent. Do not scan + # credentials or private PEMs, or silently ignore newly provisioned roles. + for path in (Path('/etc/rmm-agent-updater'), SERVER / 'devstate/agent-updates'): + require(not os.path.lexists(path), 'new_update_health_role_context_requires_review') + require(1 <= len(keys) <= 32, 'bounded_known_forbidden_roles') + original.fresh() + return sorted(keys), {'job_public_key_sha256': sha(bytes.fromhex(job['public_key_hex'])), 'certificates': certificates} + + +def quality_proof(pin, original, pin_result_raw, pin_result): + require(re.fullmatch('[0-9a-f]{64}', QUALITY_CONTROLLER_SHA), 'reviewed_quality_controller_not_bound') + require(type(QUALITY_RESULT_SHA) is str and re.fullmatch('[0-9a-f]{64}', QUALITY_RESULT_SHA), + 'actual_peer_quality_pass_not_bound') + phase = CASE / QUALITY_PHASE + require(not (phase / 'failure.json').exists(), 'original_quality_probe_failed') + raw, proof = pin.read_file(phase / 'result.json', 16384) + require(sha(raw) == QUALITY_RESULT_SHA, 'exact_actual_peer_quality_pass') + result = pin.parsed(raw) + artifact = original.artifacts['examples/operator_probe'][1] + old_probe, _ = pin.read_file(CASE / 'probe/result.json', 16384) + binding = {'profile': 'rmm.server-time-source.peer-acceptance.v1', 'original_case': CASE_ID, + 'phase': QUALITY_PHASE, 'unit': 'rmm-time-source-probe-peer-acceptance-' + CASE_ID + '.service', + 'controller_sha256': QUALITY_CONTROLLER_SHA, 'operator_sha256': pin.OPERATOR_SHA, + 'pin_controller_sha256': PIN_SHA, 'public_pin_sha256': pin_result['public_pin_sha256'], + 'source_tar_sha256': original.source_sha, 'manifest_sha256': original.manifest_sha, + 'artifact': artifact, 'original_group_receipt_sha256': GROUP_FAILURE_SHA, + 'original_probe_result_sha256': sha(old_probe), 'pin_result_sha256': sha(pin_result_raw), **OLD_QUALITY_ORIGIN, **PEER_ORIGIN} + extra = {'before_witness', 'after_witness', 'exit_code', 'sample', 'probe_log_sha256', 'source_quality_qualified', + 'runtime_boot_pin_source_preserved', 'clock_authority', 'signed_attestation', 'signer_created', 'broker_started', 'http_deployed'} + require(set(result) == set(binding) | extra and all(result[key] == value for key, value in binding.items()) and + result['source_quality_qualified'] is True and type(result['exit_code']) is int and result['exit_code'] == 0 and + result['runtime_boot_pin_source_preserved'] is True and all(result[key] is False for key in + ('clock_authority', 'signed_attestation', 'signer_created', 'broker_started', 'http_deployed')), + 'original_quality_result_binding') + old_group, old_group_state = pin.read_file(CASE / 'probe-group-acceptance-v1/result.json', 16384) + old_log, old_log_state = pin.read_file(CASE / 'probe-group-acceptance-v1/probe.log', 16384) + require(sha(old_group) == OLD_QUALITY_ORIGIN['original_group_acceptance_result_sha256'] and + sha(old_log) == OLD_QUALITY_ORIGIN['original_group_acceptance_log_sha256'], 'unchanged_original_failed_group_acceptance') + witness_records = {CASE / 'probe-group-acceptance-v1/result.json': (old_group, old_group_state), + CASE / 'probe-group-acceptance-v1/probe.log': (old_log, old_log_state)} + for leaf, expected_sha in (('result.json', PEER_ORIGIN['original_dac_acceptance_result_sha256']), + ('probe.log', PEER_ORIGIN['original_dac_acceptance_log_sha256'])): + path = CASE / 'probe-dac-acceptance-v1' / leaf + record = pin.read_file(path, 16384) + require(sha(record[0]) == expected_sha, 'unchanged_original_failed_dac_acceptance') + witness_records[path] = record + namespace_path = CASE / 'peer-namespace-bootstrap-v1/result.json' + namespace_record = pin.read_file(namespace_path, 16384) + require(sha(namespace_record[0]) == PEER_ORIGIN['peer_namespace_result_sha256'], 'actual_peer_namespace_result') + witness_records[namespace_path] = namespace_record + witnesses = [] + for name in ('before', 'after'): + link = result[name + '_witness'] + require(set(link) == {'filename', 'sha256'} and link['filename'] == name + '.json', 'fixed_quality_witness_link') + data, state = pin.read_file(phase / link['filename'], 16384) + require(sha(data) == link['sha256'], 'original_quality_witness_hash') + witness = pin.parsed(data) + require(set(witness) == set(binding) | {'witness'} and all(witness[key] == value for key, value in binding.items()), + 'original_quality_witness_binding') + actual = witness['witness'] + require(set(actual) == {'observation', 'public_pin_sha256', 'public_pin_metadata', 'target_directories', 'peer_namespace'} and + actual['observation'] == original.expected and actual['public_pin_sha256'] == pin_result['public_pin_sha256'] and + actual['public_pin_metadata'] == pin_result['public_pin_metadata'], 'original_quality_source_pin_witness') + directories = {name: {key: value[key] for key in ('dev', 'ino', 'uid', 'gid', 'mode')} + for name, value in pin_result['targets'].items() if name != str(ETC / 'chrony-pin.json')} + require(actual['target_directories'] == directories, 'original_quality_directory_witness') + peer = actual['peer_namespace'] + require(type(peer) is dict and set(peer) == {'result_sha256', 'main_profile_sha256', 'local_profile_sha256', + 'main_profile_metadata', 'local_profile_metadata', 'parent_access_acl_hex', 'profile'} and + peer['result_sha256'] == PEER_ORIGIN['peer_namespace_result_sha256'] and + peer['main_profile_sha256'] == PEER_MAIN_SHA and + peer['local_profile_sha256'] == PEER_ORIGIN['peer_namespace_local_profile_sha256'] and + type(peer['profile']) is dict and set(peer['profile']) == {'chronyd_label', 'enforcing'} and + peer['profile']['chronyd_label'] == '/usr/sbin/chronyd (enforce)' and peer['profile']['enforcing'] is True, + 'exact_peer_namespace_quality_witness') + witnesses.append(actual) + witness_records[phase / link['filename']] = (data, state) + require(witnesses[0] == witnesses[1], 'original_quality_before_after_equal') + sample = result['sample'] + keys = {'profile', 'clock_authority', 'signed_attestation', 'captured_utc_ns', 'server_error_ns', 'source_sync_age_ns', + 'server_boot_id', 'captured_monotonic_ns', 'sampled_boottime_ns', 'kernel_state'} + require(type(sample) is dict and set(sample) == keys and sample['profile'] == 'rmm.native-source-quality.once.v1' and + sample['clock_authority'] is False and sample['signed_attestation'] is False and + sample['server_boot_id'] == original.expected['boot_id'] and + all(type(sample[key]) is int for key in ('captured_utc_ns', 'server_error_ns', 'source_sync_age_ns', + 'captured_monotonic_ns', 'sampled_boottime_ns', 'kernel_state')) and + 0 < sample['captured_utc_ns'] <= (1 << 63) - 1 and 0 <= sample['server_error_ns'] <= 500_000_000 and + 0 <= sample['source_sync_age_ns'] <= 3_600_000_000_000 and 0 <= sample['kernel_state'] <= 4 and + 0 < sample['captured_monotonic_ns'] <= (1 << 64) - 1 and + sample['captured_monotonic_ns'] <= sample['sampled_boottime_ns'] <= (1 << 64) - 1, 'actual_native_quality_sample_bounds') + log_raw, log_state = pin.read_file(phase / 'probe.log', 16384) + require(sha(log_raw) == result['probe_log_sha256'] and pin.parsed(log_raw) == sample, 'original_actual_quality_sample_log') + return ({phase / 'result.json': (raw, proof), phase / 'probe.log': (log_raw, log_state), **witness_records}, + witnesses[0]['peer_namespace']) + + +class PeerNamespaceProof: + """Only the fixed reviewed namespace's read-only ACL/MAC observations.""" + def __init__(self, pin, original, expected): + self.pin, self.original, self.expected = pin, original, expected + self.code = pin.read_file(PEER_CODE, 128 * 1024) + require(sha(self.code[0]) == PEER_ORIGIN['peer_namespace_controller_sha256'], 'reviewed_peer_namespace_controller') + module = importlib.util.module_from_spec(importlib.util.spec_from_loader('rmm_peer_namespace_guard', loader=None)) + module.__file__ = str(PEER_CODE) + exec(compile(self.code[0], str(PEER_CODE), 'exec'), module.__dict__) + self.namespace = module + require(module.MAIN_SHA == PEER_MAIN_SHA and sha(module.LOCAL_BYTES) == PEER_ORIGIN['peer_namespace_local_profile_sha256'] and + module.expected_acl().hex() == expected['parent_access_acl_hex'], 'fixed_peer_namespace_contract') + self.verify() + + def verify(self): + pin, namespace = self.pin, self.namespace + actual = self.original.fresh() + require(pin.read_file(PEER_CODE, 128 * 1024) == self.code, 'peer_namespace_controller_unchanged') + main, main_state = pin.read_file(namespace.MAIN, 65536, 0o644) + local, local_state = pin.read_file(namespace.LOCAL, 16384, 0o644) + require(sha(main) == PEER_MAIN_SHA and sha(local) == PEER_ORIGIN['peer_namespace_local_profile_sha256'] and + local == namespace.LOCAL_BYTES and main_state == self.expected['main_profile_metadata'] and + local_state == self.expected['local_profile_metadata'], 'actual_held_peer_profiles_unchanged') + parent = pin.directory(namespace.PARENT) + try: + require(namespace.acl(parent) == namespace.expected_acl() and + namespace.acl(parent, 'system.posix_acl_default') is None, 'actual_exact_peer_parent_acl') + finally: + os.close(parent) + require(namespace.profile_state(actual['daemon_pid']) == self.expected['profile'], 'actual_chronyd_profile_still_enforcing') + self.original.fresh() + + +# Closed system-manager load namespace, including control, attached and +# generator precedence. The fixed /lib compatibility alias is verified below. +UNIT_ROOTS = tuple(Path(path) for path in ( + '/etc/systemd/system.control', '/run/systemd/system.control', + '/run/systemd/transient', '/run/systemd/generator.early', + '/etc/systemd/system', '/etc/systemd/system.attached', + '/run/systemd/system', '/run/systemd/system.attached', + '/run/systemd/generator', '/usr/local/lib/systemd/system', + '/usr/lib/systemd/system', '/run/systemd/generator.late')) +UNIT_LEAVES = (UNIT.name, UNIT.name + '.d', 'rmm-time-.service.d', + 'rmm-.service.d', 'service.d', UNIT.name + '.wants', + UNIT.name + '.requires', UNIT.name + '.upholds') + + +def manager_unit_paths(context): + result = command(context.pin, Path('/usr/bin/systemctl'), + ['--system', '--no-ask-password', '--no-pager', 'show', '--property=UnitPath', '--value']) + require(result.returncode == 0 and not result.stderr and result.stdout.isascii() and + len(result.stdout) <= 4096, 'actual_manager_unit_load_path') + paths = tuple(result.stdout.decode('ascii').split()) + known = {str(path) for path in UNIT_ROOTS} | {'/lib/systemd/system'} + require(paths and len(paths) <= len(known) and len(set(paths)) == len(paths) and + set(paths) <= known, 'unknown_manager_unit_load_path') + return paths + + +class UnitComposition: + """One fixed unit's protected namespace, not a general unit/path resolver.""" + def __init__(self, context): + self.context = context + self.paths = manager_unit_paths(context) + self.own = None + self.own_identity = None + self.verify() + + def close(self): + if self.own is not None: + os.close(self.own) + self.own = None + + def created(self, fd): + require(self.own is None, 'only_one_owned_broker_unit') + self.own = os.dup(fd) + proof = self.context.pin.identity(os.fstat(fd)) + self.own_identity = {key: proof[key] for key in ('dev', 'ino', 'uid', 'gid', 'nlink')} + require(proof['uid'] == proof['gid'] == 0 and proof['nlink'] == 1, + 'owned_broker_unit_identity') + + def verify(self): + context = self.context + require(manager_unit_paths(context) == self.paths, 'manager_unit_load_path_changed') + # Ubuntu's merged-/usr alias is the only permitted symlink ancestry. + # All real load roots below are opened independently without symlinks. + alias = Path('/lib') + alias_before = None + merged_alias = False + roots = UNIT_ROOTS + if os.path.lexists(alias): + alias_before = stamp(alias.lstat()) + merged_alias = stat.S_ISLNK(alias.lstat().st_mode) + if merged_alias: + require(alias.lstat().st_uid == 0 and os.readlink(alias) in ('usr/lib', '/usr/lib'), + 'fixed_merged_usr_unit_alias') + else: + fd = context.pin.directory(alias) + os.close(fd) + roots += (Path('/lib/systemd/system'),) + else: + require('/lib/systemd/system' not in self.paths, 'missing_actual_legacy_unit_root') + for root in roots: + try: + fd = context.pin.directory(root) + except FileNotFoundError: + continue + try: + before = context.pin.stable_directory(os.fstat(fd)) + for name in UNIT_LEAVES: + try: + actual = context.pin.identity(os.stat(name, dir_fd=fd, follow_symlinks=False)) + except FileNotFoundError: + continue + require(root == UNIT.parent and name == UNIT.name and self.own is not None, + 'unexpected_existing_broker_unit_composition') + held = context.pin.identity(os.fstat(self.own)) + require(actual == held and {key: held[key] for key in self.own_identity} == self.own_identity and + stat.S_ISREG(held['mode']) and stat.S_IMODE(held['mode']) in (0o600, 0o644), + 'owned_broker_unit_named_identity') + raw, proof = context.pin.read_file(UNIT, 8192, stat.S_IMODE(held['mode'])) + require(raw == UNIT_RAW and proof == context.pin.identity(os.fstat(self.own)), + 'owned_broker_unit_immutable_contents') + # A pre-existing dangling alias to this name could acquire its + # own drop-ins after our file is created. Reject it, never follow. + names = os.listdir(fd) + require(len(names) <= 8192, 'bounded_systemd_load_directory') + for name in names: + if stat.S_ISLNK(os.stat(name, dir_fd=fd, follow_symlinks=False).st_mode): + require(Path(os.readlink(name, dir_fd=fd)).name != UNIT.name, + 'unexpected_broker_unit_alias') + require(context.pin.stable_directory(os.fstat(fd)) == before, + 'protected_unit_load_directory_changed') + finally: + os.close(fd) + if alias_before is not None: + require(stamp(alias.lstat()) == alias_before and + (not merged_alias or os.readlink(alias) in ('usr/lib', '/usr/lib')), + 'merged_usr_unit_alias_changed') + require(manager_unit_paths(context) == self.paths, 'manager_unit_load_path_changed') + + +class Context: + def __init__(self, pin, pin_guard): + self.pin, self.pin_guard = pin, pin_guard + self.retained_records = {} + self.composition = None + operator, guard = pin.load_operator() + self.original = pin.Original(CASE, operator, guard) + require(self.original.artifacts['rmm-time-broker-linux'][1] == + {'bytes': BROKER_BYTES, 'sha256': BROKER_SHA, 'elf_machine': 183}, 'original_exact_broker_elf') + require(not (CASE / 'pin/failure.json').exists(), 'original_pin_failed') + self.pin_result = pin.read_file(CASE / 'pin/result.json') + result = pin.parsed(self.pin_result[0]) + require(result['profile'] == pin.PROFILE and result['case'] == CASE_ID and + result['operator_sha256'] == pin.OPERATOR_SHA and result['source_tar_sha256'] == self.original.source_sha and + result['manifest_sha256'] == self.original.manifest_sha and result['runtime_boot_chrony_preserved'] is True and + result['signer_created'] is False and result['services_started'] is False, + 'original_successful_public_pin') + self.public_pin_result = result + self.quality_records, peer_witness = quality_proof(pin, self.original, self.pin_result[0], result) + self.peer_proof = PeerNamespaceProof(pin, self.original, peer_witness) + self.forbidden, self.roles = forbidden_keys(pin, self.original) + self.fresh() + + def fresh(self): + self.pin_guard() + current = self.original.fresh() + self.peer_proof.verify() + for path, record in {**self.quality_records, **self.retained_records}.items(): + require(self.pin.read_file(path, 16384) == record, 'original_actual_quality_proof_unchanged') + require(self.pin.read_file(CASE / 'pin/result.json') == self.pin_result, 'original_pin_result_unchanged') + raw, proof = self.pin.read_file(ETC / 'chrony-pin.json', 8192) + require(raw == encoded(current) and sha(raw) == self.public_pin_result['public_pin_sha256'] and + proof == self.public_pin_result['public_pin_metadata'], 'original_chrony_pin_unchanged') + for path in (ETC, Path('/run/rmm-time-source'), Path('/run/rmm-time-source/clients')): + before = self.public_pin_result['targets'][str(path)] + fd = self.pin.directory(path) + try: + require(self.pin.stable_directory(os.fstat(fd)) == {key: before[key] for key in ('dev', 'ino', 'uid', 'gid', 'mode')}, + 'original_runtime_directory_identity') + finally: + os.close(fd) + keys, roles = forbidden_keys(self.pin, self.original) + require(keys == self.forbidden and roles == self.roles, 'actual_known_public_roles_unchanged') + if self.composition is not None: + self.composition.verify() + + +def create_file(context, path, raw, mode): + context.fresh() + parent = context.pin.directory(path.parent) + try: + context.pin.absence(parent, path.name) + fd = os.open(path.name, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, 0o600, dir_fd=parent) + try: + view = memoryview(raw) + while view: + n = os.write(fd, view) + require(n > 0, 'complete_owned_file_write') + view = view[n:] + os.fsync(fd) + if path == UNIT and context.composition is not None: + context.composition.created(fd) + context.fresh() + os.fchmod(fd, mode) + os.fsync(fd) + require(context.pin.identity(os.fstat(fd)) == context.pin.identity(os.stat(path.name, dir_fd=parent, follow_symlinks=False)), + 'owned_file_named_identity') + finally: + os.close(fd) + os.fsync(parent) + actual, proof = context.pin.read_file(path, max(8192, len(raw)), mode) + require(actual == raw, 'owned_file_exact_bytes') + return proof + finally: + os.close(parent) + + +def public_fields(configuration, public): + return {'schema_version': 1, 'algorithm': 'Ed25519', 'server_instance': configuration['server_instance'], + 'key_id': configuration['key_id'], 'key_generation': configuration['key_generation'], 'public_key_hex': public.hex()} + + +def key_phase(context): + for path in (SIGNER, PUBLIC): + require(not os.path.lexists(path), 'key_target_already_exists') + seed = os.getrandom(32) + require(len(seed) == 32, 'host_csprng_exact_seed') + public = derive_public(context.pin, seed) + require(public.hex() not in context.forbidden, 'time_key_role_reuse') + configuration = {'schema_version': 1, 'server_instance': str(uuid.uuid4()), 'key_id': 'time-' + uuid.uuid4().hex, + 'key_generation': 1, 'signing_key_hex': seed.hex(), 'forbidden_public_keys': context.forbidden, + 'expected_server_uid': 10001, 'server_gid': 10001} + public_pin = public_fields(configuration, public) + require(len(encoded(configuration)) <= 8192, 'bounded_private_signer_configuration') + proof = create_file(context, SIGNER, encoded(configuration), 0o600) + pubproof = create_file(context, PUBLIC, encoded(public_pin), 0o600) + return {'public_pin': public_pin, 'public_pin_sha256': sha(encoded(public_pin)), 'public_pin_metadata': pubproof, + 'signer_metadata': proof, 'forbidden_role_evidence': context.roles, 'seed_exported': False, + 'broker_started': False, 'time_signed': False} + + +def retained_key(context): + record, record_proof = context.pin.read_file(CASE / 'broker-key/result.json', 16384) + require(not (CASE / 'broker-key/failure.json').exists(), 'own_key_phase_failed') + result = context.pin.parsed(record)['result'] + public_raw, proof = context.pin.read_file(PUBLIC, 8192) + require(sha(public_raw) == result['public_pin_sha256'] and proof == result['public_pin_metadata'], 'own_public_key_pin_unchanged') + public = context.pin.parsed(public_raw) + raw, proof = context.pin.read_file(SIGNER, 8192) # Necessary retained-key verification; never return raw or its hash. + configuration = context.pin.parsed(raw) + require(set(configuration) == {'schema_version', 'server_instance', 'key_id', 'key_generation', 'signing_key_hex', + 'forbidden_public_keys', 'expected_server_uid', 'server_gid'} and + proof == result['signer_metadata'] and type(configuration['signing_key_hex']) is str and + re.fullmatch('[0-9a-f]{64}', configuration['signing_key_hex']) and + configuration['forbidden_public_keys'] == context.forbidden and + type(configuration['schema_version']) is int and type(configuration['key_generation']) is int and + configuration['schema_version'] == configuration['key_generation'] == 1 and + configuration['expected_server_uid'] == configuration['server_gid'] == 10001 and + str(uuid.UUID(configuration['server_instance'])) == configuration['server_instance'] and + uuid.UUID(configuration['server_instance']).int > 0 and type(configuration['key_id']) is str and + re.fullmatch('[A-Za-z0-9_-]{1,64}', configuration['key_id']), 'own_retained_signer_configuration') + require(public == public_fields(configuration, derive_public(context.pin, bytes.fromhex(configuration['signing_key_hex']))) and + public == result['public_pin'] and public['public_key_hex'] not in context.forbidden, 'own_retained_time_key_role') + context.retained_records.update({CASE / 'broker-key/result.json': (record, record_proof), + PUBLIC: context.pin.read_file(PUBLIC, 8192), SIGNER: (raw, proof)}) + return record_proof + + +def group_lookup(name_or_gid): + try: + value = grp.getgrgid(name_or_gid) if type(name_or_gid) is int else grp.getgrnam(name_or_gid) + return {'name': value.gr_name, 'gid': value.gr_gid, 'members': value.gr_mem} + except KeyError: + return None + + +def group_phase(context): + retained_key(context) + require(group_lookup(GROUP) is None and group_lookup(10001) is None, 'group_name_or_gid_already_exists') + raw, proof = context.pin.read_file(Path('/etc/group'), 1024 * 1024, 0o644) + require(raw.endswith(b'\n'), 'canonical_public_group_file') + context.fresh() + require(group_lookup(GROUP) is None and group_lookup(10001) is None, 'group_name_or_gid_collision_before_create') + result = command(context.pin, Path('/usr/sbin/groupadd'), ['--system', '--gid', '10001', GROUP]) + require(result.returncode == 0, 'own_groupadd_failed_no_retry') + context.fresh() + added = {'name': GROUP, 'gid': 10001, 'members': []} + require(group_lookup(GROUP) == group_lookup(10001) == added, 'own_group_exact_name_gid_empty_members') + after, after_proof = context.pin.read_file(Path('/etc/group'), 1024 * 1024, 0o644) + row = (GROUP + ':x:10001:\n').encode() + require(after.count(row) == 1 and after.replace(row, b'', 1) == raw, 'only_own_public_group_row_added') + return {'group': added, 'public_group_before_sha256': sha(raw), 'public_group_after_sha256': sha(after), + 'public_group_before_metadata': proof, 'public_group_after_metadata': after_proof, + 'groupadd_sha256': GROUPADD_SHA, 'existing_group_members_unchanged': True, 'service_enabled': False, 'broker_started': False} + + +def install_phase(context): + retained_key(context) + raw, group_proof = context.pin.read_file(CASE / 'broker-group/result.json', 16384) + require(not (CASE / 'broker-group/failure.json').exists(), 'own_group_phase_failed') + receipt = context.pin.parsed(raw) + require(receipt['profile'] == PROFILE and receipt['case'] == CASE_ID and receipt['phase'] == 'broker-group' and + receipt['result']['group'] == {'name': GROUP, 'gid': 10001, 'members': []} and + receipt['result']['existing_group_members_unchanged'] is True, 'own_group_creation_provenance') + require(group_lookup(GROUP) == group_lookup(10001) == {'name': GROUP, 'gid': 10001, 'members': []} and + group_lookup('_chrony')['gid'] == 989 and group_lookup(989)['name'] == '_chrony', 'actual_unit_group_resolution') + require(not os.path.lexists(BINARY), 'installation_target_already_exists') + context.composition = UnitComposition(context) # Before even a libexec mkdir or binary write. + context.retained_records[CASE / 'broker-group/result.json'] = (raw, group_proof) + if not os.path.lexists(BINARY.parent): + parent = context.pin.directory(BINARY.parent.parent) + try: + fd = context.pin.new_directory(parent, BINARY.parent.name, 0o755, 0, context) + os.close(fd) + finally: + os.close(parent) + else: + fd = context.pin.directory(BINARY.parent) + os.close(fd) + binary, _ = context.pin.read_file(context.original.artifacts['rmm-time-broker-linux'][0], BROKER_BYTES, 0o500) + require(len(binary) == BROKER_BYTES and sha(binary) == BROKER_SHA, 'original_broker_copy_bytes') + binary_proof = create_file(context, BINARY, binary, 0o500) + unit_proof = create_file(context, UNIT, UNIT_RAW, 0o644) + return {'binary_sha256': BROKER_SHA, 'binary_bytes': BROKER_BYTES, 'binary_metadata': binary_proof, + 'unit_sha256': sha(UNIT_RAW), 'unit_metadata': unit_proof, 'own_group_receipt_sha256': sha(raw), + 'manager_unit_load_paths': context.composition.paths, + 'daemon_reload': False, 'service_enabled': False, 'broker_started': False, 'time_signed': False} + + +def phase(name, action, pin, pin_guard): + case_fd = pin.directory(CASE) + phase_fd = -1 + context = None + try: + pin.absence(case_fd, name) # Before a fresh getter, seed or native command. + context = Context(pin, pin_guard) + context.fresh() + os.mkdir(name, 0o700, dir_fd=case_fd) + os.fsync(case_fd) + phase_fd = os.open(name, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=case_fd) + context.fresh() + pin.exclusive(phase_fd, 'intent.json', encoded({'profile': PROFILE, 'case': CASE_ID, 'phase': name, + 'controller_sha256': sha(Path(__file__).read_bytes()), 'pin_controller_sha256': PIN_SHA, + 'source_tar_sha256': context.original.source_sha, 'manifest_sha256': context.original.manifest_sha})) + result = action(context) + context.fresh() + receipt = {'profile': PROFILE, 'case': CASE_ID, 'phase': name, 'result': result} + pin.exclusive(phase_fd, 'result.json', encoded(receipt)) + print(encoded(receipt).decode('ascii'), end='') + except Exception as error: + failure = {'profile': PROFILE, 'case': CASE_ID, 'phase': name, 'failed': True, + 'failure_reason': str(error) if isinstance(error, Denied) else 'unexpected_broker_bootstrap_exception', + 'read_original_case_only': True, 'no_retry_cleanup_or_adopt': True} + if phase_fd >= 0: + pin.exclusive(phase_fd, 'failure.json', encoded(failure)) + print(encoded(failure).decode('ascii'), end='') + raise SystemExit(1) + finally: + if context is not None and context.composition is not None: + context.composition.close() + if phase_fd >= 0: + os.close(phase_fd) + os.close(case_fd) + + +def read(pin): + records = {} + for name in ('broker-key', 'broker-group', 'broker-install'): + records[name] = {} + for leaf in ('intent', 'result', 'failure'): + try: + raw, proof = pin.read_file(CASE / name / (leaf + '.json'), 16384) + records[name][leaf] = {'sha256': sha(raw), 'metadata': proof, 'record': pin.parsed(raw)} + except FileNotFoundError: + records[name][leaf] = None + metadata = {} + for path in (SIGNER, PUBLIC, BINARY, UNIT): + parent = -1 + try: + parent = pin.directory(path.parent) + metadata[str(path)] = pin.identity(os.stat(path.name, dir_fd=parent, follow_symlinks=False)) + except FileNotFoundError: + metadata[str(path)] = None + except (pin.Denied, NotADirectoryError): + metadata[str(path)] = {'inspection_denied': True} + finally: + if parent >= 0: + os.close(parent) + print(encoded({'profile': PROFILE, 'case': CASE_ID, 'read_only': True, 'records': records, 'metadata': metadata}).decode('ascii'), end='') + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('command', choices=('host-key', 'host-group', 'host-install', 'host-read')) + args = parser.parse_args() + require(sys.flags.isolated == 1 and os.geteuid() == 0 and os.uname().sysname == 'Linux' and os.uname().machine == 'aarch64', + 'isolated_root_linux_arm64_only') + os.umask(0o077) + resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) + pin, pin_guard = protected_code() + pin.case_path(CASE_ID) + if args.command == 'host-read': + read(pin) + else: + choices = {'host-key': ('broker-key', key_phase), 'host-group': ('broker-group', group_phase), + 'host-install': ('broker-install', install_phase)} + phase(*choices[args.command], pin, pin_guard) + + +if __name__ == '__main__': + try: + main() + except Exception: + print(encoded({'failed': True, 'failure_reason': 'unexpected_broker_bootstrap_exception', + 'read_original_case_only': True}).decode('ascii'), end='') + raise SystemExit(1) diff --git a/docs/server-time-broker-bootstrap.md b/docs/server-time-broker-bootstrap.md new file mode 100644 index 0000000..954ad8a --- /dev/null +++ b/docs/server-time-broker-bootstrap.md @@ -0,0 +1,253 @@ +# Getrennter Zeitschlüssel und demandgestützte Brokerinstallation + +`deploy/server_time_broker_bootstrap.py` liefert drei getrennte create-only +Root-Bootstrapphasen. Keine Phase startet oder aktiviert einen Dienst, lädt +Systemd neu oder erzeugt eine Zeitattestierung. Aus Sourcevorhandensein folgt +kein tatsächlicher Servernachweis; Root muss Quelle und Zielaktion jeweils +separat prüfen. RMM-Jobs behalten unverändert die WebUI-Genehmigungsgrenze. + +Der feste Originalfall ist `5b358997-3abc-43db-945f-f41855b4e3c0`. +Der unveränderte Pinbootstrap `fac85dd…` wird ausschließlich von +`/var/lib/rmm-time-source-operators//pin_bootstrap.py` geladen: +Root:Root0600, ein regulärer Link, geschützte Ancestry und exakter SHA256. +Seine tatsächlichen Original-Preflight-/Build-/Quellen-/Boot-/Runtime- und +Chrony-/Pinbindungen bleiben Pflicht. Der Broker muss genau das erfolgreiche +ARM64-ELF1067136Bytes/SHA256 +`5d8d786925c060eb042f0a592453f11970c32c4287fa4c9464f6f6a6e38cb201` +sein. Alte gescheiterte Probe-/Bootstrapversuche werden nicht umgeschrieben. + +Vor jeder der drei Phasen ist zusätzlich das tatsächliche erfolgreiche +`probe-peer-acceptance-v1/result.json` desselben Originalfalls nötig. +Der Gate bindet den separat geprüften Probecontroller, vollständige +Vorher-/Nachher-Zeugen samt ihren gespeicherten Bytes/Hashes, Sources, Artefakt, +öffentlichen Pin, ursprüngliche Fehler-/Pinbelege und identische Boot-ID. +Das tatsächliche Sample muss strikt Fehler≤500ms, Syncalter≤1h, Kernelstate0..4 +und alle unveränderten Samplefelder erfüllen. Eine Fixture, Callerbool oder +Dateipräsenz allein qualifiziert nichts. Die Qualitätsprobe muss erfolgen, +bevor die neue Supplementary-Gruppe angelegt wird. Die neue DAC-Probe belegt +das separat diagnostizierte Zugriffsprofil; die frühere GROUP-Probe mit Exit1 +bleibt fehlgeschlagen und ihre Originalbytes/-Hashes bleiben gebunden. +Eine historische erfolgreiche Probe wird nicht als aktuelle Zeitautorität +wiederverwendet; der laufende Broker muss später vor jeder Signatur selbst +frisch messen. + +Auf dem Server ausschließlich isoliert starten: + +```text +python3 -I /reviewter/absoluter/pfad/server_time_broker_bootstrap.py host-key +python3 -I /reviewter/absoluter/pfad/server_time_broker_bootstrap.py host-group +python3 -I /reviewter/absoluter/pfad/server_time_broker_bootstrap.py host-install +``` + +Jede Phase besitzt einen eigenen dauerhaften Intent im Originalfall. +Bestehende Phasen verweigern vor Getter, Entropieerhebung oder Zielaktion. +Vor jedem Zielwrite und jeder Berechtigungsänderung werden Sources, echte +Prozess-/Pin-/Runtime-/Bootzeugen und bekannte öffentliche Rollen erneut +geprüft. Jeder Fehler behält eigene Teilobjekte; kein Retry, Cleanup, Reset +oder Übernehmen vorhandener Objekte. Für verlorene Antworten ausschließlich +`host-read` aufrufen. Dieser liest nur öffentliche Phasenbelege und Metadaten; +keine Signerkonfiguration, Seeds, Tokens, TLS-Getter oder native Zeitabfrage. + +`host-key` erzeugt ausschließlich `/etc/rmm-time-source/signer.json` und +`time-public-key.json`, beide Root:Root0600 mit einem Link. Beide Namen müssen +vorher abwesend sein. Ein eigener 32-Byte-Seed entsteht ausschließlich durch +Host-CSPRNG. OpenSSL erhält die Ed25519-PKCS8-DER nur auf stdin und gibt +SPKI-Public-DER zurück; Seed und private DER erscheinen nie in argv, +Umgebung, Ausgaben oder Belegen. Coredumps sind deaktiviert. Die private +Konfiguration entspricht exakt dem bestehenden Broker-Serde-Schema: +Schema1, eigene Server-UUID, eigene Key-ID, Generation1, Seedhex nur in der +Rootdatei, tatsächliche Forbidden-Publickeys, UID/GID10001. Die öffentliche +Datei enthält ausschließlich Algorithmus, öffentlichen Key und diese +öffentlichen Kontextfelder. Ausgaben enthalten keine privaten Rohdaten oder +Hashes der privaten Konfiguration. + +Der tatsächliche Jobpublickey kommt ausschließlich vom vorhandenen öffentlichen +Getter über verifiziertes TLS: TCP127.0.0.1:18443, SNI `rmm-dev.internal`, +bestehende CA und notwendiges lokales Bearer-Reader-Token. Das Token wird nicht +zurückgegeben oder protokolliert. Die vier fest bekannten öffentlichen +Zertifikate `devstate/{pki,api-pki}/{ca.pem,server.pem}` werden ausschließlich +auf tatsächliche Ed25519-SPKIs geprüft und gegebenenfalls dedupliziert in die +Verbotsliste aufgenommen; andere Algorithmen ergeben keine Dummykeys. +Die Root-beobachtet abwesenden Update-/Healthrollenpfade müssen weiter +abwesend sein; neue Rollen benötigen eine gesonderte konkrete Kontextprüfung. +Private PEMs werden nicht gelesen und Credentials nicht durchsucht. + +`host-group` verlangt den unveränderten eigenen erfolgreichen Keyfall. Sowohl +NSS-Name `rmm-time-gateway` als auch GID10001 müssen vorab abwesend sein. +Nur das geschützte feste `/usr/sbin/groupadd --system --gid 10001 +rmm-time-gateway` darf die neue leere Gruppe anlegen. Die öffentliche +`/etc/group` muss danach bytegleich bis auf exakt die hinzugefügte Gruppenzeile +sein; bestehende Gruppen oder Mitgliedschaften werden nicht verändert oder +übernommen. Kein gshadow-Inhalt wird gelesen. Ein Fehler darf keine +Gruppenanlage wiederholen. + +`host-install` verlangt eigene unveränderte Key- und Gruppenbelege sowie echte +NSS-Auflösung der neuen leeren Gruppe und `_chrony`989. Es kopiert ausschließlich +das gebundene Original-ELF nach `/usr/local/libexec/rmm-time-broker`, Root0500, +und die feste demand-only Unit `rmm-time-broker.service`, Root0644. Vorhandene +Binary-/Unit-/Dropinpfade verweigern. Ein fehlendes `/usr/local/libexec` darf +unter gehaltenem geschütztem Rootparent create-only Root0755 entstehen; +ein vorhandener legitimer Parent wird lediglich geprüft, niemals gechmodet. +Die Unit hat keinen Installabschnitt, startet als Root mit Gruppe989 und der +neuen benannten Supplementary-Gruppe10001. NNP, ausschließlich +CAP_SYS_PTRACE und CAP_DAC_OVERRIDE, AF_UNIX-only/IP-denied, ProtectSystem=strict, ProtectHome, +PrivateDevices sowie der feste Debug-/ptrace-/process_vm-Syscallausschluss +bleiben gesetzt. Die expliziten ReadWritePaths sind auf den eigenen Runtimebereich begrenzt; +CAP_SYS_TIME wird nicht erteilt. Kein Enable, Start, Daemonreload oder HTTP- +Deployment wird durch diese Installation ausgelöst. + + +Tatsächlich notwendige DAC-Ausnahme: RootUID0 mit EGID989 und ausschließlich +CAP_SYS_PTRACE konnte laut Rootdiagnose nicht durch `/run/chrony`9890700 +traversieren oder den Socket9890755 verbinden (EACCES13). Mit zusätzlichem +CAP_DAC_OVERRIDE waren beide Zugriffe möglich. Diese Ausnahme steht deshalb +explizit im Unit-BoundingSet; Chronyverzeichnis und Socket werden nicht +gechmodet und sämtliche gehaltenen Identitäts-/Credentialprüfungen bleiben +bestehen. Root-ROFS, eigener Runtime-Schreibbereich, NNP, AF_UNIX, IP-Verbot +und Debug-/ptrace-Syscallausschluss bleiben unverändert; CAP_SYS_TIME wird +weiterhin nicht erteilt. Die Diagnose erzeugte weder Socketdatei noch Datagramm +und war selbst keine Sourcequalitätsabnahme. + +Die öffentlichen vier Zertifikate sind tatsächlich10001:100010600 unter +jeweils10001:100010700-eigenen festen PKI-Verzeichnissen. Der Reader erlaubt +nur genau diese vier öffentlichen Leafnamen, hält Rootancestry bis devstate +und PKI-/Leaf-FDs, prüft ihre Originalmetadaten vorher/nachher und bindet die +aktuellen API-/Gateway-Image-/UID-/Runtimemetadaten unabhängig davor/danach. +Das notwendige Reader-Token bleibt ausschließlich Root:Root0600. Keine +Root-Eigentümerschaft der öffentlichen PKI wird erfunden oder geändert. + + +Der Installationsgate ist ausschließlich an die neue DAC-Probe gebunden, +einschließlich ihrer fünf zusätzlichen Herkunftshashes. Das alte GROUP-Probe- +Resultat und Log werden weiterhin bytegleich gelesen und nie als erfolgreich +umgedeutet. Fehlender oder nicht erfolgreicher DAC-Nachweis verweigert bereits +vor Schlüssel-, Gruppen- oder Installationswirkungen. Der feste Groupadd- +SHA256 des tatsächlich beobachteten Root0755-Tools wird vor/nach Ausführung +zusätzlich gebunden. Die Existenz einer vorbereiteten Unit ist weder +Dienststart noch Qualitätsnachweis. + +Aktueller Sourcecheckpoint: Die neue DAC-Probe lief tatsächlich bis zum +Provider, endete jedoch ebenfalls mit Exit1 und qualifizierte keine Quelle. +Der Bootstrapgate auf diesen Beleg bleibt daher vollständig geschlossen. +Root bereitet weitere getrennte Diagnose vor. Erst ein separat reviewter, +tatsächlich erfolgreicher neuer nativer Nachweis darf durch ein konkretes +Gate-Delta gebunden werden. CLI-Trackingwerte ersetzen diesen Nachweis nicht. +Es wurden noch keine Brokerkeys, Gruppe10001, Brokerbinary oder Unit durch +diesen Sourcecheckpoint auf dem Server angelegt. + +Root bestätigte unabhängig beide Zertifikatsmounts als read-only: Gateway +`devstate/pki` und API `devstate/api-pki`, jeweils nach `/pki`; Receipt +`67083fd9d4d3ff90e93fb30957d916eb8c89e431993674333d158db6f03c0504`. +Der feste Parent bis devstate ist Rootgeschützt, die beiden PKI-Leaves gehören +der bereits gebundenen Serveridentität10001. Daraus folgt keine allgemeine +Ausnahme für beliebige fremde Verzeichnisse. + +Lokale Prüfung dieses Implementierungsschnitts: AST bestanden; drei kleine +isolierte Tmpfs-/Kryptoguardgruppen bestanden (RFC8032-Ableitung und private +Ausgabegrenze, Role-Reuse/vorhandene Ziele, tatsächliche10001-PKI-Metadaten mit +Gegenfällen). Reine Qualitygate-Fixtures prüften positive vollständige +Witnessbindung und Ablehnung geänderter Controller-, Origin-, Witnesshash- +und Samplegrenzen. NSS-Kollisionen verweigerten vor jedem Groupadd-Aufruf. +Die Autorität dieser Fixtures war ausdrücklich ersetzt: kein tatsächlicher +Token-/Zertifikats-/Serverzugriff, keine Root-Hostschlüsselgenerierung, +Gruppe oder Diensteinrichtung. Die PKI-Gegenprobe musste ihren eigenen fremd-eigenen Testfile vor chmod +zunächst zurückchownen, weil ihr bewusst CAP_FOWNER fehlte. Diese Korrektur +der Hilfsprüfung änderte keine Produktquelle und ergibt keinen Ziel- oder +Nativeerfolg. + +## Enger Reviewfix: vollständige feste Unitkomposition vor Installation + +Der ursprüngliche Controller8069 prüfte nur die exakte Unit und ihr `.d` +unter drei Rootpfaden. Das reichte für Systemd nicht: Control-/Attached-/ +Generatorpfade und geerbte Dash-Präfix-/typweite Drop-ins können andere +ExecStart- oder Capabilitywerte beitragen. Es wurde kein tatsächliches +Overlay auf dem Server nachgewiesen. Maßgeblich sind die dokumentierten +[System-Loadpaths und Drop-in-Regeln](https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html) +und der tatsächliche Manager-`UnitPath`; +[`systemd-analyze unit-paths` allein zeigt nur Compilerdefaults](https://www.freedesktop.org/software/systemd/man/latest/systemd-analyze.html). + +Der Installer prüft jetzt die zwölf festen System-Loadroots einschließlich +`system.control`, transient, attached, Generatoren und `/usr/local/lib`. +Die feste merged-usr-`/lib`-Verknüpfung wird unabhängig geprüft; ein geschütztes +reales `/lib` erhält einen zusätzlichen eigenen Scan. Der tatsächliche +Manager-Loadpath wird lesend vor/nach gebunden; unbekannte Pfade verweigern. +An jedem Root müssen exakte Unit, `rmm-time-broker.service.d`, +`rmm-time-.service.d`, `rmm-.service.d`, `service.d` sowie unit-eigene +`.wants`/`.requires`/`.upholds` fehlen. Verzeichnis-FDs und `O_NOFOLLOW` +verhindern eine stille Übernahme fremder Pfadobjekte. Ein begrenzter Scan +weist auch vorhandene direkte Aliase zum neuen Unitnamen ab, ohne deren +Konfigurationsinhalte zu lesen oder fremde Namen zu protokollieren. + +Diese Prüfung erfolgt vor dem ersten Installationswrite, jedem folgenden +Freshguard und dem Schlussbeleg. Ausschließlich die gerade per create-only +FD erzeugte eigene Unit darf anschließend mit demselben gehaltenen Inode, +Rootidentität, einem Link und exakt den festen Unitbytes vorhanden sein; +600→644 ist die einzige vorgesehene Modustransition. Fremde Unitpfade oder +frei wählbare Resume-/Skipflags gibt es nicht. + +Vor einem späteren tatsächlichen Start bleibt zusätzlich Roots unabhängige +Prüfung der effektiven Manager-Eigenschaften, Namen, Fragment-/Dropinpfade, +Exec-Befehle, Prozessimage, UID/GID und Capabilities zwingend. Die Source- +Kompositionsprüfung ist kein Startnachweis und kein Versprechen über zukünftige +vertrauenswürdige Rootänderungen. + +Lokaler Deltanachweis: Positive eigene FD-gebundene Unit, unbekannter +Managerpfad sowie negative Präfix-, typweite, Control- und Aliasfixtures +bestanden. Die negativen Fälle wurden direkt im Installationspfad vor jeglichem +Binary-/Unit-/libexec-Write abgewiesen. Systemd-/Originalautorität war dabei +ausdrücklich durch Fixtures ersetzt; alle Dateisystemzugriffe lagen im eigenen +lokalen Container-Tmpfs. Alte Controller8069- und f8cb-Originalbelege bleiben +unverändert. Der tatsächliche native Qualitätsgate bleibt weiterhin geschlossen; +keine Vorratsfreigabe oder Zielaktion folgt aus diesem Reviewfix. + + +## Separater Peer-Qualifier: weiterhin keine operative Freigabe + +Der vorbereitete Gate verwendet jetzt ausschließlich +`probe-peer-acceptance-v1/result.json`, Profil +`rmm.server-time-source.peer-acceptance.v1`, Controller +`ca89eac44d6b1e8bbbb14cca58ecabb02fd05d59292b77f703997fad0c29e3c8`. +Die alten GROUP-/DAC-Resultate bleiben fehlgeschlagen und ihre Originalbytes +und Herkunftshashes gebunden. Zusätzlich zu den bisherigen Bindings kommen +neun genaue Namespace-/DAC-Herkunftsfelder hinzu. Der tatsächliche +Namespacebootstrapcb166 mit Controller2f1, unverändertem Mainprofil214e und +lokaler Regel27e ist ausschließlich eine eng begrenzte ACL-/MAC-Voraussetzung, +keine native Sourcequalität. + +Der neue vollständige Witness bindet außerdem exakte Main-/Localmetadaten, +Parent-ACL und tatsächliches Chronyd-Enforceprofil. Vor jedem zukünftigen +Bootstrapwrite prüft ein privater read-only Guard erneut den fest gebundenen +Namespacecontroller, unveränderte Profile, exakt die benannte ACL ohne +Default-ACL sowie das tatsächliche Kernel-Enforceprofil zwischen unabhängigen +Originalprozess-/Bootprüfungen. Er führt keine ACL- oder MAC-Schreiboperation +aus. Die Unitkompositionsprüfung bleibt unverändert. + +`QUALITY_RESULT_SHA` bleibt ausdrücklich leer (`None`). Damit verweigern +sämtliche Key-/Group-/Installphasen, bevor ein unbekannter Qualifierbeleg auch +nur als Freigabe gelesen werden kann. Erst Root darf nach tatsächlichem, +separat geprüftem Peer-PASS den exakten Resultat-Hash in einem weiteren +reviewten Quellendelta binden. Weder vorbereiteter Controller, Namespace- +Voraussetzung noch eine Diagnose oder früherer fehlgeschlagener Lauf öffnet +diesen Gate. Aktuell wird kein erfolgreicher Peer-Lauf behauptet. + +Der reine lokale Deltaguard belegte die initiale geschlossene Sperre, positive +vollständige Peer-Fixture und Ablehnung anderer Controller-/Namespace-/ +Witnessbindungen. Separate read-only Guard-Fixtures wiesen geänderte ACL, +Profilmetadaten und verlorenen Enforcezustand ab. Originalautoritäten waren +in diesen Fixtures ersetzt; es gab keine Zielabfrage oder Einrichtung und +keine Wiederholung der früheren zehn Guardgruppen. + + +Nach dem vorbereiteten Quellendelta meldete Root auch den tatsächlichen +ca89-Peerprobe-Lauf mit Exit1 und `source_quality_qualified=false`. +Die gesonderte Nativefehlerdiagnose zeigte weiterhin TIME_CHRONY_CONNECT; +Kernel-Audit belegt einen AppArmor-Lesedenial am Tracking-Clientsockel. +Die erste Policyabfrage war wegen libapparmor-Pfadkürzung irreführend; +bytegleiche Kernelpolicy und korrigierte Abfrage erlauben den vollständigen +Pfad. Named-Connect bleibt verweigert. Die separate abstrakte Socketdiagnose +bestand im gleichen Profil, noch ohne Datagramm oder Sourcequalität; +[genaue Befunde](server-time-peer-diagnosis.md). Der notwendige neue +Providertransport und seine tatsächlichen Abnahmen bleiben separate Gates. +Dies ändert keinen alten Fehler in einen Erfolg. Der Brokergate bleibt +`QUALITY_RESULT_SHA=None`; weder Schlüssel noch Gruppe oder Installation +sind damit freigegeben.