Auth is a mechanism that performs authentication before a request reaches the actual service. It allows you to handle authentication at the ALB level uniformly, without implementing authentication logic in each backend service.
ALB supports two main authentication methods:
Forward Auth (External Authentication)
Basic Auth (Basic Authentication)
Global Auth
Path-level Auth
Disable Auth
alb.ingress.cpaas.io/auth-enable: "false"
Configure Basic Auth with ALB
Ingress-nginx defines a series of annotations to configure the specific details of the authentication process. Below is a list of annotations that ALB supports, where "v" indicates support and "x" indicates no support.
support | type | note | |
---|---|---|---|
forward-auth | forward auth by sending http request | ||
nginx.ingress.kubernetes.io/auth-url | v | string | |
nginx.ingress.kubernetes.io/auth-method | v | string | |
nginx.ingress.kubernetes.io/auth-signin | v | string | |
nginx.ingress.kubernetes.io/auth-signin-redirect-param | v | string | |
nginx.ingress.kubernetes.io/auth-response-headers | v | string | |
nginx.ingress.kubernetes.io/auth-proxy-set-headers | v | string | |
nginx.ingress.kubernetes.io/auth-request-redirect | v | string | |
nginx.ingress.kubernetes.io/auth-always-set-cookie | v | boolean | |
nginx.ingress.kubernetes.io/auth-snippet | x | string | |
basic-auth | auth by username and password secret | ||
nginx.ingress.kubernetes.io/auth-realm | v | string | |
nginx.ingress.kubernetes.io/auth-secret | v | string | |
nginx.ingress.kubernetes.io/auth-secret-type | v | string | |
nginx.ingress.kubernetes.io/auth-type | - | "basic" or "digest" | basic: supports apr1 digest: not supported |
auth-cache | |||
nginx.ingress.kubernetes.io/auth-cache-key | x | string | |
nginx.ingress.kubernetes.io/auth-cache-duration | x | string | |
auth-keepalive | keepalive when sending request. specify keepalive behavior through a series of annotations | ||
nginx.ingress.kubernetes.io/auth-keepalive | x | number | |
nginx.ingress.kubernetes.io/auth-keepalive-share-vars | x | "true" or "false" | |
nginx.ingress.kubernetes.io/auth-keepalive-requests | x | number | |
nginx.ingress.kubernetes.io/auth-keepalive-timeout | x | number | |
auth-tls | when request is https, extra verify the certificate. | ||
nginx.ingress.kubernetes.io/auth-tls-secret | x | string | |
nginx.ingress.kubernetes.io/auth-tls-verify-depth | x | number | |
nginx.ingress.kubernetes.io/auth-tls-verify-client | x | string | |
nginx.ingress.kubernetes.io/auth-tls-error-page | x | string | |
nginx.ingress.kubernetes.io/auth-tls-pass-certificate-to-upstream | x | "true" or "false" | |
nginx.ingress.kubernetes.io/auth-tls-match-cn | x | string |
Related annotations:
These annotations describe the modifications made to auth-request, app-request, and cli-response in the above diagram.
Auth-request's URL, value can be a variable.
Auth-request's method.
The value is a ConfigMap reference in the format ns/name
.
By default, all headers from the cli-request will be sent to the auth-server. Additional headers can be configured through proxy_set_header. The following headers are sent by default:
Value is a comma-separated string, allowing us to bring specific headers from auth-response to app-request. example:
When ALB initiates an app-request, it will include the Remote-User and Remote-Name from the auth-response headers.
auth-response and app-response can both set cookies. By default, only when app-response.success, the auth-response.set-cookie will be merged into cli-response.set-cookie.
When the auth-server returns 401, we can set the redirect header in the cli-response to instruct the browser to redirect to the url specified by auth-signin for verification.
Value is a url, specify the location header in cli-response.
The name of the query parameter in the signin-url, default is rd.
if the signin-url does not contain the auth-signin-redirect-param
specified parameter name, alb will automatically add the parameter. The parameter value will be set to $pass_access_scheme://$http_host$escaped_request_uri
, used to record the original request URL.
Set the x-auth-request-redirect
header in auth-request.
basic-auth is the authentication process described in RFC 7617. The interaction process is as follows:
description of the protected area
Which is the realm value in the WWW-Authenticate
header of cli-response.
WWW-Authenticate: Basic realm="$realm"
The type of the authentication scheme, currently only supports basic
The secret refs of the username and password, format is ns/name
Secret supports two types:
auth-file: secret's data only contains one key "auth", and its value is the string of Apache htpasswd format. for example:
auth-map: secret's data each key represents a username, and the corresponding value is the password hash (without the username in htpasswd format). for example:
Note: Currently, only htpasswd format password hashes generated using the apr1 algorithm are supported.
ALB CR has added auth-related configuration items that can be configured on ALB/Frontend/Rule CRs. During runtime, ALB will convert the annotations on Ingress into rules.
Auth supports configuration on:
.spec.config.auth
.spec.config.auth
.spec.config.auth
The inheritance order is Alb > Frontend > Rule. If a child cr is not configured, the configuration of the parent cr will be used.
In the process of handling Ingress, ALB determines the priority based on the prefix of the annotation. The priority from high to low is:
index.$rule_index-$path_index.alb.ingress.cpaas.io
alb.ingress.cpaas.io
nginx.ingress.kubernetes.io
This can handle the compatibility problem with ingress-nginx and specify the auth configuration on a specific Ingress path.
A new annotation added by ALB, used to specify whether to enable authentication functionality for the Ingress.
In ingress-nginx, you can set a global auth through the ConfigMap. This is equivalent to configuring auth for all Ingresses. In ALB, you can configure auth on the ALB2 and FT CRs. The rules under them will inherit these configurations.
In ALB, you can disable the auth function of this Ingress by configuring the annotation: alb.ingress.cpaas.io/auth-enable: "false"
on the Ingress.
X-ALB-ERR-REASON
header in the return