Skip to content

Commit 395a24c

Browse files
committed
last nits
1 parent 651d85a commit 395a24c

7 files changed

Lines changed: 59 additions & 37 deletions

File tree

internal/xds/bootstrap/bootstrap_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,9 @@ func (s) TestAllowedGRPCServices_UnmarshalJSON(t *testing.T) {
17521752
// want carries the expected target and credential identities;
17531753
// comparisons use the Equal methods via cmp.Diff.
17541754
want AllowedGRPCServices
1755+
// wantCallCreds is the number of call credentials expected to be
1756+
// built for the target.
1757+
wantCallCreds int
17551758
}{
17561759
{
17571760
name: "insecure_channel_creds",
@@ -1772,6 +1775,7 @@ func (s) TestAllowedGRPCServices_UnmarshalJSON(t *testing.T) {
17721775
Data: json.RawMessage(`{"jwt_token_file": "/var/run/secrets/tokens/istio-token"}`),
17731776
}, nil)},
17741777
}},
1778+
wantCallCreds: 1,
17751779
},
17761780
{
17771781
// Unsupported call-creds types are skipped without error, so no
@@ -1802,6 +1806,7 @@ func (s) TestAllowedGRPCServices_UnmarshalJSON(t *testing.T) {
18021806
}, nil),
18031807
},
18041808
}},
1809+
wantCallCreds: 2,
18051810
},
18061811
{
18071812
name: "tls_channel_creds",
@@ -1831,11 +1836,20 @@ func (s) TestAllowedGRPCServices_UnmarshalJSON(t *testing.T) {
18311836
t.Errorf("AllowedGRPCServices unmarshal returned unexpected diff (-want +got):\n%s", diff)
18321837
}
18331838
// Equal compares credentials by identity only, so it cannot tell
1834-
// a built bundle from a nil one; verify the bundle was built.
1835-
chanCreds, _ := got[target].SideChannelCredentials()
1839+
// a built credential from a nil one; verify the credentials were
1840+
// built.
1841+
chanCreds, callCreds := got[target].SideChannelCredentials()
18361842
if chanCreds == nil || chanCreds.Bundle() == nil {
18371843
t.Error("SideChannelCredentials() returned no built channel credentials")
18381844
}
1845+
if len(callCreds) != test.wantCallCreds {
1846+
t.Errorf("SideChannelCredentials() returned %d call credentials, want %d", len(callCreds), test.wantCallCreds)
1847+
}
1848+
for i, cc := range callCreds {
1849+
if cc.Credentials() == nil {
1850+
t.Errorf("SideChannelCredentials() call credentials[%d] have no built credentials", i)
1851+
}
1852+
}
18391853
})
18401854
}
18411855
}

