Skip to content

Conversation

@jkhelil
Copy link
Contributor

@jkhelil jkhelil commented Dec 9, 2025

This change adds minimal TLS configuration API for webhooks : TLSMaxVersion, TLSCipherSuites, and TLSCurvePreferences fields to webhook.Options for granular TLS control

  • TLSMaxVersion: enforce Modern profile
  • TLSCipherSuites: custom cipher suites
  • TLSCurvePreferences: elliptic curve configuration

Changes:

  • Add TLSMaxVersion, TLSCipherSuites, and TLSCurvePreferences fields to webhook.Options
  • Added unit tests for all new fields
  • Added documentation for webhook tls (README)
  • Maintains backward compatibility with existing TLSMinVersion usage
  • 🎁 Add new feature
  • 🐛 Fix bug

/kind enhancement

Fixes #3299

Release Note

Enhanced webhook TLS configuration with support for max version, custom cipher suites, and curve preferences.

Docs


@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 9, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: jkhelil / name: khelil (c6bbfb2)

@knative-prow
Copy link

knative-prow bot commented Dec 9, 2025

Welcome @jkhelil! It looks like this is your first PR to knative/pkg 🎉

@knative-prow knative-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 9, 2025
@knative-prow
Copy link

knative-prow bot commented Dec 9, 2025

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 /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.

Details

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-sigs/prow repository.

@knative-prow knative-prow bot requested review from creydr and skonto December 9, 2025 18:11
@vdemeester
Copy link
Contributor

cc @dprotaso

@twoGiants
Copy link

/cc @twoGiants

@knative-prow knative-prow bot requested a review from twoGiants December 15, 2025 12:55
Copy link

@twoGiants twoGiants left a 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.

// 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

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

Copy link
Contributor

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 👼🏼

Copy link
Contributor Author

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:

  1. Full api: net/http exposes complete TLSConfig https://pkg.go.dev/net/http#Server
  2. 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

}
return &cert, nil
},
webhook.tlsConfig.GetCertificate = getCertificate

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?

Copy link
Contributor Author

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

// 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 {

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.

Copy link
Contributor Author

@jkhelil jkhelil Dec 16, 2025

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.


// 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.",

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.

Copy link
Contributor Author

@jkhelil jkhelil Dec 16, 2025

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.

})
}

func TestCustomTLSConfigWebhookOption(t *testing.T) {

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.

Copy link
Contributor Author

@jkhelil jkhelil Dec 16, 2025

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.

@jkhelil jkhelil force-pushed the webhook_tlsconfig branch 3 times, most recently from 29d8caa to f75549e Compare December 16, 2025 13:59
@jkhelil jkhelil changed the title Add TLSConfig field to webhook.Options for full TLS customization Add TLSMaxVersion, TLSCipherSuites, and TLSCurvePreferences fields to webhook.Options for minimal tls customization Dec 16, 2025
@jkhelil jkhelil changed the title Add TLSMaxVersion, TLSCipherSuites, and TLSCurvePreferences fields to webhook.Options for minimal tls customization Add TLSMaxVersion, TLSCipherSuites, and TLSCurvePreferences to webhook.Options for minimal tls customization Dec 16, 2025
@jkhelil jkhelil force-pushed the webhook_tlsconfig branch 2 times, most recently from 1fe3ad7 to 9819d5e Compare December 16, 2025 14:10
@dprotaso
Copy link
Member

/ok-to-test

@knative-prow knative-prow bot 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 Dec 16, 2025
@dprotaso
Copy link
Member

dprotaso commented Dec 16, 2025

Change looks good - just see the linter warnings about extra whitespace

@codecov
Copy link

codecov bot commented Dec 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.59%. Comparing base (9cc8410) to head (c6bbfb2).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dprotaso
Copy link
Member

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Dec 17, 2025
@knative-prow
Copy link

knative-prow bot commented Dec 17, 2025

[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

Details 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

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 17, 2025
@knative-prow knative-prow bot merged commit 80c8bc4 into knative:main Dec 17, 2025
36 checks passed
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. kind/enhancement lgtm 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/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose TLS configuration for webhook servers to support platform-managed TLS policies

4 participants