External authorization (ext_authz) filter

    Sandbox environment

    Setup your sandbox environment with Docker and Docker Compose, and clone the Envoy repository with Git.

    Used to make HTTP requests.

    The External Authorization sandbox demonstrates Envoy’s ext_authz filter capability to delegate authorization of incoming requests through Envoy to an external services.

    While ext_authz can also be employed as a network filter, this sandbox is limited to exhibit ext_authz HTTP Filter, which supports to call HTTP or gRPC service.

    The setup of this sandbox is very similar to front-proxy deployment, however calls to upstream service behind the proxy will be checked by an external HTTP or gRPC service. In this sandbox, for every authorized call, the external authorization service adds additional x-current-user header entry to the original request headers to be forwarded to the upstream service.

    Change to the examples/ext_authz directory.

    To build this sandbox example and start the example services, run the following commands:

    Note

    For more information, please take a look at .

    By default, FRONT_ENVOY_YAML points to config/grpc-service/v3.yaml file which bootstraps front-envoy with ext_authz HTTP filter with gRPC service V3 (this is specified by ).

    The possible values of FRONT_ENVOY_YAML can be found inside the config directory.

    For example, to run Envoy with ext_authz HTTP filter with HTTP service will be:

    1. $ pwd
    2. envoy/examples/ext_authz
    3. $ docker-compose pull
    4. $ # Tearing down the currently running setup
    5. $ docker-compose down
    6. $ FRONT_ENVOY_YAML=config/http-service.yaml docker-compose up --build -d
    7. $ # Or you can update the .env file with the above FRONT_ENVOY_YAML value, so you don't have to specify it when running the "up" command.

    Step 4: Access the upstream-service behind the Front Envoy

    You can now try to send a request to upstream-service via the front-envoy as follows:

    As observed, the request failed with 403 Forbidden status code. This happened since the ext_authz filter employed by Envoy rejected the call. To let the request reach the upstream service, you need to provide a Bearer token via the Authorization header.

    Note

    A complete list of users is defined in file. For example, the token1 used in the below example is corresponding to user1.

    An example of successful requests can be observed as follows:

    1. * Trying 127.0.0.1...
    2. * TCP_NODELAY set
    3. * Connected to localhost (127.0.0.1) port 8000 (#0)
    4. > GET /service HTTP/1.1
    5. > Host: localhost:8000
    6. > User-Agent: curl/7.58.0
    7. > Accept: */*
    8. > Authorization: Bearer token1
    9. >
    10. < content-type: text/html; charset=utf-8
    11. < content-length: 24
    12. < server: envoy
    13. < date: Fri, 19 Jun 2020 15:04:29 GMT
    14. < x-envoy-upstream-service-time: 2
    15. <
    16. * Connection #0 to host localhost left intact
    17. Hello user1 from behind Envoy!

    We can also employ Open Policy Agent server (with plugin enabled) as the authorization server. To run this example:

    1. $ curl localhost:8000/service --verbose
    2. * Trying ::1...
    3. * TCP_NODELAY set
    4. * Connected to localhost (::1) port 8000 (#0)
    5. > GET /service HTTP/1.1
    6. > Host: localhost:8000
    7. > Accept: */*
    8. >
    9. < HTTP/1.1 200 OK
    10. < content-type: text/html; charset=utf-8
    11. < server: envoy
    12. < date: Thu, 02 Jul 2020 06:29:58 GMT
    13. < x-envoy-upstream-service-time: 2
    14. <
    15. * Connection #0 to host localhost left intact
    16. Hello OPA from behind Envoy!

    From the logs, we can observe the policy decision message from the Open Policy Agent server (for the above request against the defined policy in config/opa-service/policy.rego):

    Trying to send a request with method other than GET gives a rejection:

    1. $ curl -X POST localhost:8000/service --verbose
    2. * Trying ::1...
    3. * TCP_NODELAY set
    4. * Connected to localhost (::1) port 8000 (#0)
    5. > PUT /service HTTP/1.1
    6. > Host: localhost:8000
    7. > User-Agent: curl/7.64.1
    8. > Accept: */*
    9. >
    10. < HTTP/1.1 403 Forbidden
    11. < date: Thu, 02 Jul 2020 06:46:13 GMT
    12. < server: envoy

    See also

    Learn more about using Envoy’s ext_authz filter.

    Open Policy Agent

    Policy-based control for cloud native environments.

    Open Policy Agent Envoy plugin.

    environment variables in Compose documentation.