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

Fix: nil secret in resourceversiontable #2982

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
16 changes: 11 additions & 5 deletions internal/xds/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,14 @@
if tlsConfig == nil {
return nil, nil
}
CaSecret := buildXdsUpstreamTLSCASecret(tlsConfig)
if CaSecret != nil {
// Create a secret for the CA certificate only if it's not using the system trust store
if !tlsConfig.UseSystemTrustStore {
CaSecret := buildXdsUpstreamTLSCASecret(tlsConfig)

Check warning on line 526 in internal/xds/translator/translator.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/translator.go#L525-L526

Added lines #L525 - L526 were not covered by tests
if err := tCtx.AddXdsResource(resourcev3.SecretType, CaSecret); err != nil {
return nil, err
}
}

// for upstreamTLS , a fixed sni can be used. use auto_sni otherwise
// https://www.envoyproxy.io/docs/envoy/latest/faq/configuration/sni#faq-how-to-setup-sni:~:text=For%20clusters%2C%20a,for%20trust%20anchor.
tlsSocket, err := buildXdsUpstreamTLSSocketWthCert(tlsConfig)
Expand Down Expand Up @@ -574,9 +576,12 @@
xdsEndpoints := buildXdsClusterLoadAssignment(args.name, args.settings)
for _, ds := range args.settings {
if ds.TLS != nil {
secret := buildXdsUpstreamTLSCASecret(ds.TLS)
if err := tCtx.AddXdsResource(resourcev3.SecretType, secret); err != nil {
return err
// Create a secret for the CA certificate only if it's not using the system trust store
if !ds.TLS.UseSystemTrustStore {
secret := buildXdsUpstreamTLSCASecret(ds.TLS)
if err := tCtx.AddXdsResource(resourcev3.SecretType, secret); err != nil {
return err
}

Check warning on line 584 in internal/xds/translator/translator.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/translator.go#L583-L584

Added lines #L583 - L584 were not covered by tests
}
}
}
Expand All @@ -602,6 +607,7 @@

func buildXdsUpstreamTLSCASecret(tlsConfig *ir.TLSUpstreamConfig) *tlsv3.Secret {
// Build the tls secret
// It's just a sanity check, we shouldn't call this function if the system trust store is used
if tlsConfig.UseSystemTrustStore {
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion internal/xds/translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ func TestTranslateXds(t *testing.T) {
name: "http-route-dns-cluster",
},
{
name: "http-route-with-tls-system-truststore",
name: "http-route-with-tls-system-truststore",
requireSecrets: true,
},
{
name: "http-route-with-tlsbundle",
Expand Down
5 changes: 5 additions & 0 deletions internal/xds/types/resourceversiontable.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
}

func (t *ResourceVersionTable) AddXdsResource(rType resourcev3.Type, xdsResource types.Resource) error {
// It's a sanity check to make sure the xdsResource is not nil
if xdsResource == nil {
return fmt.Errorf("xds resource is nil")
}

Check warning on line 82 in internal/xds/types/resourceversiontable.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/types/resourceversiontable.go#L81-L82

Added lines #L81 - L82 were not covered by tests

// Perform type switch to handle different types of xdsResource
switch rType {
case resourcev3.ListenerType:
Expand Down
Loading