-
Notifications
You must be signed in to change notification settings - Fork 2
Use CA in cloudprofile for STACKIT clients #150
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
Open
nschad
wants to merge
29
commits into
main
Choose a base branch
from
use-cloudprofile-ca
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
3cac34c
Use CA in cloudprofile for STACKIT clients
nschad 1d346d4
Add CABundle to mcm-provider-stackit if specified
nschad 3fc27c4
deduplicate CABundle for CSI/CCM
nschad 3951f6d
align volumeName with CSI/CCM
nschad 1247bc8
fix some lint errors
nschad 155c48e
drop costuom-certs in provider-stackit
nschad 402ffcd
do not double-encode cloudprofile caBundle
nschad 36d70d0
fix secret chart
nschad 0e8fe95
decode cloudProfile.caBundle before using it
nschad 521eb06
use stackit SDK WithCustomHTTPClient for custom Transport with modifi…
nschad 0cb5e9c
format and simplify code
nschad 5b01a22
remove unused helm value
nschad 980bdbf
rename InjectCAIntoHTTPClient => newHTTPClientWithCustomCA
nschad 74fff99
fix: use newObj instead of old machineDeployment
nschad 5b75cf3
add unit test for webhook
nschad 059d603
add unit test for DecodeCloudProfileCABundle
nschad 232f787
use const variable instead of string for volume name
nschad be9ae1a
rename cloudProfileCABundleB64 => CABundleBase64
nschad d8a0ca0
remove stackitv1alpha1.Cloudprofile's CABundle; use gardener's CABund…
nschad aa88233
Gardener's Cloudprofile CABundle is not encoded. Encode it for the he…
nschad de1feea
use EnsureVolumeWithName and EnsureVolumeMountWithName instead of app…
nschad e85a96e
add stackit-ca-bundle from config chart to internal chart
nschad 588e65e
use EnsureEnvVarWithName for the ENV vars
nschad a966878
keep caBundle in the Cloudprofile to not breaking strict decoding
nschad bcdf4ae
improve error message for newHTTPClientWithCustomCA()
nschad 85951a0
rename stackit-ca-bundle to cloudprofile-ca-bundle
nschad d1bc758
use constant for cloudprofile-ca-bundle
nschad 40db20c
remove the mcm flag --resource-exhausted-retry as this version was re…
nschad 04db709
remove gosec nolint directive
nschad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
charts/gardener-extension-provider-stackit/templates/secret.yaml
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
charts/internal/cloud-provider-config/templates/stackit-ca-bundle.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| {{- if .Values.CABundle }} | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| name: cloudprofile-ca-bundle | ||
| namespace: {{ .Release.Namespace }} | ||
| type: Opaque | ||
| data: | ||
| {{- if .Values.CABundle }} | ||
| stackit-ca.crt: {{ .Values.CABundle | b64enc }} | ||
| {{- end }} | ||
| {{- end }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| stackitOnly: false | ||
| CABundle: "" | ||
| # [Global] | ||
| authUrl: fooURL | ||
| domainName: fooDomain | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,10 @@ package client | |
|
|
||
| import ( | ||
| "context" | ||
| "crypto/tls" | ||
| "crypto/x509" | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller" | ||
| sdkconfig "github.com/stackitcloud/stackit-sdk-go/core/config" | ||
|
|
@@ -33,18 +37,25 @@ type Factory interface { | |
| type factory struct { | ||
| StackitRegion string | ||
| StackitAPIEndpoints stackitv1alpha1.APIEndpoints | ||
| CABundleB64 string | ||
| } | ||
|
|
||
| func New(region string, cluster *extensionscontroller.Cluster) Factory { | ||
| var apiEndpoints stackitv1alpha1.APIEndpoints | ||
| var caBundle string | ||
|
|
||
| if cloudProfileConfig, err := helper.CloudProfileConfigFromCluster(cluster); err == nil { | ||
| apiEndpoints = ptr.Deref(cloudProfileConfig.APIEndpoints, stackitv1alpha1.APIEndpoints{}) | ||
| } | ||
|
|
||
| if cluster.CloudProfile != nil && cluster.CloudProfile.Spec.CABundle != nil { | ||
| caBundle = ptr.Deref(cluster.CloudProfile.Spec.CABundle, "") | ||
| } | ||
|
|
||
| return &factory{ | ||
| StackitRegion: region, | ||
| StackitAPIEndpoints: apiEndpoints, | ||
| CABundleB64: caBundle, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -54,7 +65,7 @@ func (f factory) LoadBalancing(ctx context.Context, c client.Client, secretRef c | |
| return nil, err | ||
| } | ||
|
|
||
| return NewLoadBalancingClient(ctx, f.StackitRegion, f.StackitAPIEndpoints, credentials) | ||
| return NewLoadBalancingClient(ctx, f.StackitRegion, f.StackitAPIEndpoints, credentials, f.CABundleB64) | ||
| } | ||
|
|
||
| func (f factory) IaaS(ctx context.Context, c client.Client, secretRef corev1.SecretReference) (IaaSClient, error) { | ||
|
|
@@ -63,7 +74,7 @@ func (f factory) IaaS(ctx context.Context, c client.Client, secretRef corev1.Sec | |
| return nil, err | ||
| } | ||
|
|
||
| return NewIaaSClient(f.StackitRegion, f.StackitAPIEndpoints, credentials) | ||
| return NewIaaSClient(f.StackitRegion, f.StackitAPIEndpoints, credentials, f.CABundleB64) | ||
| } | ||
|
|
||
| func (f factory) DNS(ctx context.Context, c client.Client, secretRef corev1.SecretReference) (DNSClient, error) { | ||
|
|
@@ -72,10 +83,28 @@ func (f factory) DNS(ctx context.Context, c client.Client, secretRef corev1.Secr | |
| return nil, err | ||
| } | ||
|
|
||
| return NewDNSClient(ctx, f.StackitAPIEndpoints, credentials) | ||
| return NewDNSClient(ctx, f.StackitAPIEndpoints, credentials, f.CABundleB64) | ||
| } | ||
|
|
||
| // newHTTPClientWithCustomCA creates an http.Client with a custom CA | ||
| func newHTTPClientWithCustomCA(caBundle []byte) (*http.Client, error) { | ||
| caCertPool, err := x509.SystemCertPool() | ||
| if err != nil { | ||
| // we could also fall back here and use an empty pool via x509.NewCertPool() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think erroring is fine but we should customize the error to state what is broken and where does it come from. |
||
| return nil, fmt.Errorf("failed to load system cert pool: %w", err) | ||
| } | ||
| if ok := caCertPool.AppendCertsFromPEM(caBundle); !ok { | ||
| return nil, fmt.Errorf("failed to append CA bundle to cert pool") | ||
| } | ||
|
|
||
| return &http.Client{Transport: &http.Transport{ | ||
| TLSClientConfig: &tls.Config{ | ||
| RootCAs: caCertPool, | ||
| }, | ||
| }}, nil | ||
| } | ||
|
|
||
| func clientOptions(endpoints stackitv1alpha1.APIEndpoints, credentials *stackit.Credentials) []sdkconfig.ConfigurationOption { | ||
| func clientOptions(endpoints stackitv1alpha1.APIEndpoints, credentials *stackit.Credentials, caBundle string) ([]sdkconfig.ConfigurationOption, error) { | ||
| result := []sdkconfig.ConfigurationOption{ | ||
| sdkconfig.WithUserAgent(UserAgent), | ||
| sdkconfig.WithServiceAccountKey(credentials.SaKeyJSON), | ||
|
|
@@ -85,5 +114,13 @@ func clientOptions(endpoints stackitv1alpha1.APIEndpoints, credentials *stackit. | |
| result = append(result, sdkconfig.WithTokenEndpoint(*endpoints.TokenEndpoint)) | ||
| } | ||
|
|
||
| return result | ||
| if caBundle != "" { | ||
| customHttpClient, err := newHTTPClientWithCustomCA([]byte(caBundle)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| result = append(result, sdkconfig.WithHTTPClient(customHttpClient)) | ||
| } | ||
|
|
||
| return result, nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.