To integrate heimdall with the NGINX Ingress Controller you can make use of the nginx.ingress.kubernetes.io/auth-url
, nginx.ingress.kubernetes.io/auth-response-headers
and the nginx.ingress.kubernetes.io/auth-snippet
annotation as shown in the example below. This will result in an NGINX configuration corresponding to the integration option, described in the Forward all information in X-Forwarded-*
headers section.
| The configuration used in the example below requires proper configuration of trusted_proxies . |
Example 3. Possible Configuration
nginx.ingress.kubernetes.io/auth-url: "http://<heimdall service name>.<namespace>.svc.cluster.local:<decision port>" (1)
nginx.ingress.kubernetes.io/auth-response-headers: Authorization (2)
nginx.ingress.kubernetes.io/auth-snippet: | (3)
proxy_set_header X-Forwarded-Method $request_method;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Uri $request_uri;
# other annotations required
1 | Configures the controller to use heimdall’s decision service endpoint with <heimdall service name> , <namespace> and <decision port> depending on your configuration. |
2 | Let NGINX forward the Authorization header set by heimdall to the upstream service upon successful response. This configuration depends on
your Contextualizers and Finalizers configuration. If not configured, NGINX will only react on Set-Cookie headers in responses from heimdall by default. |
3 | Configures the required headers to pass the information about the used HTTP scheme, host and port, request path and used query parameters to be forwarded to heimdall. | Without that, heimdall will not be able extracting relevant information from the NGINX request as it does not support NGINX proprietary X-Original-Method and X-Original-Uri used by it for the same purposes. |
|
Alternatively, if you don’t want configuring trusted_proxies
and do not rely on the used HTTP scheme, host and port in your rules, you can also use the nginx.ingress.kubernetes.io/configuration-snippet
and nginx.ingress.kubernetes.io/server-snippet
annotations and use the configuration shown below.
Example 4. Possible Configuration
This example is an exact copy of the configuration used in the very first integration option described above.
nginx.ingress.kubernetes.io/configuration-snippet: |
auth_request /_auth;
auth_request_set $auth_cookie $upstream_http_set_cookie;
add_header Set-Cookie $auth_cookie;
auth_request_set $auth_header $upstream_http_authorization;
proxy_set_header 'Authorization' $auth_header;
proxy_set_header Proxy "";
nginx.ingress.kubernetes.io/server-snippet: |
location = /_auth {
internal;
access_log off;
proxy_method $request_method;
proxy_pass http://<heimdall service name>.<namespace>.svc.cluster.local:<decision port>$request_uri;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header Host $http_host;
}
# other annotations required
Checkout the examples on GitHub for a working demo.