add caBundleSecretRef field support to internal APIs

Signed-off-by: Sankalp Yengaldas <sankalp.yb@fmr.com>
This commit is contained in:
Sankalp Yengaldas 2024-04-24 02:31:09 -04:00
parent 066ed9045d
commit 660be1d278
6 changed files with 69 additions and 0 deletions

View File

@ -142,6 +142,13 @@ type VenafiTPP struct {
// If undefined, the certificate bundle in the cert-manager controller container
// is used to validate the chain.
CABundle []byte
// Reference to a Secret containing a base64-encoded bundle of PEM CAs
// which will be used to validate the certificate chain presented by the TPP server.
// Only used if using HTTPS; ignored for HTTP. Mutually exclusive with CABundle.
// If neither CABundle nor CABundleSecretRef is defined, the certificate bundle in
// the cert-manager controller container is used to validate the TLS connection.
CABundleSecretRef *cmmeta.SecretKeySelector `json:"caBundleSecretRef,omitempty"`
}
// VenafiCloud defines connection configuration details for Venafi Cloud

View File

@ -156,6 +156,14 @@ type VenafiTPP struct {
// is used to validate the chain.
// +optional
CABundle []byte `json:"caBundle,omitempty"`
// Reference to a Secret containing a base64-encoded bundle of PEM CAs
// which will be used to validate the certificate chain presented by the TPP server.
// Only used if using HTTPS; ignored for HTTP. Mutually exclusive with CABundle.
// If neither CABundle nor CABundleSecretRef is defined, the certificate bundle in
// the cert-manager controller container is used to validate the TLS connection.
// +optional
CABundleSecretRef *cmmeta.SecretKeySelector `json:"caBundleSecretRef,omitempty"`
}
// VenafiCloud defines connection configuration details for Venafi Cloud

View File

@ -156,6 +156,14 @@ type VenafiTPP struct {
// is used to validate the chain.
// +optional
CABundle []byte `json:"caBundle,omitempty"`
// Reference to a Secret containing a base64-encoded bundle of PEM CAs
// which will be used to validate the certificate chain presented by the TPP server.
// Only used if using HTTPS; ignored for HTTP. Mutually exclusive with CABundle.
// If neither CABundle nor CABundleSecretRef is defined, the certificate bundle in
// the cert-manager controller container is used to validate the TLS connection.
// +optional
CABundleSecretRef *cmmeta.SecretKeySelector `json:"caBundleSecretRef,omitempty"`
}
// VenafiCloud defines connection configuration details for Venafi Cloud

View File

@ -158,6 +158,14 @@ type VenafiTPP struct {
// is used to validate the chain.
// +optional
CABundle []byte `json:"caBundle,omitempty"`
// Reference to a Secret containing a base64-encoded bundle of PEM CAs
// which will be used to validate the certificate chain presented by the TPP server.
// Only used if using HTTPS; ignored for HTTP. Mutually exclusive with CABundle.
// If neither CABundle nor CABundleSecretRef is defined, the certificate bundle in
// the cert-manager controller container is used to validate the TLS connection.
// +optional
CABundleSecretRef *cmmeta.SecretKeySelector `json:"caBundleSecretRef,omitempty"`
}
// VenafiCloud defines connection configuration details for Venafi Cloud

View File

@ -359,6 +359,25 @@ func ValidateVenafiTPP(tpp *certmanager.VenafiTPP, fldPath *field.Path) (el fiel
// TODO: validate CABundle using validateCABundleNotEmpty
// Validate only one of CABundle/CABundleSecretRef is passed
el = append(el, validateVenafiTPPCABundleUnique(tpp, fldPath)...)
return el
}
func validateVenafiTPPCABundleUnique(tpp *certmanager.VenafiTPP, fldPath *field.Path) (el field.ErrorList) {
numCAs := 0
if len(tpp.CABundle) > 0 {
numCAs++
}
if tpp.CABundleSecretRef != nil {
numCAs++
}
if numCAs > 1 {
el = append(el, field.Forbidden(fldPath, "may not specify more than one of caBundle/caBundleSecretRef as TPP CA Bundle"))
}
return el
}

View File

@ -1642,6 +1642,10 @@ func TestValidateVenafiIssuerConfig(t *testing.T) {
}
func TestValidateVenafiTPP(t *testing.T) {
caBundle := unitcrypto.MustCreateCryptoBundle(t,
&pubcmapi.Certificate{Spec: pubcmapi.CertificateSpec{CommonName: "test"}},
clock.RealClock{},
).CertBytes
fldPath := field.NewPath("test")
scenarios := map[string]struct {
cfg *cmapi.VenafiTPP
@ -1658,6 +1662,21 @@ func TestValidateVenafiTPP(t *testing.T) {
field.Required(fldPath.Child("url"), ""),
},
},
"venafi TPP issuer defines both caBundle and caBundleSecretRef": {
cfg: &cmapi.VenafiTPP{
URL: "https://tpp.example.com/vedsdk",
CABundle: caBundle,
CABundleSecretRef: &cmmeta.SecretKeySelector{
Key: "ca.crt",
LocalObjectReference: cmmeta.LocalObjectReference{
Name: "test-secret",
},
},
},
errs: []*field.Error{
field.Forbidden(fldPath, "may not specify more than one of caBundle/caBundleSecretRef as TPP CA Bundle"),
},
},
}
for n, s := range scenarios {