Skip to content
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

feat: add value for supplying an existing secret containing the JWT server keypair #67

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ chart and deletes the release.
| jobCreateGpgKeys.extraPodLabels | object | `{}` | |
| jobCreateJwtKeys.extraPodLabels | object | `{}` | |
| jwtCreateKeysForced | bool | `false` | Forces overwrite JWT keys |
| jwtExistingSecret | string | `""` | Name of the existing secret for the JWT server keypair. The secret must contain the `jwt.key` and `jwt.pem` keys. |
| jwtPath | string | `"/etc/passbolt/jwt"` | Configure passbolt jwt directory |
| jwtServerPrivate | string | `""` | JWT server private key in base64 |
| jwtServerPublic | string | `""` | JWT server public key in base64 |
Expand Down
10 changes: 9 additions & 1 deletion templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Show error message if the user didn't set the needed values during upgrade
{{- $message = printf "%s\n%s" $message (printf " export FINGERPRINT=$(kubectl exec deploy/%s -c %s -- grep PASSBOLT_GPG_SERVER_KEY_FINGERPRINT /etc/environment | awk -F= '{gsub(/\"/, \"\"); print $2}')" $dpName $containerName) -}}
{{- $arguments = printf "%s %s" $arguments (printf "--set %s=$%s --set %s=$%s --set %s=$%s" "gpgServerKeyPrivate" "PRIVATE_KEY" "gpgServerKeyPublic" "PUBLIC_KEY" "passboltEnv.secret.PASSBOLT_GPG_SERVER_KEY_FINGERPRINT" "FINGERPRINT" ) -}}
{{- end }}
{{ if and $.Release.IsUpgrade .Values.passboltEnv.plain.PASSBOLT_PLUGINS_JWT_AUTHENTICATION_ENABLED ( not .Values.jwtCreateKeysForced ) (or ( not $.Values.jwtServerPublic ) ( not $.Values.jwtServerPrivate )) }}
{{ if and $.Release.IsUpgrade .Values.passboltEnv.plain.PASSBOLT_PLUGINS_JWT_AUTHENTICATION_ENABLED ( not .Values.jwtCreateKeysForced ) ( not .Values.jwtExistingSecret ) (or ( not $.Values.jwtServerPublic ) ( not $.Values.jwtServerPrivate )) }}
{{- if eq $header "" }}
{{- $header = printf "JWT" -}}
{{- else }}
Expand Down Expand Up @@ -222,3 +222,11 @@ imagePullSecrets:
{{- printf "%s-sec-gpg" .name -}}
{{- end }}
{{- end }}

