From 9823c7d1aa2a47016f4df49163601fab43f7af9d Mon Sep 17 00:00:00 2001 From: = Date: Sat, 18 Jan 2025 18:58:00 +0530 Subject: [PATCH 1/7] feat: added base64DecodeBytes function to operator template --- .../infisical-secret-crd-with-template.yml} | 1 + .../infisicalsecret/infisicalsecret_helper.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) rename k8-operator/config/samples/{sample-with-template.yml => crd/infisicalsecret/infisical-secret-crd-with-template.yml} (98%) 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 9d9d86ab5..e167583a7 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 28a9843c9..8fb41621a 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) } From 11aac3f5dcc466b876fc589ebe116c120ace47fd Mon Sep 17 00:00:00 2001 From: = Date: Sat, 18 Jan 2025 18:58:26 +0530 Subject: [PATCH 2/7] docs: updated k8s operator template section with base64DecodeBytes content --- .../platforms/kubernetes/infisical-secret-crd.mdx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx b/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx index f263b518a..9e01f36d9 100644 --- a/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx +++ b/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx @@ -672,6 +672,10 @@ When you set `includeAllSecrets` as `false` the Kubernetes secrets outputs will {"NEW_KEY":"LyBoZWxsbw=="} ``` +Available Template Functions + +- `base64DecodeBytes`: Converts a base64-encoded string into a byte array. This is commonly used for storing binary data in Infisical as base64 and syncing it with the operator. However, Kubernetes also performs base64 encoding, leading to double base64 conversion. To avoid this, you can decode the base64 string just before saving it to the operator. + Creation polices allow you to control whether or not owner references should be added to the managed Kubernetes secret that is generated by the Infisical operator. @@ -960,4 +964,5 @@ metadata: type: Opaque ``` - \ No newline at end of file + + From 5b40de16cf0b335d7dcdc8540a6914c6ecd5c63a Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Sat, 18 Jan 2025 17:11:52 -0500 Subject: [PATCH 3/7] improve docs and add missing function to create mamaged secret --- .../kubernetes/infisical-secret-crd.mdx | 269 ++++++++---------- .../infisical-secret-crd-with-template.yml | 2 +- .../infisicalsecret/infisicalsecret_helper.go | 12 +- 3 files changed, 127 insertions(+), 156 deletions(-) diff --git a/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx b/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx index 9e01f36d9..00b31532d 100644 --- a/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx +++ b/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx @@ -4,7 +4,8 @@ title: "Using the InfisicalSecret CRD" description: "Learn how to use the InfisicalSecret CRD to fetch secrets from Infisical and store them as native Kubernetes secret resource" --- -Once you have installed the operator to your cluster, you'll need to create a `InfisicalSecret` custom resource definition (CRD). +Once you have installed the operator to your cluster, you'll need to create a `InfisicalSecret` custom resource definition (CRD). +In this CRD, you'll define the authentication method to use, the secrets to fetch, and the target location to store the secrets within your cluster. ```yaml example-infisical-secret-crd.yaml apiVersion: secrets.infisical.com/v1alpha1 @@ -17,103 +18,29 @@ metadata: example.com/annotation-to-be-passed-to-managed-secret: "sample-value" spec: hostAPI: https://app.infisical.com/api - resyncInterval: 10 + resyncInterval: 10 authentication: - # Make sure to only have 1 authentication method defined, serviceToken/universalAuth. - # If you have multiple authentication methods defined, it may cause issues. - - # (Deprecated) Service Token Auth - serviceToken: - serviceTokenSecretReference: - secretName: service-token - secretNamespace: default - secretsScope: - envSlug: - secretsPath: - recursive: true - - # Universal Auth - universalAuth: - secretsScope: - projectSlug: new-ob-em - envSlug: dev # "dev", "staging", "prod", etc.. - secretsPath: "/" # Root is "/" - recursive: true # Whether or not to use recursive mode (Fetches all secrets in an environment from a given secret path, and all folders inside the path) / defaults to false - credentialsRef: - secretName: universal-auth-credentials - secretNamespace: default - - # Native Kubernetes Auth kubernetesAuth: identityId: serviceAccountRef: name: namespace: - # secretsScope is identical to the secrets scope in the universalAuth field in this sample. - secretsScope: - projectSlug: your-project-slug - envSlug: prod - secretsPath: "/path" - recursive: true - - # AWS IAM Auth - awsIamAuth: - identityId: - - # secretsScope is identical to the secrets scope in the universalAuth field in this sample. - secretsScope: - projectSlug: your-project-slug - envSlug: prod - secretsPath: "/path" - recursive: true - - # Azure Auth - azureAuth: - identityId: - resource: https://management.azure.com/&client_id=CLIENT_ID # (Optional) This is the Azure resource that you want to access. For example, "https://management.azure.com/". If no value is provided, it will default to "https://management.azure.com/" - - # secretsScope is identical to the secrets scope in the universalAuth field in this sample. - secretsScope: - projectSlug: your-project-slug - envSlug: prod - secretsPath: "/path" - recursive: true - - # GCP ID Token Auth - gcpIdTokenAuth: - identityId: - - # secretsScope is identical to the secrets scope in the universalAuth field in this sample. - secretsScope: - projectSlug: your-project-slug - envSlug: prod - secretsPath: "/path" - recursive: true - - # GCP IAM Auth - gcpIamAuth: - identityId: - - # secretsScope is identical to the secrets scope in the universalAuth field in this sample. - secretsScope: - projectSlug: your-project-slug - envSlug: prod - secretsPath: "/path" - recursive: true - managedSecretReference: secretName: managed-secret secretNamespace: default - creationPolicy: "Orphan" ## Owner | Orphan - # template: - # includeAllSecrets: true - # data: - # CUSTOM_KEY: "{{ .KEY.SecretPath }} {{ .KEY.Value }}" - # secretType: kubernetes.io/dockerconfigjson + creationPolicy: "Orphan" + template: + includeAllSecrets: true + data: + NEW_KEY_NAME: "{{ .KEY.SecretPath }} {{ .KEY.Value }}" + KEY_WITH_BINARY_VALUE: "{{ .KEY.SecretPath }} {{ .KEY.Value }}" ``` -### InfisicalSecret CRD properties +## CRD properties + +### Generic +The following properties help define what instance of Infisical the operator will interact with, the interval it will sync secrets and any CA certificates that may be required to connect. If you are fetching secrets from a self-hosted instance of Infisical set the value of `hostAPI` to @@ -165,9 +92,11 @@ When `hostAPI` is not defined the operator fetches secrets from Infisical Cloud. CA certificate to use for connecting to the Infisical instance with SSL/TLS. +### Authentication methods +To retrieve the requested secrets, the operator must first authenticate with Infisical. +The list of available authentication methods are shown below. + - This block defines the method that will be used to authenticate with Infisical - so that secrets can be fetched @@ -605,13 +534,12 @@ spec: +### Operator managed secrets +The managed secret properties specify where to store the secrets retrieved from your Infisical project. +This includes defining the name and namespace of the Kubernetes secret that will hold these secrets. +The Infisical operator will automatically create the Kubernetes secret in the specified name/namespace and ensure it stays up-to-date. + -The `managedSecretReference` field is used to define the target location for storing secrets retrieved from an Infisical project. -This field requires specifying both the name and namespace of the Kubernetes secret that will hold these secrets. -The Infisical operator will automatically create the Kubernetes secret with the specified name/namespace and keep it continuously updated. - -Note: The managed secret be should be created in the same namespace as the deployment that will use it. - The name of the managed Kubernetes secret to be created @@ -621,61 +549,6 @@ The namespace of the managed Kubernetes secret to be created. Override the default Opaque type for managed secrets with this field. Useful for creating kubernetes.io/dockerconfigjson secrets. - - -Templates enable you to transform data from Infisical before storing it as a Kubernetes Secret. - - -When set to true, this option injects all secrets retrieved from Infisical into your configuration. -Secrets defined in the template will override the automatically injected secrets. - - -Define secret keys and their corresponding templates. -Each data value uses a Golang template with access to all secrets retrieved from the specified scope. - -Secrets are structured as follows: - -```golang -type TemplateSecret struct { - Value string `json:"value"` - SecretPath string `json:"secretPath"` -} -``` - -#### Example template configuration: - -```golang - managedSecretReference: - secretName: managed-secret - secretNamespace: default - template: - includeAllSecrets: true - data: - NEW_KEY: "{{ .KEY1.SecretPath }} {{ .KEY1.Value }}" -``` - -When you run the following command: - -```bash -kubectl get secret managed-secret -o jsonpath='{.data}' -``` - -You'll receive Kubernetes secrets output that includes the NEW_KEY: - -```bash -{... "KEY":"d29ybGQ=","NEW_KEY":"LyBoZWxsbw=="} -``` - -When you set `includeAllSecrets` as `false` the Kubernetes secrets outputs will be: - -```bash -{"NEW_KEY":"LyBoZWxsbw=="} -``` - -Available Template Functions - -- `base64DecodeBytes`: Converts a base64-encoded string into a byte array. This is commonly used for storing binary data in Infisical as base64 and syncing it with the operator. However, Kubernetes also performs base64 encoding, leading to double base64 conversion. To avoid this, you can decode the base64 string just before saving it to the operator. - Creation polices allow you to control whether or not owner references should be added to the managed Kubernetes secret that is generated by the Infisical operator. @@ -693,7 +566,99 @@ This is useful for tools such as ArgoCD, where every resource requires an owner -### Apply the InfisicalSecret CRD to your cluster +### Manged secret templating +Fetching secrets from Infisical as is via the operator may not be enough. This is where templating functionality may be helpful. +Using Go templates, you can format, combine, and create new key-value pairs from secrets fetched from Infisical before storing them as Kubernetes Secrets. + + + + + This property controls what secrets are included in your managed secret when using templates. + When set to `true`, all secrets fetched from your Infisical project will be added into your managed Kubernetes secret resource. + Use this option when you would like to sync all secrets from Infisical to Kubernetes but want to template a subset of them. + + When set to `false`, only secrets defined in the `managedSecretReference.template.data` field of the template will be included in the managed secret. + Use this option when you would like to sync only a subset of secrets from Infisical to Kubernetes. + + +Define secret keys and their corresponding templates. +Each data value uses a Golang template with access to all secrets retrieved from the specified scope. + +Secrets are structured as follows: + +```golang +type TemplateSecret struct { + Value string `json:"value"` + SecretPath string `json:"secretPath"` +} +``` + +#### Example template configuration: + +```yaml +managedSecretReference: + secretName: managed-secret + secretNamespace: default + template: + includeAllSecrets: true + data: + # Create new secret key that doesn't exist in your Infisical project using values of other secrets + NEW_KEY: "{{ .DB_PASSWORD.Value }}" + # Override an existing secret key in Infisical project with a new value using values of other secrets + API_URL: "https://api.{{.COMPANY_NAME.Value}}.{{.REGION.Value}}.com" +``` + +For this example, let's assume the following secrets exist in your Infisical project: +``` +DB_PASSWORD = "secret123" +COMPANY_NAME = "acme" +REGION = "us-east-1" +API_URL = "old-url" # This will be overridden +``` + +The resulting managed Kubernetes secret will then contain: +``` +# Original secrets (from includeAllSecrets: true) +DB_PASSWORD = "secret123" +COMPANY_NAME = "acme" +REGION = "us-east-1" + +# New and overridden templated secrets +NEW_KEY = "secret123" # New secret created from template +API_URL = "https://api.acme.us-east-1.com" # Existing secret overridden by template +``` + +To help transform your secrets further, the operator provides a set of built-in functions that you can use in your templates. + +### Available templating functions + + + **Function name**: toBase64DecodedString + + **Description**: + Given a base64 encoded string, this function will decodes the base64-encoded string. + This function is useful when your secrets are already stored as base64 encoded value in Infisical. + + **Returns**: The decoded base64 string + + **Example**: + The example below assumes that the `BINARY_KEY_BASE64` secret is stored as a base64 encoded value in Infisical. + The resulting managed secret will contain the decoded value of `BINARY_KEY_BASE64`. + + ```yaml + managedSecretReference: + secretName: managed-secret + secretNamespace: default + template: + includeAllSecrets: true + data: + BINARY_KEY: "{{ toBase64DecodedString .BINARY_KEY_BASE64.Value }}" + ``` + + + + +## Applying CRD Once you have configured the InfisicalSecret CRD with the required fields, you can apply it to your cluster. After applying, you should notice that the managed secret has been created in the desired namespace your specified. @@ -702,8 +667,6 @@ After applying, you should notice that the managed secret has been created in th kubectl apply -f example-infisical-secret-crd.yaml ``` -### Verify managed secret creation - To verify that the operator has successfully created the managed secret, you can check the secrets in the namespace that was specified. ```bash @@ -718,7 +681,7 @@ kubectl get secrets -n ## Using managed secret in your deployment -Incorporating the managed secret created by the operator into your deployment can be achieved through several methods. +To make use of the managed secret created by the operator into your deployment can be achieved through several methods. Here, we will highlight three of the most common ways to utilize it. Learn more about Kubernetes secrets [here](https://kubernetes.io/docs/concepts/configuration/secret/) diff --git a/k8-operator/config/samples/crd/infisicalsecret/infisical-secret-crd-with-template.yml b/k8-operator/config/samples/crd/infisicalsecret/infisical-secret-crd-with-template.yml index e167583a7..127838772 100644 --- a/k8-operator/config/samples/crd/infisicalsecret/infisical-secret-crd-with-template.yml +++ b/k8-operator/config/samples/crd/infisicalsecret/infisical-secret-crd-with-template.yml @@ -104,7 +104,7 @@ spec: includeAllSecrets: true data: SSH_KEY: "{{ .KEY.SecretPath }} {{ .KEY.Value }}" - BINARY_KEY: "{{ base64DecodeBytes .BINARY_KEY_BASE64.Value }}" + BINARY_KEY: "{{ toBase64DecodedString .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 8fb41621a..4da4226ef 100644 --- a/k8-operator/controllers/infisicalsecret/infisicalsecret_helper.go +++ b/k8-operator/controllers/infisicalsecret/infisicalsecret_helper.go @@ -176,7 +176,15 @@ func (r *InfisicalSecretReconciler) createInfisicalManagedKubeSecret(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{ + "toBase64DecodedString": 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) } @@ -263,7 +271,7 @@ func (r *InfisicalSecretReconciler) updateInfisicalManagedKubeSecret(ctx context for templateKey, userTemplate := range managedTemplateData.Data { tmpl, err := template.New("secret-templates").Funcs(template.FuncMap{ - "base64DecodeBytes": func(encodedString string) string { + "toBase64DecodedString": func(encodedString string) string { decoded, err := base64.StdEncoding.DecodeString(encodedString) if err != nil { return fmt.Sprintf("Error: %v", err) From 8de9ddfb8ba5b7edb93ae8da32b5ac6b7bdefe49 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Sun, 19 Jan 2025 11:29:55 -0500 Subject: [PATCH 4/7] update k8s operator doc --- .../platforms/kubernetes/infisical-secret-crd.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx b/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx index 00b31532d..37eec35c7 100644 --- a/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx +++ b/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx @@ -575,10 +575,10 @@ Using Go templates, you can format, combine, and create new key-value pairs from This property controls what secrets are included in your managed secret when using templates. When set to `true`, all secrets fetched from your Infisical project will be added into your managed Kubernetes secret resource. - Use this option when you would like to sync all secrets from Infisical to Kubernetes but want to template a subset of them. + **Use this option when you would like to sync all secrets from Infisical to Kubernetes but want to template a subset of them.** When set to `false`, only secrets defined in the `managedSecretReference.template.data` field of the template will be included in the managed secret. - Use this option when you would like to sync only a subset of secrets from Infisical to Kubernetes. + Use this option when you would like to sync **only** a subset of secrets from Infisical to Kubernetes. Define secret keys and their corresponding templates. From 5ef2be1a9c0255512f3a87cbdb674f4b9a568ed0 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 20 Jan 2025 00:08:06 +0530 Subject: [PATCH 5/7] feat: updated function name --- .../infisicalsecret/infisicalsecret_helper.go | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/k8-operator/controllers/infisicalsecret/infisicalsecret_helper.go b/k8-operator/controllers/infisicalsecret/infisicalsecret_helper.go index 4da4226ef..a41d12b38 100644 --- a/k8-operator/controllers/infisicalsecret/infisicalsecret_helper.go +++ b/k8-operator/controllers/infisicalsecret/infisicalsecret_helper.go @@ -155,6 +155,16 @@ func (r *InfisicalSecretReconciler) getInfisicalServiceAccountCredentialsFromKub return model.ServiceAccountDetails{AccessKey: string(accessKeyFromSecret), PrivateKey: string(privateKeyFromSecret), PublicKey: string(publicKeyFromSecret)}, nil } +var infisicalSecretTemplateFunctions = template.FuncMap{ + "decodeBase64ToBytes": func(encodedString string) []byte { + decoded, err := base64.StdEncoding.DecodeString(encodedString) + if err != nil { + panic(fmt.Sprintf("Error: %v", err)) + } + return decoded + }, +} + func (r *InfisicalSecretReconciler) createInfisicalManagedKubeSecret(ctx context.Context, logger logr.Logger, infisicalSecret v1alpha1.InfisicalSecret, secretsFromAPI []model.SingleEnvironmentVariable, ETag string) error { plainProcessedSecrets := make(map[string][]byte) secretType := infisicalSecret.Spec.ManagedSecretReference.SecretType @@ -176,15 +186,7 @@ func (r *InfisicalSecretReconciler) createInfisicalManagedKubeSecret(ctx context } for templateKey, userTemplate := range managedTemplateData.Data { - tmpl, err := template.New("secret-templates").Funcs(template.FuncMap{ - "toBase64DecodedString": func(encodedString string) string { - decoded, err := base64.StdEncoding.DecodeString(encodedString) - if err != nil { - return fmt.Sprintf("Error: %v", err) - } - return string(decoded) - }, - }).Parse(userTemplate) + tmpl, err := template.New("secret-templates").Funcs(infisicalSecretTemplateFunctions).Parse(userTemplate) if err != nil { return fmt.Errorf("unable to compile template: %s [err=%v]", templateKey, err) } @@ -270,15 +272,7 @@ func (r *InfisicalSecretReconciler) updateInfisicalManagedKubeSecret(ctx context } for templateKey, userTemplate := range managedTemplateData.Data { - tmpl, err := template.New("secret-templates").Funcs(template.FuncMap{ - "toBase64DecodedString": func(encodedString string) string { - decoded, err := base64.StdEncoding.DecodeString(encodedString) - if err != nil { - return fmt.Sprintf("Error: %v", err) - } - return string(decoded) - }, - }).Parse(userTemplate) + tmpl, err := template.New("secret-templates").Funcs(infisicalSecretTemplateFunctions).Parse(userTemplate) if err != nil { return fmt.Errorf("unable to compile template: %s [err=%v]", templateKey, err) } @@ -429,11 +423,6 @@ func (r *InfisicalSecretReconciler) ReconcileInfisicalSecret(ctx context.Context return errors.New("no authentication method provided yet. Please configure a authentication method then try again") } - if !updateDetails.Modified { - logger.Info("ReconcileInfisicalSecret: No secrets modified so reconcile not needed") - return nil - } - if managedKubeSecret == nil { return r.createInfisicalManagedKubeSecret(ctx, logger, infisicalSecret, plainTextSecretsFromApi, updateDetails.ETag) } else { From 5cc5a4f03d410fbca8e2127b0c38cfd454478f59 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 20 Jan 2025 00:08:22 +0530 Subject: [PATCH 6/7] feat: updated doc for the function name --- .../kubernetes/infisical-secret-crd.mdx | 76 ++++++++++--------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx b/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx index 37eec35c7..df0730d87 100644 --- a/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx +++ b/docs/integrations/platforms/kubernetes/infisical-secret-crd.mdx @@ -4,7 +4,7 @@ title: "Using the InfisicalSecret CRD" description: "Learn how to use the InfisicalSecret CRD to fetch secrets from Infisical and store them as native Kubernetes secret resource" --- -Once you have installed the operator to your cluster, you'll need to create a `InfisicalSecret` custom resource definition (CRD). +Once you have installed the operator to your cluster, you'll need to create a `InfisicalSecret` custom resource definition (CRD). In this CRD, you'll define the authentication method to use, the secrets to fetch, and the target location to store the secrets within your cluster. ```yaml example-infisical-secret-crd.yaml @@ -18,7 +18,7 @@ metadata: example.com/annotation-to-be-passed-to-managed-secret: "sample-value" spec: hostAPI: https://app.infisical.com/api - resyncInterval: 10 + resyncInterval: 10 authentication: kubernetesAuth: identityId: @@ -29,17 +29,18 @@ spec: managedSecretReference: secretName: managed-secret secretNamespace: default - creationPolicy: "Orphan" + creationPolicy: "Orphan" template: - includeAllSecrets: true - data: - NEW_KEY_NAME: "{{ .KEY.SecretPath }} {{ .KEY.Value }}" - KEY_WITH_BINARY_VALUE: "{{ .KEY.SecretPath }} {{ .KEY.Value }}" + includeAllSecrets: true + data: + NEW_KEY_NAME: "{{ .KEY.SecretPath }} {{ .KEY.Value }}" + KEY_WITH_BINARY_VALUE: "{{ .KEY.SecretPath }} {{ .KEY.Value }}" ``` ## CRD properties ### Generic + The following properties help define what instance of Infisical the operator will interact with, the interval it will sync secrets and any CA certificates that may be required to connect. @@ -93,11 +94,11 @@ When `hostAPI` is not defined the operator fetches secrets from Infisical Cloud. ### Authentication methods -To retrieve the requested secrets, the operator must first authenticate with Infisical. + +To retrieve the requested secrets, the operator must first authenticate with Infisical. The list of available authentication methods are shown below. - - + The universal machine identity authentication method is used to authenticate with Infisical. The client ID and client secret needs to be stored in a Kubernetes secret. This block defines the reference to the name and namespace of secret that stores these credentials. @@ -535,8 +536,9 @@ spec: ### Operator managed secrets -The managed secret properties specify where to store the secrets retrieved from your Infisical project. -This includes defining the name and namespace of the Kubernetes secret that will hold these secrets. + +The managed secret properties specify where to store the secrets retrieved from your Infisical project. +This includes defining the name and namespace of the Kubernetes secret that will hold these secrets. The Infisical operator will automatically create the Kubernetes secret in the specified name/namespace and ensure it stays up-to-date. @@ -566,7 +568,8 @@ This is useful for tools such as ArgoCD, where every resource requires an owner -### Manged secret templating +### Manged secret templating + Fetching secrets from Infisical as is via the operator may not be enough. This is where templating functionality may be helpful. Using Go templates, you can format, combine, and create new key-value pairs from secrets fetched from Infisical before storing them as Kubernetes Secrets. @@ -577,8 +580,9 @@ Using Go templates, you can format, combine, and create new key-value pairs from When set to `true`, all secrets fetched from your Infisical project will be added into your managed Kubernetes secret resource. **Use this option when you would like to sync all secrets from Infisical to Kubernetes but want to template a subset of them.** - When set to `false`, only secrets defined in the `managedSecretReference.template.data` field of the template will be included in the managed secret. - Use this option when you would like to sync **only** a subset of secrets from Infisical to Kubernetes. +When set to `false`, only secrets defined in the `managedSecretReference.template.data` field of the template will be included in the managed secret. +Use this option when you would like to sync **only** a subset of secrets from Infisical to Kubernetes. + Define secret keys and their corresponding templates. @@ -609,6 +613,7 @@ managedSecretReference: ``` For this example, let's assume the following secrets exist in your Infisical project: + ``` DB_PASSWORD = "secret123" COMPANY_NAME = "acme" @@ -617,6 +622,7 @@ API_URL = "old-url" # This will be overridden ``` The resulting managed Kubernetes secret will then contain: + ``` # Original secrets (from includeAllSecrets: true) DB_PASSWORD = "secret123" @@ -632,33 +638,34 @@ To help transform your secrets further, the operator provides a set of built-in ### Available templating functions - - **Function name**: toBase64DecodedString + + **Function name**: decodeBase64ToBytes - **Description**: - Given a base64 encoded string, this function will decodes the base64-encoded string. - This function is useful when your secrets are already stored as base64 encoded value in Infisical. +**Description**: +Given a base64 encoded string, this function will decodes the base64-encoded string. +This function is useful when your secrets are already stored as base64 encoded value in Infisical. - **Returns**: The decoded base64 string +**Returns**: The decoded base64 string as bytes. - **Example**: - The example below assumes that the `BINARY_KEY_BASE64` secret is stored as a base64 encoded value in Infisical. - The resulting managed secret will contain the decoded value of `BINARY_KEY_BASE64`. +**Example**: +The example below assumes that the `BINARY_KEY_BASE64` secret is stored as a base64 encoded value in Infisical. +The resulting managed secret will contain the decoded value of `BINARY_KEY_BASE64`. + +```yaml +managedSecretReference: +secretName: managed-secret +secretNamespace: default +template: + includeAllSecrets: true + data: + BINARY_KEY: "{{ decodeBase64ToBytes .BINARY_KEY_BASE64.Value }}" +``` - ```yaml - managedSecretReference: - secretName: managed-secret - secretNamespace: default - template: - includeAllSecrets: true - data: - BINARY_KEY: "{{ toBase64DecodedString .BINARY_KEY_BASE64.Value }}" - ``` -## Applying CRD +## Applying CRD Once you have configured the InfisicalSecret CRD with the required fields, you can apply it to your cluster. After applying, you should notice that the managed secret has been created in the desired namespace your specified. @@ -928,4 +935,3 @@ type: Opaque ``` - From b9d06ff6866ba224a468bc473e6053b2e7432c68 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Sun, 19 Jan 2025 13:50:24 -0500 Subject: [PATCH 7/7] update operator version --- helm-charts/secrets-operator/Chart.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helm-charts/secrets-operator/Chart.yaml b/helm-charts/secrets-operator/Chart.yaml index 6e59c8d0c..bf418ec3d 100644 --- a/helm-charts/secrets-operator/Chart.yaml +++ b/helm-charts/secrets-operator/Chart.yaml @@ -13,9 +13,9 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: v0.8.2 +version: v0.8.3 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "v0.8.2" +appVersion: "v0.8.3"