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: make HUB_CERTIFICATE_AUTHORITY optional to allow agent use OS's root CA #149

Merged
merged 5 commits into from
May 22, 2023

Conversation

mingqishao
Copy link
Contributor

@mingqishao mingqishao commented May 19, 2023

What type of PR is this?
/kind feature

What this PR does / why we need it:
When network controllers use secure TLS to talk the hub, a CA data configuration is mandatory today. This changes to make it optional so that allows network controller to use OS's root certificate to talk hub cluster.

Which issue(s) this PR fixes:

Fixes #

Requirements:

How has this code been tested

Special notes for your reviewer

@codecov
Copy link

codecov bot commented May 19, 2023

Codecov Report

Merging #149 (129467b) into main (fbf584c) will increase coverage by 0.24%.
The diff coverage is 50.00%.

@@            Coverage Diff             @@
##             main     #149      +/-   ##
==========================================
+ Coverage   78.62%   78.86%   +0.24%     
==========================================
  Files          20       20              
  Lines        2737     2735       -2     
==========================================
+ Hits         2152     2157       +5     
+ Misses        466      460       -6     
+ Partials      119      118       -1     
Impacted Files Coverage Δ
pkg/common/uniquename/uniquename.go 82.96% <ø> (ø)
...rollers/member/internalmembercluster/controller.go 70.77% <ø> (+2.59%) ⬆️
pkg/common/hubconfig/hubconfig.go 80.00% <50.00%> (-0.71%) ⬇️

... and 4 files with indirect coverage changes

pkg/common/hubconfig/fake-config-path Outdated Show resolved Hide resolved
pkg/common/hubconfig/hubconfig_test.go Outdated Show resolved Hide resolved
pkg/common/hubconfig/hubconfig_test.go Outdated Show resolved Hide resolved
pkg/common/hubconfig/hubconfig_test.go Outdated Show resolved Hide resolved
Copy link
Member

@jim-minter jim-minter left a comment

Choose a reason for hiding this comment

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

lgtm, @ryanzhang-oss ptal/merge?

@mingqishao mingqishao merged commit f901a19 into main May 22, 2023
9 of 10 checks passed
if err != nil {
klog.ErrorS(err, "Cannot decode hub cluster certificate authority data")
return nil, err
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is that the err != nil not checked?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the env.Lookup() is customized function in this module which wrap the os.Envlookup(). err == nil mean the environment be found.

Actually I do feel this wrap function is a kind of confusing, I use it only because of keeping consistent with other codes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if err == nil {
// use the agent OS's root CA when the hubCA env is not set
if err == nil { // check if hubCA env is not set

Please add the comment here to improve the readability as in normal case we check the err != nil and need some signal here to indicate why we check err == nil here.

api/v1alpha1/common_types.go Show resolved Hide resolved
Comment on lines +56 to +58
// - the input object namespace is a valid RFC 1123 DNS label; and
// - the input object name follows one of the three formats used in Kubernetes (RFC 1123 DNS subdomain,
// RFC 1123 DNS label, RFC 1035 DNS label).
Copy link
Contributor

Choose a reason for hiding this comment

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

why are those in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those changes was made by "make reviewable"

}
hubConfig = &rest.Config{
BearerTokenFile: tokenFilePath,
Host: hubURL,
TLSClientConfig: rest.TLSClientConfig{
Insecure: tlsClientInsecure,
CAData: decodedClusterCaCertificate,
CAData: caData,
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please clarify that, if the hubCAEnvKey is not set, the caData will be empty, it will use the OS's root CA?

Have you manually tested the agent using OS's root CA to talk to hub api server?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could you please clarify that, if the hubCAEnvKey is not set, the caData will be empty, it will use the OS's root CA?
Yes. that is the purpose of this PR.

Have you manually tested the agent using OS's root CA to talk to hub api server?
Yes, I did. I tested it manually.

@zhiying-lin zhiying-lin deleted the minsha/cadata-optional branch April 25, 2024 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants