根据文档,AWS ALB本身支持HTTPS监听器,因此可以在ALB上直接启用SSL/TLS,而无需在每个NGINX ingress上做额外配置。具体步骤如下:
代码示例(使用Terraform):
resource "aws_lb_listener" "https" {
load_balancer_arn = aws_lb.example.arn
port = 443
protocol = "HTTPS"
default_action {
authenticate_oidc {
issuer = data.aws_sso_oidc.provider.url
authorization_endpoint = "${data.aws_sso_oidc.provider.url}/authorize"
token_endpoint = "${data.aws_sso_oidc.provider.url}/token"
user_info_endpoint = "${data.aws_sso_oidc.provider.url}/user-info"
client_id = var.oidc_client_id
client_secret = var.oidc_client_secret
scope = "openid"
session_cookie_name = "example-cookie"
session_timeout_minutes = 60
authentication_request_extra_params = {
"response_type" = "code"
"nonce" = random_string.nonce.result
}
}
forward {
target_group_arn = aws_lb_target_group.http.arn
stickiness {
type = "lb_cookie"
duration = 86400
enabled = true