Other proxies with Kubernetes
Contributors: @kdwils, @pushpinderbal
Using with ingress-nginx
Section titled “Using with ingress-nginx”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-urlspecifies the URL whereingress-nginxshould send requests to verify if the user is authenticated.nginx.ingress.kubernetes.io/auth-signinspecifies the URL whereingress-nginxshould send unauthenticated users to sign in.nginx.ingress.kubernetes.io/auth-signin-redirect-paramspecifies the key of the query parameter used to set the redirect URI.
apiVersion: networking.k8s.io/v1kind: Ingressmetadata: 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_urispec: ingressClassName: nginx rules: - host: my-host.example.com http: paths: - path: / pathType: Prefix backend: service: name: my-service port: number: 8080Using with Istio
Section titled “Using with Istio”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.
Define the External Authorizer
Section titled “Define the External Authorizer”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"]Create Authorization Policy
Section titled “Create Authorization Policy”Given that you have a HTTPRoute under a Gateway that exposes your application, you can now create
an AuthorizationPolicy to protect it using Tinyauth.
apiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata: name: myapp-http-route labels: app: myappspec: parentRefs: - name: my-public-gateway namespace: ingress sectionName: https hostnames: - myapp.example.com rules: - backendRefs: - name: myapp-service port: 80apiVersion: security.istio.io/v1kind: AuthorizationPolicymetadata: name: tinyauth-policy namespace: ingressspec: 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.