Skip to content

Commit 4cb7cb1

Browse files
committed
Refactor Keycloak
1 parent ba42118 commit 4cb7cb1

9 files changed

Lines changed: 78 additions & 115 deletions

File tree

‎hack/e2e.sh‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ machine:
124124
op: create
125125
126126
cluster:
127+
apiServer:
128+
extraArgs:
129+
oidc-issuer-url: "https://keycloak.example.org/realms/cozy"
130+
oidc-client-id: "kubernetes"
131+
oidc-username-claim: "preferred_username"
132+
oidc-groups-claim: "groups"
127133
network:
128134
cni:
129135
name: none
@@ -182,7 +188,8 @@ timeout 60 sh -c 'until nc -nzv 192.168.123.11 50000 && nc -nzv 192.168.123.12 5
182188
timeout 10 sh -c 'until talosctl bootstrap -n 192.168.123.11 -e 192.168.123.11; do sleep 1; done'
183189

184190
# Wait for etcd
185-
timeout 180 sh -c 'while talosctl etcd members -n 192.168.123.11,192.168.123.12,192.168.123.13 -e 192.168.123.10 2>&1 | grep "rpc error"; do sleep 1; done'
191+
timeout 180 sh -c 'until timeout -s 9 2 talosctl etcd members -n 192.168.123.11,192.168.123.12,192.168.123.13 -e 192.168.123.10 2>&1; do sleep 1; done'
192+
timeout 60 sh -c 'while talosctl etcd members -n 192.168.123.11,192.168.123.12,192.168.123.13 -e 192.168.123.10 2>&1 | grep "rpc error"; do sleep 1; done'
186193

187194
rm -f kubeconfig
188195
talosctl kubeconfig kubeconfig -e 192.168.123.10 -n 192.168.123.10
@@ -203,6 +210,8 @@ data:
203210
ipv4-pod-gateway: "10.244.0.1"
204211
ipv4-svc-cidr: "10.96.0.0/16"
205212
ipv4-join-cidr: "100.64.0.0/16"
213+
root-host: example.org
214+
api-server-endpoint: https://192.168.123.10:6443
206215
EOT
207216

208217
#
@@ -287,23 +296,23 @@ spec:
287296
avoidBuggyIPs: false
288297
EOT
289298

290-
kubectl patch -n tenant-root hr/tenant-root --type=merge -p '{"spec":{ "values":{
299+
kubectl patch -n tenant-root tenants.apps.cozystack.io root --type=merge -p '{"spec":{
291300
"host": "example.org",
292301
"ingress": true,
293302
"monitoring": true,
294303
"etcd": true,
295304
"isolated": true
296-
}}}'
305+
}}'
297306

298307
# Wait for HelmRelease be created
299308
timeout 60 sh -c 'until kubectl get hr -n tenant-root etcd ingress monitoring tenant-root; do sleep 1; done'
300309

301310
# Wait for HelmReleases be installed
302311
kubectl wait --timeout=2m --for=condition=ready -n tenant-root hr etcd ingress monitoring tenant-root
303312

304-
kubectl patch -n tenant-root hr/ingress --type=merge -p '{"spec":{ "values":{
313+
kubectl patch -n tenant-root ingresses.apps.cozystack.io ingress --type=merge -p '{"spec":{
305314
"dashboard": true
306-
}}}'
315+
}}'
307316

308317
# Wait for nginx-ingress-controller
309318
timeout 60 sh -c 'until kubectl get deploy -n tenant-root root-ingress-controller; do sleep 1; done'
@@ -326,3 +335,12 @@ ip=$(kubectl get svc -n tenant-root root-ingress-controller -o jsonpath='{.statu
326335

327336
# Check Grafana
328337
curl -sS -k "https://$ip" -H 'Host: grafana.example.org' | grep Found
338+
339+
340+
# Test OIDC
341+
kubectl patch -n cozy-system cm/cozystack --type=merge -p '{"data":{
342+
"oidc-enabled": "true"
343+
}}'
344+
345+
timeout 60 sh -c 'until kubectl get hr -n cozy-keycloak keycloak keycloak-configure keycloak-operator; do sleep 1; done'
346+
kubectl wait --timeout=10m --for=condition=ready -n cozy-keycloak hr keycloak keycloak-configure keycloak-operator
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
name: {{ include "tenant.name" . }}-dashboard-resources
5+
namespace: {{ .Release.namespace }}
6+
rules:
7+
- apiGroups:
8+
- ""
9+
resources:
10+
- secrets
11+
resourceNames:
12+
- kubeconfig-{{ include "tenant.name" . }}
13+
verbs: ["get", "list", "watch"]

‎packages/apps/tenant/templates/keycloakgroups.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{{- $cozyConfig := lookup "v1" "ConfigMap" "cozy-system" "cozystack" }}
2+
{{- $oidcEnabled := index $cozyConfig.data "oidc-enabled" }}
3+
{{- if $oidcEnabled }}
14
apiVersion: v1.edp.epam.com/v1
25
kind: KeycloakRealmGroup
36
metadata:
@@ -47,3 +50,4 @@ spec:
4750
realmRef:
4851
name: keycloakrealm-cozy
4952
kind: ClusterKeycloakRealm
53+
{{- end }}
Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
{{- $cozyConfig := lookup "v1" "ConfigMap" "cozy-system" "cozystack" }}
22
{{- $host := index $cozyConfig.data "root-host" }}
3-
{{- $apiServerAdress := index $cozyConfig.data "api-server-adress" }}
43
{{- $k8sClientSecret := lookup "v1" "Secret" "cozy-keycloak" "k8s-client" }}
4+
5+
{{- if $k8sClientSecret }}
6+
{{- $apiServerEndpoint := index $cozyConfig.data "api-server-endpoint" }}
57
{{- $k8sClient := index $k8sClientSecret.data "client-secret-key" | b64dec }}
68
{{- $rootSaConfigMap := lookup "v1" "ConfigMap" "kube-system" "kube-root-ca.crt" }}
79
{{- $k8sCa := index $rootSaConfigMap.data "ca.crt" | b64enc }}
8-
9-
apiVersion: rbac.authorization.k8s.io/v1
10-
kind: Role
11-
metadata:
12-
name: {{ include "tenant.name" . }}-dashboard-resources
13-
namespace: {{ .Release.namespace }}
14-
rules:
15-
- apiGroups:
16-
- ""
17-
resources:
18-
- secrets
19-
resourceNames:
20-
- kubeconfig-{{ include "tenant.name" . }}
21-
verbs: ["get", "list", "watch"]
22-
23-
2410
---
25-
2611
apiVersion: v1
2712
kind: Secret
2813
metadata:
@@ -33,7 +18,7 @@ stringData:
3318
apiVersion: v1
3419
clusters:
3520
- cluster:
36-
server: https://{{ $apiServerAdress }}:6443
21+
server: {{ $apiServerEndpoint }}
3722
certificate-authority-data: {{ $k8sCa }}
3823
name: cluster
3924
contexts:
@@ -57,3 +42,4 @@ stringData:
5742
- --skip-open-browser
5843
- --grant-type=password
5944
command: kubectl
45+
{{- end }}

‎packages/core/platform/bundles/distro-full.yaml‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,3 @@ releases:
188188
namespace: cozy-keycloak
189189
optional: true
190190
dependsOn: [keycloak]
191-
192-
- name: keycloak-configure
193-
releaseName: keycloak-configure
194-
chart: cozy-keycloak-configure
195-
namespace: cozy-keycloak
196-
optional: true
197-
dependsOn: [keycloak-operator]

‎packages/core/platform/bundles/distro-hosted.yaml‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,3 @@ releases:
138138
namespace: cozy-keycloak
139139
optional: true
140140
dependsOn: [keycloak]
141-
142-
- name: keycloak-configure
143-
releaseName: keycloak-configure
144-
chart: cozy-keycloak-configure
145-
namespace: cozy-keycloak
146-
optional: true
147-
dependsOn: [keycloak-operator]

‎packages/core/platform/bundles/paas-full.yaml‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{{- $cozyConfig := lookup "v1" "ConfigMap" "cozy-system" "cozystack" }}
2+
{{- $oidcEnabled := index $cozyConfig.data "oidc-enabled" }}
23
{{- $host := index $cozyConfig.data "root-host" }}
34
{{- if not $host }}
45
{{- fail "ERROR need root-host in cozystack ConfigMap" }}
56
{{- end }}
7+
{{- $apiServerEndpoint := index $cozyConfig.data "api-server-endpoint" }}
8+
{{- if not $apiServerEndpoint }}
9+
{{- fail "ERROR need api-server-endpoint in cozystack ConfigMap" }}
10+
{{- end }}
611

712
releases:
813
- name: fluxcd-operator
@@ -205,10 +210,6 @@ releases:
205210
chart: cozy-dashboard
206211
namespace: cozy-dashboard
207212
dependsOn: [cilium,kubeovn,keycloak-configure]
208-
valuesFrom:
209-
- kind: ConfigMap
210-
name: kubeapps-auth-config
211-
valuesKey: values.yaml
212213
{{- if .Capabilities.APIVersions.Has "source.toolkit.fluxcd.io/v1" }}
213214
{{- with (lookup "source.toolkit.fluxcd.io/v1" "HelmRepository" "cozy-public" "").items }}
214215
values:
@@ -222,6 +223,15 @@ releases:
222223
{{- end }}
223224
{{- end }}
224225
{{- end }}
226+
{{- if $oidcEnabled }}
227+
dependsOn: [keycloak-configure]
228+
valuesFrom:
229+
- kind: ConfigMap
230+
name: kubeapps-auth-config
231+
valuesKey: values.yaml
232+
{{- else }}
233+
dependsOn: []
234+
{{- end }}
225235

226236
- name: kamaji
227237
releaseName: kamaji
@@ -257,6 +267,7 @@ releases:
257267
optional: true
258268
dependsOn: [cilium,kubeovn]
259269

270+
{{- if $oidcEnabled }}
260271
- name: keycloak
261272
releaseName: keycloak
262273
chart: cozy-keycloak
@@ -274,3 +285,4 @@ releases:
274285
chart: cozy-keycloak-configure
275286
namespace: cozy-keycloak
276287
dependsOn: [keycloak-operator]
288+
{{- end }}

‎packages/core/platform/bundles/paas-hosted.yaml‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{{- $cozyConfig := lookup "v1" "ConfigMap" "cozy-system" "cozystack" }}
2+
{{- $oidcEnabled := index $cozyConfig.data "oidc-enabled" }}
23
{{- $host := index $cozyConfig.data "root-host" }}
34
{{- if not $host }}
45
{{- fail "ERROR need root-host in cozystack ConfigMap" }}
56
{{- end }}
7+
{{- $apiServerEndpoint := index $cozyConfig.data "api-server-endpoint" }}
8+
{{- if not $apiServerEndpoint }}
9+
{{- fail "ERROR need api-server-endpoint in cozystack ConfigMap" }}
10+
{{- end }}
611

712
releases:
813
- name: fluxcd-operator
@@ -134,11 +139,6 @@ releases:
134139
releaseName: dashboard
135140
chart: cozy-dashboard
136141
namespace: cozy-dashboard
137-
dependsOn: [keycloak-configure]
138-
valuesFrom:
139-
- kind: ConfigMap
140-
name: kubeapps-auth-config
141-
valuesKey: values.yaml
142142
{{- if .Capabilities.APIVersions.Has "source.toolkit.fluxcd.io/v1" }}
143143
{{- with (lookup "source.toolkit.fluxcd.io/v1" "HelmRepository" "cozy-public" "").items }}
144144
values:
@@ -153,7 +153,17 @@ releases:
153153
{{- end }}
154154
{{- end }}
155155
{{- end }}
156+
{{- if $oidcEnabled }}
157+
dependsOn: [keycloak-configure]
158+
valuesFrom:
159+
- kind: ConfigMap
160+
name: kubeapps-auth-config
161+
valuesKey: values.yaml
162+
{{- else }}
163+
dependsOn: []
164+
{{- end }}
156165

