diff --git a/src/main/helm/templates/_helpers.tpl b/src/main/helm/templates/_helpers.tpl index d59b652ef42c838efa9acc93c794dc93d864c8c9..e6d9c8ad3c0c651c342697ccc99a741a46791248 100644 --- a/src/main/helm/templates/_helpers.tpl +++ b/src/main/helm/templates/_helpers.tpl @@ -42,4 +42,31 @@ app.kubernetes.io/namespace: {{ include "app.namespace" . }} {{- define "app.ozgcloudEnvironment" -}} {{- required "Environment muss angegeben sein" (.Values.ozgcloud).environment -}} +{{- end -}} + +{{- define "app.ssoRealm" -}} +{{ printf "%s-%s-%s" (include "app.ozgcloudBundesland" .) ( include "app.ozgcloudBezeichner" . ) ( include "app.ozgcloudEnvironment" . ) | trunc 63 | trimSuffix "-" }} +{{- end -}} + +{{- define "app.ozgcloudBundesland" -}} +{{- required "Bundesland muss angegeben sein" (.Values.ozgcloud).bundesland }} +{{- end -}} + +{{- define "app.ozgcloudBezeichner" -}} +{{- required "ozgcloud.bezeichner muss angegeben sein" (.Values.ozgcloud).bezeichner -}} +{{- if lt 27 (len (.Values.ozgcloud).bezeichner) -}} +{{ fail (printf "ozgcloud.bezeichner %s ist zu lang (max. 27 Zeichen)" (.Values.ozgcloud).bezeichner) }} +{{- end -}} +{{- end -}} + +{{- define "app.ssoClientName" -}} +{{- if (.Values.sso).client_name -}} +{{ printf "%s" (.Values.sso).client_name }} +{{- else -}} +{{ printf "administration" }} +{{- end -}} +{{- end -}} + +{{- define "app.ssoServerUrl" -}} +{{- required "sso.serverUrl muss angegeben sein" (.Values.sso).serverUrl -}} {{- end -}} \ No newline at end of file diff --git a/src/main/helm/templates/deployment.yaml b/src/main/helm/templates/deployment.yaml index c5c0cf7411b990d848ab845e1f6a7bff0122472c..dfbadbc7c4591bb2d064d5b580be401e598c524e 100644 --- a/src/main/helm/templates/deployment.yaml +++ b/src/main/helm/templates/deployment.yaml @@ -61,6 +61,12 @@ spec: value: "/bindings" - name: spring_profiles_active value: {{ include "app.envSpringProfiles" . }} + - name: ozgcloud_oauth2_realm + value: {{ include "app.ssoRealm" . }} + - name: ozgcloud_oauth2_resource + value: {{ include "app.ssoClientName" . }} + - name: ozgcloud_oauth2_auth-server-url + value: {{ include "app.ssoServerUrl" . }} {{- if not (.Values.database).useExternal }} - name: spring_data_mongodb_uri valueFrom: @@ -71,7 +77,7 @@ spec: - name: spring_data_mongodb_database value: {{ .Values.database.databaseName | default "administration-database" }} {{- end }} - + envFrom: {{- if (.Values.database).useExternal }} - secretRef: diff --git a/src/main/helm/templates/network_policy.yaml b/src/main/helm/templates/network_policy.yaml index 0b04539f5f49f11190eeeddf9de4c0fb867e7fd9..efe20f5232454748e707d50e2fb5539dc5736cfb 100644 --- a/src/main/helm/templates/network_policy.yaml +++ b/src/main/helm/templates/network_policy.yaml @@ -27,7 +27,7 @@ spec: protocol: TCP # public keycloak ip - to: - - ipBlock: + - ipBlock: cidr: {{ required "networkPolicy.ssoPublicIp must be set" (.Values.networkPolicy).ssoPublicIp }} - to: - namespaceSelector: diff --git a/src/main/resources/application-dev.yaml b/src/main/resources/application-dev.yaml index 174b55dcb8dee4e35f6b11275f4d563dc4371669..c3514d2f7c0a361129dde64e8f53fb137c55a67f 100644 --- a/src/main/resources/application-dev.yaml +++ b/src/main/resources/application-dev.yaml @@ -1,6 +1,2 @@ ozgcloud: - production: false - oauth2: - auth-server-url: https://sso.dev.by.ozg-cloud.de - realm: by-kiel-dev - resource: admin \ No newline at end of file + production: false \ No newline at end of file diff --git a/src/test/helm/deployment_database_test.yaml b/src/test/helm/deployment_database_test.yaml index bde6a7f20fcca8b5db8234965c1c38cad365f268..8c747b650b4925c6026325d50f46de3ee42e6c73 100644 --- a/src/test/helm/deployment_database_test.yaml +++ b/src/test/helm/deployment_database_test.yaml @@ -28,6 +28,12 @@ release: namespace: sh-helm-test templates: - templates/deployment.yaml +set: + ozgcloud: + bundesland: sh + bezeichner: helm + sso: + serverUrl: https://sso.company.local tests: - it: should have a volume for the mongodb certificate asserts: @@ -73,4 +79,4 @@ tests: path: spec.template.spec.containers[0].envFrom content: secretRef: - name: administration-database-spring \ No newline at end of file + name: administration-database-spring diff --git a/src/test/helm/deployment_defaults_sso_test.yaml b/src/test/helm/deployment_defaults_sso_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..70a0cac25bae20872a5556b66f68021159f391cb --- /dev/null +++ b/src/test/helm/deployment_defaults_sso_test.yaml @@ -0,0 +1,89 @@ +# +# Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +suite: test deployment +release: + name: administration + namespace: sh-helm-test +templates: + - templates/deployment.yaml +set: + baseUrl: test.company.local + ozgcloud: + environment: test + bundesland: sh + bezeichner: helm + sso: + serverUrl: https://sso.company.local +tests: + - it: check default values + asserts: + - isKind: + of: Deployment + - contains: + path: spec.template.spec.containers[0].env + content: + name: ozgcloud_oauth2_realm + value: sh-helm-test + - contains: + path: spec.template.spec.containers[0].env + content: + name: ozgcloud_oauth2_resource + value: administration + - contains: + path: spec.template.spec.containers[0].env + content: + name: ozgcloud_oauth2_auth-server-url + value: https://sso.company.local + + - it: check realm with long namespace + set: + ozgcloud: + bezeichner: eins-zwei-drei + environment: dev + bundesland: sh + sso: + serverUrl: https://sso.company.local + asserts: + - isKind: + of: Deployment + - contains: + path: spec.template.spec.containers[0].env + content: + name: ozgcloud_oauth2_realm + value: sh-eins-zwei-drei-dev + + - it: check different client name + set: + sso: + client_name: different-client + serverUrl: https://sso.company.local + asserts: + - isKind: + of: Deployment + - contains: + path: spec.template.spec.containers[0].env + content: + name: ozgcloud_oauth2_resource + value: different-client diff --git a/src/test/helm/deployment_image_pull_secret_test.yaml b/src/test/helm/deployment_image_pull_secret_test.yaml index 7aea9cb83872375b74ff8f737eb6d2165d940093..44f285aa845dddef22c11220bef7714efdc1f9ae 100644 --- a/src/test/helm/deployment_image_pull_secret_test.yaml +++ b/src/test/helm/deployment_image_pull_secret_test.yaml @@ -27,6 +27,12 @@ templates: release: name: administration namespace: helm-test +set: + ozgcloud: + bundesland: sh + bezeichner: helm + sso: + serverUrl: https://sso.company.local tests: - it: should use default image pull secret asserts: @@ -41,4 +47,4 @@ tests: - contains: path: spec.template.spec.imagePullSecrets content: - name: custom-image-pull-secret \ No newline at end of file + name: custom-image-pull-secret diff --git a/src/test/helm/deployment_resources_test.yaml b/src/test/helm/deployment_resources_test.yaml index 29322c2183f84bf7515fff981bb1f4bc849c63f3..d37443f22191266721ac95118b716692cebfeeb0 100644 --- a/src/test/helm/deployment_resources_test.yaml +++ b/src/test/helm/deployment_resources_test.yaml @@ -27,6 +27,12 @@ templates: release: name: administration namespace: helm-test +set: + ozgcloud: + bundesland: sh + bezeichner: helm + sso: + serverUrl: https://sso.company.local tests: - it: should have customizable resources set: @@ -34,4 +40,4 @@ tests: asserts: - equal: path: spec.template.spec.containers[0].resources - value: { "test": 1 } \ No newline at end of file + value: { "test": 1 } diff --git a/src/test/helm/deployment_spring_profile_test.yaml b/src/test/helm/deployment_spring_profile_test.yaml index 35c8ad1d614d343022a87aff7bdabaf623082b10..f99d9b9893a31a013693ccf7b6402603f8bc390f 100644 --- a/src/test/helm/deployment_spring_profile_test.yaml +++ b/src/test/helm/deployment_spring_profile_test.yaml @@ -28,6 +28,12 @@ release: namespace: sh-helm-test templates: - templates/deployment.yaml +set: + ozgcloud: + bundesland: sh + bezeichner: helm + sso: + serverUrl: https://sso.company.local tests: - it: should override the spring profiles set: @@ -48,4 +54,4 @@ tests: path: spec.template.spec.containers[0].env content: name: spring_profiles_active - value: oc, dev \ No newline at end of file + value: oc, dev diff --git a/src/test/helm/deployment_test.yaml b/src/test/helm/deployment_test.yaml index 7168d78dd2471583010650f08e3900c8d7aea49a..6bd31db1bcadaa990cef70e13f04845e42e6f9e7 100644 --- a/src/test/helm/deployment_test.yaml +++ b/src/test/helm/deployment_test.yaml @@ -28,7 +28,12 @@ release: templates: - templates/deployment.yaml set: - ozgcloud.environment: "default" + ozgcloud: + environment: "default" + bundesland: sh + bezeichner: helm + sso: + serverUrl: https://sso.company.local tests: - it: should have metadata values asserts: diff --git a/src/test/helm/deployment_volume_test.yaml b/src/test/helm/deployment_volume_test.yaml index 0625a237b77e1d234ed73d6669f686ad0990b97e..6546763a8b9a03d0ce9fc964a503fe6fbb847092 100644 --- a/src/test/helm/deployment_volume_test.yaml +++ b/src/test/helm/deployment_volume_test.yaml @@ -28,8 +28,13 @@ release: templates: - templates/deployment.yaml set: - Release.Name: "administration" - ozgcloud.environment: "default" + Release.Name: "administration" + ozgcloud: + environment: "default" + bundesland: sh + bezeichner: helm + sso: + serverUrl: https://sso.company.local tests: - it: should have volumeMounts on it's container asserts: @@ -73,4 +78,4 @@ tests: value: "ozg-mongodb-tls-cert" - equal: path: spec.template.spec.volumes[1].secret.optional - value: true \ No newline at end of file + value: true