diff --git a/helm-charts/secrets-operator/templates/infisicalsecret-crd.yaml b/helm-charts/secrets-operator/templates/infisicalsecret-crd.yaml index 18198d365..e024758ee 100644 --- a/helm-charts/secrets-operator/templates/infisicalsecret-crd.yaml +++ b/helm-charts/secrets-operator/templates/infisicalsecret-crd.yaml @@ -1,4 +1,3 @@ -{{- if .Values.installCRDs }} apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: @@ -301,6 +300,48 @@ spec: - secretName - secretNamespace type: object + managedSecretReferences: + items: + properties: + creationPolicy: + default: Orphan + description: 'The Kubernetes Secret creation policy. Enum with + values: ''Owner'', ''Orphan''. Owner creates the secret and + sets .metadata.ownerReferences of the InfisicalSecret CRD that + created it. Orphan will not set the secret owner. This will + result in the secret being orphaned and not deleted when the + resource is deleted.' + type: string + secretName: + description: The name of the Kubernetes Secret + type: string + secretNamespace: + description: The name space where the Kubernetes Secret is located + type: string + secretType: + default: Opaque + description: 'The Kubernetes Secret type (experimental feature). + More info: https://kubernetes.io/docs/concepts/configuration/secret/#secret-types' + type: string + template: + description: The template to transform the secret data + properties: + data: + additionalProperties: + type: string + description: The template key values + type: object + includeAllSecrets: + description: This injects all retrieved secrets into the top + level of your template. Secrets defined in the template + will take precedence over the injected ones. + type: boolean + type: object + required: + - secretName + - secretNamespace + type: object + type: array resyncInterval: default: 60 type: integer @@ -338,7 +379,6 @@ spec: - secretNamespace type: object required: - - managedSecretReference - resyncInterval type: object status: @@ -425,5 +465,4 @@ status: kind: "" plural: "" conditions: [] - storedVersions: [] -{{- end }} \ No newline at end of file + storedVersions: [] \ No newline at end of file diff --git a/k8-operator/controllers/infisicalsecret/infisicalsecret_controller.go b/k8-operator/controllers/infisicalsecret/infisicalsecret_controller.go index 7df44c8d2..5c0b14600 100644 --- a/k8-operator/controllers/infisicalsecret/infisicalsecret_controller.go +++ b/k8-operator/controllers/infisicalsecret/infisicalsecret_controller.go @@ -89,6 +89,12 @@ func (r *InfisicalSecretReconciler) Reconcile(ctx context.Context, req ctrl.Requ managedSecretReferences = append(managedSecretReferences, infisicalSecretCRD.Spec.ManagedSecretReference) } + if len(managedSecretReferences) == 0 { + errMessage := "InfisicalSecret CRD must have at least one managed secret reference set in the `managedSecretReferences` field" + logger.Error(defaultErrors.New(errMessage), errMessage) + return ctrl.Result{}, defaultErrors.New(errMessage) + } + // Remove finalizers if they exist. This is to support previous InfisicalSecret CRD's that have finalizers on them. // In order to delete secrets with finalizers, we first remove the finalizers so we can use the simplified and improved deletion process if !infisicalSecretCRD.ObjectMeta.DeletionTimestamp.IsZero() && len(infisicalSecretCRD.ObjectMeta.Finalizers) > 0 {