{{- define "passbolt.jwt.secretName" -}}
{{- if .Values.jwtExistingSecret -}}
{{- printf "%s" .Values.jwtExistingSecret -}}
{{- else }}
{{- printf "%s-sec-jwt" .name -}}
{{- end }}
{{- end }}
8 changes: 4 additions & 4 deletions templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
checksum/sec-gpg: {{ include (print $.Template.BasePath "/secret-gpg.yaml") . | sha256sum }}
{{- end }}
checksum/cm-env: {{ include (print $.Template.BasePath "/configmap-env.yaml") . | sha256sum }}
{{- if .Values.passboltEnv.plain.PASSBOLT_PLUGINS_JWT_AUTHENTICATION_ENABLED }}
{{- if and .Values.passboltEnv.plain.PASSBOLT_PLUGINS_JWT_AUTHENTICATION_ENABLED ( not .Values.jwtExistingSecret ) }}
checksum/sec-jwt: {{ include (print $.Template.BasePath "/secret-jwt.yaml") . | sha256sum }}
{{- end }}
{{- if .Values.app.cache.redis.sentinelProxy.enabled }}
Expand Down Expand Up @@ -151,7 +151,7 @@ spec:
readOnly: true
{{- end }}
{{- if .Values.passboltEnv.plain.PASSBOLT_PLUGINS_JWT_AUTHENTICATION_ENABLED }}
- name: {{ $fullName }}-sec-jwt
- name: {{ include "passbolt.jwt.secretName" ( dict "name" $Name "Values" $.Values ) }}
mountPath: {{ quote .Values.jwtPath }}
readOnly: true
{{- end }}
Expand Down Expand Up @@ -205,9 +205,9 @@ spec:
path: subscription_key.txt
{{- end }}
{{- if .Values.passboltEnv.plain.PASSBOLT_PLUGINS_JWT_AUTHENTICATION_ENABLED }}
- name: {{ $fullName }}-sec-jwt
- name: {{ include "passbolt.jwt.secretName" ( dict "name" $Name "Values" $.Values ) }}
secret:
secretName: {{ $Name }}-sec-jwt
secretName: {{ include "passbolt.jwt.secretName" ( dict "name" $Name "Values" $.Values ) }}
{{- end }}
{{- if .Values.app.cache.redis.sentinelProxy.enabled }}
- name: {{ $fullName }}-sec-redis-proxy
Expand Down
6 changes: 3 additions & 3 deletions templates/job-create-jwt.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and .Values.passboltEnv.plain.PASSBOLT_PLUGINS_JWT_AUTHENTICATION_ENABLED (or ( not .Values.jwtServerPrivate ) ( not .Values.jwtServerPublic )) }}
{{- if and .Values.passboltEnv.plain.PASSBOLT_PLUGINS_JWT_AUTHENTICATION_ENABLED ( not .Values.jwtExistingSecret ) (or ( not .Values.jwtServerPrivate ) ( not .Values.jwtServerPublic )) }}
{{- $type := "job" -}}
{{- $action := "create-jwt-keys" -}}
{{- $Name := include "passbolt-library.fullname" . -}}
Expand Down Expand Up @@ -48,8 +48,8 @@ spec:
kubectlDownload=${KUBECTL_DOWNLOAD_CMD:-'curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"'}
eval $kubectlDownload
chmod +x kubectl
./kubectl patch secret {{ $Name }}-sec-jwt --type='json' -p='[{"op": "replace", "path" : "/data/jwt.key", "value" : '"${PUBLIC_JWT_KEY}"'}]'
./kubectl patch secret {{ $Name }}-sec-jwt --type='json' -p='[{"op": "replace", "path" : "/data/jwt.pem", "value" : '"${PUBLIC_JWT_KEY}"'}]'
./kubectl patch secret {{ include "passbolt.jwt.secretName" ( dict "name" $Name "Values" $.Values ) }} --type='json' -p='[{"op": "replace", "path" : "/data/jwt.key", "value" : '"${PUBLIC_JWT_KEY}"'}]'
./kubectl patch secret {{ include "passbolt.jwt.secretName" ( dict "name" $Name "Values" $.Values ) }} --type='json' -p='[{"op": "replace", "path" : "/data/jwt.pem", "value" : '"${PUBLIC_JWT_KEY}"'}]'
touch /tmp/pod/success
echo "Success"
env:
Expand Down
4 changes: 2 additions & 2 deletions templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ rules:
- {{ $Name }}-cm-env
- {{ $Name }}-sec-env
- {{ include "passbolt.gpg.secretName" ( dict "name" $Name "Values" $.Values ) }}
- {{ $Name }}-sec-jwt
- {{ include "passbolt.jwt.secretName" ( dict "name" $Name "Values" $.Values ) }}
- {{ $Name }}-sec-tls
- {{ $Name }}-sec-tls-ing
- {{ $Name }}-sec-subscription
Expand Down Expand Up @@ -113,7 +113,7 @@ rules:
resources: [ "configmaps", "secrets" ]
resourceNames:
- {{ $Name }}-cm-env
- {{ $Name }}-sec-jwt
- {{ include "passbolt.jwt.secretName" ( dict "name" $Name "Values" $.Values ) }}
- {{ $Name }}-sec-env
- {{ $Name }}-sec-redis-proxy
verbs: ["get", "patch"]
Expand Down
2 changes: 1 addition & 1 deletion templates/secret-jwt.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.passboltEnv.plain.PASSBOLT_PLUGINS_JWT_AUTHENTICATION_ENABLED }}
{{- if and .Values.passboltEnv.plain.PASSBOLT_PLUGINS_JWT_AUTHENTICATION_ENABLED ( not .Values.jwtExistingSecret ) }}
{{- $type := "sec" -}}
{{- $action := "jwt" -}}
{{- $Name := include "passbolt-library.fullname" . -}}
Expand Down
11 changes: 10 additions & 1 deletion tests/auto_jwt_keys_creation_install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tests:
kind: Job
name: test-passbolt-job-create-jwt-keys

