Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Validate fields of OpenstackDataPlaneServiceCert in OpenStackDataPlaneServiceSpec #852

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jpodivin
Copy link
Contributor

@jpodivin jpodivin commented Apr 23, 2024

No description provided.

Copy link
Contributor

openshift-ci bot commented Apr 23, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link
Contributor

openshift-ci bot commented Apr 23, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jpodivin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

// +kubebuilder:validation:Optional
KeyUsages []certmgrv1.KeyUsage `json:"keyUsages,omitempty" yaml:"keyUsages,omitempty"`
// +kubebuilder:default={"key encipherment","digital signature","server auth"}
KeyUsages []certmgrv1.KeyUsage `json:"keyUsages" yaml:"keyUsages"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making the default explicit is good. I thought though, that when you mentioned this tightening of the spec would include turning the Contents field into an enum - with "dnsnames" and "ips" as the two possible options. That would result in validation errors in the same way that KeyUsages currently does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contents is list, not a string, enum wouldn't work there because you need list a approved values. Hence the ValidateContents method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but we can -- and that what I thought you wanted to do -- redefine Contents as a list of enums - just like keyusages is a list of certmgrv1.KeyUsage. We can define a new enum of CertificateContents for example.

Copy link
Contributor Author

@jpodivin jpodivin Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That isn't really the point. Kubebuilder enum [0] should be used in cases when field must have only one of the values from approved a list. Not when the field is supposed to be a list of approved values.

Enum validation just doesn't fit our use case here, and we shouldn't try to change the API just to make it fit.
Putting the validation in a function is, imho, a cleaner approach.
[0] https://book.kubebuilder.io/reference/markers/crd-validation.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe enum wasn't the right thing here. My point is that we expect contents to be one of a set of approved values. KeyUsages (https://github.com/cert-manager/cert-manager/blob/eb9f8880fdf9a02c2f85e73cc08617c350717378/pkg/api/util/usages.go#L26) is a similar thing, and we can use an equivalent structure to make that explicit - and thereby enforce it in the same way that KeyUsages are enforced.

r.KeyUsages,
fmt.Sprintf("error validating contents of TLSCert, %s, only valid contents are %v ", val, allowedContents)))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um -- this validation function is all confused. You are defining the allowed contents for "Contents" and checking that - while putting up an error message associated with KeyUsages. That said - if we changed Contents to be an enum - with the appropriate default - would this whole function be necessary at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because it started is function for keyusages. I wanted to see the test results, before rewriting the comment's, logs etc.

@jpodivin jpodivin changed the title Validate fields of OpenstackDataPlaneServiceCert in OpenStackDataPlan… Validate fields of OpenstackDataPlaneServiceCert in OpenStackDataPlaneServiceSpec May 28, 2024
Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://review.rdoproject.org/zuul/buildset/c084a42e51dc48049e85622f9d5dd6f0

✔️ openstack-k8s-operators-content-provider SUCCESS in 2h 08m 30s
podified-multinode-edpm-deployment-crc RETRY_LIMIT in 29m 59s
✔️ cifmw-crc-podified-edpm-baremetal SUCCESS in 1h 14m 35s

…eServiceSpec

Set default KeyUsages to "key encipherment","digital signature","server auth".

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants