-
Notifications
You must be signed in to change notification settings - Fork 2k
Add OIDC PKCE configuration through policy #7765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
javorszky
wants to merge
35
commits into
main
Choose a base branch
from
feat/issue-6713-oidc-pkce-enable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
ae6561a
Fix leading whitespace in tmpl files
javorszky a1143db
Add PKCE Enabled flag
javorszky b79734d
Implement pkce in configs
javorszky 3b49cfa
Add check for OIDC to guard for a nil pointer
javorszky fb41f5a
Fix some whitespace alignment in tmpl files
javorszky d2c925c
Update snapshots to realign with whitespaces
javorszky f660f55
Add tests for PKCE enabled true
javorszky 246781c
Update CRDs based on policy files
javorszky d455320
Add pkceEnabled to oidc pytest setup yaml
javorszky 745c9c0
Terminate include directive with a ;
javorszky ef9bbe3
Set pkce enabled to an int instead of a string
javorszky ee4af70
OIDC test doesn't need pkce enabled
javorszky ff1367e
Add PKCE pytest
javorszky b321042
Update snapshot after changing a str -> int
javorszky dc28293
oidc and pkce pytest fixture scope to function
javorszky eaf255a
OIDC tests should be class fixtured
javorszky 7fdcdab
Remove a parameter from pkce test
javorszky 122a68c
pkce test fixture should also be class scoped
javorszky b58b413
Add debug prints
javorszky 63382f3
Merge pkce test into oidc test file
javorszky dd329ef
Add unit tests for the bool to int util function
javorszky 6157e2b
Add docs to create keycloak client via api
javorszky 6a5dc61
Reword options because no tabs
javorszky 3f02842
OIDC example deploy keycloak into nginx-ingress ns
javorszky f800126
Add plus-mgmt-configmap.yaml to instructions
javorszky f7f42ff
Redo list numbers in oidc example readme
javorszky bf05969
Reset keycloak to be in default namespace
javorszky 72f4ef7
Add note on not using client secret for PKCE
javorszky 56e6c20
Move applying the plus mgmt to common resources
javorszky 20a632b
Add pkceEnabled to policy resource doc
javorszky e4ff105
Rename pkceEnabled from past to present tense
javorszky bd287c4
Fix product name in example readme
javorszky e66df56
Change console code type to shell
javorszky a87153c
Turn choice into unordered list
javorszky 9cbb395
Replace const default pkce secret with init val
javorszky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,24 @@ application using an OpenID Connect policy and [Keycloak](https://www.keycloak.o | |
|
||
**Note**: The KeyCloak container does not support IPv6 environments. | ||
|
||
**Note**: This example assumes that your default namespace is set to `default`. You can check this with | ||
|
||
```shell | ||
kubectl config view --minify | grep namespace | ||
``` | ||
|
||
If it's not empty, and anything other than `default`, you can set to `default` with the following command: | ||
|
||
```shell | ||
kubectl config set-context --namespace default --current | ||
``` | ||
|
||
## Prerequisites | ||
|
||
1. Follow the [installation](https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/) | ||
instructions to deploy the Ingress Controller. This example requires that the HTTPS port of the Ingress Controller is | ||
`443`. | ||
1. Save the public IP address of the Ingress Controller into `/etc/hosts` of your machine: | ||
instructions to deploy NGINX Ingress Controller. This example requires that the HTTPS port of the Ingress | ||
Controller is `443`. | ||
2. Save the public IP address of the Ingress Controller into `/etc/hosts` of your machine: | ||
|
||
```text | ||
... | ||
|
@@ -27,29 +39,29 @@ application using an OpenID Connect policy and [Keycloak](https://www.keycloak.o | |
Create a secret with the TLS certificate and key that will be used for TLS termination of the web application and | ||
Keycloak: | ||
|
||
```console | ||
```shell | ||
kubectl apply -f tls-secret.yaml | ||
``` | ||
|
||
## Step 2 - Deploy a Web Application | ||
|
||
Create the application deployment and service: | ||
|
||
```console | ||
```shell | ||
kubectl apply -f webapp.yaml | ||
``` | ||
|
||
## Step 3 - Deploy Keycloak | ||
|
||
1. Create the Keycloak deployment and service: | ||
|
||
```console | ||
```shell | ||
kubectl apply -f keycloak.yaml | ||
``` | ||
|
||
1. Create a VirtualServer resource for Keycloak: | ||
2. Create a VirtualServer resource for Keycloak: | ||
|
||
```console | ||
```shell | ||
kubectl apply -f virtual-server-idp.yaml | ||
``` | ||
|
||
|
@@ -59,27 +71,30 @@ To set up Keycloak: | |
|
||
1. Follow the steps in the "Configuring Keycloak" [section of the documentation](https://docs.nginx.com/nginx/deployment-guides/single-sign-on/keycloak/#configuring-keycloak): | ||
1. To connect to Keycloak, use `https://keycloak.example.com`. | ||
1. Make sure to save the client secret for NGINX-Plus client to the `SECRET` shell variable: | ||
2. Make sure to save the client secret for NGINX-Plus client to the `SECRET` shell variable: | ||
|
||
```console | ||
```shell | ||
SECRET=value | ||
``` | ||
|
||
1. Alternatively, [execute the commands](./keycloak_setup.md). | ||
2. Alternatively, [execute the commands](./keycloak_setup.md). | ||
|
||
## Step 5 - Deploy the Client Secret | ||
|
||
**Note**: If you're using PKCE, skip this step. PKCE clients do not have client secrets. Applying this will result | ||
in a broken deployment. | ||
|
||
Comment on lines
+84
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do our examples have branching logic in them? I thought they we single use examples. |
||
1. Encode the secret, obtained in the previous step: | ||
|
||
```console | ||
```shell | ||
echo -n $SECRET | base64 | ||
``` | ||
|
||
1. Edit `client-secret.yaml`, replacing `<insert-secret-here>` with the encoded secret. | ||
2. Edit `client-secret.yaml`, replacing `<insert-secret-here>` with the encoded secret. | ||
|
||
1. Create a secret with the name `oidc-secret` that will be used by the OIDC policy: | ||
3. Create a secret with the name `oidc-secret` that will be used by the OIDC policy: | ||
|
||
```console | ||
```shell | ||
kubectl apply -f client-secret.yaml | ||
``` | ||
|
||
|
@@ -96,23 +111,23 @@ Steps: | |
|
||
1. Apply the ConfigMap `nginx-config.yaml`, which contains `zone-sync` configuration parameter that enable zone synchronization and the resolver using the kube-dns service. | ||
|
||
```console | ||
```shell | ||
kubectl apply -f nginx-config.yaml | ||
``` | ||
|
||
## Step 7 - Deploy the OIDC Policy | ||
|
||
Create a policy with the name `oidc-policy` that references the secret from the previous step: | ||
|
||
```console | ||
```shell | ||
kubectl apply -f oidc.yaml | ||
``` | ||
|
||
## Step 8 - Configure Load Balancing | ||
|
||
Create a VirtualServer resource for the web application: | ||
|
||
```console | ||
```shell | ||
kubectl apply -f virtual-server.yaml | ||
``` | ||
|
||
|
@@ -122,15 +137,15 @@ Note that the VirtualServer references the policy `oidc-policy` created in Step | |
|
||
1. Open a web browser and navigate to the URL of the web application: `https://webapp.example.com`. You will be | ||
redirected to Keycloak. | ||
1. Log in with the username and password for the user you created in Keycloak, `nginx-user` and `test`. | ||
2. Log in with the username and password for the user you created in Keycloak, `nginx-user` and `test`. | ||
 | ||
1. Once logged in, you will be redirected to the web application and get a response from it. Notice the field `User ID` | ||
3. Once logged in, you will be redirected to the web application and get a response from it. Notice the field `User ID` | ||
in the response, this will match the ID for your user in Keycloak.  | ||
|
||
## Step 10 - Log Out | ||
|
||
1. To log out, navigate to `https://webapp.example.com/logout`. Your session will be terminated, and you will be | ||
redirected to the default post logout URI `https://webapp.example.com/_logout`. | ||
 | ||
1. To confirm that you have been logged out, navigate to `https://webapp.example.com`. You will be redirected to | ||
2. To confirm that you have been logged out, navigate to `https://webapp.example.com`. You will be redirected to | ||
Keycloak to log in again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# https://nginx.org/en/docs/http/ngx_http_keyval_module.html | ||
# context: http | ||
|
||
# keyval_zone keyval_zone zone=name:size [state=file] [timeout=time] [type=string|ip|prefix] [sync]; | ||
keyval_zone zone=oidc_pkce:128K timeout=90s sync; # Temporary storage for PKCE code verifier. | ||
|
||
# keyval key $variable zone | ||
keyval $pkce_id $pkce_code_verifier zone=oidc_pkce; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.