- it: should not create a gpg job
- it: should not create a gpg job if key values are supplied
templates:
- job-create-jwt.yaml
set:
Expand All @@ -38,6 +38,15 @@ tests:
- hasDocuments:
count: 0

- it: should not create a gpg job if an existing secret is supplied
templates:
- job-create-jwt.yaml
set:
jwtExistingSecret: "my-jwt-secret"
asserts:
- hasDocuments:
count: 0

- it: should be executed only on pre-install
templates:
- job-create-jwt.yaml
Expand Down
46 changes: 46 additions & 0 deletions tests/deployment_jwt_secret_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
suite: deployment jwt secret
release:
name: test
values:
- values-test.yaml
tests:
- it: should contain a volumes and volumeMounts section for jwt secret
templates:
- deployment.yaml
asserts:
- contains:
path: spec.template.spec.containers[0].volumeMounts
content:
name: test-passbolt-sec-jwt
count: 1
any: true
- contains:
path: spec.template.spec.volumes
content:
name: test-passbolt-sec-jwt
secret:
secretName: test-passbolt-sec-jwt
count: 1
any: true

- it: should use the existing jwt secret if supplied
templates:
- deployment.yaml
set:
jwtExistingSecret: "my-jwt-secret"
asserts:
- contains:
path: spec.template.spec.containers[0].volumeMounts
content:
name: my-jwt-secret
count: 1
any: true
- contains:
path: spec.template.spec.volumes
content:
name: my-jwt-secret
secret:
secretName: my-jwt-secret
count: 1
any: true
35 changes: 35 additions & 0 deletions tests/secret_jwt_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
suite: secret jwt
release:
name: test
values:
- values-test.yaml
tests:
- it: should create a jwt secret
templates:
- secret-jwt.yaml
set:
jwtExistingSecret: ""
asserts:
- containsDocument:
apiVersion: v1
kind: Secret
name: test-passbolt-sec-jwt

- it: should not create a jwt secret when an existing secret is supplied
templates:
- secret-jwt.yaml
set:
jwtExistingSecret: "my-jwt-secret"
asserts:
- hasDocuments:
count: 0

- it: should not create a jwt secret when jwt authentication is disabled
templates:
- secret-jwt.yaml
set:
passboltEnv.plain.PASSBOLT_PLUGINS_JWT_AUTHENTICATION_ENABLED: false
asserts:
- hasDocuments:
count: 0
2 changes: 2 additions & 0 deletions tests/values-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ gpgServerKeyPublic: ""
# -- Name of the existing secret for the GPG server keypair. The secret must contain the `serverkey.asc` and `serverkey_private.asc` keys.
gpgExistingSecret: ""

# -- Name of the existing secret for the JWT server keypair. The secret must contain the `jwt.key` and `jwt.pem` keys.
jwtExistingSecret: ""
# -- Configure passbolt jwt directory
jwtPath: /etc/passbolt/jwt
# -- JWT server private key in base64
Expand Down
2 changes: 2 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ gpgServerKeyPublic: ""
# -- Name of the existing secret for the GPG server keypair. The secret must contain the `serverkey.asc` and `serverkey_private.asc` keys.
gpgExistingSecret: ""

# -- Name of the existing secret for the JWT server keypair. The secret must contain the `jwt.key` and `jwt.pem` keys.
jwtExistingSecret: ""
# -- Configure passbolt jwt directory
jwtPath: /etc/passbolt/jwt
# -- JWT server private key in base64
Expand Down