Skip to content

Commit 0cb4e88

Browse files
authored
Lab8 fixes after running through clean install (#58)
* Lab8 fixes after running through clean install * Found the issue - nginx.conf has the resolve items which seems cleaner. * Cleaned up Lab9 with all the previous labs done.
1 parent 4d2ae50 commit 0cb4e88

14 files changed

+93
-93
lines changed

labs/lab7/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ Now that you have a self signed TLS certificate for testing, you will configure
286286
287287
![Browser Cert Invalid](media/lab7_browser_cert_invalid.png)
288288
289-
1. You can use browser's built-in certificate viewer to look at the details of the TLS certificate that was sent from NGINX to your browser. In address bar, click on the `Not Secure` icon, then click on `Certificate is not valid`. This will display the certificate. You can verify looking at the `Comman Name` field that this is the same certificate that you provided to NGINX for Azure resource.
289+
1. You can use browser's built-in certificate viewer to look at the details of the TLS certificate that was sent from NGINX to your browser. In the address bar, click on the `Not Secure` icon, then click on `Certificate is not valid`. This will display the certificate. You can verify looking at the `Common Name` field that this is the same certificate that you provided to NGINX for Azure resource.
290290

291291
![Browser Cert Details](media/lab7_browser_cert_details.png)
292292

labs/lab8/cafe.example.com.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
server {
55

66
# Include AzureAD Auth configuration files
7-
include /etc/nginx/conf.d/oidc/openid_connect.server_conf; # Authorization code flow and Relying Party processing
7+
include /etc/nginx/oidc/openid_connect.server_conf; # Authorization code flow and Relying Party processing
88

99
listen 443 ssl; # Listening on port 443 with "ssl" parameter for terminating TLS on all IP addresses on this machine
1010

96.1 KB
Loading
135 KB
Loading
70 KB
Loading
88.7 KB
Loading

labs/lab8/media/lab8_overview.png

71.1 KB
Loading
91.9 KB
Loading

labs/lab8/nginx.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ http {
6666

6767
stream {
6868

69+
resolver 127.0.0.1:49153 valid=20s;
70+
71+
server {
72+
listen 9000; # should match the port specified with zone_sync_server
73+
74+
zone_sync;
75+
zone_sync_server internal.nginxaas.nginx.com:9000 resolve;
76+
}
77+
6978
include /etc/nginx/stream/*.conf; # Stream TCP nginx files
7079

7180
}

labs/lab8/openid_connect.server_conf

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
# Nginx for Azure / OpenID Connect configuration
2-
# Chris Akker, Shouvik Dutta, Adam Currier - Mar 2024
3-
#
4-
# Advanced configuration START
1+
# Advanced configuration START
52
set $internal_error_message "NGINX / OpenID Connect login failure\n";
63
set $pkce_id "";
74
resolver 8.8.8.8; # For DNS lookup of IdP endpoints;
85
subrequest_output_buffer_size 32k; # To fit a complete tokenset response
96
gunzip on; # Decompress IdP responses if necessary
107
# Advanced configuration END
118

12-
js_import oidc from /etc/nginx/oidc/openid_connect.js;
13-
149
location = /_jwks_uri {
1510
internal;
1611
proxy_cache jwk; # Cache the JWK Set recieved from IdP
@@ -34,9 +29,9 @@
3429
# This location is called by the IdP after successful authentication
3530
status_zone "OIDC code exchange";
3631
js_content oidc.codeExchange;
37-
error_page 500 502 504 @oidc_error;
32+
error_page 500 502 504 @oidc_error;
3833
}
39-
34+
4035
location = /_token {
4136
# This location is called by oidcCodeExchange(). We use the proxy_ directives
4237
# to construct the OpenID Connect token request, as per:
@@ -90,3 +85,5 @@
9085
default_type text/plain;
9186
return 500 $internal_error_message;
9287
}
88+
89+
# vim: syntax=nginx

labs/lab8/openid_connect_configuration.conf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
#
55
map $host $oidc_authz_endpoint {
6-
cafe.example.com <authorization_endpoint>; # Your Authorization Endpoint URL
6+
default "https://<Auth Endpoint URL>"; # Your Authorization Endpoint URL
77
#default "http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/auth";
88
}
99

@@ -20,17 +20,17 @@ map $host $oidc_authz_extra_args {
2020
}
2121

2222
map $host $oidc_token_endpoint {
23-
cafe.example.com <token_endpoint>; # Your Token Endpoint URL
23+
default "https://<Token Endpoint URL>"; # Your Token Endpoint URL
2424
#default "http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/token";
2525
}
2626

2727
map $host $oidc_jwt_keyfile {
28-
cafe.example.com <jwks_uri>; # Your jwks_uri URL
28+
default "https://<JWKS URL>"; # Your jwks_uri URL
2929
#default "http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/certs";
3030
}
3131

3232
map $host $oidc_client {
33-
cafe.example.com <client_id>; # Your $MY_CLIENT_ID value
33+
default "<MY_CLIENT_ID>"; # Your $MY_CLIENT_ID value
3434
#default "<default-value>";
3535
}
3636

@@ -39,7 +39,7 @@ map $host $oidc_pkce_enable {
3939
}
4040

4141
map $host $oidc_client_secret {
42-
cafe.example.com <client_secret>; # Your $MY_CLIENT_SECRET value
42+
default "<MY_CLIENT_SECRET>"; # Your $MY_CLIENT_SECRET value
4343
#default "<default-value>";
4444
}
4545

labs/lab8/readme.md

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,38 @@ NGINXaaS Azure | Entra ID | Cafe App
3434
To enable an application to use Entra ID / Azure AD for authentication, you will need to create a new `app registration` from within the Azure Entra ID Portal.
3535

3636
1. Login into Microsoft Azure Portal and navigate to `App registrations`.
37-
2. CLick the `+` button at the top for `New registration`
37+
2. Click the `+` button at the top for `New registration`
38+
39+
![Redirect URI setup!](media/lab8_app-registrations.png)
3840
3. Fill out the name your application registration.
3941
For this workshop we provided the name of `example.com`.
40-
4. Select the necessary account types based on who would be using this application. For this lab exercise, you will select *"Accounts in this organizational directory only (<name> - Single tenant)"*, which means users of your current Subscription. (Using other Account types is not covered in this workshop).
41-
5. Click `+ Platform`, and select `Web` for the Platform.
42-
43-
On the `Configure Web` panel, you will need to provide a `redirect URI`. You can optionally also provide a `Front-channel logout URL`. For the `redirect URI`, you will want to fill in with the hostname of the application you want to Protect, including the port number, with `/_codexch`.
42+
4. Select the necessary account types based on who would be using this application. For this lab exercise, you will select *"Accounts in this organizational directory only (<name> - Single tenant)"*, which means users of your current Subscription. (Using other Account types is not covered in this workshop).
43+
5. In the Redirect URI (optional) section, select `Web` and provide a `redirect URI`. For the `redirect URI`, you will want to fill in with the hostname of the application you want to Protect, including the port number, with `/_codexch`.
4444

4545
For example, in this workshop, NGINXaaS will be configured for OIDC to access `cafe.example.com`. So the `redirect URI` for the workshop will be the following:
4646

4747
```bash
4848
https://cafe.example.com:443/_codexch
49-
5049
```
5150

52-
Click `Configure` on the bottom of the Configure Web panel.
53-
54-
![Redirect URI setup!](media/redirect_url_setup.png)
5551

5652
>**Note:** Make sure you are specifing `HTTPS` and port 443. This is a required setting.
5753
5854
6. Click on `Register` to register your application.
5955

60-
![App registration](media/App_Registration.png)
56+
![App registration](media/lab8_example-register.png)
6157

6258
7. Once the application has been registered you will be redirected to the `Overview` page of the newly created application.
6359

64-
![Post App registration](media/Post_App_Registration.png)
60+
![Post App registration](media/lab8_overview.png)
6561

6662
Take note of the `Application (client) ID` and `Directory (tenant) ID`.
6763

6864
8. Copy and set the following ENVIRONMENT variables for the Client and Tenant IDs, to be used in the next section:
6965

7066
```bash
71-
export $MY_CLIENT_ID=<ApplicationClientID>
72-
export $MY_TENANT_ID=<DirectoryTenantID>
73-
67+
export MY_CLIENT_ID="<ApplicationClientID>"
68+
export MY_TENANT_ID="<DirectoryTenantID>"
7469
```
7570

7671
## Creating N4A Client Credentials
@@ -81,25 +76,24 @@ You will need to create a new `Client credentials secret` that will be used by N
8176

8277
2. Click the `+ New client secret` button within the `Client Secrets` tab to create a new client secret that will be used by NGINXaaS. This secret will be used in the Nginx config as part of the Auth workflow.
8378

84-
![New Secret Creation](media/New_Secret_Creation.png)
79+
![New Secret Creation](media/lab8_new-secret-creation.png)
8580

8681
3. Fill out the description for the client secret. For this workshop we provided the name as `example.com`.
8782

88-
4. You can also change the Duration for the client secret expiriration or keep the default recommended value. Click on `Add` to generate the new client secret.
83+
4. You can also change the Duration for the client secret expiration or keep the default recommended value. Click on `Add` to generate the new client secret.
8984

90-
![Fill Secret Details](media/Fill_Secret_details.png)
85+
![Fill Secret Details](media/lab8_fill-secret-details.png)
9186

9287
5. Once you click on the `Add` button, you will see the secret within the `Client Secrets` tab as seen in below screenshot. The `Value` column will be the field you want to look for and copy. This Client Secret will be used by Nginx to communicate with Entra ID.
9388

94-
![Post Secret Creation](media/Post_Secret_Creation.png)
89+
![Post Secret Creation](media/lab8_post-secret-creation.png)
9590

96-
6. Copy the `Value` portion of the client secret to the clipboard, and also save it on your computer as you will use it in next section of this lab. **NOTE:** It is important that you have a backup of this `Client Secret Value`, *as it is only shown here at creation time.* If you lose the Client Secret, you can easily create a new one in this same Azure Portal page and you will have to update your N4A configuration.
91+
6. Copy the `Value` portion of the client secret to the clipboard, and also save it on your computer as you will use it in next section of this lab. **NOTE:** It is important that you have a backup of this `Client Secret Value`, *as it is only shown here at creation time.* If you lose the Client Secret, you can easily create a new one in this same Azure Portal page and you will have to update your N4A configuration.
9792

9893
7. Copy and set the following ENVIRONMENT variable for the Client Secret, to be used in the next section:
9994

10095
```bash
101-
export $MY_CLIENT_SECRET=<Client Secret Value>
102-
96+
export MY_CLIENT_SECRET="<Client Secret Value>"
10397
```
10498

10599
### Collecting the Required URLs
@@ -108,7 +102,6 @@ You will need to create a new `Client credentials secret` that will be used by N
108102

109103
```bash
110104
curl https://login.microsoftonline.com/$MY_TENANT_ID/v2.0/.well-known/openid-configuration | jq
111-
112105
```
113106

114107
There are three URLs required, which you will use in your Nginx for Azure configuration:
@@ -205,37 +198,12 @@ Now that the Azure Entra ID configurations are complete, you will configure Ngin
205198

206199
As there are 2 Active/Active instances of Nginx `under the hood` of an N4A deployment, synchronizing the KeyValue shared memory zone used for OIDC tokens is required. This NginxPlus feature uses a module called `ngx_stream_zone_sync_module`. The module uses a dedicated TCP connection between N4A pairs to send updates of the shared memory to each other. For the Nginx OIDC solution, the shared memory is used to cache the users' Auth Tokens, so that subsequent requests do NOT have to be validated with the IDP. Caching these Auth Tokens provides a large performance improvement to users accessing OIDC protected content. Without this Nginx caching feature, `every request would suffer the Round Trip delay` of going back and forth to the Identity provider, slowing your application Response Time to a dismal crawl, and potentially prompting for user credentials repeatedly.
207200

208-
<< N4A zone sync diagram here >>
209-
210-
1. Using the N4A console, create a new `/etc/nginx/stream/zonesync.conf` file in the `stream context`. Use the example file provided, just copy/paste:
211-
212-
```nginx
213-
# Nginx for Azure Zone Sync config
214-
# Chris Akker, Shouvik Dutta, Adam Currier - Mar 2024
215-
#
216-
# zonesync.conf
217-
#
218-
resolver 127.0.0.1:49153 valid=20s;
219-
220-
server {
221-
222-
listen 9000; # should match the port specified with zone_sync_server
223-
status_zone n4a-zonesync;
224-
225-
zone_sync;
226-
zone_sync_server internal.nginxaas.nginx.com:9000 resolve;
227-
228-
}
229-
230-
```
231-
232-
Submit your Nginx Configuration.
233201

234202
### Customize the Nginx OpenID Connect files
235203

236204
1. Copy the three `openid_connect` files from the /lab8 folder, to your Nginx for Azure `/etc/nginx/oidc` folder. You will have to create each file and copy/paste the contents from the examples provided in the lab8 folder.
237205

238-
1. Modify the `/etc/nginx/oidc/openid_connect_configuration.conf` file as follows:
206+
1. Create and modify the `/etc/nginx/oidc/openid_connect_configuration.conf` file as follows:
239207

240208
There are 5 lines to edit in this configuration file, shown as follows:
241209

@@ -246,9 +214,14 @@ Submit your Nginx Configuration.
246214
3. Line #28, change the `jwks_uri` to your URL
247215

248216
4. Line #33, change the `client_id` to your Value
249-
217+
```bash
218+
echo $MY_CLIENT_ID
219+
```
250220
5. Line #42, change the `client_secret` to your Value
251-
221+
```bash
222+
echo $MY_CLIENT_SECRET
223+
```
224+
Take those values and put them into the file mentioned above (/etc/nginx/oidc/openid_connect_configuration.conf).
252225
```nginx
253226
# Nginx for Azure / OpenID Connect configuration
254227
# Chris Akker, Shouvik Dutta, Adam Currier - Mar 2024
@@ -299,9 +272,9 @@ Submit your Nginx Configuration.
299272
```
300273

301274

302-
1. There are no changes needed for the `/etc/nginx/oidc/openid_connect.server_conf`.
275+
1. There are no changes needed for the `/etc/nginx/oidc/openid_connect.server_conf` - just copy and paste it.
303276

304-
1. There are no changes needed for the `/etc/nginx/oidc/openid_connect.js` Javascript file. This is the core Nginx Javascript code that gets executed for this OIDC Solution.
277+
1. There are no changes needed for the `/etc/nginx/oidc/openid_connect.js` Javascript file - just copy and paste it. This is the core Nginx Javascript code that gets executed for this OIDC Solution. Once the three files are created/modified, click `Submit` to have them loaded into the N4A instance.
305278

306279
1. Copy the `cafe.example.com.conf` file provided to `/etc/nginx/conf.d/cafe.example.com.conf`. Notice the new /location block with a REGEX that captures the `/beer and /wine` URIs. This new location block will be protected by Azure Entra ID using OIDC.
307280

@@ -395,7 +368,7 @@ Submit your Nginx Configuration.
395368

396369
## Test Nginx 4 Azure with Entra ID
397370

398-
1. You can now test your Azure Entra ID with OIDC config with NGINXaaS. To test open up your browser, open Dev Tools, and try `https://cafe.example.com/beer`. **NOTE:** You will likely have to use a new `Chrome Incognito` browser, because it is caching and using your current credentials, *and you need to start with fresh browser.*
371+
1. You can now test your Azure Entra ID with OIDC config with NGINXaaS. To test, open up your browser, open Dev Tools, and try `https://cafe.example.com/beer`. **NOTE:** You will likely have to use a new `Chrome Incognito` browser, because it is caching and using your current credentials, *and you need to start with fresh browser.*
399372

400373
If everything has been configured correctly, you should see the browser Redirect you to Entra ID for an Azure user authentication logon prompt, and Dev Tools should show you the details of the Redirect to `microsoftonline.com`, highlighted below. Take a moment to look as some of the other objects/headers in the Dev Tools, it should look familiar if you have used OpenID before.
401374

labs/lab9/nginx.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ http {
5858

5959
stream {
6060

61+
resolver 127.0.0.1:49153 valid=20s;
62+
63+
server {
64+
listen 9000; # should match the port specified with zone_sync_server
65+
66+
zone_sync;
67+
zone_sync_server internal.nginxaas.nginx.com:9000 resolve;
68+
}
69+
6170
include /etc/nginx/stream/*.conf; # Stream TCP nginx files
6271

6372
}

0 commit comments

Comments
 (0)