test(ci): diagnose socat startup and add private Python fallback
This commit is contained in:
1 parent
5f542a6aa3
commit
7b80f411b2
24 files changed
+338
-31
No files matched your search
@@ -31,3 +31,6 @@ Add new CI checks and update `MINIFEST.md`, `project/`, `docs/`, and `notes/` in
|
||||
|
||||
|
||||
**P05-OIDC-02 Run #91:** Existing manual real-browser workflow with new CI-only forwarder source proved four healthy services, no host-published ports, private Traefik:80 `Host: localhost:8080` HTTP 200 and prebuilt socat version/digest check PASS. But the private forwarding process exited immediately with code **1**; actual client/user setup and browser/callback/session tests **NOT RUN**. `always()` cleanup verified absence of all run-owned state, PASS. No repeated run, no Auth.js or app edits. Preserve this exact evidence for a narrow P05-OIDC-03 startup diagnostic.
|
||||
|
||||
|
||||
**P05-OIDC-03:** `tests/ci/oidc_e2e/forwarder.py` is an stdlib-only private 127.0.0.1 TCP relay. `run.sh` classifies pre-credential socat startup failures and, if needed, switches to the official Python image pinned by sha256 within a single isolated CI cycle; existing exact-owner cleanup and original OAuth/Browser tests unchanged. Do not treat forwarder readiness alone as real OIDC authentication acceptance.
|
||||
@@ -6,6 +6,7 @@
|
||||
| [MINIFEST.md](MINIFEST.md) | Exact registered files in this new first-party directory |
|
||||
| [compose.owner.override.yaml](compose.owner.override.yaml) | Disposable first-instance IAM_OWNER PAT bootstrap only; no developer/prod change |
|
||||
| [run.sh](run.sh) | Run-ID Docker ownership preflight, portless stack startup, secret volume/provisioning, private browser launch |
|
||||
| [forwarder.py](forwarder.py) | CI-only Python stdlib opaque TCP 127.0.0.1:8080 to :80 fallback for the exit-1 socat process |
|
||||
| [provision.py](provision.py) | Official ZITADEL project/OIDC client/human creation via ephemeral owner PAT; no secret output |
|
||||
| [browser.sh](browser.sh) | Pinned Playwright image CI-only npm installs, isolated Account app dependencies and browser harness |
|
||||
| [browser.cjs](browser.cjs) | Real Chromium OIDC PKCE/state/nonce/username/password/callback/session and negative contracts |
|
||||
|
||||
@@ -21,3 +21,8 @@ The environment is a temporary `zitplane-p05-{GITHUB_RUN_ID}` Compose stack cont
|
||||
|
||||
|
||||
**P05-OIDC-02 single-run evidence:** Gitea Run #91 tested `4831165`: private Traefik:80/Host HTTP 200 and versioned socat/digest verification PASS, then run-owned forwarder process `exited` with code 1. `provision.py` and `browser.cjs` **not run**. Cleanup PASS; no owned containers/network/credentials left. The status-only readiness change exists in source but is not CI-proven because the forwarder failed first. Startup errno/error class requires a new approved CI-only P05-OIDC-03 scope. No reruns under P05-OIDC-02.
|
||||
|
||||
|
||||
## P05-OIDC-03: forwarder diagnosis and same-run Python fallback
|
||||
|
||||
The official four-service P02 backend, original browser/auth and Gitea workflow remain read-only. Run #91 proved private Traefik/Host route PASS but socat process exited 1. Now a single run-owned socat start checks status/HTTP and classifies only safe startup error classes from **pre-credential** logs. When unhealthy, only the owned diagnostic sidecar is removed; its container name/owner label and private proxy net namespace are reused by official `python:3.12-alpine` pinned to its pulled sha256 registry digest. Only the tracked `forwarder.py` is copied; it transparently relays 127.0.0.1:8080 → 127.0.0.1:80 with no HTTP parsing, storage, external port or token access. Both must satisfy original issuer/Host HTTP 200 before project/client/user creation. The existing `always()` cleanup is unchanged. Full browser login/session acceptance requires actual Gitea result; **source is not CI-verified yet**.
|
||||
@@ -0,0 +1,101 @@
|
||||
"""CI-only, private-network, opaque TCP relay for ZITADEL localhost issuer.
|
||||
|
||||
Run exclusively in the run-owned Traefik proxy 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.
|
||||
No public bind, privileged sockets, credentials or filesystem writes.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import errno
|
||||
import sys
|
||||
|
||||
LISTEN_ADDRESS = "127.0.0.1"
|
||||
LISTEN_PORT = 8080
|
||||
TARGET_ADDRESS = "127.0.0.1"
|
||||
TARGET_PORT = 80
|
||||
CHUNK_SIZE = 65536
|
||||
|
||||
|
||||
async def copy_bytes(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
|
||||
"""Opaque, bounded-chunk bidirectional flow; never log payloads."""
|
||||
try:
|
||||
while True:
|
||||
chunk = await reader.read(CHUNK_SIZE)
|
||||
if not chunk:
|
||||
break
|
||||
writer.write(chunk)
|
||||
await writer.drain()
|
||||
except (ConnectionError, BrokenPipeError, OSError):
|
||||
pass
|
||||
finally:
|
||||
try:
|
||||
writer.write_eof()
|
||||
except (AttributeError, ConnectionError, OSError):
|
||||
pass
|
||||
|
||||
|
||||
async def serve_client(reader: asyncio.StreamReader, client: asyncio.StreamWriter) -> None:
|
||||
upstream = None
|
||||
try:
|
||||
target_reader, upstream = await asyncio.wait_for(
|
||||
asyncio.open_connection(TARGET_ADDRESS, TARGET_PORT),
|
||||
timeout=7,
|
||||
)
|
||||
await asyncio.gather(
|
||||
copy_bytes(reader, upstream),
|
||||
copy_bytes(target_reader, client),
|
||||
)
|
||||
except (TimeoutError, ConnectionError, OSError):
|
||||
# Only safe stages go to stderr. No raw HTTP, cookies, secrets, URL.
|
||||
print("OIDC_CI_FORWARDER_UPSTREAM_NOT_AVAILABLE", file=sys.stderr, flush=True)
|
||||
finally:
|
||||
if upstream is not None:
|
||||
upstream.close()
|
||||
client.close()
|
||||
if upstream is not None:
|
||||
try:
|
||||
await asyncio.wait_for(upstream.wait_closed(), timeout=2)
|
||||
except (TimeoutError, ConnectionError, OSError):
|
||||
pass
|
||||
try:
|
||||
await asyncio.wait_for(client.wait_closed(), timeout=2)
|
||||
except (TimeoutError, ConnectionError, OSError):
|
||||
pass
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
# A loopback-only listener: the runner never publishes host ports.
|
||||
try:
|
||||
server = await asyncio.start_server(
|
||||
serve_client,
|
||||
host=LISTEN_ADDRESS,
|
||||
port=LISTEN_PORT,
|
||||
family=2, # AF_INET, never an IPv6 wildcard
|
||||
backlog=64,
|
||||
reuse_address=True,
|
||||
limit=CHUNK_SIZE,
|
||||
)
|
||||
except OSError as exc:
|
||||
if exc.errno == errno.EADDRINUSE:
|
||||
code = "ADDRESS_IN_USE"
|
||||
elif exc.errno == errno.EACCES:
|
||||
code = "PERMISSION_DENIED"
|
||||
elif exc.errno == errno.EADDRNOTAVAIL:
|
||||
code = "ADDRESS_NOT_AVAILABLE"
|
||||
else:
|
||||
code = "SOCKET_STARTUP_UNKNOWN"
|
||||
print("OIDC_CI_PYTHON_FORWARDER_STARTUP_" + code, file=sys.stderr, flush=True)
|
||||
raise SystemExit(1) from None
|
||||
|
||||
print("ZITPLANE_OIDC_PYTHON_FORWARDER_LOOPBACK_LISTENING_PASS", flush=True)
|
||||
async with server:
|
||||
await server.serve_forever()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
asyncio.run(main())
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
+100
-12
@@ -114,14 +114,95 @@ case "$forwarder_image" in
|
||||
*) echo OIDC_CI_FORWARDER_IMAGE_DIGEST_MISSING >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
# NetNS-local listener 127.0.0.1:8080 -> netNS-local Traefik 127.0.0.1:80.
|
||||
# The original P02 external issuer remains exactly http://localhost:8080.
|
||||
docker run -d --name "$forwarder" \
|
||||
# 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.
|
||||
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
|
||||
docker start "$forwarder" >/dev/null
|
||||
|
||||
# Bounded socket+exact Host HTTP probe. Container existence is NOT readiness.
|
||||
forwarder_http_ready() {
|
||||
# No private HTTP contents or query parameters are printed.
|
||||
docker run --rm --network "container:$proxy_id" python:3.12-alpine \
|
||||
python -c '
|
||||
import http.client
|
||||
conn = http.client.HTTPConnection("127.0.0.1", 8080, timeout=5)
|
||||
conn.request("GET", "/debug/ready", headers={"Host": "localhost:8080"})
|
||||
assert conn.getresponse().status == 200
|
||||
' >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Bounded socat startup check. If it remains unreliable, switch once to the
|
||||
# official version/digest-pinned Python stdlib forwarder within THIS CI run.
|
||||
socat_ready=0
|
||||
attempt=0
|
||||
while [ "$attempt" -lt 3 ]; do
|
||||
attempt=$((attempt + 1))
|
||||
state="$(docker inspect -f '{{.State.Status}}' "$forwarder")"
|
||||
if [ "$state" != running ]; then
|
||||
break
|
||||
fi
|
||||
if forwarder_http_ready; then
|
||||
socat_ready=1
|
||||
break
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
|
||||
if [ "$socat_ready" -ne 1 ]; then
|
||||
state="$(docker inspect -f '{{.State.Status}}' "$forwarder")"
|
||||
exitcode="$(docker inspect -f '{{.State.ExitCode}}' "$forwarder")"
|
||||
echo "OIDC_CI_SOCAT_DIAGNOSTIC_STATE=$state EXIT_CODE=$exitcode"
|
||||
|
||||
# Only whitelisted error classifications, never raw docker logs. The
|
||||
# diagnostic container has NO test user/client/password/token access.
|
||||
docker logs "$forwarder" 2>&1 | python3 -c '
|
||||
import sys
|
||||
data = sys.stdin.read(8192).lower()
|
||||
classes = (
|
||||
("ADDRESS_IN_USE", ("address already in use", "eaddrinuse")),
|
||||
("PERMISSION_DENIED", ("permission denied", "eacces")),
|
||||
("ADDRESS_OPTION_INVALID", ("unknown device/address", "unknown option", "wrong number of parameters")),
|
||||
("SOCAT_ARGUMENT_COUNT", ("exactly 2 addresses required", "too many parameters")),
|
||||
("SOCKET_BIND_ERROR", ("bind(", "cannot bind")),
|
||||
("BINARY_RUNTIME_ERROR", ("exec format error", "not found")),
|
||||
)
|
||||
reason = next((name for name, words in classes if any(s in data for s in words)), "UNCLASSIFIED")
|
||||
print("OIDC_CI_SOCAT_STARTUP_ERROR_CLASS=" + reason)
|
||||
' || echo OIDC_CI_SOCAT_ERROR_CLASSIFIER_UNAVAILABLE
|
||||
|
||||
label="$(docker inspect -f '{{ index .Config.Labels "zitplane.oidc.run" }}' "$forwarder")"
|
||||
if [ "$label" != "$GITHUB_RUN_ID" ]; then
|
||||
echo OIDC_CI_UNOWNED_FORWARDER_FALLBACK_REFUSED >&2
|
||||
exit 1
|
||||
fi
|
||||
docker rm -f "$forwarder" >/dev/null
|
||||
|
||||
# Existing official python:3.12-alpine CI image is resolved to an immutable
|
||||
# registry SHA256 digest and runs ONLY the audited stdlib byte relay.
|
||||
python_forwarder_tag="python:3.12-alpine"
|
||||
docker pull "$python_forwarder_tag" >/dev/null
|
||||
python_forwarder_image="$(docker image inspect --format '{{index .RepoDigests 0}}' "$python_forwarder_tag")"
|
||||
case "$python_forwarder_image" in
|
||||
python@sha256:*|docker.io/library/python@sha256:*)
|
||||
echo ZITPLANE_OIDC_PYTHON_FORWARDER_IMAGE_DIGEST_VERIFIED_PASS ;;
|
||||
*) echo OIDC_CI_PYTHON_FORWARDER_DIGEST_MISSING >&2; exit 1 ;;
|
||||
esac
|
||||
docker create --name "$forwarder" \
|
||||
--label "zitplane.oidc.run=$GITHUB_RUN_ID" \
|
||||
--network "container:$proxy_id" "$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
|
||||
echo ZITPLANE_OIDC_PYTHON_FORWARDER_FALLBACK_STARTED
|
||||
else
|
||||
echo ZITPLANE_OIDC_SOCAT_FORWARDER_READY_PASS
|
||||
fi
|
||||
|
||||
# The SAME no-host-port status/Host contract applies to either forwarding
|
||||
# process. Never provision a client/user unless this proves HTTP 200.
|
||||
ready=0
|
||||
attempt=0
|
||||
while [ "$attempt" -lt 12 ]; do
|
||||
@@ -130,15 +211,23 @@ while [ "$attempt" -lt 12 ]; do
|
||||
if [ "$state" != running ]; then
|
||||
exitcode="$(docker inspect -f '{{.State.ExitCode}}' "$forwarder")"
|
||||
echo "OIDC_CI_FORWARDER_NOT_RUNNING_STATE=$state EXIT_CODE=$exitcode" >&2
|
||||
# Python diagnostic emits ONLY fixed error classes; never raw logs.
|
||||
docker logs "$forwarder" 2>&1 | python3 -c '
|
||||
import sys
|
||||
s=sys.stdin.read(4096)
|
||||
for marker in ("OIDC_CI_PYTHON_FORWARDER_STARTUP_ADDRESS_IN_USE",
|
||||
"OIDC_CI_PYTHON_FORWARDER_STARTUP_PERMISSION_DENIED",
|
||||
"OIDC_CI_PYTHON_FORWARDER_STARTUP_ADDRESS_NOT_AVAILABLE",
|
||||
"OIDC_CI_PYTHON_FORWARDER_STARTUP_SOCKET_STARTUP_UNKNOWN"):
|
||||
if marker in s:
|
||||
print(marker)
|
||||
break
|
||||
else:
|
||||
print("OIDC_CI_FORWARDER_EXIT_REASON_UNCLASSIFIED")
|
||||
' || true
|
||||
exit 1
|
||||
fi
|
||||
if docker run --rm --network "container:$proxy_id" python:3.12-alpine \
|
||||
python -c '
|
||||
import http.client
|
||||
conn = http.client.HTTPConnection("127.0.0.1", 8080, timeout=5)
|
||||
conn.request("GET", "/debug/ready", headers={"Host": "localhost:8080"})
|
||||
assert conn.getresponse().status == 200
|
||||
' >/dev/null 2>&1; then
|
||||
if forwarder_http_ready; then
|
||||
ready=1
|
||||
break
|
||||
fi
|
||||
@@ -148,7 +237,6 @@ 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
|
||||
# One redacted diagnostic: print only an HTTP status or a fixed socket marker.
|
||||
docker run --rm --network "container:$proxy_id" python:3.12-alpine \
|
||||
python -c '
|
||||
import http.client, sys
|
||||
|
||||
Reference in new issue
Block a user