You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by zh...@apache.org on 2023/07/07 07:53:08 UTC

[apisix-helm-chart] branch master updated: feat: allow to provide etcd creds from secrets (#555)

This is an automated email from the ASF dual-hosted git repository.

zhangjintao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-helm-chart.git


The following commit(s) were added to refs/heads/master by this push:
     new f5c7256  feat: allow to provide etcd creds from secrets (#555)
f5c7256 is described below

commit f5c7256ea9c0d07ac897cdf2fdcd365e429a3e26
Author: ikatlinsky <il...@gmail.com>
AuthorDate: Fri Jul 7 09:53:02 2023 +0200

    feat: allow to provide etcd creds from secrets (#555)
    
    Co-authored-by: Katlinsky, Ilya <i....@itransition.com>
---
 charts/apisix/README.md                    | 10 ++++--
 charts/apisix/ci/default-values.yaml       |  0
 charts/apisix/ci/etcd-password-values.yaml | 21 +++++++++++
 charts/apisix/templates/_helpers.tpl       | 56 ++++++++++++++++++++++++++++++
 charts/apisix/templates/_pod.tpl           | 19 ++++++++++
 charts/apisix/templates/configmap.yaml     |  8 +----
 charts/apisix/templates/secrets.yaml       | 14 ++++++++
 charts/apisix/values.yaml                  | 16 +++++++++
 8 files changed, 135 insertions(+), 9 deletions(-)

diff --git a/charts/apisix/README.md b/charts/apisix/README.md
index feb67db..72eeefd 100644
--- a/charts/apisix/README.md
+++ b/charts/apisix/README.md
@@ -144,9 +144,11 @@ The command removes all the Kubernetes components associated with the chart and
 | dns.resolvers[5] | string | `"8.8.8.8"` |  |
 | dns.timeout | int | `5` |  |
 | dns.validity | int | `30` |  |
-| etcd | object | `{"auth":{"rbac":{"create":false,"rootPassword":""},"tls":{"certFilename":"","certKeyFilename":"","enabled":false,"existingSecret":"","sni":"","verify":true}},"enabled":true,"host":["http://etcd.host:2379"],"password":"","prefix":"/apisix","replicaCount":3,"service":{"port":2379},"timeout":30,"user":""}` | etcd configuration use the FQDN address or the IP of the etcd |
-| etcd.auth | object | `{"rbac":{"create":false,"rootPassword":""},"tls":{"certFilename":"","certKeyFilename":"","enabled":false,"existingSecret":"","sni":"","verify":true}}` | if etcd.enabled is true, set more values of bitnami/etcd helm chart |
+| etcd | object | `{"auth":{"rbac":{"create":false,"existingSecret":"","existingSecretPasswordKey":"","rootPassword":""},"tls":{"certFilename":"","certKeyFilename":"","enabled":false,"existingSecret":"","sni":"","verify":true}},"enabled":true,"existingSecret":"","existingSecretPasswordKey":"","existingSecretUserKey":"","host":["http://etcd.host:2379"],"password":"","prefix":"/apisix","replicaCount":3,"service":{"port":2379},"timeout":30,"user":""}` | etcd configuration use the FQDN addre [...]
+| etcd.auth | object | `{"rbac":{"create":false,"existingSecret":"","existingSecretPasswordKey":"","rootPassword":""},"tls":{"certFilename":"","certKeyFilename":"","enabled":false,"existingSecret":"","sni":"","verify":true}}` | if etcd.enabled is true, set more values of bitnami/etcd helm chart |
 | etcd.auth.rbac.create | bool | `false` | No authentication by default. Switch to enable RBAC authentication |
+| etcd.auth.rbac.existingSecret | string | `""` | Name of the existing secret containing credentials for the root user |
+| etcd.auth.rbac.existingSecretPasswordKey | string | `""` | Name of key containing password to be retrieved from the existing secret |
 | etcd.auth.rbac.rootPassword | string | `""` | root password for etcd. Requires etcd.auth.rbac.create to be true. |
 | etcd.auth.tls.certFilename | string | `""` | etcd client cert filename using in etcd.auth.tls.existingSecret |
 | etcd.auth.tls.certKeyFilename | string | `""` | etcd client cert key filename using in etcd.auth.tls.existingSecret |
@@ -155,6 +157,9 @@ The command removes all the Kubernetes components associated with the chart and
 | etcd.auth.tls.sni | string | `""` | specify the TLS Server Name Indication extension, the ETCD endpoint hostname will be used when this setting is unset. |
 | etcd.auth.tls.verify | bool | `true` | whether to verify the etcd endpoint certificate when setup a TLS connection to etcd |
 | etcd.enabled | bool | `true` | install etcd(v3) by default, set false if do not want to install etcd(v3) together |
+| etcd.existingSecret | string | `""` | Name of the existing secret containing user and password for external etcd, overrides etcd.user and etcd.password |
+| etcd.existingSecretPasswordKey | string | `""` | Name of key containing password to be retrieved from the existing secret, has a value of password by default |
+| etcd.existingSecretUserKey | string | `""` | Name of key containing username to be retrieved from the existing secret, has a value of user by default |
 | etcd.host | list | `["http://etcd.host:2379"]` | if etcd.enabled is false, use external etcd, support multiple address, if your etcd cluster enables TLS, please use https scheme, e.g. https://127.0.0.1:2379. |
 | etcd.password | string | `""` | if etcd.enabled is false, password for external etcd. If etcd.enabled is true, use etcd.auth.rbac.rootPassword instead. |
 | etcd.prefix | string | `"/apisix"` | apisix configurations prefix |
@@ -185,6 +190,7 @@ The command removes all the Kubernetes components associated with the chart and
 | gateway.tls.sslProtocols | string | `"TLSv1.2 TLSv1.3"` | TLS protocols allowed to use. |
 | gateway.type | string | `"NodePort"` | Apache APISIX service type for user access itself |
 | global.imagePullSecrets | list | `[]` | Global Docker registry secret names as an array |
+| global.secrets | list | `[]` | Secrets to be created with apisix |
 | ingress-controller | object | `{"config":{"apisix":{"adminAPIVersion":"v3"}},"enabled":false}` | Ingress controller configuration |
 | initContainer.image | string | `"busybox"` | Init container image |
 | initContainer.tag | float | `1.28` | Init container tag |
diff --git a/charts/apisix/ci/default-values.yaml b/charts/apisix/ci/default-values.yaml
new file mode 100644
index 0000000..e69de29
diff --git a/charts/apisix/ci/etcd-password-values.yaml b/charts/apisix/ci/etcd-password-values.yaml
new file mode 100644
index 0000000..e337e44
--- /dev/null
+++ b/charts/apisix/ci/etcd-password-values.yaml
@@ -0,0 +1,21 @@
+global:
+  secrets:
+    - name: etcd-secret
+      values:
+        - name: user
+          value: root
+        - name: password
+          value: root
+
+etcd:
+  enabled: true
+  replicaCount: 1
+  existingSecret: "etcd-secret"
+  existingSecretUserKey: "user"
+  existingSecretPasswordKey: "password"
+
+  auth:
+    rbac:
+      create: true
+      existingSecret: "etcd-secret"
+      existingSecretPasswordKey: "password"
diff --git a/charts/apisix/templates/_helpers.tpl b/charts/apisix/templates/_helpers.tpl
index 41a98b1..e3b09f1 100644
--- a/charts/apisix/templates/_helpers.tpl
+++ b/charts/apisix/templates/_helpers.tpl
@@ -133,3 +133,59 @@ Key to use to fetch viewer token from secret
 {{- "viewer" }}
 {{- end }}
 {{- end }}
+
+{{/*
+Key to use to fetch username for external etcd from secret
+*/}}
+{{- define "apisix.etcd.credentials.userKey" -}}
+{{- if .Values.etcd.existingSecretUserKey }}
+{{- .Values.etcd.existingSecretUserKey | quote }}
+{{- else }}
+{{- "user" }}
+{{- end }}
+{{- end }}
+
+{{/*
+Key to use to fetch password for external etcd from secret
+*/}}
+{{- define "apisix.etcd.credentials.passwordKey" -}}
+{{- if .Values.etcd.existingSecretPasswordKey }}
+{{- .Values.etcd.existingSecretPasswordKey | quote }}
+{{- else }}
+{{- "password" }}
+{{- end }}
+{{- end }}
+
+{{/*
+Key to use to fetch root password for rbac
+*/}}
+{{- define "apisix.etcd.auth.rbac.passwordKey" -}}
+{{- if .Values.etcd.auth.rbac.existingSecretPasswordKey }}
+{{- .Values.etcd.auth.rbac.existingSecretPasswordKey | quote }}
+{{- else }}
+{{- "etcd-root-password" }}
+{{- end }}
+{{- end }}
+
+{{/*
+Configuration of user and password for etcd
+*/}}
+{{- define "apisix.etcd.credentials.config" -}}
+{{- if not .Values.etcd.enabled }}
+{{- if .Values.etcd.existingSecret }}
+user: "${{"{{"}}APISIX_ETCD_USER{{"}}"}}"
+password: "${{"{{"}}APISIX_ETCD_PASSWORD{{"}}"}}"
+{{- else if .Values.etcd.user }}
+user: {{ .Values.etcd.user | quote }}
+password: {{ .Values.etcd.password | quote }}
+{{- end }}
+{{- else if .Values.etcd.auth.rbac.create }}
+{{- if .Values.etcd.auth.rbac.existingSecret }}
+user: "root"
+password: "${{"{{"}}APISIX_ETCD_PASSWORD{{"}}"}}"
+{{- else }}
+user: "root"
+password: {{ .Values.etcd.auth.rbac.rootPassword | quote }}
+{{- end }}
+{{- end }}
+{{- end }}
diff --git a/charts/apisix/templates/_pod.tpl b/charts/apisix/templates/_pod.tpl
index 535a0dc..136a33f 100644
--- a/charts/apisix/templates/_pod.tpl
+++ b/charts/apisix/templates/_pod.tpl
@@ -53,6 +53,25 @@ spec:
               name: {{ .Values.admin.credentials.secretName | quote }}
               key: {{ include "apisix.admin.credentials.secretViewerKey" . }}
       {{- end }}
+      {{- if and (not .Values.etcd.enabled) .Values.etcd.existingSecret }}
+        - name: APISIX_ETCD_USER
+          valueFrom:
+            secretKeyRef:
+              name: {{ .Values.etcd.existingSecret | quote }}
+              key: {{ include "apisix.etcd.credentials.userKey" . }}
+        - name: APISIX_ETCD_PASSWORD
+          valueFrom:
+            secretKeyRef:
+              name: {{ .Values.etcd.existingSecret | quote }}
+              key: {{ include "apisix.etcd.credentials.passwordKey" . }} 
+      {{- end }}
+      {{- if and .Values.etcd.enabled .Values.etcd.auth.rbac.existingSecret }}
+        - name: APISIX_ETCD_PASSWORD
+          valueFrom:
+            secretKeyRef:
+              name: {{ .Values.etcd.auth.rbac.existingSecret | quote }}
+              key: {{ include "apisix.etcd.auth.rbac.passwordKey" . }} 
+      {{- end }}
 
       ports:
         - name: http
diff --git a/charts/apisix/templates/configmap.yaml b/charts/apisix/templates/configmap.yaml
index ead25d4..6037052 100644
--- a/charts/apisix/templates/configmap.yaml
+++ b/charts/apisix/templates/configmap.yaml
@@ -351,13 +351,7 @@ data:
       {{- end }}
         prefix: {{ .Values.etcd.prefix | quote }}    # configuration prefix in etcd
         timeout: {{ .Values.etcd.timeout }}    # 30 seconds
-        {{- if and (not .Values.etcd.enabled) .Values.etcd.user }}
-        user: {{ .Values.etcd.user | quote }}
-        password: {{ .Values.etcd.password | quote }}
-        {{- else if and .Values.etcd.enabled .Values.etcd.auth.rbac.create }}
-        user: "root"
-        password: {{ .Values.etcd.auth.rbac.rootPassword | quote }}
-        {{- end }}
+        {{- include "apisix.etcd.credentials.config" . | nindent 8 }}
         {{- if .Values.etcd.auth.tls.enabled }}
         tls:
           cert: "/etcd-ssl/{{ .Values.etcd.auth.tls.certFilename }}"
diff --git a/charts/apisix/templates/secrets.yaml b/charts/apisix/templates/secrets.yaml
new file mode 100644
index 0000000..7f07b8c
--- /dev/null
+++ b/charts/apisix/templates/secrets.yaml
@@ -0,0 +1,14 @@
+{{- range $secret := .Values.global.secrets -}}
+---
+apiVersion: v1
+kind: Secret
+metadata:
+  name: {{ $secret.name | quote }}
+  namespace: {{ $.Release.Namespace | quote }}
+type: Opaque
+data:
+  {{- range $value := $secret.values }}
+  {{ $value.name }}: {{ $value.value | b64enc | quote }}
+  {{- end }}
+---
+{{- end }}
diff --git a/charts/apisix/values.yaml b/charts/apisix/values.yaml
index e946a21..18b3e4d 100644
--- a/charts/apisix/values.yaml
+++ b/charts/apisix/values.yaml
@@ -21,6 +21,12 @@ global:
   #   - other-registry-secrets
   # -- Global Docker registry secret names as an array
   imagePullSecrets: []
+  # -- Secrets to be created with apisix
+  secrets: []
+    # - name: secret-name
+    #   values:
+    #     - name: secret-key
+    #       value: secret=value
 
 apisix:
   # -- Enable or disable Apache APISIX itself
@@ -603,6 +609,12 @@ etcd:
   prefix: "/apisix"
   # -- Set the timeout value in seconds for subsequent socket operations from apisix to etcd cluster
   timeout: 30
+  # -- Name of the existing secret containing user and password for external etcd, overrides etcd.user and etcd.password
+  existingSecret: ""
+  # -- Name of key containing username to be retrieved from the existing secret, has a value of user by default
+  existingSecretUserKey: ""
+  # -- Name of key containing password to be retrieved from the existing secret, has a value of password by default
+  existingSecretPasswordKey: ""
 
   # -- if etcd.enabled is true, set more values of bitnami/etcd helm chart
   auth:
@@ -611,6 +623,10 @@ etcd:
       create: false
       # -- root password for etcd. Requires etcd.auth.rbac.create to be true.
       rootPassword: ""
+      # -- Name of the existing secret containing credentials for the root user
+      existingSecret: ""
+      # -- Name of key containing password to be retrieved from the existing secret
+      existingSecretPasswordKey: ""
     tls:
       # -- enable etcd client certificate
       enabled: false