3.6 KiB
title | lang | meta | description | |||||
---|---|---|---|---|---|---|---|---|
Nginx | en-US |
|
This guide covers how to use Pomerium to protect services behind an nginx proxy. |
Securing Nginx
This recipe's sources can be found on github
At the end, you will have a locally running install of verify behind nginx with policy enforced by Pomerium.
Background
Nginx can be configured to authorize requests by calling an external authorization service. Pomerium is compatible with this external authentication protocol and can thus be used to protect services behind nginx. In this configuration, Pomerium does not proxy traffic, but authorizes it on behalf of nginx. This is useful for integrating into existing load balancer infrastructure.
For more information on using Pomerium as an external authorization endpoint, see forward auth in the Pomerium docs.
How It Works
- Create a standard pomerium configuration to authenticate against your identity provider (IdP)
- Configure nginx to authorize incoming requests via pomerium
- Pomerium authenticates users via IdP
- Nginx queries Pomerium on each request to verify the traffic is authorized
- Pomerium verifies the traffic against policy, responding to nginx
- Nginx proxies the traffic or responds with an error
Pre-requisites
This recipe is designed to run on a local docker-compose instance. The included configuration can be adopted for any nginx deployment.
- docker
- docker-compose
- A copy of the example repo checked out
- Valid credentials for your OIDC provider
- (Optional)
mkcert
to generate locally trusted certificates
Certificates (optional)
This demo comes with its own certificates, but they will generate warnings in your browser. You may instead provide your own or use mkcert to generate locally trusted certificates.
After installing mkcert
, run the following inside the example repo:
mkcert -install
mkcert '*.localhost.pomerium.io'
This will install a trusted CA and generate a new wildcard certificate:
_wildcard.localhost.pomerium.io.pem
_wildcard.localhost.pomerium.io-key.pem
To provide your own certificates through another mechanism, please overwrite these files or update docker-compose.yaml
accordingly.
Configure
Pomerium
Update config.yaml
with your IdP settings and desired policy
<<< @/examples/nginx/config.yaml
Nginx - pomerium
Nginx configuration for Pomerium endpoints
<<< @/examples/nginx/pomerium.conf
Nginx - verify
Nginx configuration for the protected endpoint
<<< @/examples/nginx/verify.conf
Docker Compose
<<< @/examples/nginx/docker-compose.yaml
Run docker-compose up
. After a few seconds, browse to verify.localhost.pomerium.io.
You should be prompted to log in through your IdP and then granted access to the deployed verify
instance.
That's it!
Your verify
install is protected by Pomerium.
Adapting
To re-use the configuration in this demo in other contexts:
- Update
verify.conf
to reflect the correct forward auth URL inlocation @error401
- Update
pomerium.conf
to reflect the pomerium hostname(s) or IP(s) inupstream pomerium
- Update
pomerium.conf
to reflect your pomerium authenticate and forward auth hostnames inserver_name