-
Notifications
You must be signed in to change notification settings - Fork 891
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
fix(util/proxy): fix tls.config when secret.spec.caBundle is nil #4371
Conversation
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #4371 +/- ##
==========================================
+ Coverage 51.87% 51.89% +0.01%
==========================================
Files 243 243
Lines 24114 24112 -2
==========================================
+ Hits 12509 12512 +3
+ Misses 10922 10918 -4
+ Partials 683 682 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
/assign @jwcesign |
pkg/util/proxy/proxy.go
Outdated
@@ -124,7 +124,7 @@ func NewThrottledUpgradeAwareProxyHandler(location *url.URL, transport http.Roun | |||
|
|||
func GetTlsConfigForCluster(ctx context.Context, cluster *clusterapis.Cluster, secretGetter SecretGetterFunc) (*tls.Config, error) { | |||
// 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 { | |||
if cluster.Spec.SecretRef == nil || cluster.Spec.InsecureSkipTLSVerification { |
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.
Should we set the RootCAs even if InsecureSkipTLSVerification is true(If the caBundle exists)?
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.
Should we set the RootCAs even if InsecureSkipTLSVerification is true(If the caBundle exists)?
en.., sure, It's a batter choice
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.
/cc @jwcesign
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.
lgtm
cc @chaosi-zju for double checking
pkg/util/proxy/proxy.go
Outdated
caBundle, err := getClusterCABundle(cluster.Name, caSecret) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get CA bundle for cluster %s: %v", cluster.Name, err) | ||
return &tls.Config{ | ||
MinVersion: tls.VersionTLS13, | ||
// Ignore false positive warning: "TLS InsecureSkipVerify may be true. (gosec)" | ||
// Whether to skip server certificate verification depends on the | ||
// configuration(.spec.insecureSkipTLSVerification, defaults to false) in a Cluster object. | ||
InsecureSkipVerify: cluster.Spec.InsecureSkipTLSVerification, //nolint:gosec | ||
}, nil |
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, in your case, cluster.Spec.InsecureSkipTLSVerification=true
and caBundle=""
, you code works fine.
But, if cluster.Spec.InsecureSkipTLSVerification=false
and caBundle=""
, this case may be we should report error if caBundle is empty?
Otherwise, you see, caBundle is empty and we return &tls.Config{InsecureSkipVerify: false}
, this is a invalid 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.
if cluster.Spec.InsecureSkipTLSVerification=false and caBundle="", this case may be we should report error if caBundle is empty?
I think, if the ca in the container is correct, it will still work fine
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, in your case,
cluster.Spec.InsecureSkipTLSVerification=true
andcaBundle=""
, you code works fine.But, if
cluster.Spec.InsecureSkipTLSVerification=false
andcaBundle=""
, this case may be we should report error if caBundle is empty?Otherwise, you see, caBundle is empty and we return
&tls.Config{InsecureSkipVerify: false}
, this is a invalid config.
got it!!!
pkg/util/proxy/proxy.go
Outdated
InsecureSkipVerify: cluster.Spec.InsecureSkipTLSVerification, //nolint:gosec | ||
}, nil | ||
} | ||
return nil, fmt.Errorf("insecureSkipTLSVerification is false, but failed to get CA bundle for cluster %s: %v", cluster.Name, err) |
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.
How about this? @chaosi-zju @CharlesQQ
func getClusterCABundle(clusterName string, secret *corev1.Secret) []byte {
caBundle, found := secret.Data[clusterapis.SecretCADataKey]
if !found {
return []byte{}
}
return caBundle
}
func GetTlsConfigForCluster(ctx context.Context, cluster *clusterapis.Cluster, secretGetter SecretGetterFunc) (*tls.Config, error) {
...
caBundle := getClusterCABundle(cluster.Name, caSecret)
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caBundle)
return &tls.Config{
RootCAs: caCertPool,
MinVersion: tls.VersionTLS13,
// Ignore false positive warning: "TLS InsecureSkipVerify may be true. (gosec)"
// Whether to skip server certificate verification depends on the
// configuration(.spec.insecureSkipTLSVerification, defaults to false) in a Cluster object.
InsecureSkipVerify: cluster.Spec.InsecureSkipTLSVerification, //nolint:gosec
}, nil
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 think, if the ca in the container is correct, it will still work fine
I got your point.
How about this?
I think perfect.
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, @CharlesQQ
Can you help update this?
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.
How about this? @chaosi-zju @CharlesQQ
func getClusterCABundle(clusterName string, secret *corev1.Secret) []byte { caBundle, found := secret.Data[clusterapis.SecretCADataKey] if !found { return []byte{} } return caBundle } func GetTlsConfigForCluster(ctx context.Context, cluster *clusterapis.Cluster, secretGetter SecretGetterFunc) (*tls.Config, error) { ... caBundle := getClusterCABundle(cluster.Name, caSecret) caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caBundle) return &tls.Config{ RootCAs: caCertPool, MinVersion: tls.VersionTLS13, // Ignore false positive warning: "TLS InsecureSkipVerify may be true. (gosec)" // Whether to skip server certificate verification depends on the // configuration(.spec.insecureSkipTLSVerification, defaults to false) in a Cluster object. InsecureSkipVerify: cluster.Spec.InsecureSkipTLSVerification, //nolint:gosec }, nil
motified!!!
Signed-off-by: chang.qiangqiang <[email protected]>
Nice work! Thanks for your contribution. /lgtm |
/cc @RainbowMango |
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.
Thanks @CharlesQQ
LGMT
I think this should affect user behavior. Can we add a release note to explain it?
/kind bug |
Of cause |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: XiShanYongYe-Chang 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 |
…k-of-#4371-upstream-release-1.8 Automated cherry pick of #4371: fix(util/proxy): fix tls.config when secret.spec.caBundle is
What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #4370
Special notes for your reviewer:
Does this PR introduce a user-facing change?: