-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ingress for rewriting Keycloak requests from /auth to /
Keycloak based on Wilfly had a default relativ path of /auth. Since the migration to Quarkus this would be / by default. Existing clients can not be migrated in a big bang scenario. This adds the capability to serve the Keycloak requests on / and /auth at the same time. NGNIX-Ingress and OpenShift has been tested.
- Loading branch information
Gabriel Mainberger
committed
Sep 18, 2023
1 parent
c422e2f
commit c7a2555
Showing
48 changed files
with
1,576 additions
and
2 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
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,64 @@ | ||
local kap = import 'lib/kapitan.libjsonnet'; | ||
local kube = import 'lib/kube.libjsonnet'; | ||
local inv = kap.inventory(); | ||
local params = inv.parameters.keycloak; | ||
|
||
local ingress_name = 'keycloakx-auth-rewrite'; | ||
local keycloak_name = 'keycloakx'; | ||
local ingress_class_name = | ||
if params.ingressAuthRewrite.ingressClassName != null then | ||
{ ingressClassName: params.ingressAuthRewrite.ingressClassName } | ||
else | ||
{}; | ||
local ingress_path = | ||
if inv.parameters.facts.distribution == 'openshift4' then | ||
'/auth' | ||
else | ||
'/auth(/|$)(.*)'; | ||
|
||
local ingress = | ||
kube.Ingress(ingress_name) { | ||
metadata+: { | ||
annotations: params.ingressAuthRewrite.annotations, | ||
labels: params.labels, | ||
}, | ||
spec+: | ||
ingress_class_name | ||
{ | ||
rules: [ | ||
{ | ||
host: params.fqdn, | ||
http: | ||
{ | ||
paths: [ | ||
{ | ||
path: ingress_path, | ||
pathType: 'Prefix', | ||
backend: { | ||
service: { | ||
name: keycloak_name + '-http', | ||
port: { | ||
name: params.helm_values.ingress.servicePort, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
tls: [ | ||
{ | ||
hosts: [ | ||
params.fqdn, | ||
], | ||
secretName: params.ingressAuthRewrite.tls.secretName, | ||
}, | ||
], | ||
|
||
}, | ||
}; | ||
|
||
{ | ||
[if params.ingressAuthRewrite.enabled then '20_ingress_auth_rewrite']: ingress, | ||
} |
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,52 @@ | ||
--- | ||
applications: | ||
- prometheus | ||
|
||
parameters: | ||
kapitan: | ||
dependencies: | ||
- type: https | ||
source: https://raw.githubusercontent.com/projectsyn/component-prometheus/master/lib/prometheus.libsonnet | ||
output_path: vendor/lib/prometheus.libsonnet | ||
|
||
prometheus: | ||
defaultInstance: monitoring | ||
|
||
keycloak: | ||
namespaceLabels: | ||
test: testing | ||
extraEnv: | ||
FOO: | ||
value: "bar" | ||
KC_DB_URL_PORT: | ||
value: "patched" | ||
extraInitContainers: | ||
theme-provider: | ||
image: company/keycloak-theme:v1.0.0 | ||
imagePullPolicy: IfNotPresent | ||
command: | ||
- sh | ||
args: | ||
- -c | ||
- | | ||
echo "Copying theme..." | ||
cp -R /theme/* /company-theme | ||
volumeMounts: | ||
- name: theme | ||
mountPath: /company-theme | ||
extraVolumes: | ||
theme: | ||
emptyDir: {} | ||
extraVolumeMounts: | ||
test: | ||
name: theme | ||
readOnly: true | ||
mountPath: /opt/test | ||
ingressAuthRewrite: | ||
enabled: true | ||
helm_values: | ||
networkPolicy: | ||
enabled: true | ||
http: | ||
# Default for Keycloak Quarkus | ||
relativePath: "/" |
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,21 @@ | ||
package builtin_auth_rewrite | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/projectsyn/component-keycloak/common" | ||
"github.com/stretchr/testify/assert" | ||
networkingv1 "k8s.io/api/networking/v1" | ||
) | ||
|
||
var ( | ||
basePath = "../../compiled/builtin-auth-rewrite/builtin-auth-rewrite" | ||
ingressPath = "/20_ingress_auth_rewrite.yaml" | ||
) | ||
|
||
func Test_IngressApiVersion(t *testing.T) { | ||
subject := &networkingv1.Ingress{} | ||
scheme := common.NewSchemeWithDefault(t) | ||
ingress := common.DecodeWithSchema(t, basePath+ingressPath, subject, scheme).(*networkingv1.Ingress) | ||
assert.Equal(t, "keycloakx-auth-rewrite", ingress.Name) | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/golden/builtin-auth-rewrite/builtin-auth-rewrite/apps/builtin-auth-rewrite.yaml
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,6 @@ | ||
spec: | ||
ignoreDifferences: | ||
- group: '' | ||
jsonPointers: | ||
- /imagePullSecrets | ||
kind: ServiceAccount |
9 changes: 9 additions & 0 deletions
9
...s/golden/builtin-auth-rewrite/builtin-auth-rewrite/builtin-auth-rewrite/00_namespace.yaml
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,9 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
annotations: {} | ||
labels: | ||
monitoring.syn.tools/monitoring: 'true' | ||
name: syn-builtin-auth-rewrite | ||
test: testing | ||
name: syn-builtin-auth-rewrite |
32 changes: 32 additions & 0 deletions
32
...-auth-rewrite/builtin-auth-rewrite/01_keycloak_helmchart/keycloakx/templates/ingress.yaml
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,32 @@ | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
annotations: | ||
cert-manager.io/cluster-issuer: letsencrypt-production | ||
nginx.ingress.kubernetes.io/backend-protocol: HTTPS | ||
route.openshift.io/termination: reencrypt | ||
labels: | ||
app.kubernetes.io/component: keycloak | ||
app.kubernetes.io/instance: builtin-auth-rewrite | ||
app.kubernetes.io/managed-by: commodore | ||
app.kubernetes.io/name: keycloak | ||
app.kubernetes.io/version: 20.0.3 | ||
helm.sh/chart: keycloakx-2.2.1 | ||
name: keycloakx | ||
namespace: syn-builtin-auth-rewrite | ||
spec: | ||
rules: | ||
- host: keycloak.example.com | ||
http: | ||
paths: | ||
- backend: | ||
service: | ||
name: keycloakx-http | ||
port: | ||
name: https | ||
path: / | ||
pathType: Prefix | ||
tls: | ||
- hosts: | ||
- keycloak.example.com | ||
secretName: ingress-tls |
41 changes: 41 additions & 0 deletions
41
...rewrite/builtin-auth-rewrite/01_keycloak_helmchart/keycloakx/templates/networkpolicy.yaml
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,41 @@ | ||
apiVersion: networking.k8s.io/v1 | ||
kind: NetworkPolicy | ||
metadata: | ||
labels: | ||
app.kubernetes.io/instance: keycloakx | ||
app.kubernetes.io/managed-by: Helm | ||
app.kubernetes.io/name: keycloakx | ||
app.kubernetes.io/version: 20.0.3 | ||
helm.sh/chart: keycloakx-2.2.1 | ||
name: keycloakx | ||
namespace: syn-builtin-auth-rewrite | ||
spec: | ||
ingress: | ||
- from: | ||
- namespaceSelector: | ||
matchLabels: | ||
kubernetes.io/metadata.name: ingress-nginx | ||
podSelector: | ||
matchLabels: | ||
app.kubernetes.io/name: ingress-nginx | ||
ports: | ||
- port: 8080 | ||
protocol: TCP | ||
- port: 8443 | ||
protocol: TCP | ||
- from: | ||
- podSelector: | ||
matchLabels: | ||
app.kubernetes.io/instance: keycloakx | ||
app.kubernetes.io/name: keycloakx | ||
ports: | ||
- port: 8080 | ||
protocol: TCP | ||
- port: 8443 | ||
protocol: TCP | ||
podSelector: | ||
matchLabels: | ||
app.kubernetes.io/instance: keycloakx | ||
app.kubernetes.io/name: keycloakx | ||
policyTypes: | ||
- Ingress |
16 changes: 16 additions & 0 deletions
16
...ewrite/builtin-auth-rewrite/01_keycloak_helmchart/keycloakx/templates/prometheusrule.yaml
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,16 @@ | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: PrometheusRule | ||
metadata: | ||
labels: | ||
app.kubernetes.io/component: keycloak | ||
app.kubernetes.io/instance: builtin-auth-rewrite | ||
app.kubernetes.io/managed-by: commodore | ||
app.kubernetes.io/name: keycloak | ||
app.kubernetes.io/version: 20.0.3 | ||
helm.sh/chart: keycloakx-2.2.1 | ||
name: keycloakx | ||
namespace: syn-builtin-auth-rewrite | ||
spec: | ||
groups: | ||
- name: keycloakx | ||
rules: [] |
Oops, something went wrong.