fix: legg til X-Internal-Key bypass i require_auth for m2m

This commit is contained in:
Chris Christiansen 2026-07-02 20:24:05 +00:00
parent e04a95b952
commit 1f4df47083
2 changed files with 7 additions and 2 deletions

View File

@ -190,7 +190,12 @@ def require_auth(func):
if user: if user:
return await func(request, *args, **kwargs) return await func(request, *args, **kwargs)
# 2. Bearer token (Cloud Run identity token) # 2. Internal API key (maskin-til-maskin, opax-mcp → osvauco-agent)
internal_key = request.headers.get('X-Internal-Key', '')
if internal_key and internal_key == os.environ.get('INTERNAL_API_KEY', ''):
return await func(request, *args, **kwargs)
# 3. Bearer token (Cloud Run identity token)
auth_header = request.headers.get('Authorization', '') auth_header = request.headers.get('Authorization', '')
if auth_header.startswith('Bearer '): if auth_header.startswith('Bearer '):
token = auth_header[7:] token = auth_header[7:]

View File

@ -116,7 +116,7 @@ def _osvauco_agent_identity_token() -> str:
raise raise
def _osvauco_agent_headers() -> dict: def _osvauco_agent_headers() -> dict:
return {"Authorization": f"Bearer {_osvauco_agent_identity_token()}", "X-MCP-Secret": os.environ.get("MCP_SECRET", ""), "Content-Type": "application/json"} return {"Authorization": f"Bearer {_osvauco_agent_identity_token()}", "X-Internal-Key": os.environ.get("INTERNAL_API_KEY", ""), "Content-Type": "application/json"}
async def _osvauco_agent_post(path: str, body: dict) -> Any: async def _osvauco_agent_post(path: str, body: dict) -> Any:
"""Kaller osvauco-agent direkte med service-to-service auth.""" """Kaller osvauco-agent direkte med service-to-service auth."""