From b387c80528e841afa7e5aeef404466a4b4ff8ca1 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 23 Aug 2026 19:34:42 +0200 Subject: [PATCH] fix(container): reject a directory standing in for a CA bind source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit must_exist accepted any existing path, so a directory that dockerd auto-created where a bind source was missing passed the guard. The wrapper was then mounted over the container path and set as --entrypoint, and every image that has an ENTRYPOINT died with rc 126 'is a directory: permission denied' — seven identical retries, because the directory persists. Requiring a regular file routes that state into the existing 'CA injection disabled' fallback, which the same suite already exercises green when the wrapper is simply absent. Co-Authored-By: Claude Opus 5 (1M context) --- .../files/python/container.py | 4 +-- .../sys-svc-container/files/test_container.py | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/roles/sys-svc-container/files/python/container.py b/roles/sys-svc-container/files/python/container.py index 551cefe73b..1473caa77c 100755 --- a/roles/sys-svc-container/files/python/container.py +++ b/roles/sys-svc-container/files/python/container.py @@ -21,8 +21,8 @@ def warn(msg: str) -> None: def must_exist(path: str, label: str) -> str: p = Path(path) - if not p.exists(): - die(f"{label} does not exist: {path}") + if not p.is_file(): + die(f"{label} is not a regular file: {path}") return str(p) diff --git a/tests/unit/python/roles/sys-svc-container/files/test_container.py b/tests/unit/python/roles/sys-svc-container/files/test_container.py index 35646997b3..15a11fd48c 100644 --- a/tests/unit/python/roles/sys-svc-container/files/test_container.py +++ b/tests/unit/python/roles/sys-svc-container/files/test_container.py @@ -292,6 +292,37 @@ class TestContainerWrapper(unittest.TestCase): os.environ.clear() os.environ.update(old_env) + def test_require_ca_env_soft_directory_bind_source_returns_none_and_warns(self): + """ + A dockerd-auto-created directory standing in for a CA bind source must + disable CA injection, not be mounted over the container path. + """ + old_env = dict(os.environ) + try: + with tempfile.TemporaryDirectory() as tmp: + shadow = Path(tmp) / "with-ca-trust.sh" + shadow.mkdir() + cert = Path(tmp) / "ca.crt" + cert.write_text("cert") + + os.environ["CA_TRUST_CERT_HOST"] = str(cert) + os.environ["CA_TRUST_WRAPPER_HOST"] = str(shadow) + os.environ["CA_TRUST_NAME"] = "test-ca" + os.environ["CA_TRUST_CERT_CONTAINER"] = CA_CERT_CONTAINER + os.environ["CA_TRUST_WRAPPER_CONTAINER"] = CA_WRAPPER_CONTAINER + + buf = io.StringIO() + with contextlib.redirect_stderr(buf): + res = container.require_ca_env_soft() + + self.assertIsNone(res) + self.assertIn( + "CA injection disabled (CA files not found)", buf.getvalue() + ) + finally: + os.environ.clear() + os.environ.update(old_env) + def test_require_ca_env_soft_ok_returns_tuple(self): """ If env vars and referenced files exist, require_ca_env_soft() should return tuple.