diff --git a/deploy/crds/crd-certificates.yaml b/deploy/crds/crd-certificates.yaml index dc1758b63..ec7d01b48 100644 --- a/deploy/crds/crd-certificates.yaml +++ b/deploy/crds/crd-certificates.yaml @@ -134,7 +134,7 @@ spec: - passwordSecretRef properties: create: - description: Create enables JKS keystore creation for the Certificate. If true, a file named `keystore.jks` will be created in the target Secret resource, encrypted using the password stored in `passwordSecretRef`. The keystore file will be updated immediately. A file named `truststore.jks` will also be created in the target Secret resource, encrypted using the password stored in `passwordSecretRef` containing the issuing Certificate Authority + description: Create enables JKS keystore creation for the Certificate. If true, a file named `keystore.jks` will be created in the target Secret resource, encrypted using the password stored in `passwordSecretRef`. The keystore file will be updated immediately. If the issuer provided a CA certificate, a file named `truststore.jks` will also be created in the target Secret resource, encrypted using the password stored in `passwordSecretRef` containing the issuing Certificate Authority type: boolean passwordSecretRef: description: PasswordSecretRef is a reference to a key in a Secret resource containing the password used to encrypt the JKS keystore. @@ -156,7 +156,7 @@ spec: - passwordSecretRef properties: create: - description: Create enables PKCS12 keystore creation for the Certificate. If true, a file named `keystore.p12` will be created in the target Secret resource, encrypted using the password stored in `passwordSecretRef`. The keystore file will be updated immediately. A file named `truststore.p12` will also be created in the target Secret resource, encrypted using the password stored in `passwordSecretRef` containing the issuing Certificate Authority + description: Create enables PKCS12 keystore creation for the Certificate. If true, a file named `keystore.p12` will be created in the target Secret resource, encrypted using the password stored in `passwordSecretRef`. The keystore file will be updated immediately. If the issuer provided a CA certificate, a file named `truststore.p12` will also be created in the target Secret resource, encrypted using the password stored in `passwordSecretRef` containing the issuing Certificate Authority type: boolean passwordSecretRef: description: PasswordSecretRef is a reference to a key in a Secret resource containing the password used to encrypt the PKCS12 keystore. diff --git a/internal/controller/certificates/policies/checks.go b/internal/controller/certificates/policies/checks.go index e3a65d428..c38bc63a6 100644 --- a/internal/controller/certificates/policies/checks.go +++ b/internal/controller/certificates/policies/checks.go @@ -33,6 +33,7 @@ import ( "sigs.k8s.io/structured-merge-diff/v4/fieldpath" "sigs.k8s.io/structured-merge-diff/v4/value" + cmmeta "github.com/cert-manager/cert-manager/internal/apis/meta" internalcertificates "github.com/cert-manager/cert-manager/internal/controller/certificates" cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" "github.com/cert-manager/cert-manager/pkg/util/pki" @@ -100,6 +101,8 @@ func SecretPrivateKeyMatchesSpec(input Input) (string, string, bool) { // If the private key rotation is set to "Never", the key store related values are re-encoded // as per the certificate specification func SecretKeystoreFormatMatchesSpec(input Input) (string, string, bool) { + _, issuerProvidesCA := input.Secret.Data[cmmeta.TLSCAKey] + if input.Certificate.Spec.Keystores == nil { if len(input.Secret.Data[cmapi.PKCS12SecretKey]) != 0 || len(input.Secret.Data[cmapi.PKCS12TruststoreKey]) != 0 || @@ -113,8 +116,8 @@ func SecretKeystoreFormatMatchesSpec(input Input) (string, string, bool) { if input.Certificate.Spec.Keystores.JKS != nil { if input.Certificate.Spec.Keystores.JKS.Create { if len(input.Secret.Data[cmapi.JKSSecretKey]) == 0 || - len(input.Secret.Data[cmapi.JKSTruststoreKey]) == 0 { - return SecretMismatch, "JKS Keystore keys does not contain data", true + (len(input.Secret.Data[cmapi.JKSTruststoreKey]) == 0 && issuerProvidesCA) { + return SecretMismatch, "JKS Keystore key does not contain data", true } } else { if len(input.Secret.Data[cmapi.JKSSecretKey]) != 0 || @@ -132,8 +135,8 @@ func SecretKeystoreFormatMatchesSpec(input Input) (string, string, bool) { if input.Certificate.Spec.Keystores.PKCS12 != nil { if input.Certificate.Spec.Keystores.PKCS12.Create { if len(input.Secret.Data[cmapi.PKCS12SecretKey]) == 0 || - len(input.Secret.Data[cmapi.PKCS12TruststoreKey]) == 0 { - return SecretMismatch, "PKCS12 Keystore keys does not contain data", true + (len(input.Secret.Data[cmapi.PKCS12TruststoreKey]) == 0 && issuerProvidesCA) { + return SecretMismatch, "PKCS12 Keystore key does not contain data", true } } else { if len(input.Secret.Data[cmapi.PKCS12SecretKey]) != 0 || diff --git a/pkg/apis/certmanager/v1/types_certificate.go b/pkg/apis/certmanager/v1/types_certificate.go index 5ede2120a..767a18ffc 100644 --- a/pkg/apis/certmanager/v1/types_certificate.go +++ b/pkg/apis/certmanager/v1/types_certificate.go @@ -357,9 +357,10 @@ type JKSKeystore struct { // Secret resource, encrypted using the password stored in // `passwordSecretRef`. // The keystore file will be updated immediately. - // A file named `truststore.jks` will also be created in the target - // Secret resource, encrypted using the password stored in - // `passwordSecretRef` containing the issuing Certificate Authority + // If the issuer provided a CA certificate, a file named `truststore.jks` + // will also be created in the target Secret resource, encrypted using the + // password stored in `passwordSecretRef` + // containing the issuing Certificate Authority Create bool `json:"create"` // PasswordSecretRef is a reference to a key in a Secret resource @@ -375,9 +376,10 @@ type PKCS12Keystore struct { // Secret resource, encrypted using the password stored in // `passwordSecretRef`. // The keystore file will be updated immediately. - // A file named `truststore.p12` will also be created in the target - // Secret resource, encrypted using the password stored in - // `passwordSecretRef` containing the issuing Certificate Authority + // If the issuer provided a CA certificate, a file named `truststore.p12` will + // also be created in the target Secret resource, encrypted using the + // password stored in `passwordSecretRef` containing the issuing Certificate + // Authority Create bool `json:"create"` // PasswordSecretRef is a reference to a key in a Secret resource