Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook: validate certificateRefs when tls is set and mode is Terminate. #1460

Merged

Conversation

gyohuangxin
Copy link
Member

@gyohuangxin gyohuangxin commented Oct 17, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

When the TLSModeType is set to terminate, there is always the need for a valid certificate to terminate the TLS connection.
This PR validates the certificateRefs must be set and not empty when tls config is set and tls mode is terminate.

Which issue(s) this PR fixes:

Fixes #1441

Does this PR introduce a user-facing change?:

NONE

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 17, 2022
@gyohuangxin gyohuangxin marked this pull request as ready for review October 17, 2022 05:54
@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Oct 17, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @gyohuangxin. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 17, 2022
@gyohuangxin
Copy link
Member Author

@mlavacca Since you created the issue, please review this PR, thanks.

Copy link
Member

@mlavacca mlavacca left a comment

Choose a reason for hiding this comment

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

This validation should be put into the v1alpha2 package as well.

apis/v1beta1/validation/gateway.go Outdated Show resolved Hide resolved
apis/v1beta1/validation/gateway.go Outdated Show resolved Hide resolved
apis/v1beta1/validation/gateway.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 18, 2022
@gyohuangxin
Copy link
Member Author

@mlavacca Thanks for your comments, please review again.

@gyohuangxin gyohuangxin force-pushed the vilidate_certificateRefs branch from f705a8d to 02e1e0d Compare October 18, 2022 13:41
@shaneutt shaneutt requested a review from mlavacca October 18, 2022 14:15
@mlavacca
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 18, 2022
Copy link
Member

@mlavacca mlavacca left a comment

Choose a reason for hiding this comment

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

Apart from a tiny nit related to the comment, it looks good. Thank you!

apis/v1alpha2/validation/gateway.go Outdated Show resolved Hide resolved
@gyohuangxin
Copy link
Member Author

@mlavacca Thank you for your comments!

Copy link
Member

@shaneutt shaneutt left a comment

Choose a reason for hiding this comment

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

Everything looks good, the only thing is in other PRs we're trying to consolidate copied code between v1alpha2 and v1beta1. I would ask that since it appears there are no differences, just keep the v1beta1 copy of the code and tests, and include that in the v1alpha2 validation for the time being.

@gyohuangxin
Copy link
Member Author

@shaneutt Sounds good, could you give the example PR I can refer to?

@shaneutt
Copy link
Member

Sure, #1412 is the most recent example.

@gyohuangxin gyohuangxin force-pushed the vilidate_certificateRefs branch from 1160fff to 7b2d1bb Compare October 19, 2022 02:30
@gyohuangxin
Copy link
Member Author

@shaneutt I keep the v1beta1 validation code and tests, and include that in the v1alpha2 validation. Please review again, thanks.

@gyohuangxin
Copy link
Member Author

A request not related to this PR, I'd like to join the kubernetes-sigs org to continuously contribute to this project in the future. Would you like to be my sponsors @mlavacca @shaneutt ?

@mlavacca
Copy link
Member

A request not related to this PR, I'd like to join the kubernetes-sigs org to continuously contribute to this project in the future. Would you like to be my sponsors @mlavacca @shaneutt ?

I'd like to, but unfortunately, I'm not a reviewer. Hence, I cannot sponsor you, as stated on the community page.

@michaelbeaumont
Copy link
Contributor

TLS is the TLS configuration for the Listener. This field is required if the Protocol field is “HTTPS” or “TLS”.

From reading the docs, i.e. the field comments, I would say we can validate that tls must be set when HTTPS is the protocol. Terminate is the default mode and when Terminate is set, certificateRefs must be set, right?

@gyohuangxin
Copy link
Member Author

TLS is the TLS configuration for the Listener. This field is required if the Protocol field is “HTTPS” or “TLS”.

From reading the docs, i.e. the field comments, I would say we can validate that tls must be set when HTTPS is the protocol. Terminate is the default mode and when Terminate is set, certificateRefs must be set, right?

Correct, but the validation to validate that tls must be set when HTTPS/TLS is the protocol is not implemented yet. We can implement it quickly in this function ValidateTLSCertificateRefs or create another PR for another independent validation function. What do you think? @mlavacca @michaelbeaumont

@gyohuangxin
Copy link
Member Author

A request not related to this PR, I'd like to join the kubernetes-sigs org to continuously contribute to this project in the future. Would you like to be my sponsors @mlavacca @shaneutt ?

I'd like to, but unfortunately, I'm not a reviewer. Hence, I cannot sponsor you, as stated on the community page.

It's OK, sorry for missing this, thanks anyway.

@mlavacca
Copy link
Member

mlavacca commented Oct 19, 2022

I think we should add this validation here, where we already check that TLS must not be set when the protocol is HTTP, TCP, or UDP. If you want to implement this check here, @gyohuangxin, I suggest updating the issue fixed by this PR by adding this check, or creating a new issue, since this looks like a new webhook feature.

@gyohuangxin
Copy link
Member Author

@mlavacca Yes, it's a better place. I prefer create another issue to implement it, I will create one later.

Copy link
Member

@shaneutt shaneutt left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 19, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gyohuangxin, mlavacca, shaneutt

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 19, 2022
@shaneutt shaneutt added this to the v0.6.0 milestone Oct 19, 2022
@k8s-ci-robot k8s-ci-robot merged commit b9f9770 into kubernetes-sigs:main Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

webhook: validate certificateRefs when tls is set and mode is Terminate
5 participants