Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: added base64DecodeBytes function to operator template

=9823c7d1aa2a
diff --git a/k8-operator/config/samples/sample-with-template.yml b/k8-operator/config/samples/crd/infisicalsecret/infisical-secret-crd-with-template.yml
similarity index 98%
rename from k8-operator/config/samples/sample-with-template.yml
rename to k8-operator/config/samples/crd/infisicalsecret/infisical-secret-crd-with-template.yml
index 9d9d86ab58..e167583a79 100644
--- a/k8-operator/config/samples/sample-with-template.yml
+++ b/k8-operator/config/samples/crd/infisicalsecret/infisical-secret-crd-with-template.yml
@@ -104,6 +104,7 @@ spec:
includeAllSecrets: true
data:
SSH_KEY: "{{ .KEY.SecretPath }} {{ .KEY.Value }}"
+ BINARY_KEY: "{{ base64DecodeBytes .BINARY_KEY_BASE64.Value }}"
creationPolicy: "Orphan" ## Owner | Orphan
# secretType: kubernetes.io/dockerconfigjson
diff --git a/k8-operator/controllers/infisicalsecret/infisicalsecret_helper.go b/k8-operator/controllers/infisicalsecret/infisicalsecret_helper.go
index 28a9843c90..8fb41621af 100644
--- a/k8-operator/controllers/infisicalsecret/infisicalsecret_helper.go
+++ b/k8-operator/controllers/infisicalsecret/infisicalsecret_helper.go
@@ -3,6 +3,7 @@ package controllers
import (
"bytes"
"context"
+ "encoding/base64"
"errors"
"fmt"
"strings"
@@ -261,7 +262,15 @@ func (r *InfisicalSecretReconciler) updateInfisicalManagedKubeSecret(ctx context
}
for templateKey, userTemplate := range managedTemplateData.Data {
- tmpl, err := template.New("secret-templates").Parse(userTemplate)
+ tmpl, err := template.New("secret-templates").Funcs(template.FuncMap{
+ "base64DecodeBytes": func(encodedString string) string {
+ decoded, err := base64.StdEncoding.DecodeString(encodedString)
+ if err != nil {
+ return fmt.Sprintf("Error: %v", err)
+ }
+ return string(decoded)
+ },
+ }).Parse(userTemplate)
if err != nil {
return fmt.Errorf("unable to compile template: %s [err=%v]", templateKey, err)
}