fix(ci): narrow Auth.js subject and extend disposable P05 verification
This commit is contained in:
1 parent
42adaba004
commit
c27fe3d323
23 files changed
+415
-45
No files matched your search
+69
-13
@@ -1,4 +1,7 @@
|
||||
"""Read-only OIDC smoke: disposable Docker network only; not a login E2E."""
|
||||
"""Disposable ZITADEL OIDC metadata/JWKS and fail-closed negative checks.
|
||||
|
||||
No interactive login, account provisioning, MFA or real user sessions.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
@@ -10,30 +13,83 @@ PROXY = os.environ.get("ZITPLANE_CI_PROXY", "http://proxy")
|
||||
EXPECTED_ISSUER = "http://localhost:8080"
|
||||
HOST = "localhost:8080"
|
||||
|
||||
def fetch(path: str):
|
||||
|
||||
def verify_metadata(discovery: dict) -> str:
|
||||
if discovery.get("issuer") != EXPECTED_ISSUER:
|
||||
raise RuntimeError("OIDC issuer does not match disposable local origin")
|
||||
for field in ("authorization_endpoint", "token_endpoint", "jwks_uri"):
|
||||
value = discovery.get(field)
|
||||
if not isinstance(value, str):
|
||||
raise RuntimeError(f"OIDC {field} missing")
|
||||
parsed = urlparse(value)
|
||||
if (
|
||||
parsed.scheme != "http"
|
||||
or parsed.netloc != "localhost:8080"
|
||||
or not parsed.path.startswith("/")
|
||||
or parsed.username or parsed.password
|
||||
):
|
||||
raise RuntimeError(f"OIDC {field} not on the allowed origin")
|
||||
return urlparse(discovery["jwks_uri"]).path
|
||||
|
||||
|
||||
def verify_jwks(jwks: dict) -> None:
|
||||
keys = jwks.get("keys")
|
||||
if not isinstance(keys, list) or not keys:
|
||||
raise RuntimeError("JWKS must contain at least one public key")
|
||||
for key in keys:
|
||||
if not isinstance(key, dict) or not key.get("kty"):
|
||||
raise RuntimeError("JWKS contains an invalid public key")
|
||||
|
||||
|
||||
def verify_negative_contracts() -> None:
|
||||
safe = {
|
||||
"issuer": EXPECTED_ISSUER,
|
||||
"authorization_endpoint": EXPECTED_ISSUER + "/oauth/v2/authorize",
|
||||
"token_endpoint": EXPECTED_ISSUER + "/oauth/v2/token",
|
||||
"jwks_uri": EXPECTED_ISSUER + "/oauth/v2/keys",
|
||||
}
|
||||
for field, dangerous in (
|
||||
("issuer", "http://evil.invalid"),
|
||||
("jwks_uri", "https://evil.invalid/keys"),
|
||||
("authorization_endpoint", "//evil.invalid/authorize"),
|
||||
("token_endpoint", "http://localhost:8080.evil.invalid/token"),
|
||||
):
|
||||
obj = {**safe, field: dangerous}
|
||||
try:
|
||||
verify_metadata(obj)
|
||||
except RuntimeError:
|
||||
continue
|
||||
raise AssertionError(f"Unsafe OIDC {field} accepted")
|
||||
for obj in ({"keys": []}, {"keys": "wrong"}, {"keys": [{}]}):
|
||||
try:
|
||||
verify_jwks(obj)
|
||||
except RuntimeError:
|
||||
continue
|
||||
raise AssertionError("Unsafe JWKS payload accepted")
|
||||
print("ZITPLANE_OIDC_NEGATIVE_CONTRACTS_PASS")
|
||||
|
||||
|
||||
def fetch(path: str) -> bytes:
|
||||
if PROXY != "http://proxy" or not path.startswith("/") or path.startswith("//"):
|
||||
raise RuntimeError("Only disposable Docker proxy is allowed")
|
||||
request = Request(PROXY + path, headers={"Host": HOST, "Accept": "application/json"})
|
||||
with urlopen(request, timeout=20) as reply:
|
||||
if reply.status != 200:
|
||||
raise RuntimeError(f"HTTP {reply.status}: {path}")
|
||||
return reply.read()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
verify_negative_contracts()
|
||||
fetch("/debug/ready")
|
||||
print("ZITPLANE_BACKEND_READY_PASS")
|
||||
discovery = json.loads(fetch("/.well-known/openid-configuration"))
|
||||
if discovery.get("issuer") != EXPECTED_ISSUER:
|
||||
raise RuntimeError("OIDC issuer does not match local dev origin")
|
||||
for field in ("authorization_endpoint", "token_endpoint", "jwks_uri"):
|
||||
value = discovery.get(field)
|
||||
if not isinstance(value, str) or not value.startswith(EXPECTED_ISSUER + "/"):
|
||||
raise RuntimeError(f"Missing/unsafe OIDC {field}")
|
||||
jwks_path = verify_metadata(discovery)
|
||||
print("ZITPLANE_OIDC_DISCOVERY_PASS")
|
||||
jwks_path = urlparse(discovery["jwks_uri"]).path
|
||||
jwks = json.loads(fetch(jwks_path))
|
||||
if not isinstance(jwks.get("keys"), list):
|
||||
raise RuntimeError("Invalid JWKS shape")
|
||||
verify_jwks(json.loads(fetch(jwks_path)))
|
||||
print("ZITPLANE_OIDC_JWKS_PASS")
|
||||
print("ZITPLANE_OIDC_INTERACTIVE_E2E_BLOCKED: no disposable OIDC app/user provisioning in P05")
|
||||
print("ZITPLANE_OIDC_INTERACTIVE_E2E_DEFERRED: no disposable OIDC client/user")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user