-
Notifications
You must be signed in to change notification settings - Fork 339
Add TLSMaxVersion, TLSCipherSuites, and TLSCurvePreferences to webhook.Options for minimal tls customization #3300
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
Conversation
|
|
|
Welcome @jkhelil! It looks like this is your first PR to knative/pkg 🎉 |
|
Hi @jkhelil. Thanks for your PR. I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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-sigs/prow repository. |
5f6a041 to
4104846
Compare
|
cc @dprotaso |
|
/cc @twoGiants |
twoGiants
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jkhelil ! Thank you for the contribution 😸
I propose to go a more defensive approach or if we use the tls.Config to deprecate the current API. See my comments below.
webhook/webhook.go
Outdated
| // Note: When providing TLSConfig, ensure MinVersion is set appropriately for security. | ||
| // If MinVersion is not set in the provided TLSConfig, it will default to Go's default | ||
| // (currently TLS 1.2), which may be less secure than the webhook's default of TLS 1.3. | ||
| TLSConfig *tls.Config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First point I want to mention.
Not sure if providing access to the full tls.Config API is necessary. I prefer minimal API where possible, but I am not a TLS expert and maybe that is the call here BUT hear me out 😺 :
How about expanding the current API to support:
type Options struct {
TLSMinVersion uint16 // Existing
TLSMaxVersion uint16 // NEW - for Modern profile (TLS 1.3 only)
TLSCipherSuites []uint16 // NEW
TLSCurvePreferences []tls.CurveID // NEW
TLSPreferServerCiphers bool // NEW - for Old profile
}Then all you mentioned in the issue would be covered. But for future needs/changes another code change would be needed => which I personally prefer over a bigger API.
Second point I want to mention.
If it is decided to go the route of keeping the current TLSMinVersion AND adding the full tls.Config like in the PR => I would prefer to deprecating the current TLSMinVersion and then switch entirely to the tls.Config. Then the min version validation for >= 1.2 must be done on the provided tls.Config so that the current functionality remains preserved. Deprecation comments then be added here and in the documentation and in the code and we probably need an issue so we don't forget to remove it in the next or later versions. Also I would then enforce the user to be able to use only one of the options => either set TLSMinVersion or tls.Config but not both.
What do the others say? @vdemeester @dprotaso @creydr @Cali0707
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to agree with @twoGiants here 👼🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@twoGiants Thank you for the thoughtful review. I appreciate your preference for a minimal API, and I share that hesitation.
I've observed two patterns in the ecosystem:
- Full api: net/http exposes complete TLSConfig https://pkg.go.dev/net/http#Server
- Selected fields: Kubernetes apiserver exposes specific fields https://github.com/kubernetes/apiserver/blob/master/pkg/server/options/serving.go#L66
After reflection, I'm leaning toward the minimal API approach for the following reasons:
- We can keep the existing TLSMinVersion field without deprecation
- Reduces breaking changes and migration burden
- WEBHOOK_TLS_MIN_VERSION env var continues working as-is(prevents breaking TLS 1.2 clients)
- Users won't accidentally override certificate loading logic
- Smaller API surface to review and maintain
and it makes the pr much more simple
webhook/webhook.go
Outdated
| } | ||
| return &cert, nil | ||
| }, | ||
| webhook.tlsConfig.GetCertificate = getCertificate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe bug: Now if the user provides a GetCertificate function with his tls.Config it will be overwritten => this is not documented. Is this desired?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the recent update, this is nolonger relevant
webhook/webhook.go
Outdated
| // Use custom TLSConfig if provided, otherwise create default config | ||
| if opts.TLSConfig != nil { | ||
| // Check if both custom TLSConfig and environment variable are set | ||
| if envTLSVersion := TLSMinVersionFromEnv(0); envTLSVersion != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the new configuration the TLSMinVersion can remain unset or even be set to some old insecure versions. Currently this is not possible => only TLS 1.2 and 1.3 are allowed and the default is TLS 1.3. There is a warning but the setup continues => I would prefer to return an error if it's lower than 1.2.
And as mentioned above => I would prefer to use one way OR the other and enforce the user to do so too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the latest changes, this concern is no longer relevant.
webhook/webhook.go
Outdated
|
|
||
| // Warn if MinVersion is not set in the provided TLSConfig | ||
| if webhook.tlsConfig.MinVersion == 0 { | ||
| logger.Warnw("TLSConfig.MinVersion is not set, will use Go's default (TLS 1.2). Consider setting MinVersion explicitly for better security.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is 1.3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the latest changes, this concern is no longer relevant.
webhook/webhook_test.go
Outdated
| }) | ||
| } | ||
|
|
||
| func TestCustomTLSConfigWebhookOption(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing testcase for tls.Config without TLSMinVerision or a lower than 1.2 version => which should not be possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the latest changes, this concern is no longer relevant.
29d8caa to
f75549e
Compare
1fe3ad7 to
9819d5e
Compare
|
/ok-to-test |
|
Change looks good - just see the linter warnings about extra whitespace |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3300 +/- ##
=======================================
Coverage 74.58% 74.59%
=======================================
Files 188 188
Lines 8187 8190 +3
=======================================
+ Hits 6106 6109 +3
Misses 1841 1841
Partials 240 240 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…k.Options for enhanced TLS control
9819d5e to
c6bbfb2
Compare
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dprotaso, jkhelil The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This change adds minimal TLS configuration API for webhooks : TLSMaxVersion, TLSCipherSuites, and TLSCurvePreferences fields to webhook.Options for granular TLS control
Changes:
/kind enhancement
Fixes #3299
Release Note
Docs