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

add windows support for root CA cert stores #84

Merged
merged 10 commits into from
May 5, 2022
Merged

add windows support for root CA cert stores #84

merged 10 commits into from
May 5, 2022

Conversation

rosskirkpat
Copy link
Contributor

@rosskirkpat rosskirkpat commented May 4, 2022

Summary

Move the get/create of a root CA cert store into OS dependent functions

Fixes #83
Unblocks rancher/windows#161

Occurred changes and/or fixed issues

Windows does not support x509.SystemCertPool() in <go1.18. This PR implements a workaround to load the System Cert Store on Windows nodes.

Technical notes summary

This is adapted from the following workaround: golang/go#16736 (comment)

Error seen on Windows machines:
Message : error loading system cert pool for probe (kubelet): crypto/x509: system root pool is not available on Windows

Since <go1.18 on Windows cannot load the root CA cert store, this PR leverages syscalls to load the certificate context from the Root CA cert store and then create a new x509 cert pool that contains the Root CAs. This will likely cause a performance drop on Windows as each probe that requires a CACert will need to build it's own x509 cert pool with the root CAs.

Once system-agent is upgraded to go1.18+ the differing code paths should no longer be required.

Areas or cases that should be tested

This PR cannot be tested before it is merged as far as I am aware.

Areas which could experience regressions

These changes should only impact system agent functionality on Windows. The existing functionality for linux hosts has been shuffled into a new function but the underlying code is still the same. For windows, given that loading the CA certs from the root store is currently broken I do not see any potential for regression.

Screenshot/Video

N/A

@rosskirkpat rosskirkpat added bug Something isn't working enhancement New feature or request labels May 4, 2022
@rosskirkpat rosskirkpat self-assigned this May 4, 2022
pkg/prober/prober.go Show resolved Hide resolved
pkg/prober/prober_windows.go Outdated Show resolved Hide resolved
pkg/prober/prober_windows.go Outdated Show resolved Hide resolved
@rosskirkpat rosskirkpat requested a review from thedadams May 5, 2022 18:14
pkg/prober/prober_windows.go Outdated Show resolved Hide resolved
@rosskirkpat rosskirkpat requested a review from brandond May 5, 2022 19:11
@rosskirkpat
Copy link
Contributor Author

@snasovich If @Oats87 is not able to review this by EOD today as he is out of office, can I get your approval to merge once I have another round of approvals from @brandond and @thedadams ?

pkg/prober/prober.go Show resolved Hide resolved
Comment on lines +20 to +22
if caCertPool == nil {
return nil, fmt.Errorf("[GetSystemCertPoolWindows] x509 returned a nil certpool for probe (%s)", probeName)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the nil check inside each of the functions for linux/windows as it allows the function to fail faster for Windows and avoid a situation where a nil pointer causes a failure before we could check it in the main prober.go. Waiting to check until after the caCertPool is returned could result in a nil pointer being returned when we try to append the certs from the syscall to the caCertPool.

pkg/prober/prober_windows.go Outdated Show resolved Hide resolved
@rosskirkpat rosskirkpat merged commit 46fbba3 into rancher:main May 5, 2022
tmacam added a commit to tmacam/dapr-components-contrib that referenced this pull request Nov 30, 2022
Tests in vault_test.go had the following :

```go
    // This call will throw an error on Windows systems because of the of
    // the call x509.SystemCertPool() because system root pool is not
    // available on Windows so ignore the error for when the tests are run
    // on the Windows platform during CI
    _ = target.Init(m)
```

As of Go 1.18 this is not the case for Windows anymore and
we can instead enforce error checking. References:

* golang/go#16736
* golang/go#18609
* rancher/system-agent#84
* jaegertracing/jaeger#2756

Given Dapr depends on Go 1.19, we can enforce tests on `Init` result
and remove this comment.

While enforcing error checking we notice that the code above was
actually hiding errors in the test setup. Component initialization was
ending prematurely due to those errors and the test code was wrongfully
testing for the behavior of a component that has not been successfully
initialized. This is also addressed in this PR.

Closes dapr#2330.

Signed-off-by: Tiago Alves Macambira <tmacam@burocrata.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Windows does not support x509.SystemCertPool() in <go1.18
7 participants