External authorization (ext_authz
) filter
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:
$ pwd
envoy/examples/ext_authz
$ docker-compose pull
$ # Tearing down the currently running setup
$ docker-compose down
$ FRONT_ENVOY_YAML=config/http-service.yaml docker-compose up --build -d
$ # 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:
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET /service HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.58.0
> Accept: */*
> Authorization: Bearer token1
>
< content-type: text/html; charset=utf-8
< content-length: 24
< server: envoy
< date: Fri, 19 Jun 2020 15:04:29 GMT
< x-envoy-upstream-service-time: 2
<
* Connection #0 to host localhost left intact
Hello user1 from behind Envoy!
We can also employ Open Policy Agent server (with plugin enabled) as the authorization server. To run this example:
$ curl localhost:8000/service --verbose
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8000 (#0)
> GET /service HTTP/1.1
> Host: localhost:8000
> Accept: */*
>
< HTTP/1.1 200 OK
< content-type: text/html; charset=utf-8
< server: envoy
< date: Thu, 02 Jul 2020 06:29:58 GMT
< x-envoy-upstream-service-time: 2
<
* Connection #0 to host localhost left intact
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:
$ curl -X POST localhost:8000/service --verbose
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8000 (#0)
> PUT /service HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 403 Forbidden
< date: Thu, 02 Jul 2020 06:46:13 GMT
< server: envoy
See also
Learn more about using Envoy’s ext_authz
filter.
Policy-based control for cloud native environments.
Open Policy Agent Envoy plugin.