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

feat: Add ca to check the validation of the member clusters' server certificate #4183

Merged
merged 1 commit into from
Oct 26, 2023

Conversation

jwcesign
Copy link
Member

@jwcesign jwcesign commented Oct 26, 2023

What type of PR is this?
/kind feature

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #4182

Special notes for your reviewer:
If I change the following line to false:

TLS: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec

It will have the following error in karmada-aggregated-apiserver:
01d9281bfb18dfd30d78ab197884c43

And karmadactl couldn't list the pods in member clusters:
d2a7ad79b3a939f7263191265be2176

With this PR, everything works fine

Does this PR introduce a user-facing change?:

`karmada-aggregated-apiserver`: Add ca to check the validation of the member clusters' server certificate.

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Oct 26, 2023
@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 26, 2023
@jwcesign
Copy link
Member Author

Copy link
Member

@zishen zishen left a comment

Choose a reason for hiding this comment

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

Good for validating the member clusters' server certificate

@RainbowMango
Copy link
Member

@@ -94,14 +102,39 @@ func NewThrottledUpgradeAwareProxyHandler(location *url.URL, transport http.Roun
return proxy.NewUpgradeAwareHandler(location, transport, wrapTransport, upgradeRequired, proxy.NewErrorResponder(responder))
}

func GetTlsConfigForCluster(ctx context.Context, cluster *clusterapis.Cluster, secretGetter SecretGetterFunc) (*tls.Config, error) {
if cluster.Spec.SecretRef == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Can you remind me when the secret would not exist?

Copy link
Member Author

@jwcesign jwcesign Oct 26, 2023

Choose a reason for hiding this comment

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

From my point of view, it couldn't be empty. But I saw it's an optional field in the struct comment. Or I delete this field with kubectl.

Copy link
Member

Choose a reason for hiding this comment

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

For Pull mode cluster, the karmada-agent may not set the secret, see the usage from karmada-agent:

      --report-secrets strings                                                                                                                                                                     
                The secrets that are allowed to be reported to the Karmada control plane during registering. Valid values are 'KubeCredentials', 'KubeImpersonator' and 'None'. e.g
                'KubeCredentials,KubeImpersonator' or 'None'. (default [KubeCredentials,KubeImpersonator])

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if cluster.Spec.SecretRef == nil {
// The secret is optional for a pull-mode cluster, if no secret just returns a config with root CA unset.
if cluster.Spec.SecretRef == nil {

Maybe we can have a comment here.

return &tls.Config{
RootCAs: caCertPool,
MinVersion: tls.VersionTLS13,
InsecureSkipVerify: cluster.Spec.InsecureSkipTLSVerification, //nolint:gosec
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove the nolint:gosec now?

Same as above.

Copy link
Member Author

@jwcesign jwcesign Oct 26, 2023

Choose a reason for hiding this comment

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

If delete it, there is a lint error: cluster.Spec.InsecureSkipTLSVerification may be true.

But it's allowed to be true(if users want to do it).

Copy link
Member

Choose a reason for hiding this comment

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

Before:

pkg/util/proxy/proxy.go:109:24: G402: TLS InsecureSkipVerify set true. (gosec)
			InsecureSkipVerify: true,

After:

pkg/util/proxy/proxy.go:109:24: G402: TLS InsecureSkipVerify may be true. (gosec)
			InsecureSkipVerify: cluster.Spec.InsecureSkipTLSVerification,

we might need a comment to explain it.

@karmada-bot karmada-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 26, 2023
@jwcesign jwcesign force-pushed the fix-insecure branch 2 times, most recently from a360866 to 4e89504 Compare October 26, 2023 12:36
pkg/util/proxy/proxy.go Outdated Show resolved Hide resolved
@@ -94,14 +102,39 @@ func NewThrottledUpgradeAwareProxyHandler(location *url.URL, transport http.Roun
return proxy.NewUpgradeAwareHandler(location, transport, wrapTransport, upgradeRequired, proxy.NewErrorResponder(responder))
}

func GetTlsConfigForCluster(ctx context.Context, cluster *clusterapis.Cluster, secretGetter SecretGetterFunc) (*tls.Config, error) {
if cluster.Spec.SecretRef == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if cluster.Spec.SecretRef == nil {
// The secret is optional for a pull-mode cluster, if no secret just returns a config with root CA unset.
if cluster.Spec.SecretRef == nil {

Maybe we can have a comment here.

@codecov-commenter
Copy link

Codecov Report

Attention: 36 lines in your changes are missing coverage. Please review.

Comparison is base (3267155) 52.91% compared to head (473b2be) 52.86%.
Report is 2 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4183      +/-   ##
==========================================
- Coverage   52.91%   52.86%   -0.06%     
==========================================
  Files         239      239              
  Lines       23526    23571      +45     
==========================================
+ Hits        12449    12460      +11     
- Misses      10401    10434      +33     
- Partials      676      677       +1     
Flag Coverage Δ
unittests 52.86% <38.98%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
pkg/registry/cluster/storage/storage.go 0.00% <0.00%> (ø)
pkg/util/proxy/proxy.go 74.14% <46.00%> (-15.76%) ⬇️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 26, 2023
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 26, 2023
@karmada-bot karmada-bot merged commit edeb94b into karmada-io:master Oct 26, 2023
12 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/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. 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.

feat: support cluster certificate validation instead of configuring InsecureSkipVerify
5 participants