166+
{{- if $oidcEnabled }}
157167
- name: keycloak
158168
releaseName: keycloak
159169
chart: cozy-keycloak
@@ -171,3 +181,4 @@ releases:
171181
chart: cozy-keycloak-configure
172182
namespace: cozy-keycloak
173183
dependsOn: [keycloak-operator]
184+
{{- end }}

‎packages/system/keycloak-configure/templates/configure-kk.yaml‎

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{{- $cozyConfig := lookup "v1" "ConfigMap" "cozy-system" "cozystack" }}
22
{{- $host := index $cozyConfig.data "root-host" }}
3-
{{- $apiServerAdress := index $cozyConfig.data "api-server-adress" }}
43
{{- $k8sClient := randAlphaNum 32 -}}
54
{{- $kubeappsClient := randAlphaNum 32 -}}
65
{{- $rootSaConfigMap := lookup "v1" "ConfigMap" "kube-system" "kube-root-ca.crt" }}
@@ -82,7 +81,7 @@ spec:
8281
clientId: kubernetes
8382
directAccess: true
8483
public: false
85-
webUrl: https://{{ $apiServerAdress }}/oauth2/callback
84+
webUrl: https://localhost:8000/oauth2/callback
8685
webOrigins:
8786
- /*
8887
defaultClientScopes:
@@ -175,69 +174,3 @@ data:
175174
- --cookie-secure=false
176175
- --scope=openid email groups
177176
- --oidc-issuer-url=https://keycloak.{{ $host }}/realms/cozy
178-
179-
---
180-
181-
apiVersion: v1.edp.epam.com/v1
182-
kind: KeycloakRealmGroup
183-
metadata:
184-
name: kubeapps-admin
185-
namespace: {{ include "tenant.name" . }}
186-
spec:
187-
name: kubeapps-admin
188-
realmRef:
189-
name: keycloakrealm-cozy
190-
kind: ClusterKeycloakRealm
191-
192-
---
193-
194-
apiVersion: rbac.authorization.k8s.io/v1
195-
kind: Role
196-
metadata:
197-
name: tenant-root-dashboard-resources
198-
namespace: tenant-root
199-
rules:
200-
- apiGroups:
201-
- ""
202-
resources:
203-
- secrets
204-
resourceNames:
205-
- kubeconfig
206-
verbs: ["get", "list", "watch"]
207-
208-
209-
---
210-
211-
apiVersion: v1
212-
kind: Secret
213-
metadata:
214-
name: kubeconfig
215-
namespace: tenant-root
216-
stringData:
217-
kubeconfig: |
218-
apiVersion: v1
219-
clusters:
220-
- cluster:
221-
server: https://{{ $apiServerAdress }}:6443
222-
certificate-authority-data: {{ $k8sCa }}
223-
name: cluster
224-
contexts:
225-
- context:
226-
cluster: cluster
227-
user: keycloak
228-
name: default
229-
current-context: default
230-
users:
231-
- name: keycloak
232-
user:
233-
exec:
234-
apiVersion: client.authentication.k8s.io/v1beta1
235-
args:
236-
- oidc-login
237-
- get-token
238-
- --oidc-issuer-url=https://keycloak.{{ $host }}/realms/cozy
239-
- --oidc-client-id=kubernetes
240-
- --oidc-client-secret={{ $k8sClient }}
241-
- --skip-open-browser
242-
- --grant-type=password
243-
command: kubectl

0 commit comments

Comments
 (0)