Envoy OAuth2

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an envoy oauth2 filter to check user tokens before requests reach your backend apps. This filter sends unauthenticated users to your login provider and trades auth codes for valid tokens. Teams often place this filter at the edge to protect internal web tools. Still, once a user logs in, broad role permissions often grant full reign over the upstream app. A single valid token might let an engineer run any action inside that backend service. How the envoy oauth2 workflow operates Th

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up an envoy oauth2 filter to check user tokens before requests reach your backend apps. This filter sends unauthenticated users to your login provider and trades auth codes for valid tokens. Teams often place this filter at the edge to protect internal web tools. Still, once a user logs in, broad role permissions often grant full reign over the upstream app. A single valid token might let an engineer run any action inside that backend service.

How the envoy oauth2 workflow operates

The envoy oauth2 filter acts as a gatekeeper within your HTTP connection manager. When a user visits a protected route, the filter checks the request for a valid cookie. If the cookie is missing, the filter stops the request right away. It then redirects the browser to your identity provider login page. The user logs in with their work email and password, plus multi-factor prompts.

After the user logs in, the identity provider sends an auth code back to a callback path. The filter catches this callback request and talks to the token endpoint behind the scenes. It sends its client secret and the auth code to get an access token. Then the filter sets encrypted cookies in the user browser to hold the session state. Future requests carry these cookies, so the filter lets them pass through to the upstream service.

You must also manage secret storage for this filter to work well. The filter needs a client secret to talk to the identity provider token endpoint. It also needs a shared key to sign and check the session cookies it creates. Teams usually mount these secrets from an external secret store or pass them via secret discovery.

Where edge login checks fall short

Edge login filters solve a major problem for internal web apps that lack built-in login flows. You do not need to write custom login code into every single microservice you run. The edge handles the browser redirects, the token exchange, and the session cookie checks. It stops anonymous network traffic from ever hitting your internal backend services.

Still, this setup only checks who logs in at the start of a web session. It does not check what individual statements, commands, or requests do in flight beyond basic HTTP paths. Once the filter validates the cookie, the user gets broad access to the upstream app. If that app is a database admin tool, the user can run destructive queries or dump tables. The edge filter does not inspect database queries or API payloads for sensitive data.

Envoy Proxy Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Also, the native filter only works for HTTP browser traffic and fails for raw TCP tools. Engineers still need direct CLI sessions to databases, Kubernetes clusters, and cloud hosts for daily work. An HTTP cookie flow cannot govern an interactive terminal session or mask sensitive fields like card numbers. Teams end up managing separate network rules and shared secrets for all their non-web engineering tools.

Managing secrets and token rotation

Running this login flow in production requires careful secret rotation across your edge fleet. Every instance must share the exact same signing key to validate user cookies across load balancers. If one instance has an old key, users will face random login loops during their sessions. You must sync key updates across all instances without dropping active user traffic.

You also need a clear plan for token lifetimes and refresh cycles. If the cookie lifetime is too long, a revoked user might keep working after leaving the team. If the lifetime is too short, engineers must log in again many times each day. Balancing security and daily speed takes ongoing tuning as your internal app count grows.

Add response masking and path guardrails beside HTTP APIs

Tokens, OAuth scopes, and network rules govern who reaches an internal HTTP endpoint. Even so, an allowed service or agent can call a delete method or get raw personal data in a JSON response. In practice, hoop.dev runs beside the service as a sidecar for your HTTP API and checks requests and responses alongside your existing API auth.

With hoop.dev HTTP controls, guardrails refuse disallowed paths, methods, and headers before they reach the service. Data masking rewrites sensitive JSON keys in responses in memory before they return to the client. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for GDPR, HIPAA, and PCI DSS programs. View the source on GitHub.

Frequently asked questions

Does the envoy oauth2 filter validate JSON Web Tokens on its own?

No, this filter handles the browser redirect flow and trades auth codes for tokens. To check JWT signatures and claims on every call, you must pair it with a separate JWT filter.

How do multiple edge instances share user session state?

The filter stores session state inside encrypted cookies on the user browser rather than a local database. As long as all edge instances share the same HMAC secret, any instance can check the cookie.

Can this filter protect non-HTTP services like Postgres or SSH?

No, the filter operates strictly inside the HTTP connection manager and relies on browser redirects and cookies. It cannot handle native database wire protocols or interactive terminal sessions over raw TCP.

The query runs. The emails stay hidden.