Skip to content

Conversation

@mingqishao
Copy link
Contributor

Description of your changes

When member agent use secure TLS talk to hub, it use either a specified CA bundle or CA data in configuration. This changes to allow member agent use OS's root certificate.

The changes are:

  1. refactor the codes of building hub's kubeconfig
  2. It is not mandatory to specify CA data or CA bundle in arguments

I have:

  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

Special notes for your reviewer

@mingqishao mingqishao requested a review from ryanzhang-oss May 19, 2023 17:59
jim-minter
jim-minter previously approved these changes May 19, 2023
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.

A couple of nits, but LGTM. I have checked through the refactor carefully. Thanks for adding the unit test.

I have also checked that our base Docker image does indeed include a CA cert bundle.

@ryanzhang-oss please merge?

Co-authored-by: Jim Minter <jim-minter@users.noreply.github.com>
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!

@mingqishao mingqishao merged commit b557353 into main May 22, 2023
Comment on lines +161 to +163
hubConfig.TLSClientConfig.Insecure = tlsClientInsecure
if !tlsClientInsecure {
hubConfig.TLSClientConfig.CAFile = os.Getenv("CA_BUNDLE")
Copy link
Contributor

Choose a reason for hiding this comment

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

this value empty should not be supported when the TLS is secure. Linkedin has this use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, the original logic is specific for Linkedin, that is vendor specified and should not be in upstream's codes.

If CA_BUNDLE is empty, that will fallback to OS's default CA bundle. Other open sources are using same logic, for example curl. The OS's CA bundle is always be used by default unless user specific in argument or in environment variable CURL_CA_BUNDLE

var (
scheme = runtime.NewScheme()
useCAAuth = flag.Bool("use-ca-auth", false, "Use identity and CA bundle to authenticate the member agent.")
useCertificateAuth = flag.Bool("use-ca-auth", false, "Use key and certificate to authenticate the member agent.")
Copy link
Contributor

Choose a reason for hiding this comment

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

why change this name when it's passed down to the function as useCAAuth? I agree that the original name is not good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR has been merged, so I fixed it in separate PR: #365

if !tlsClientInsecure {
hubConfig.TLSClientConfig.CAFile = os.Getenv("CA_BUNDLE")
hubCA := os.Getenv("HUB_CERTIFICATE_AUTHORITY")
if hubCA != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

we are using "" to imply that we use OS's root certificate but there is no way for us to know if user leave them blank deliberately or by mistake. I think we better ask user to explicitly indicate that they want to use OS root

klog.ErrorS(err, "cannot decode hub cluster certificate authority data")
return nil, err
}
hubConfig.TLSClientConfig.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.

This will override the CAFile so it's another place that we want to make sure that users know what they are doing. It's either or.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, the HUB_CERTIFICATE_AUTHORITY will override the CA_BUNDLE. I do agree that will make confuse for user.

Do you want me to add a validation for that? the validation will check only one of them will be present, otherwise will return a error

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.

5 participants