Skip to content

Commit f5c42ca

Browse files
authored
xds/client: Export a method to return bootstrap config. (#4033)
1 parent b88744b commit f5c42ca

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
lines changed

xds/internal/balancer/cdsbalancer/cdsbalancer.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"google.golang.org/grpc/resolver"
3636
"google.golang.org/grpc/serviceconfig"
3737
"google.golang.org/grpc/xds/internal/balancer/edsbalancer"
38+
"google.golang.org/grpc/xds/internal/client/bootstrap"
3839

3940
xdsinternal "google.golang.org/grpc/xds/internal"
4041
xdsclient "google.golang.org/grpc/xds/internal/client"
@@ -131,7 +132,7 @@ func (cdsBB) ParseConfig(c json.RawMessage) (serviceconfig.LoadBalancingConfig,
131132
// the cdsBalancer. This will be faked out in unittests.
132133
type xdsClientInterface interface {
133134
WatchCluster(string, func(xdsclient.ClusterUpdate, error)) func()
134-
CertProviderConfigs() map[string]*certprovider.BuildableConfig
135+
BootstrapConfig() *bootstrap.Config
135136
Close()
136137
}
137138

@@ -241,13 +242,14 @@ func (b *cdsBalancer) handleSecurityConfig(config *xdsclient.SecurityConfig) err
241242
return nil
242243
}
243244

244-
cpc := b.xdsClient.CertProviderConfigs()
245-
if cpc == nil {
245+
bc := b.xdsClient.BootstrapConfig()
246+
if bc == nil || bc.CertProviderConfigs == nil {
246247
// Bootstrap did not find any certificate provider configs, but the user
247248
// has specified xdsCredentials and the management server has sent down
248249
// security configuration.
249250
return errors.New("xds: certificate_providers config missing in bootstrap file")
250251
}
252+
cpc := bc.CertProviderConfigs
251253

252254
// A root provider is required whether we are using TLS or mTLS.
253255
rootProvider, err := buildProvider(cpc, config.RootInstanceName, config.RootCertName, false, true)

xds/internal/balancer/cdsbalancer/cdsbalancer_security_test.go

+14-11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"google.golang.org/grpc/internal/testutils"
3232
"google.golang.org/grpc/resolver"
3333
xdsclient "google.golang.org/grpc/xds/internal/client"
34+
"google.golang.org/grpc/xds/internal/client/bootstrap"
3435
xdstestutils "google.golang.org/grpc/xds/internal/testutils"
3536
"google.golang.org/grpc/xds/internal/testutils/fakeclient"
3637
)
@@ -43,7 +44,7 @@ const (
4344

4445
var (
4546
fpb1, fpb2 *fakeProviderBuilder
46-
bootstrapCertProviderConfigs map[string]*certprovider.BuildableConfig
47+
bootstrapConfig *bootstrap.Config
4748
cdsUpdateWithGoodSecurityCfg = xdsclient.ClusterUpdate{
4849
ServiceName: serviceName,
4950
SecurityCfg: &xdsclient.SecurityConfig{
@@ -64,9 +65,11 @@ func init() {
6465
fpb2 = &fakeProviderBuilder{name: fakeProvider2Name}
6566
cfg1, _ := fpb1.ParseConfig(fakeConfig + "1111")
6667
cfg2, _ := fpb2.ParseConfig(fakeConfig + "2222")
67-
bootstrapCertProviderConfigs = map[string]*certprovider.BuildableConfig{
68-
"default1": cfg1,
69-
"default2": cfg2,
68+
bootstrapConfig = &bootstrap.Config{
69+
CertProviderConfigs: map[string]*certprovider.BuildableConfig{
70+
"default1": cfg1,
71+
"default2": cfg2,
72+
},
7073
}
7174
certprovider.Register(fpb1)
7275
certprovider.Register(fpb2)
@@ -326,7 +329,7 @@ func (s) TestSecurityConfigNotFoundInBootstrap(t *testing.T) {
326329

327330
if i == 0 {
328331
// Set the bootstrap config used by the fake client.
329-
xdsC.SetCertProviderConfigs(bootstrapCertProviderConfigs)
332+
xdsC.SetBootstrapConfig(bootstrapConfig)
330333
}
331334

332335
// Here we invoke the watch callback registered on the fake xdsClient. A bad
@@ -373,7 +376,7 @@ func (s) TestCertproviderStoreError(t *testing.T) {
373376
defer func() { buildProvider = origBuildProvider }()
374377

375378
// Set the bootstrap config used by the fake client.
376-
xdsC.SetCertProviderConfigs(bootstrapCertProviderConfigs)
379+
xdsC.SetBootstrapConfig(bootstrapConfig)
377380

378381
// Here we invoke the watch callback registered on the fake xdsClient. Even
379382
// though the received update is good, the certprovider.Store is configured
@@ -409,7 +412,7 @@ func (s) TestSecurityConfigUpdate_BadToGood(t *testing.T) {
409412
}()
410413

411414
// Set the bootstrap config used by the fake client.
412-
xdsC.SetCertProviderConfigs(bootstrapCertProviderConfigs)
415+
xdsC.SetBootstrapConfig(bootstrapConfig)
413416

414417
// Here we invoke the watch callback registered on the fake xdsClient. A bad
415418
// security config is passed here. So, we expect the CDS balancer to not
@@ -465,7 +468,7 @@ func (s) TestGoodSecurityConfig(t *testing.T) {
465468
}()
466469

467470
// Set the bootstrap config used by the fake client.
468-
xdsC.SetCertProviderConfigs(bootstrapCertProviderConfigs)
471+
xdsC.SetBootstrapConfig(bootstrapConfig)
469472

470473
// Here we invoke the watch callback registered on the fake xdsClient. This
471474
// will trigger the watch handler on the CDS balancer, which will attempt to
@@ -496,7 +499,7 @@ func (s) TestSecurityConfigUpdate_GoodToFallback(t *testing.T) {
496499
}()
497500

498501
// Set the bootstrap config used by the fake client.
499-
xdsC.SetCertProviderConfigs(bootstrapCertProviderConfigs)
502+
xdsC.SetBootstrapConfig(bootstrapConfig)
500503

501504
// Here we invoke the watch callback registered on the fake xdsClient. This
502505
// will trigger the watch handler on the CDS balancer, which will attempt to
@@ -546,7 +549,7 @@ func (s) TestSecurityConfigUpdate_GoodToBad(t *testing.T) {
546549
}()
547550

548551
// Set the bootstrap config used by the fake client.
549-
xdsC.SetCertProviderConfigs(bootstrapCertProviderConfigs)
552+
xdsC.SetBootstrapConfig(bootstrapConfig)
550553

551554
// Here we invoke the watch callback registered on the fake xdsClient. This
552555
// will trigger the watch handler on the CDS balancer, which will attempt to
@@ -617,7 +620,7 @@ func (s) TestSecurityConfigUpdate_GoodToGood(t *testing.T) {
617620
defer func() { buildProvider = origBuildProvider }()
618621

619622
// Set the bootstrap config used by the fake client.
620-
xdsC.SetCertProviderConfigs(bootstrapCertProviderConfigs)
623+
xdsC.SetBootstrapConfig(bootstrapConfig)
621624

622625
// Here we invoke the watch callback registered on the fake xdsClient. This
623626
// will trigger the watch handler on the CDS balancer, which will attempt to

xds/internal/client/client.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
v2corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
3131
v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
3232
"github.com/golang/protobuf/proto"
33-
"google.golang.org/grpc/credentials/tls/certprovider"
33+
3434
"google.golang.org/grpc/xds/internal/client/load"
3535

3636
"google.golang.org/grpc"
@@ -390,11 +390,10 @@ func newWithConfig(config *bootstrap.Config, watchExpiryTimeout time.Duration) (
390390
return c, nil
391391
}
392392

393-
// CertProviderConfigs returns the certificate provider configuration from the
394-
// "certificate_providers" field of the bootstrap file. The key in the returned
395-
// map is the plugin_instance_name. Callers must not modify the returned map.
396-
func (c *Client) CertProviderConfigs() map[string]*certprovider.BuildableConfig {
397-
return c.config.CertProviderConfigs
393+
// BootstrapConfig returns the configuration read from the bootstrap file.
394+
// Callers must treat the return value as read-only.
395+
func (c *Client) BootstrapConfig() *bootstrap.Config {
396+
return c.config
398397
}
399398

400399
// run is a goroutine for all the callbacks.

xds/internal/testutils/fakeclient/client.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ package fakeclient
2222
import (
2323
"context"
2424

25-
"google.golang.org/grpc/credentials/tls/certprovider"
2625
"google.golang.org/grpc/internal/testutils"
2726
xdsclient "google.golang.org/grpc/xds/internal/client"
27+
"google.golang.org/grpc/xds/internal/client/bootstrap"
2828
"google.golang.org/grpc/xds/internal/client/load"
2929
)
3030

@@ -43,7 +43,7 @@ type Client struct {
4343
loadReportCh *testutils.Channel
4444
closeCh *testutils.Channel
4545
loadStore *load.Store
46-
certConfigs map[string]*certprovider.BuildableConfig
46+
bootstrapCfg *bootstrap.Config
4747

4848
ldsCb func(xdsclient.ListenerUpdate, error)
4949
rdsCb func(xdsclient.RouteConfigUpdate, error)
@@ -223,14 +223,14 @@ func (xdsC *Client) WaitForClose(ctx context.Context) error {
223223
return err
224224
}
225225

226-
// CertProviderConfigs returns the configured certificate provider configs.
227-
func (xdsC *Client) CertProviderConfigs() map[string]*certprovider.BuildableConfig {
228-
return xdsC.certConfigs
226+
// BootstrapConfig returns the bootstrap config.
227+
func (xdsC *Client) BootstrapConfig() *bootstrap.Config {
228+
return xdsC.bootstrapCfg
229229
}
230230

231-
// SetCertProviderConfigs updates the certificate provider configs.
232-
func (xdsC *Client) SetCertProviderConfigs(configs map[string]*certprovider.BuildableConfig) {
233-
xdsC.certConfigs = configs
231+
// SetBootstrapConfig updates the bootstrap config.
232+
func (xdsC *Client) SetBootstrapConfig(cfg *bootstrap.Config) {
233+
xdsC.bootstrapCfg = cfg
234234
}
235235

236236
// Name returns the name of the xds client.

0 commit comments

Comments
 (0)