Skip to content

fix: bypass JWT middleware for health endpoint in Python agent-framework sample#222

Open
pratapladhani wants to merge 1 commit intomicrosoft:mainfrom
pratapladhani:fix/health-endpoint-jwt-bypass
Open

fix: bypass JWT middleware for health endpoint in Python agent-framework sample#222
pratapladhani wants to merge 1 commit intomicrosoft:mainfrom
pratapladhani:fix/health-endpoint-jwt-bypass

Conversation

@pratapladhani
Copy link

Problem

When agentic authentication is enabled, jwt_authorization_middleware rejects all unauthenticated requests - including health probes from container orchestrators (Azure Container Apps, Kubernetes, App Service) hitting /api/health. The platform marks the container as unhealthy and restarts or decommissions it.

Fix

Wrap the existing JWT middleware so that requests to /api/health pass through without token validation, while all other routes remain protected.

Scope

  • 1 file changed, 11 insertions, 1 deletion
  • Only affects python/agent-framework/sample-agent/host_agent_server.py
  • No new dependencies

Testing

Validated during Azure Container Apps deployment - health probes now return 200 while /api/messages remains JWT-protected.

Fixes #186 (partial - addresses the health probe failure mode)

…ork sample

Container orchestrators (Azure Container Apps, Kubernetes, App Service) send
unauthenticated health probes to /api/health. When agentic authentication is
enabled, jwt_authorization_middleware rejects these probes with 401, causing
the platform to consider the container unhealthy.

Wrap the JWT middleware so requests to /api/health pass through without token
validation while all other routes remain protected.

Fixes microsoft#186
@pratapladhani pratapladhani requested a review from a team as a code owner February 16, 2026 23:57
Copilot AI review requested due to automatic review settings February 16, 2026 23:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a critical production deployment issue where container orchestrators (Azure Container Apps, Kubernetes, App Service) fail health checks because the /api/health endpoint requires JWT authentication. The fix wraps the existing JWT middleware to bypass token validation specifically for the health endpoint while keeping all other routes protected.

Changes:

  • Modified JWT middleware in python/agent-framework/sample-agent/host_agent_server.py to wrap jwt_authorization_middleware with conditional bypass logic for /api/health
  • Added inline documentation explaining the bypass is needed for container orchestrator health probes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"a365 deploy" failed in python/agent-framework sample because the site did not start within the expected time

2 participants