From 1e191868be010c64d4910683d08a16469770b34a Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 30 Sep 2026 16:29:26 +0300 Subject: [PATCH] Fix B2 foundation proof for Compose omitted false bind option --- infra/deploy-runner/DEVICE_B2_FOUNDATION.md | 19 +++++ .../device-b2-foundation-compose220/README.md | 36 +++++++++ .../device-b2-foundation-compose220/base.json | 67 +++++++++++++++ .../device-b2-foundation-compose220/base.yml | 29 +++++++ .../candidate.json | 74 +++++++++++++++++ .../override.yml | 11 +++ infra/deploy-runner/nodedc-deploy | 15 +++- .../test_device_b2_foundation.py | 81 +++++++++++++++++++ 8 files changed, 328 insertions(+), 4 deletions(-) create mode 100644 infra/deploy-runner/fixtures/device-b2-foundation-compose220/README.md create mode 100644 infra/deploy-runner/fixtures/device-b2-foundation-compose220/base.json create mode 100644 infra/deploy-runner/fixtures/device-b2-foundation-compose220/base.yml create mode 100644 infra/deploy-runner/fixtures/device-b2-foundation-compose220/candidate.json create mode 100644 infra/deploy-runner/fixtures/device-b2-foundation-compose220/override.yml diff --git a/infra/deploy-runner/DEVICE_B2_FOUNDATION.md b/infra/deploy-runner/DEVICE_B2_FOUNDATION.md index fe13af8..0698cad 100644 --- a/infra/deploy-runner/DEVICE_B2_FOUNDATION.md +++ b/infra/deploy-runner/DEVICE_B2_FOUNDATION.md @@ -46,6 +46,25 @@ and exact schema on preflight and acceptance. A SQL failure before Core recreati does not mark runtime as changed or restart Core during rollback. Existing Dockerfile/migration immutability remains unchanged. +Runner016 was installed (SHA256 +`1cda852fec9e940cfbec835b27159f04e96b13e24b6bbcd3ef87dd1a91f306aa`), +but plan001 rejected the effective Compose comparison before mutation. Official +Compose2.20.1 reproduced that rejection on all five current NAS Compose files: +the sole mismatch was the new mount's `bind: {}` versus an expected explicit +`create_host_path: false`. Existing synthetic tests missed this serializer form. +The corrected transition is `device-b2-foundation-v1-20260930-002`;001 is rejected +by identity and must not be applied. SQL, source YAML, predecessor and runtime +scope are unchanged. + +Runner017 normalizes only omitted/false `create_host_path` on this one new bind, +in private comparison copies, alongside the existing false `read_only` rule. +Actual config hashes remain untouched. True/null/non-boolean values, missing +bind objects, unknown bind options, duplicate mounts and unrelated changes fail. +See `fixtures/device-b2-foundation-compose220` for real parser output and exact +reproduction. Qualification with that fixture and with all five NAS files proves +the old failure and corrected exact comparison. This is local parser evidence, +not proof of NAS apply or runtime acceptance. + Local validation: foundation boundary/negative tests, deterministic artifact, real archive through runner loader, existing release/network-priority/autodeploy and Device Plane registry regression. SQL was also executed after all17 existing diff --git a/infra/deploy-runner/fixtures/device-b2-foundation-compose220/README.md b/infra/deploy-runner/fixtures/device-b2-foundation-compose220/README.md new file mode 100644 index 0000000..f955174 --- /dev/null +++ b/infra/deploy-runner/fixtures/device-b2-foundation-compose220/README.md @@ -0,0 +1,36 @@ +# B2 foundation: Compose 2.20.1 serialization regression + +These JSON files are real `config --format json` output, generated from the +synthetic, secret-free `base.yml` and the exact production `override.yml`. +No Docker daemon, container, worker or production mutation is involved. + +Official Docker Compose v2.20.1 Darwin arm64 release binary SHA256: +`e5449e23d14740092c4e764dd9e66cc693d8b02747167c045fd4edfd64fda958`. +Source: . +This is the upstream parser version; the NAS build is +`2.20.1-6047-g6817716`, not this exact binary. + +Generate from this directory, using a separately SHA-verified binary: + +```sh +"$COMPOSE_BINARY" -p nodedc-device-plane --env-file /dev/null \ + --project-directory /volume1/docker/nodedc-device-plane \ + -f base.yml config --format json > base.json +"$COMPOSE_BINARY" -p nodedc-device-plane --env-file /dev/null \ + --project-directory /volume1/docker/nodedc-device-plane \ + -f base.yml -f override.yml config --format json > candidate.json +``` + +JSON whitespace is formatted with Python `json.dumps(..., indent=2)`. +The new mount emits `bind: {}` and omits `read_only`: both booleans are false. +Runner016 incorrectly expected an explicit `create_host_path: false` property. +Runner017 removes that exact false property only from the new B2 mount inside +comparison copies. Raw config, its digest, fixed YAML, all old mounts and +other properties stay exact. True/null/numeric/string values and unknown bind +options are rejected. The source YAML must still explicitly disable directory +creation; accepting this JSON output cannot authorize a different YAML. + +The same failure and fix were also reproduced using all five current NAS +Compose files through SMB, without reading any referenced secret file. +Only filenames, hashes and comparison outcomes are retained in public evidence; +the full effective configuration is not a fixture or a deploy payload. diff --git a/infra/deploy-runner/fixtures/device-b2-foundation-compose220/base.json b/infra/deploy-runner/fixtures/device-b2-foundation-compose220/base.json new file mode 100644 index 0000000..ae11a61 --- /dev/null +++ b/infra/deploy-runner/fixtures/device-b2-foundation-compose220/base.json @@ -0,0 +1,67 @@ +{ + "name": "nodedc-device-plane", + "networks": { + "default": { + "name": "nodedc-device-plane_default", + "ipam": {}, + "external": false + }, + "egress": { + "name": "nodedc-device-plane_egress", + "ipam": {}, + "external": false + }, + "private": { + "name": "nodedc-device-plane_private", + "ipam": {}, + "external": false, + "internal": true + } + }, + "services": { + "device-control-core": { + "command": null, + "entrypoint": null, + "environment": { + "EXISTING": "synthetic-preserved" + }, + "image": "nodedc/device-control-core:local", + "networks": { + "egress": {}, + "private": { + "priority": 100 + } + }, + "volumes": [ + { + "type": "bind", + "source": "/synthetic/existing-secret-reference", + "target": "/run/existing-secret-reference", + "read_only": true, + "bind": {} + } + ] + }, + "device-postgres": { + "command": null, + "entrypoint": null, + "image": "postgres:16", + "networks": { + "default": null + }, + "volumes": [ + { + "type": "volume", + "source": "existing-data", + "target": "/var/lib/postgresql/data" + } + ] + } + }, + "volumes": { + "existing-data": { + "name": "nodedc-device-plane_existing-data", + "external": false + } + } +} diff --git a/infra/deploy-runner/fixtures/device-b2-foundation-compose220/base.yml b/infra/deploy-runner/fixtures/device-b2-foundation-compose220/base.yml new file mode 100644 index 0000000..cf03e72 --- /dev/null +++ b/infra/deploy-runner/fixtures/device-b2-foundation-compose220/base.yml @@ -0,0 +1,29 @@ +services: + device-control-core: + image: nodedc/device-control-core:local + environment: + EXISTING: synthetic-preserved + volumes: + - type: bind + source: /synthetic/existing-secret-reference + target: /run/existing-secret-reference + read_only: true + bind: + create_host_path: false + networks: + private: + priority: 100 + egress: + priority: 0 + device-postgres: + image: postgres:16 + volumes: + - type: volume + source: existing-data + target: /var/lib/postgresql/data +networks: + private: + internal: true + egress: {} +volumes: + existing-data: {} diff --git a/infra/deploy-runner/fixtures/device-b2-foundation-compose220/candidate.json b/infra/deploy-runner/fixtures/device-b2-foundation-compose220/candidate.json new file mode 100644 index 0000000..0772d9b --- /dev/null +++ b/infra/deploy-runner/fixtures/device-b2-foundation-compose220/candidate.json @@ -0,0 +1,74 @@ +{ + "name": "nodedc-device-plane", + "networks": { + "default": { + "name": "nodedc-device-plane_default", + "ipam": {}, + "external": false + }, + "egress": { + "name": "nodedc-device-plane_egress", + "ipam": {}, + "external": false + }, + "private": { + "name": "nodedc-device-plane_private", + "ipam": {}, + "external": false, + "internal": true + } + }, + "services": { + "device-control-core": { + "command": null, + "entrypoint": null, + "environment": { + "DEVICE_B2_SECRET_ROOT": "/run/nodedc-b2-connections", + "EXISTING": "synthetic-preserved" + }, + "image": "nodedc/device-control-core:local", + "networks": { + "egress": {}, + "private": { + "priority": 100 + } + }, + "volumes": [ + { + "type": "bind", + "source": "/synthetic/existing-secret-reference", + "target": "/run/existing-secret-reference", + "read_only": true, + "bind": {} + }, + { + "type": "bind", + "source": "/volume1/docker/nodedc-device-plane/private-b2-connections", + "target": "/run/nodedc-b2-connections", + "bind": {} + } + ] + }, + "device-postgres": { + "command": null, + "entrypoint": null, + "image": "postgres:16", + "networks": { + "default": null + }, + "volumes": [ + { + "type": "volume", + "source": "existing-data", + "target": "/var/lib/postgresql/data" + } + ] + } + }, + "volumes": { + "existing-data": { + "name": "nodedc-device-plane_existing-data", + "external": false + } + } +} diff --git a/infra/deploy-runner/fixtures/device-b2-foundation-compose220/override.yml b/infra/deploy-runner/fixtures/device-b2-foundation-compose220/override.yml new file mode 100644 index 0000000..92f5b75 --- /dev/null +++ b/infra/deploy-runner/fixtures/device-b2-foundation-compose220/override.yml @@ -0,0 +1,11 @@ +services: + device-control-core: + environment: + DEVICE_B2_SECRET_ROOT: /run/nodedc-b2-connections + volumes: + - type: bind + source: /volume1/docker/nodedc-device-plane/private-b2-connections + target: /run/nodedc-b2-connections + read_only: false + bind: + create_host_path: false diff --git a/infra/deploy-runner/nodedc-deploy b/infra/deploy-runner/nodedc-deploy index 6e6302d..d29475d 100755 --- a/infra/deploy-runner/nodedc-deploy +++ b/infra/deploy-runner/nodedc-deploy @@ -42805,7 +42805,7 @@ def main(argv): # Additive external VPS management foundation. The payload never contains keys. -DEVICE_B2_ID = 'device-b2-foundation-v1-20260930-001' +DEVICE_B2_ID = 'device-b2-foundation-v1-20260930-002' DEVICE_B2_DESCRIPTOR = 'deployment/device-b2-foundation-v1.json' DEVICE_B2_SQL = 'deployment/device-b2-foundation-v1.sql' DEVICE_B2_OVERRIDE = 'docker-compose.device-b2-foundation.yml' @@ -42948,12 +42948,19 @@ def device_b2_config_proof(base, candidate): core.setdefault('volumes', []).append({'type': 'bind', 'source': str(DEVICE_B2_SECRET_ROOT), 'target': DEVICE_B2_DESTINATION, 'bind': {'create_host_path': False}}) actual = json.loads(json.dumps(candidate)) - # Compose versions can explicitly serialize read_only:false or omit it. + # Compose 2.20.1 omits false booleans, including create_host_path inside + # bind:{}. Normalize only the approved new mount in comparison copies. + # The fixed source YAML still requires create_host_path:false. True, null, + # non-booleans, other bind options and all existing mounts stay exact. for value in (expected, actual): volumes = value['services']['device-control-core'].get('volumes', []) for v in volumes: - if v.get('target') == DEVICE_B2_DESTINATION and v.get('read_only') is False: - v.pop('read_only') + if v.get('target') == DEVICE_B2_DESTINATION: + if v.get('read_only') is False: + v.pop('read_only') + bind = v.get('bind') + if isinstance(bind, dict) and bind.get('create_host_path') is False: + bind.pop('create_host_path') volumes.sort(key=lambda v: v['target']) if expected != actual: die('Device B2 foundation changes more than its one private mount/environment entry') diff --git a/infra/deploy-runner/test_device_b2_foundation.py b/infra/deploy-runner/test_device_b2_foundation.py index bd3b946..b2484d3 100644 --- a/infra/deploy-runner/test_device_b2_foundation.py +++ b/infra/deploy-runner/test_device_b2_foundation.py @@ -26,7 +26,88 @@ def candidate(): return v +FIXTURE = Path(__file__).with_name('fixtures') / 'device-b2-foundation-compose220' + + +def compose_fixture(): + return tuple(json.loads((FIXTURE / (name + '.json')).read_text()) for name in ('base', 'candidate')) + + class Foundation(unittest.TestCase): + def test_source_yaml_and_new_identity_remain_exact(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + (root / 'deployment').mkdir() + (root / R.DEVICE_B2_DESCRIPTOR).write_text(json.dumps(R.device_b2_descriptor())) + yaml = root / R.DEVICE_B2_OVERRIDE + yaml.write_text(R.DEVICE_B2_YAML) + # Isolate the YAML/identity guard; no database or SQL execution. + with mock.patch.object(R, 'sha256_file', return_value=R.DEVICE_B2_SQL_SHA): + R.validate_device_b2_payload(root, R.DEVICE_B2_ENTRIES, R.DEVICE_B2_ID) + with self.assertRaises(R.DeployError): + R.validate_device_b2_payload(root, R.DEVICE_B2_ENTRIES, 'device-b2-foundation-v1-20260930-001') + for replacement in ('true', 'null', '0'): + yaml.write_text(R.DEVICE_B2_YAML.replace('create_host_path: false', 'create_host_path: ' + replacement)) + with self.subTest(replacement=replacement), self.assertRaises(R.DeployError): + R.validate_device_b2_payload(root, R.DEVICE_B2_ENTRIES, R.DEVICE_B2_ID) + yaml.write_text(R.DEVICE_B2_YAML.replace(' create_host_path: false\n', '')) + with self.assertRaises(R.DeployError): + R.validate_device_b2_payload(root, R.DEVICE_B2_ENTRIES, R.DEVICE_B2_ID) + + def test_real_compose_2201_output_preserves_raw_inputs_and_digest(self): + base, actual = compose_fixture() + saved = copy.deepcopy((base, actual)) + mount = next(v for v in actual['services']['device-control-core']['volumes'] + if v['target'] == R.DEVICE_B2_DESTINATION) + self.assertEqual(mount['bind'], {}) + self.assertNotIn('read_only', mount) + self.assertEqual(R.device_b2_config_proof(base, actual), R.device_release_drift_digest(actual)) + self.assertEqual((base, actual), saved) + self.assertEqual((FIXTURE / 'override.yml').read_text(), R.DEVICE_B2_YAML) + + def test_real_compose_new_mount_accepts_only_false_or_omitted_booleans(self): + base, actual = compose_fixture() + for read_only in ('omitted', False): + for create in ('omitted', False): + v = copy.deepcopy(actual) + mount = next(m for m in v['services']['device-control-core']['volumes'] + if m['target'] == R.DEVICE_B2_DESTINATION) + if read_only != 'omitted': mount['read_only'] = read_only + if create != 'omitted': mount['bind']['create_host_path'] = create + with self.subTest(read_only=read_only, create=create): + R.device_b2_config_proof(base, v) + for key in ('read_only', 'create_host_path'): + for value in (True, None, 0, 1, 0.0, 'false', {}, []): + v = copy.deepcopy(actual) + mount = next(m for m in v['services']['device-control-core']['volumes'] + if m['target'] == R.DEVICE_B2_DESTINATION) + target = mount if key == 'read_only' else mount['bind'] + target[key] = value + with self.subTest(key=key, value=value), self.assertRaises(R.DeployError): + R.device_b2_config_proof(base, v) + + def test_real_compose_rejects_other_mount_options_and_unrelated_changes(self): + base, actual = compose_fixture() + for mutation in ('source', 'type', 'bind-null', 'bind-absent', 'propagation', + 'existing-bind', 'existing-readonly', 'duplicate', 'env', 'network', 'database'): + v = copy.deepcopy(actual) + core = v['services']['device-control-core'] + mount = next(m for m in core['volumes'] if m['target'] == R.DEVICE_B2_DESTINATION) + existing = next(m for m in core['volumes'] if m['target'] != R.DEVICE_B2_DESTINATION) + if mutation == 'source': mount['source'] = '/other' + if mutation == 'type': mount['type'] = 'volume' + if mutation == 'bind-null': mount['bind'] = None + if mutation == 'bind-absent': mount.pop('bind') + if mutation == 'propagation': mount['bind']['propagation'] = 'rshared' + if mutation == 'existing-bind': existing['bind']['create_host_path'] = False + if mutation == 'existing-readonly': existing['read_only'] = False + if mutation == 'duplicate': core['volumes'].append(copy.deepcopy(mount)) + if mutation == 'env': core['environment']['EXISTING'] = 'changed' + if mutation == 'network': core['networks']['private']['priority'] = 0 + if mutation == 'database': v['services']['device-postgres']['image'] = 'changed' + with self.subTest(mutation=mutation), self.assertRaises(R.DeployError): + R.device_b2_config_proof(base, v) + def test_scope_has_only_core_and_no_build(self): self.assertEqual(R.component_services('device-b2-foundation',R.DEVICE_B2_ENTRIES),('device-control-core',)) self.assertFalse(R.component_builds('device-b2-foundation',R.DEVICE_B2_ENTRIES))