From 3c888c5543345163c078682055961f5685c9d41e Mon Sep 17 00:00:00 2001 From: "Mark E. DeYoung" <1854350+mark-e-deyoung@users.noreply.github.com> Date: Sat, 14 Nov 2026 17:10:43 +0100 Subject: [PATCH] fix(security): redact health-failure output in public nightly Actions --- scripts/ci/wait-for-container-health.sh | 20 ++++++++--- tests/test_ci_unit_isolation.py | 46 +++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/scripts/ci/wait-for-container-health.sh b/scripts/ci/wait-for-container-health.sh index 0fc87b00..74ca4b22 100755 --- a/scripts/ci/wait-for-container-health.sh +++ b/scripts/ci/wait-for-container-health.sh @@ -17,6 +17,18 @@ if ! [[ "$sleep_seconds" =~ ^[0-9]+$ ]] || [ "$sleep_seconds" -lt 1 ]; then exit 2 fi +# Classify container startup failures without echoing untrusted service logs +# into public Actions output. Raw logs remain job-local for gated inspection. +diagnose_health_failure() { + classifier="$(dirname "$0")/classify-startup-logs.py" + if [ -f "$classifier" ] && command -v python3 >/dev/null 2>&1; then + docker compose -f "$compose_file" --profile "$profile" logs --no-color --tail 200 "$service" 2>/dev/null | + python3 "$classifier" || echo "STARTUP_DIAGNOSTIC stage=classifier_failed" + else + echo "STARTUP_DIAGNOSTIC stage=classifier_unavailable" + fi +} + container_id="$(docker compose -f "$compose_file" --profile "$profile" ps -q "$service" | head -n1)" if [ -z "${container_id}" ]; then echo "ERROR: no container found for service=${service} profile=${profile}" >&2 @@ -27,12 +39,12 @@ for ((i=1; i<=max_attempts; i++)); do status="$(docker inspect --format='{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "$container_id" 2>/dev/null || echo unknown)" case "$status" in healthy) - echo "Service ${service} is healthy (${container_id})" + echo "Service ${service} is healthy" exit 0 ;; unhealthy) - echo "ERROR: service ${service} became unhealthy (${container_id})" >&2 - docker compose -f "$compose_file" --profile "$profile" logs --tail 200 "$service" || true + echo "ERROR: service ${service} became unhealthy" >&2 + diagnose_health_failure exit 1 ;; *) @@ -43,5 +55,5 @@ for ((i=1; i<=max_attempts; i++)); do done echo "ERROR: service ${service} did not become healthy after ${max_attempts} attempts" >&2 -docker compose -f "$compose_file" --profile "$profile" logs --tail 200 "$service" || true +diagnose_health_failure exit 1 diff --git a/tests/test_ci_unit_isolation.py b/tests/test_ci_unit_isolation.py index c6cab0ce..8538ffe6 100644 --- a/tests/test_ci_unit_isolation.py +++ b/tests/test_ci_unit_isolation.py @@ -71,5 +71,51 @@ def test_generated_api_token_is_not_ever_echoed(self): self.assertIn('echo -n "$API_TOKEN" > /tmp/winebot_api_token', source) + def test_health_wait_failure_output_is_allowlisted(self): + source = (ROOT / "scripts/ci/wait-for-container-health.sh").read_text( + encoding="utf-8" + ) + self.assertEqual(source.count("diagnose_health_failure"), 3) + self.assertIn('python3 "$classifier"', source) + self.assertIn('logs --no-color --tail 200 "$service" 2>/dev/null', source) + self.assertNotIn('logs --tail 200 "$service" || true', source) + + def test_health_waiter_never_echoes_sensitive_service_log_content(self): + import os + import subprocess + import tempfile + + with tempfile.TemporaryDirectory() as directory: + mock_docker = Path(directory) / "docker" + mock_docker.write_text( + """#!/bin/sh +case "$1" in + inspect) printf '%s\\n' unhealthy;; + compose) + case " $* " in + *" ps -q "*) printf '%s\\n' mock123;; + *" logs "*) printf '%s\\n' SYNTHETIC_SECRET 'WINEBOT_STARTUP_ERROR stage=services/trace-log-path rc=1';; + *) exit 4;; + esac;; + *) exit 4;; +esac +""", + encoding="utf-8", + ) + mock_docker.chmod(0o755) + env = os.environ.copy() + env["PATH"] = directory + os.pathsep + env["PATH"] + result = subprocess.run( + ["bash", str(ROOT / "scripts/ci/wait-for-container-health.sh"), + "compose/docker-compose.yml", "interactive", + "winebot-interactive", "1", "1"], + env=env, capture_output=True, text=True, timeout=10, check=False + ) + self.assertEqual(result.returncode, 1) + self.assertIn("STARTUP_DIAGNOSTIC stage=failed_trace_log_path", + result.stdout + result.stderr) + self.assertNotIn("SYNTHETIC_SECRET", result.stdout + result.stderr) + self.assertNotIn("mock123", result.stdout + result.stderr) + if __name__ == "__main__": unittest.main()