diff --git a/roles/test-e2e-playwright/README.md b/roles/test-e2e-playwright/README.md index a7bb9b2e57..d6f1e42ce6 100644 --- a/roles/test-e2e-playwright/README.md +++ b/roles/test-e2e-playwright/README.md @@ -30,7 +30,7 @@ This role: - Renders `.env` from `templates/playwright.env.j2` using Ansible variables (`application_id`, `domains`, `users`, `applications`) - Optionally waits until the application responds with HTTP `200` or `302` - Injects CA trust automatically for `TLS_MODE=self_signed` (via `CA_TRUST.*`), so Playwright accepts self-signed cert chains -- Runs Playwright in Docker with stable browser settings (`--ipc=host`, `--shm-size=1g`) +- Runs Playwright in Docker with stable browser settings (`--ipc=host`, `--shm-size=1g`) and without core dumps (`--ulimit=core=0`), so a crashing browser cannot fill the container's disk - Runs the suite once per role on one network it is served on (`lookup('network_siblings', ...)`), picked at random when there are several and kept for the flake retry, with the `.env` rendered for that network's vhost - Stores per-role reports/artifacts under `TEST_E2E_PLAYWRIGHT_REPORTS_BASE_DIR/`, or under `+` when the pick is not the canonical network diff --git a/roles/test-e2e-playwright/files/spec_secrets_container.py b/roles/test-e2e-playwright/files/spec_secrets_container.py index 337992a325..2e5adce400 100644 --- a/roles/test-e2e-playwright/files/spec_secrets_container.py +++ b/roles/test-e2e-playwright/files/spec_secrets_container.py @@ -59,6 +59,7 @@ OPTIONS = { "--oom-score-adj": re.compile(r"-?[0-9]+"), "--network": re.compile(r"host|none"), "--user": re.compile(r"[0-9]+:[0-9]+"), + "--ulimit": re.compile(r"core=0"), "-w": re.compile(r"/e2e"), "-e": re.compile(r"[A-Z][A-Z0-9_]*=.*"), "-v": re.compile(r"/[^:]+:/[^:]+(?::ro)?"), diff --git a/roles/test-e2e-playwright/tasks/03_run_pass.yml b/roles/test-e2e-playwright/tasks/03_run_pass.yml index ff9bffe224..3def07ab20 100644 --- a/roles/test-e2e-playwright/tasks/03_run_pass.yml +++ b/roles/test-e2e-playwright/tasks/03_run_pass.yml @@ -110,7 +110,7 @@ {{ (['python3', '-I', '-B', TEST_E2E_PLAYWRIGHT_TOOLS_DIR ~ '/spec_secrets.py', 'guard'] if (_playwright_secrets_template_stat.stat.exists | bool) else []) + TEST_E2E_PLAYWRIGHT_MASK_ARGV - + [('docker' if (_playwright_secrets_template_stat.stat.exists | bool) else 'container'), 'run', '--rm', '--ipc=host', '--shm-size=1g'] + + [('docker' if (_playwright_secrets_template_stat.stat.exists | bool) else 'container'), 'run', '--rm', '--ipc=host', '--shm-size=1g', '--ulimit=core=0'] + ( ['--network', 'host'] if IS_SWARM_MODE diff --git a/scripts/tests/e2e/rerun-spec.sh b/scripts/tests/e2e/rerun-spec.sh index 29c12efb30..e77cdea08d 100755 --- a/scripts/tests/e2e/rerun-spec.sh +++ b/scripts/tests/e2e/rerun-spec.sh @@ -203,7 +203,7 @@ for sub in addons fixtures; do done run=(docker run --rm - --ipc=host --shm-size=1g + --ipc=host --shm-size=1g --ulimit=core=0 "${net_args[@]}" --env-file "$env_file" -e "INFINITO_PLAYWRIGHT_KEEP=${INFINITO_PLAYWRIGHT_KEEP:-}" diff --git a/tests/unit/python/roles/test-e2e-playwright/test_spec_secrets_container.py b/tests/unit/python/roles/test-e2e-playwright/test_spec_secrets_container.py index f0c62e8ce7..e40e924465 100644 --- a/tests/unit/python/roles/test-e2e-playwright/test_spec_secrets_container.py +++ b/tests/unit/python/roles/test-e2e-playwright/test_spec_secrets_container.py @@ -148,6 +148,8 @@ def argv_triggers(stage: Path, run: Path) -> dict[str, tuple[str, list[str]]]: ), "entrypoint": ("-w", ["--entrypoint", "/bin/sh", "-w"]), "privileged": ("-w", ["--privileged", "-w"]), + "core_dumps": ("-w", ["--ulimit=core=-1", "-w"]), + "other_ulimit": ("-w", ["--ulimit", "nofile=1048576", "-w"]), "other_cidfile": (f"--cidfile={run}/.cid", ["--cidfile=/srv/x/.cid"]), "no_log_driver": ("--log-driver=none", []), "reports_elsewhere": (f"{run}/reports:/reports", ["/srv/x:/reports"]), @@ -212,6 +214,12 @@ class TestSpecSecretsContainer(unittest.TestCase): def test_the_command_a_run_with_spec_secrets_starts_passes(self) -> None: self.assertFalse(self.refused(container_argv(self.root, self.run_dir))) + def test_a_run_without_core_dumps_passes(self) -> None: + argv = container_argv(self.root, self.run_dir) + at = argv.index("-w") + argv[at:at] = ["--ulimit=core=0"] + self.assertFalse(self.refused(argv)) + def test_a_docker_config_the_caller_exports_stays_out_of_the_checks(self) -> None: argv = container_argv(self.root, self.run_dir) exported = {"DOCKER_CONFIG": str(open_config(self.root))} diff --git a/tests/unit/python/roles/test-e2e-playwright/test_spec_secrets_mount.py b/tests/unit/python/roles/test-e2e-playwright/test_spec_secrets_mount.py index 8feca6cef8..b3858b1e1a 100644 --- a/tests/unit/python/roles/test-e2e-playwright/test_spec_secrets_mount.py +++ b/tests/unit/python/roles/test-e2e-playwright/test_spec_secrets_mount.py @@ -3,6 +3,7 @@ from __future__ import annotations import copy import re import unittest +from itertools import pairwise from . import role_task from ._spec_secrets_wiring import ( @@ -27,6 +28,7 @@ from ._spec_secrets_wiring import ( mount_violations, prune_violations, render, + render_argv, role_tasks, run_argv, ) @@ -313,6 +315,14 @@ class TestSpecSecretsMount(unittest.TestCase): queued = role_task("03_run_pass.yml", "📬")["vars"]["_playwright_argv"] self.assertEqual(queued, run_argv()) + def test_every_run_disables_core_dumps_in_the_container(self) -> None: + for exists, directory in ((False, STALE_DIR), (True, SECRETS_DIR)): + with self.subTest(template=exists): + argv = render_argv(run_argv(), exists, directory) + self.assertIn( + ("--shm-size=1g", "--ulimit=core=0"), list(pairwise(argv)) + ) + def test_the_role_level_env_file_is_untouched(self) -> None: self.assertEqual(env_task()["ansible.builtin.copy"]["mode"], "0644") self.assertNotIn("secrets", str(env_task()))