From a2bc383e1520e7106bd9fd10df5b208048eed6cc Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 20 Feb 2022 07:21:17 +0000 Subject: [PATCH] Allow bootstrapping policies with special characters in Helm (#14356) If the policy fails MinIO's minimum threshold for a valid policy, they'll still (correctly) fail, but policies with a : (and probably a /) should be allowed since they work with standard MC/MinIO Console interactions. This creates the files as policy_IDX.json instead of .json to avoid any issues with the name + Kubernetes ConfigMaps since ConfigMap keys must be: [-._a-zA-Z0-9]+ --- helm/minio/templates/_helper_create_policy.txt | 10 ++++++---- helm/minio/templates/configmap.yaml | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/helm/minio/templates/_helper_create_policy.txt b/helm/minio/templates/_helper_create_policy.txt index e5f2edb6a..d565b161e 100644 --- a/helm/minio/templates/_helper_create_policy.txt +++ b/helm/minio/templates/_helper_create_policy.txt @@ -43,17 +43,19 @@ checkPolicyExists() { return $? } -# createPolicy($name) +# createPolicy($name, $filename) createPolicy () { NAME=$1 + FILENAME=$2 # Create the name if it does not exist + echo "Checking policy: $NAME (in /config/$FILENAME.json)" if ! checkPolicyExists $NAME ; then echo "Creating policy '$NAME'" else echo "Policy '$NAME' already exists." fi - ${MC} admin policy add myminio $NAME /config/$NAME.json + ${MC} admin policy add myminio $NAME /config/$FILENAME.json } @@ -67,7 +69,7 @@ connectToMinio $scheme {{ if .Values.policies }} # Create the policies -{{- range .Values.policies }} -createPolicy {{ .name }} +{{- range $idx, $policy := .Values.policies }} +createPolicy {{ $policy.name }} policy_{{ $idx }} {{- end }} {{- end }} \ No newline at end of file diff --git a/helm/minio/templates/configmap.yaml b/helm/minio/templates/configmap.yaml index 29fc70540..95a7c6038 100644 --- a/helm/minio/templates/configmap.yaml +++ b/helm/minio/templates/configmap.yaml @@ -15,8 +15,9 @@ data: {{ include (print $.Template.BasePath "/_helper_create_user.txt") . | indent 4 }} add-policy: |- {{ include (print $.Template.BasePath "/_helper_create_policy.txt") . | indent 4 }} -{{- range .Values.policies }} - {{ .name }}.json: |- +{{- range $idx, $policy := .Values.policies }} + # {{ $policy.name }} + policy_{{ $idx }}.json: |- {{ include (print $.Template.BasePath "/_helper_policy.tpl") . | indent 4 }} {{ end }} custom-command: |-