Skip to content

Other proxies with Kubernetes

Contributors: @kdwils, @pushpinderbal

This ingress resource configures ingress-nginx to forward authentication checks for the host my-host.domain.com to a specific URL (auth-url). If the user is not authenticated, they will be redirected to a login page (auth-signin).

Documentation for these annotations can be found in the ingress-nginx repository annotations.md.

  • nginx.ingress.kubernetes.io/auth-url specifies the URL where ingress-nginx should send requests to verify if the user is authenticated.
  • nginx.ingress.kubernetes.io/auth-signin specifies the URL where ingress-nginx should send unauthenticated users to sign in.
  • nginx.ingress.kubernetes.io/auth-signin-redirect-param specifies the key of the query parameter used to set the redirect URI.
ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
namespace: my-namespace
annotations:
nginx.ingress.kubernetes.io/auth-url: "http://tinyauth.tinyauth.svc.cluster.local:3000/api/auth/nginx"
nginx.ingress.kubernetes.io/auth-signin: "http://auth.example.com/login"
nginx.ingress.kubernetes.io/auth-signin-redirect-param: redirect_uri
spec:
ingressClassName: nginx
rules:
- host: my-host.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-service
port:
number: 8080

External authorization in Istio is configured using the AuthorizationPolicy CRD and can be set up to use Tinyauth as the external authorization provider for both Ingress and Gateway API resources. Istio uses Envoy proxy under the hood, so this configuration can also be adapted for standalone Envoy filters.

Add Tinyauth as an external authorization provider in your Istio mesh configuration.

extensionProviders:
- name: "tinyauth"
envoyExtAuthzHttp:
service: "tinyauth.tinyauth.svc.cluster.local"
port: "3000"
pathPrefix: "/api/auth/envoy?path="
includeRequestHeadersInCheck: ["cookie", "x-forwarded-for", "x-forwarded-proto", "x-forwarded-host", "accept", "user-agent"]
includeAdditionalHeadersInCheck:
"x-forwarded-for": "%DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT%"
"x-real-ip": "%DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT%"
"x-forwarded-proto": "%REQ(:SCHEME)%"
"x-forwarded-host": "%REQ(:AUTHORITY)%"
"x-forwarded-uri": "%REQ(:PATH)%"
"x-forwarded-method": "%REQ(:METHOD)%"
headersToDownstreamOnAllow: ["set-cookie"]
headersToDownstreamOnDeny: ["content-type", "set-cookie"]

If you install Istio using helm, you can supply extensionProviders configuration in the values.yaml files as follows:

meshConfig:
extensionProviders:
- name: "tinyauth"
envoyExtAuthzHttp:
service: "tinyauth.tinyauth.svc.cluster.local"
port: "3000"
pathPrefix: "/api/auth/envoy?path="
includeRequestHeadersInCheck: ["cookie", "x-forwarded-for", "x-forwarded-proto", "x-forwarded-host", "accept", "user-agent"]
includeAdditionalHeadersInCheck:
"x-forwarded-for": "%DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT%"
"x-real-ip": "%DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT%"
"x-forwarded-proto": "%REQ(:SCHEME)%"
"x-forwarded-host": "%REQ(:AUTHORITY)%"
"x-forwarded-uri": "%REQ(:PATH)%"
"x-forwarded-method": "%REQ(:METHOD)%"
headersToDownstreamOnAllow: ["set-cookie"]
headersToDownstreamOnDeny: ["content-type", "set-cookie"]

Given that you have a HTTPRoute under a Gateway that exposes your application, you can now create an AuthorizationPolicy to protect it using Tinyauth.

http-route.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: myapp-http-route
labels:
app: myapp
spec:
parentRefs:
- name: my-public-gateway
namespace: ingress
sectionName: https
hostnames:
- myapp.example.com
rules:
- backendRefs:
- name: myapp-service
port: 80
authorization-policy.yaml
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
name: tinyauth-policy
namespace: ingress
spec:
targetRefs:
- kind: Gateway
group: gateway.networking.k8s.io
name: my-public-gateway
action: CUSTOM
provider:
name: "tinyauth"
rules:
- to:
- operation:
hosts: ["myapp.example.com"]

For more information, refer to the Istio External Authorization and Authorization Policy documentation.