Skip to content

Commit 500692e

Browse files
NLB-6239: Update native oidc with protected file
1 parent 61415e9 commit 500692e

File tree

6 files changed

+55
-12
lines changed

6 files changed

+55
-12
lines changed

terraform/configurations/native-oidc/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ terraform destroy --auto-approve
3737
## Notes
3838

3939
- The deployment uses a self-signed certificate for demonstration. For production, use a certificate issued by a trusted CA.
40-
- OIDC configuration requires NGINX Plus R34 or later.
40+
- Native OIDC configuration requires NGINX Plus R35 or later.
4141
- For more details on how to configure the OIDC in NGINXaaS, please refer to the references below
4242
- https://docs.nginx.com/nginx/deployment-guides/single-sign-on/entra-id/
4343
- https://docs.nginx.com/nginxaas/azure/quickstart/runtime-state-sharing/
4444
- https://docs.nginx.com/nginx/releases/#r34
4545
- https://community.f5.com/kb/technicalarticles/f5-nginx-plus-r34-release-now-available/340300
4646
- https://nginx.org/en/docs/http/ngx_http_oidc_module.html
4747
- https://docs.nginx.com/nginxaas/azure/getting-started/ssl-tls-certificates/
48+
- https://community.f5.com/kb/technicalarticles/f5-nginx-plus-r35-release-now-available/342962
4849

4950

terraform/configurations/native-oidc/main.tf

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,18 @@ resource "azurerm_role_assignment" "example" {
9292

9393
locals {
9494
nginx_config = templatefile("${path.module}/nginx.conf.tpl", {
95-
issuer = var.issuer
96-
client_id = var.client_id
97-
client_secret = var.client_secret
98-
resolver = var.resolver
95+
resolver = var.resolver
96+
})
97+
98+
# Use provided post_logout_uri if specified, otherwise auto-generate using IP address
99+
effective_post_logout_uri = var.post_logout_uri != "" ? var.post_logout_uri : "https://${azurerm_nginx_deployment.example.ip_address}/post_logout/"
100+
101+
# Protected OIDC provider configuration with sensitive client secret
102+
oidc_provider_config = templatefile("${path.module}/oidc-secrets.conf.tpl", {
103+
issuer = var.issuer
104+
client_id = var.client_id
105+
client_secret = var.client_secret
106+
post_logout_uri = local.effective_post_logout_uri
99107
})
100108
}
101109

@@ -143,6 +151,12 @@ resource "azurerm_nginx_configuration" "example" {
143151
virtual_path = "/etc/nginx/nginx.conf"
144152
}
145153

154+
# Protected configuration file containing the entire OIDC provider block
155+
protected_file {
156+
content = base64encode(local.oidc_provider_config)
157+
virtual_path = "/etc/nginx/oidc-provider.conf"
158+
}
159+
146160
depends_on = [
147161
azurerm_nginx_certificate.example
148162
]

terraform/configurations/native-oidc/nginx.conf.tpl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@ http {
33
resolver ${resolver} ipv4=on ipv6=off valid=300s;
44
keyval_zone zone=oidc:8M state=/opt/oidc_id_tokens.json timeout=1h sync;
55

6-
oidc_provider entra {
7-
# issuer URL, client_id, client_secret values are obtained from IdP configuration (microsoft entra id in this example)
8-
issuer ${issuer};
9-
client_id ${client_id};
10-
client_secret ${client_secret};
11-
session_store oidc;
12-
}
6+
# Include OIDC provider configuration from protected file
7+
include /etc/nginx/oidc-provider.conf;
138
server {
149
listen 443 ssl;
1510
server_name demo.example.com;
@@ -24,6 +19,14 @@ http {
2419
2520
proxy_pass http://127.0.0.1:8080;
2621
}
22+
23+
# Post-logout endpoint - this example uses /post_logout/
24+
# You can change this path or customize the response as needed
25+
# Make sure to update the post_logout_uri variable accordingly
26+
location /post_logout/ {
27+
return 200 "You have been logged out.\n";
28+
default_type text/plain;
29+
}
2730
}
2831

2932
server {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# OIDC provider configuration with sensitive information
2+
# This file contains sensitive information and should be protected
3+
4+
oidc_provider entra {
5+
# issuer URL, client_id, client_secret values are obtained from IdP configuration (microsoft entra id in this example)
6+
issuer ${issuer};
7+
client_id ${client_id};
8+
client_secret ${client_secret};
9+
session_store oidc;
10+
logout_uri /logout;
11+
post_logout_uri ${post_logout_uri};
12+
logout_token_hint on;
13+
userinfo on;
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
output "ip_address" {
22
description = "IP address of NGINXaaS deployment."
33
value = azurerm_nginx_deployment.example.ip_address
4+
}
5+
6+
output "post_logout_uri" {
7+
description = "Post logout URI configured in OIDC provider."
8+
value = local.effective_post_logout_uri
49
}

terraform/configurations/native-oidc/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,10 @@ variable "client_secret" {
4646
variable "resolver" {
4747
description = "OIDC resolver"
4848
type = string
49+
}
50+
51+
variable "post_logout_uri" {
52+
description = "OIDC post logout uri. If not provided, will default to https://IP_ADDRESS/post_logout/ (matching the example configuration). You can change this to match your custom logout endpoint."
53+
type = string
54+
default = "" # Empty string means use auto-generated URI with /post_logout/ path
4955
}

0 commit comments

Comments
 (0)