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.