fix(ci): capture private socket owner and isolate OIDC forwarder namespace

This commit is contained in:
victorsteele428 committed 2026-11-22 19:40:34 +00:00
1 parent 1cf6d65f04
commit 79dac4f5bb
2 files changed
+70 -13

No files matched your search

+3 -3
View File
@@ -1,8 +1,8 @@
"""CI-only, private-network, opaque TCP relay for ZITADEL localhost issuer.
Run exclusively in the run-owned Traefik proxy network namespace. This code
Run exclusively in a separate run-owned private Docker network namespace. This code
never sees or parses HTTP requests, headers, query strings, credentials or
cookies; it forwards bytes from IPv4 127.0.0.1:8080 to 127.0.0.1:80.
cookies; it forwards bytes from IPv4 127.0.0.1:8080 to private proxy:80.
No public bind, privileged sockets, credentials or filesystem writes.
"""
from __future__ import annotations
@@ -13,7 +13,7 @@ import sys
LISTEN_ADDRESS = "127.0.0.1"
LISTEN_PORT = 8080
TARGET_ADDRESS = "127.0.0.1"
TARGET_ADDRESS = "proxy"
TARGET_PORT = 80
CHUNK_SIZE = 65536
+67 -10
View File
@@ -98,6 +98,62 @@ except (OSError, http.client.HTTPException):
print("ZITPLANE_OIDC_PRIVATE_PROXY_HOST_ROUTE_PASS")
'
# P05-OIDC-04: inspect the run-owned proxy socket and PID namespace BEFORE
# binding any forwarder. Print ONLY numeric inode/PID and sanitized comm,
# never argv, env, credentials, raw logs, HTTP content or query strings.
docker run --rm -i --network "container:$proxy_id" --pid "container:$proxy_id" \
python:3.12-alpine python - <<'PY'
from pathlib import Path
import os
import re
listeners = []
for family, filename in (("TCP4", "/proc/net/tcp"), ("TCP6", "/proc/net/tcp6")):
try:
rows = Path(filename).read_text(encoding="ascii").splitlines()[1:]
except OSError:
print("OIDC_CI_PROXY_PORT8080_SOCKET_TABLE_UNAVAILABLE=" + family, flush=True)
continue
for row in rows:
parts = row.split()
if len(parts) < 10:
continue
try:
port = int(parts[1].rsplit(":", 1)[1], 16)
except (ValueError, IndexError):
continue
if port == 8080 and parts[3] == "0A":
listeners.append((family, parts[9]))
if not listeners:
print("OIDC_CI_PROXY_PORT8080_LISTENER=NONE", flush=True)
for family, inode in listeners:
owner = None
for pid in (p for p in os.listdir("/proc") if p.isdecimal()):
try:
for fd in os.listdir("/proc/" + pid + "/fd"):
try:
if os.readlink("/proc/" + pid + "/fd/" + fd) == "socket:[" + inode + "]":
owner = pid
break
except OSError:
continue
except OSError:
continue
if owner is not None:
break
comm = "UNKNOWN"
if owner is not None:
try:
name = Path("/proc/" + owner + "/comm").read_text(encoding="ascii").strip()
comm = re.sub(r"[^A-Za-z0-9_.-]", "_", name)[:32] or "UNKNOWN"
except OSError:
pass
print("OIDC_CI_PROXY_PORT8080_LISTENER=" + family +
" INODE=" + inode + " PID=" + (owner or "UNKNOWN") +
" COMM=" + comm, flush=True)
PY
echo ZITPLANE_OIDC_PROXY_PREBIND_SOCKET_FORENSICS_PASS
# Docker Hub alpine/socat has socat preinstalled, with an explicit versioned
# published tag; no shell and no package installation during container start.
# Resolve to a verified digest and run that IMMUTABLE digest, never latest.
@@ -114,18 +170,19 @@ case "$forwarder_image" in
*) echo OIDC_CI_FORWARDER_IMAGE_DIGEST_MISSING >&2; exit 1 ;;
esac
# First reproduce and classify the previously observed socat startup failure.
# This diagnostic happens BEFORE generating any OIDC client/user credentials.
# Use exactly one run-owned container name; remove it before any fallback.
# The forwarder owns a separate private network namespace, not Traefik's.
# The issuer remains localhost:8080; downstream private proxy DNS is proxy:80.
# Provisioning and Chromium join the forwarder's namespace. The original
# Compose, issuer, Host, browser and auth contract remain unchanged.
docker create --name "$forwarder" \
--label "zitplane.oidc.run=$GITHUB_RUN_ID" \
--network "container:$proxy_id" "$forwarder_image" \
TCP-LISTEN:8080,bind=127.0.0.1,reuseaddr,fork TCP:127.0.0.1:80 >/dev/null
--network "$network" "$forwarder_image" \
TCP-LISTEN:8080,bind=127.0.0.1,reuseaddr,fork TCP:proxy:80 >/dev/null
docker start "$forwarder" >/dev/null
forwarder_http_ready() {
# No private HTTP contents or query parameters are printed.
docker run --rm --network "container:$proxy_id" python:3.12-alpine \
docker run --rm --network "container:$forwarder" python:3.12-alpine \
python -c '
import http.client
conn = http.client.HTTPConnection("127.0.0.1", 8080, timeout=5)
@@ -192,7 +249,7 @@ print("OIDC_CI_SOCAT_STARTUP_ERROR_CLASS=" + reason)
esac
docker create --name "$forwarder" \
--label "zitplane.oidc.run=$GITHUB_RUN_ID" \
--network "container:$proxy_id" "$python_forwarder_image" \
--network "$network" "$python_forwarder_image" \
python -u /tmp/forwarder.py >/dev/null
docker cp tests/ci/oidc_e2e/forwarder.py "$forwarder:/tmp/forwarder.py"
docker start "$forwarder" >/dev/null
@@ -237,7 +294,7 @@ if [ "$ready" -ne 1 ]; then
state="$(docker inspect -f '{{.State.Status}}' "$forwarder")"
exitcode="$(docker inspect -f '{{.State.ExitCode}}' "$forwarder")"
echo "OIDC_CI_FORWARDER_HTTP_NOT_READY_STATE=$state EXIT_CODE=$exitcode" >&2
docker run --rm --network "container:$proxy_id" python:3.12-alpine \
docker run --rm --network "container:$forwarder" python:3.12-alpine \
python -c '
import http.client, sys
try:
@@ -256,7 +313,7 @@ docker volume create --name "$secret_volume" \
# Provisioning container only: holds ephemeral IAM_OWNER PAT READ-ONLY and
# writes a CI-only client/user credential file to a separate short-lived volume.
docker run --rm -i --network "container:$proxy_id" \
docker run --rm -i --network "container:$forwarder" \
-e "OIDC_CI_RUN_ID=$GITHUB_RUN_ID" \
--volume "$bootstrap_volume:/zitadel/bootstrap:ro" \
--volume "$secret_volume:/ci/secret" \
@@ -267,7 +324,7 @@ echo ZITPLANE_OIDC_DISPOSABLE_PROVISIONING_PASS
# throwaway browser container. Docker cp does NOT depend on runner host paths.
docker create --name "$browser" \
--label "zitplane.oidc.run=$GITHUB_RUN_ID" \
--network "container:$proxy_id" \
--network "container:$forwarder" \
--volume "$secret_volume:/ci/secret:ro" \
mcr.microsoft.com/playwright:v1.58.2-noble \
bash /tmp/oidc_e2e/browser.sh >/dev/null