-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Dean Coakley <[email protected]> Co-authored-by: Michael Pleshakov <[email protected]> Co-authored-by: Mike Stephen <[email protected]>
- Loading branch information
1 parent
1ba5b5c
commit 5b0b177
Showing
42 changed files
with
2,282 additions
and
403 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -6,6 +6,7 @@ FROM debian:buster-slim AS base | |
LABEL maintainer="NGINX Docker Maintainers <[email protected]>" | ||
|
||
ENV NGINX_PLUS_VERSION 23-1~buster | ||
ENV NGINX_NJS_VERSION 23+0.5.0-1~buster | ||
ARG IC_VERSION | ||
|
||
# Download certificate and key from the customer portal (https://cs.nginx.com) | ||
|
@@ -36,7 +37,7 @@ RUN --mount=type=secret,id=nginx-repo.crt \ | |
&& echo "Acquire::https::plus-pkgs.nginx.com::SslKey \"/etc/ssl/nginx/nginx-repo.key\";" >> /etc/apt/apt.conf.d/90nginx \ | ||
&& echo "Acquire::https::plus-pkgs.nginx.com::User-Agent \"k8s-ic-$IC_VERSION-apt\";" >> /etc/apt/apt.conf.d/90nginx \ | ||
&& printf "deb https://plus-pkgs.nginx.com/debian buster nginx-plus\n" > /etc/apt/sources.list.d/nginx-plus.list \ | ||
&& apt-get update && apt-get install -y nginx-plus=${NGINX_PLUS_VERSION} \ | ||
&& apt-get update && apt-get install -y nginx-plus=${NGINX_PLUS_VERSION} nginx-plus-module-njs=${NGINX_NJS_VERSION} \ | ||
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \ | ||
'cap_net_bind_service=+ep' /usr/sbin/nginx-debug \ | ||
&& apt-get remove --purge --auto-remove -y gnupg1 \ | ||
|
@@ -54,9 +55,10 @@ RUN ln -sf /proc/1/fd/1 /var/log/nginx/access.log \ | |
RUN mkdir -p /var/lib/nginx \ | ||
/etc/nginx/secrets \ | ||
/etc/nginx/stream-conf.d \ | ||
/etc/nginx/oidc \ | ||
&& chown -R nginx:0 /etc/nginx \ | ||
/var/cache/nginx \ | ||
/var/lib/nginx/ \ | ||
/var/cache/nginx \ | ||
/var/lib/nginx/ \ | ||
&& apt-get remove --purge -y libcap2-bin \ | ||
&& rm /etc/nginx/conf.d/* | ||
|
||
|
@@ -67,6 +69,8 @@ COPY internal/configs/version1/nginx-plus.ingress.tmpl \ | |
internal/configs/version2/nginx-plus.virtualserver.tmpl \ | ||
internal/configs/version2/nginx-plus.transportserver.tmpl / | ||
|
||
COPY internal/configs/oidc/* /etc/nginx/oidc/ | ||
|
||
# Uncomment the line below if you would like to add the default.pem to the image | ||
# and use it as a certificate and key for the default server | ||
# ADD default.pem /etc/nginx/secrets/default | ||
|
This file contains 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 |
---|---|---|
|
@@ -14,6 +14,7 @@ FROM debian:buster-slim AS base | |
LABEL maintainer="NGINX Docker Maintainers <[email protected]>" | ||
|
||
ENV NGINX_PLUS_VERSION 23-1~buster | ||
ENV NGINX_NJS_VERSION 23+0.5.0-1~buster | ||
ENV NGINX_OPENTRACING_MODULE_VERSION 23+0.9.0-1~buster | ||
|
||
ARG IC_VERSION | ||
|
@@ -47,7 +48,7 @@ RUN --mount=type=secret,id=nginx-repo.crt \ | |
&& echo "Acquire::https::plus-pkgs.nginx.com::User-Agent \"k8s-ic-$IC_VERSION-apt\";" >> /etc/apt/apt.conf.d/90nginx \ | ||
&& printf "deb https://plus-pkgs.nginx.com/debian buster nginx-plus\n" > /etc/apt/sources.list.d/nginx-plus.list \ | ||
&& apt-get update && apt-get install -y \ | ||
nginx-plus=${NGINX_PLUS_VERSION} \ | ||
nginx-plus=${NGINX_PLUS_VERSION} nginx-plus-module-njs=${NGINX_NJS_VERSION} \ | ||
# Install OpenTracing module | ||
nginx-plus-module-opentracing=${NGINX_OPENTRACING_MODULE_VERSION} \ | ||
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \ | ||
|
@@ -70,9 +71,10 @@ COPY --from=tracer-downloader /usr/local/lib/libjaegertracing_plugin.so /usr/loc | |
RUN mkdir -p /var/lib/nginx \ | ||
/etc/nginx/secrets \ | ||
/etc/nginx/stream-conf.d \ | ||
/etc/nginx/oidc \ | ||
&& chown -R nginx:0 /etc/nginx \ | ||
/var/cache/nginx \ | ||
/var/lib/nginx/ \ | ||
/var/cache/nginx \ | ||
/var/lib/nginx/ \ | ||
&& apt-get remove --purge -y libcap2-bin \ | ||
&& rm /etc/nginx/conf.d/* | ||
|
||
|
@@ -83,6 +85,8 @@ COPY internal/configs/version1/nginx-plus.ingress.tmpl \ | |
internal/configs/version2/nginx-plus.virtualserver.tmpl \ | ||
internal/configs/version2/nginx-plus.transportserver.tmpl / | ||
|
||
COPY internal/configs/oidc/* /etc/nginx/oidc/ | ||
|
||
# Uncomment the line below if you would like to add the default.pem to the image | ||
# and use it as a certificate and key for the default server | ||
# ADD default.pem /etc/nginx/secrets/default | ||
|
This file contains 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 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 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 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 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 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,98 @@ | ||
# OIDC | ||
|
||
In this example, we deploy keycloak and a web application configure load balancing for it via a VirtualServer, and apply an OpenID Connect policy. | ||
|
||
## Prerequisites | ||
|
||
1. Follow the [installation](https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/) instructions to deploy the Ingress Controller. | ||
1. Save the public IP address of the Ingress Controller into `/etc/hosts`: | ||
``` | ||
... | ||
XXX.YYY.ZZZ.III webapp.example.com | ||
XXX.YYY.ZZZ.III keycloak.example.com | ||
``` | ||
## Step 1 - Deploy a Web Application | ||
Create the application deployment and service: | ||
``` | ||
$ kubectl apply -f webapp.yaml | ||
``` | ||
## Step 2 - Deploy Keycloak | ||
1. Create keycloak deployment and service: | ||
``` | ||
$ kubectl apply -f keycloak.yaml | ||
``` | ||
1. Create a VirtualServer resource for Keycloak: | ||
``` | ||
$ kubectl apply -f virtual-server-idp.yaml | ||
``` | ||
To set up Keycloak, you can either follow the steps in the "Configuring Keycloak" section of the documentation [here](https://docs.nginx.com/nginx/deployment-guides/single-sign-on/keycloak/#configuring-keycloak) or execute the commands [here](./keycloak_setup.md). | ||
## Step 3 - Deploy the Client Secret | ||
1. Edit `client-secret.yaml` with your secret. | ||
1. Create a secret with the name `oidc-secret` that will be used for OIDC validation: | ||
``` | ||
$ kubectl apply -f client-secret.yaml | ||
``` | ||
## Step 4 - Deploy the OIDC Policy | ||
1. Modify the URL `authEndpoint` in `oidc.yaml` with the public IP address or DNS of keycloak. | ||
1. Create a policy with the name `oidc-policy` that references the secret from the previous step: | ||
``` | ||
$ kubectl apply -f oidc.yaml | ||
``` | ||
## Step 5 - Deploy the Service for the Ingress Controller and update ConfigMap | ||
1. Deploy the service for Ingress Controller. | ||
``` | ||
$ kubectl apply -f service/nodeport.yaml | ||
``` | ||
1. Update the ConfigMap with the config required for OIDC. | ||
```yaml | ||
kind: ConfigMap | ||
apiVersion: v1 | ||
metadata: | ||
name: nginx-config | ||
namespace: nginx-ingress | ||
data: | ||
stream-snippets: | | ||
resolver 10.96.0.10 valid=5s; | ||
server { | ||
listen 12345; | ||
zone_sync; | ||
zone_sync_server nginx-ingress.nginx-ingress.svc.cluster.local:12345 resolve; | ||
} | ||
resolver: 10.96.0.10 | ||
resolver-valid: 5s | ||
``` | ||
1. Apply the ConfigMap. | ||
``` | ||
$ kubectl apply -f common/nginx-config.yaml | ||
``` | ||
## Step 6 - Configure Load Balancing and TLS Termination | ||
1. Create the secret with the TLS certificate and key: | ||
``` | ||
$ kubectl create -f tls-secret.yaml | ||
``` | ||
2. Create a VirtualServer resource for the web application: | ||
``` | ||
$ kubectl apply -f virtual-server.yaml | ||
``` | ||
Note that the VirtualServer references the policy `oidc-policy` created in Step 4. | ||
## Step 5 - Test the Configuration | ||
Open a web browser and navigate to the URL of the Ingress Controller |
This file contains 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,7 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: oidc-secret | ||
type: nginx.org/oidc | ||
data: | ||
client-secret: c3VwZXItc2VjcmV0IQo |
Oops, something went wrong.