fix(main): exempt health/readiness paths from IAP middleware
/health and probe endpoints reach Cloud Run directly without the IAP-injected x-goog-authenticated-user-email header. Without an exemption the middleware returned 401 on /health, which would break Cloud Run health checks, CI/CD deploys, and the Phase 8 verification. Powered by Jason, Crafted by Vauco
This commit is contained in:
parent
b751a6fd38
commit
7a098716ae
6
main.py
6
main.py
|
|
@ -51,8 +51,14 @@ app = FastAPI(
|
||||||
version="0.1.0",
|
version="0.1.0",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Paths exempt from IAP enforcement (health/readiness probes reach Cloud Run
|
||||||
|
# directly without the IAP-injected x-goog-authenticated-user-email header).
|
||||||
|
IAP_EXEMPT_PATHS = {"/health", "/healthz", "/readiness", "/liveness"}
|
||||||
|
|
||||||
@app.middleware("http")
|
@app.middleware("http")
|
||||||
async def require_iap(request: Request, call_next):
|
async def require_iap(request: Request, call_next):
|
||||||
|
if request.url.path in IAP_EXEMPT_PATHS:
|
||||||
|
return await call_next(request)
|
||||||
if not request.headers.get("x-goog-authenticated-user-email"):
|
if not request.headers.get("x-goog-authenticated-user-email"):
|
||||||
return Response(status_code=401, content="Unauthorized")
|
return Response(status_code=401, content="Unauthorized")
|
||||||
return await call_next(request)
|
return await call_next(request)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user