internal/xds/credentials/tls.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ func buildTLSCredentials(config *anypb.Any, resolver CertProviderConfigResolver)
5858
if rootInstanceName == "" {
5959
return nil, nil, fmt.Errorf("credentials: tls credentials must specify root_certificate_provider with an instance_name")
6060
}
61-
rootCfg, err := certProviderConfig(resolver, rootInstanceName)
61+
rootCfg, err := certProviderConfig(resolver, rootInstanceName, "root")
6262
if err != nil {
63-
return nil, nil, fmt.Errorf("credentials: tls credentials root certificate provider: %v", err)
63+
return nil, nil, err
6464
}
6565
rootProvider, err := rootCfg.Build(certprovider.BuildOptions{
6666
CertName: tlsCfg.GetRootCertificateProvider().GetCertificateName(),
@@ -79,10 +79,10 @@ func buildTLSCredentials(config *anypb.Any, resolver CertProviderConfigResolver)
7979
rootProvider.Close()
8080
return nil, nil, fmt.Errorf("credentials: tls credentials identity_certificate_provider must specify an instance_name")
8181
}
82-
identityCfg, err := certProviderConfig(resolver, identityInstanceName)
82+
identityCfg, err := certProviderConfig(resolver, identityInstanceName, "identity")
8383
if err != nil {
8484
rootProvider.Close()
85-
return nil, nil, fmt.Errorf("credentials: tls credentials identity certificate provider: %v", err)
85+
return nil, nil, err
8686
}
8787
identityProvider, err := identityCfg.Build(certprovider.BuildOptions{
8888
CertName: identity.GetCertificateName(),
@@ -98,11 +98,12 @@ func buildTLSCredentials(config *anypb.Any, resolver CertProviderConfigResolver)
9898
}
9999

100100
// certProviderConfig looks up the certificate provider instance with the
101-
// given name via the resolver.
102-
func certProviderConfig(resolver CertProviderConfigResolver, instanceName string) (*certprovider.BuildableConfig, error) {
101+
// given name via the resolver. kind names the certificate the provider is
102+
// used for (root or identity), for error messages.
103+
func certProviderConfig(resolver CertProviderConfigResolver, instanceName, kind string) (*certprovider.BuildableConfig, error) {
103104
cfg, ok := resolver.CertProviderConfigs()[instanceName]
104105
if !ok {
105-
return nil, fmt.Errorf("certificate provider instance name %q missing in bootstrap configuration", instanceName)
106+
return nil, fmt.Errorf("credentials: tls credentials %s certificate provider: instance name %q missing in bootstrap configuration", kind, instanceName)
106107
}
107108
return cfg, nil
108109
}

internal/xds/grpcservice/grpcservice_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,25 @@ func (s) TestParse(t *testing.T) {
207207
config: bootstrapConfig(t, allowedInsecure),
208208
want: &Config{TargetURI: target, ChannelCredentials: xdscreds.NewChannelCreds(nil, xdscreds.Identity{Type: "insecure"}, nil)},
209209
},
210+
{
211+
// The proto's call-creds plugins are ignored along with its
212+
// channel-creds plugins: the allowlist's call creds are used.
213+
name: "untrusted_allowlisted_uses_allowlist_call_creds",
214+
gs: googleGrpcService(target, []*anypb.Any{insecurePlugin}, []*anypb.Any{tokenPlugin}, nil),
215+
sc: untrustedServerConfig(t),
216+
config: bootstrapConfig(t, `{"dns:///my-service:443":{"channel_creds":[{"type":"insecure"}],"call_creds":[{"type":"jwt_token_file","config":{"jwt_token_file":"/tokens/token"}}]}}`),
217+
want: &Config{
218+
TargetURI: target,
219+
ChannelCredentials: xdscreds.NewChannelCreds(nil, xdscreds.Identity{Type: "insecure"}, nil),
220+
CallCredentials: []*xdscreds.CallCreds{xdscreds.NewCallCreds(nil, xdscreds.Identity{
221+
Type: "jwt_token_file",
222+
// Bootstrap parsing normalizes the configuration JSON
223+
// via json.Indent, and the identity carries the
224+
// normalized bytes.
225+
Data: json.RawMessage("{\n\"jwt_token_file\": \"/tokens/token\"\n}"),
226+
}, nil)},
227+
},
228+
},
210229
{
211230
name: "untrusted_not_allowlisted",
212231
gs: googleGrpcService(target, nil, nil, nil),
@@ -279,6 +298,9 @@ func (s) TestParse(t *testing.T) {
279298
if err != nil {
280299
t.Fatalf("Parse() returned unexpected error: %v", err)
281300
}
301+
// The cmp.Diff below compares credentials by identity only, so it
302+
// cannot tell a built credential from a nil one; verify the
303+
// credentials were built.
282304
if got.ChannelCredentials.Bundle() == nil {
283305
t.Error("Parse() returned channel credentials without a built bundle")
284306
}

internal/xds/httpfilter/ext_authz/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
type config struct {
3030
httpfilter.FilterConfig
3131
// grpcService is the configuration for the external authorization server.
32-
grpcService grpcservice.Config
32+
grpcService *grpcservice.Config
3333
// filterEnabled specifies the percentage of requests to be authorized by
3434
// the external authorization server.
3535
filterEnabled fraction

internal/xds/httpfilter/ext_authz/ext_authz.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ func init() {
4646
var (
4747
// TODO: Parse via grpcservice.Parse with the filter parse options,
4848
// as ext_proc does, when ext_authz is wired up for gRFC A102.
49-
parseGRPCServiceConfig = func(*v3corepb.GrpcService) (grpcservice.Config, error) {
50-
return grpcservice.Config{}, fmt.Errorf("parseGRPCServiceConfig not implemented")
49+
parseGRPCServiceConfig = func(*v3corepb.GrpcService) (*grpcservice.Config, error) {
50+
return nil, fmt.Errorf("parseGRPCServiceConfig not implemented")
5151
}
5252
)
5353

internal/xds/httpfilter/ext_authz/ext_authz_test.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,16 @@ func Test(t *testing.T) {
5353
// testParseGRPCServiceConfig is a helper function that parses a GrpcService
5454
// proto message into a GRPCServiceConfig. This is a temporary test
5555
// implementation that will be removed once gRFC A102 is implemented.
56-
func testParseGRPCServiceConfig(grpcService *corepb.GrpcService) (grpcservice.Config, error) {
57-
if grpcService == nil {
58-
return grpcservice.Config{}, nil
59-
}
56+
func testParseGRPCServiceConfig(grpcService *corepb.GrpcService) (*grpcservice.Config, error) {
6057
if grpcService.GetGoogleGrpc() == nil {
61-
return grpcservice.Config{}, fmt.Errorf("only google_grpc grpc_service is supported")
58+
return nil, fmt.Errorf("only google_grpc grpc_service is supported")
6259
}
6360
if grpcService.GetGoogleGrpc().GetTargetUri() == "" {
64-
return grpcservice.Config{}, fmt.Errorf("targetURI must be a non-empty string")
61+
return nil, fmt.Errorf("targetURI must be a non-empty string")
6562
}
66-
67-
sc := grpcservice.Config{
63+
return &grpcservice.Config{
6864
TargetURI: grpcService.GetGoogleGrpc().GetTargetUri(),
69-
}
70-
return sc, nil
65+
}, nil
7166
}
7267

7368
var cmpOpts = []cmp.Option{
@@ -114,7 +109,7 @@ func (s) TestParseFilterConfig_Success(t *testing.T) {
114109
},
115110
}),
116111
wantCfg: config{
117-
grpcService: grpcservice.Config{
112+
grpcService: &grpcservice.Config{
118113
TargetURI: "localhost:1234",
119114
},
120115
filterEnabled: fraction{
@@ -170,7 +165,7 @@ func (s) TestParseFilterConfig_Success(t *testing.T) {
170165
IncludePeerCertificate: true,
171166
}),
172167
wantCfg: config{
173-
grpcService: grpcservice.Config{
168+
grpcService: &grpcservice.Config{
174169
TargetURI: "localhost:5678",
175170
},
176171
filterEnabled: fraction{

internal/xds/httpfilter/extproc/ext_proc.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import (
5151
"google.golang.org/protobuf/types/known/anypb"
5252
"google.golang.org/protobuf/types/known/structpb"
5353

54-
v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
5554
v3procfilterpb "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ext_proc/v3"
5655
v3procservicegrpc "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3"
5756
v3procservicepb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3"
@@ -110,15 +109,6 @@ func validateBodyProcessingMode(mode *v3procfilterpb.ProcessingMode) error {
110109
return nil
111110
}
112111

113-
// parseGRPCService parses the GrpcService proto identifying the external
114-
// processor server. The gRFC A102 trust policy — honoring the proto's
115-
// credentials only when the delivering xDS management server is trusted, and
116-
// requiring an untrusted server's target to be present in the bootstrap
117-
// allowed_grpc_services map — is applied by grpcservice.Parse.
118-
func parseGRPCService(gs *v3corepb.GrpcService, opts httpfilter.ParseOptions) (*grpcservice.Config, error) {
119-
return grpcservice.Parse(gs, opts.BootstrapConfig, opts.ServerConfig)
120-
}
121-
122112
// ParseFilterConfig parses the provided filter configuration. The GrpcService
123113
// identifying the external processor server is validated against the provided
124114
// parse options, as per gRFC A102.
@@ -168,7 +158,7 @@ func (builder) ParseFilterConfig(cfg proto.Message, opts httpfilter.ParseOptions
168158
if msg.GetGrpcService() == nil {
169159
return nil, fmt.Errorf("extproc: empty grpc_service provided in config %v", cfg)
170160
}
171-
server, err := parseGRPCService(msg.GetGrpcService(), opts)
161+
server, err := grpcservice.Parse(msg.GetGrpcService(), opts.BootstrapConfig, opts.ServerConfig)
172162
if err != nil {
173163
return nil, fmt.Errorf("extproc: failed to parse grpc_service: %v", err)
174164
}
@@ -218,8 +208,8 @@ func (builder) ParseFilterConfigOverride(ov proto.Message, opts httpfilter.Parse
218208
// Parse the GrpcService last, so that no error path can drop the built
219209
// credentials: the caller owns them from here on.
220210
var serverOpt optional.Optional[*grpcservice.Config]
221-
if override.GetGrpcService() != nil {
222-
server, err := parseGRPCService(override.GetGrpcService(), opts)
211+
if gs := override.GetGrpcService(); gs != nil {
212+
server, err := grpcservice.Parse(gs, opts.BootstrapConfig, opts.ServerConfig)
223213
if err != nil {
224214
return nil, fmt.Errorf("extproc: failed to parse grpc_service: %v", err)
225215
}

0 commit comments

Comments
 (0)