diff --git a/tests/tools/test_docker_environment.py b/tests/tools/test_docker_environment.py index b92f2dcda1..cafc174e8d 100644 --- a/tests/tools/test_docker_environment.py +++ b/tests/tools/test_docker_environment.py @@ -56,6 +56,7 @@ def _make_dummy_env(**kwargs): persist_across_processes=kwargs.get("persist_across_processes", True), shared_container_key=kwargs.get("shared_container_key", ""), shm_size=kwargs.get("shm_size", docker_env._DEFAULT_SHM_SIZE), + snap_compat=kwargs.get("snap_compat", False), ) @@ -485,6 +486,27 @@ def test_security_args_include_setuid_setgid_for_privdrop(monkeypatch): assert "SETGID" in added, "SETGID cap missing — image privilege-drop will fail" +def test_snap_compat_drops_only_init_and_no_new_privileges(monkeypatch): + """#9730: snap-packaged Docker under AppArmor turns ``--init`` and ``no-new-privileges`` into + "exec: operation not permitted" for every process in the container. The opt-out drops exactly + those two flags; cap-drop, tmpfs hardening and the privdrop caps are unchanged.""" + monkeypatch.setattr(docker_env, "find_docker", lambda: "/usr/bin/docker") + + def run_args(**kw): + calls = _mock_subprocess_run(monkeypatch) + _make_dummy_env(**kw) + return next(c[0] for c in calls if isinstance(c[0], list) and len(c[0]) >= 2 and c[0][1] == "run") + + default, compat = run_args(), run_args(snap_compat=True) + assert "--init" in default and "no-new-privileges" in default + assert "--init" not in compat and "no-new-privileges" not in compat + + def strip(argv): # everything except the two flags and the random container name + return [a for a in argv if a not in ("--init", "--security-opt", "no-new-privileges") and not a.startswith("hermes-")] + + assert strip(default) == strip(compat) + + # ── run_as_host_user tests ──────────────────────────────────────── diff --git a/tests/tools/test_terminal_config_env_sync.py b/tests/tools/test_terminal_config_env_sync.py index c7b98babb1..021c8e46c5 100644 --- a/tests/tools/test_terminal_config_env_sync.py +++ b/tests/tools/test_terminal_config_env_sync.py @@ -321,3 +321,12 @@ def test_docker_forward_env_is_bridged_everywhere(): assert "docker_forward_env" in _gateway_env_map_keys() assert "docker_forward_env" in _save_config_env_sync_keys() assert "TERMINAL_DOCKER_FORWARD_ENV" in _terminal_tool_env_var_names() + + +def test_docker_snap_compat_is_bridged_everywhere(): + """#9730: ``terminal.docker_snap_compat`` must reach the container on the CLI, gateway and + ``hermes config set`` paths, like every other docker_* key (see docker_extra_args above).""" + assert "docker_snap_compat" in _cli_env_map_keys() + assert "docker_snap_compat" in _gateway_env_map_keys() + assert "docker_snap_compat" in _save_config_env_sync_keys() + assert "TERMINAL_DOCKER_SNAP_COMPAT" in _terminal_tool_env_var_names()