recipes/envoy-extauthz

Envoy External Authorization

External authorization with Envoy.

Fiber as an Envoy External Authorization HTTP Service

Github StackBlitz

One way of extending the popular Envoy proxy is by developing an external authorization service.

This example illustrates using fiber and the keyauth middleware as an authorization service for a front proxy (the configuration could also be used for an L2 / Sidecar proxy). See authz.

It also uses fiber as a sample upstream service, with the following endpoints. See app.

Architecture

Client
  β”‚
  β”‚  HTTP request (port 8000)
  β–Ό
Envoy (front-envoy)
  β”‚
  β”œβ”€β”€β–Ί AuthZ service (fiber_authz :1337)
  β”‚      Checks x-api-key header via keyauth middleware.
  β”‚      Returns 200 OK β†’ Envoy forwards request upstream.
  β”‚      Returns 403 Forbidden β†’ Envoy rejects request immediately.
  β”‚
  └──► App service (fiber_app) β€” only reached when AuthZ approves
         Serves /health (unprotected) and /api/resource (protected).

All three services run in the same Docker network (envoymesh). Envoy is the sole ingress point; the app service is never exposed directly.

Prerequisites

  • Docker with the Compose plugin

Endpoints

NameRouteProtectedMethod
Health/healthNoGET
Resource/api/resourceYesGET

Run

docker compose up --build -d

The Dockerfiles start with FROM --platform=$BUILDPLATFORM, which needs BuildKit, the default builder of Docker Engine 23 and later and of Docker Desktop. With an older Docker Engine set DOCKER_BUILDKIT=1, and with docker-compose v1 also COMPOSE_DOCKER_CLI_BUILD=1.

Test

NameCommandStatus
Not protectedcurl localhost:8000/health -i200
Missing API keycurl localhost:8000/api/resource -i403
Invalid API keycurl localhost:8000/api/resource -i -H "x-api-key: invalid-key"403
Valid API keycurl localhost:8000/api/resource -i -H "x-api-key: valid-key"200

Stop

docker compose down