Browse Source

added some example for v2 literal templating (#3007)

Signed-off-by: Robert Paschedag <robert.paschedag@sap.com>
Co-authored-by: Robert Paschedag <robert.paschedag@sap.com>
Robert Paschedag 2 years ago
parent
commit
45e2bd3796
2 changed files with 39 additions and 0 deletions
  1. 16 0
      docs/guides/templating.md
  2. 23 0
      docs/snippets/template-v2-literal-example.yaml

+ 16 - 0
docs/guides/templating.md

@@ -55,6 +55,22 @@ You do not have to define your templates inline in an ExternalSecret but you can
 
 Lastly, `TemplateFrom` also supports adding `Literal` blocks for quick templating. These `Literal` blocks differ from `Template.Data` as they are rendered as a a `key:value` pair (while the `Template.Data`, you can only template the value).
 
+See an example, how to produce a `htpasswd` file that can be used by an ingress-controller (for example: https://kubernetes.github.io/ingress-nginx/examples/auth/basic/) where the contents of the `htpasswd` file needs to be presented via the `auth` key. We use the `htpasswd` function to create a `bcrytped` hash of the password.
+
+Suppose you have multiple key-value pairs within your provider secret like
+
+```json
+{
+  "user1": "password1",
+  "user2": "password2",
+  ...
+}
+```
+
+```yaml
+{% include 'template-v2-literal-example.yaml' %}
+```
+
 ### Extract Keys and Certificates from PKCS#12 Archive
 
 You can use pre-defined functions to extract data from your secrets. Here: extract keys and certificates from a PKCS#12 archive and store it as PEM.

+ 23 - 0
docs/snippets/template-v2-literal-example.yaml

@@ -0,0 +1,23 @@
+{% raw %}
+apiVersion: external-secrets.io/v1beta1
+kind: ExternalSecret
+metadata:
+  name: my-template-example
+spec:
+  # ...
+  target:
+    name: secret-to-be-created
+    template:
+      engineVersion: v2
+      templateFrom:
+      - target: Data
+        literal: |-
+          {{- $creds := list }}
+          {{- range $user, $pw := . }}
+            {{- $creds = append $creds (printf "%s" (htpasswd $user $pw)) }}
+          {{- end }}
+          auth: {{ $creds | join "\n" | quote }}
+  dataFrom:
+  - extract:
+      key: /ingress-controller/valid-users
+{% endraw %}