Skip to content

Commit 30ce1d5

Browse files
authored
xds: support injecting bootstrap and server config into HTTP filter config parsing (A102) (grpc#9315)
1 parent 54c743e commit 30ce1d5

25 files changed

Lines changed: 326 additions & 151 deletions

internal/xds/httpfilter/ext_authz/ext_authz.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func grpcStatusCode(httpStatus int32) codes.Code {
8989
return codes.Unknown
9090
}
9191

92-
func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, error) {
92+
func (builder) ParseFilterConfig(cfg proto.Message, _ httpfilter.ParseOptions) (httpfilter.FilterConfig, error) {
9393
m, ok := cfg.(*anypb.Any)
9494
if !ok {
9595
return nil, fmt.Errorf("extauthz: error parsing config %v: unknown type %T, want *anypb.Any", cfg, cfg)
@@ -166,7 +166,7 @@ func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, er
166166
// resource validation, no filter configuration object is returned. Per-route
167167
// disabling is supported via the generic FilterConfig wrapper mechanism rather
168168
// than the ExtAuthzPerRoute.disabled field directly.
169-
func (builder) ParseFilterConfigOverride(overrideCfg proto.Message) (httpfilter.FilterConfig, error) {
169+
func (builder) ParseFilterConfigOverride(overrideCfg proto.Message, _ httpfilter.ParseOptions) (httpfilter.FilterConfig, error) {
170170
m, ok := overrideCfg.(*anypb.Any)
171171
if !ok {
172172
return nil, fmt.Errorf("extauthz: error parsing override config %v: unknown type %T, want *anypb.Any", overrideCfg, overrideCfg)

internal/xds/httpfilter/ext_authz/ext_authz_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (s) TestParseFilterConfig_Success(t *testing.T) {
200200
t.Run(tt.name, func(t *testing.T) {
201201
t.Log(tt.desc)
202202
b := builder{}
203-
got, err := b.ParseFilterConfig(tt.cfg)
203+
got, err := b.ParseFilterConfig(tt.cfg, httpfilter.ParseOptions{})
204204
if err != nil {
205205
t.Fatalf("ParseFilterConfig() failed with unexpected error: %v", err)
206206
}
@@ -316,7 +316,7 @@ func (s) TestParseFilterConfig_Failure(t *testing.T) {
316316
t.Run(tt.name, func(t *testing.T) {
317317
t.Log(tt.desc)
318318
b := builder{}
319-
if _, err := b.ParseFilterConfig(tt.cfg); err == nil || !strings.Contains(err.Error(), tt.wantErr) {
319+
if _, err := b.ParseFilterConfig(tt.cfg, httpfilter.ParseOptions{}); err == nil || !strings.Contains(err.Error(), tt.wantErr) {
320320
t.Fatalf("ParseFilterConfig() returned error = %v, wantErr containing %v", err, tt.wantErr)
321321
}
322322
})
@@ -333,7 +333,7 @@ func (s) TestParseFilterConfigOverride_Success(t *testing.T) {
333333
})
334334

335335
b := builder{}
336-
got, err := b.ParseFilterConfigOverride(override)
336+
got, err := b.ParseFilterConfigOverride(override, httpfilter.ParseOptions{})
337337
if err != nil {
338338
t.Fatalf("ParseFilterConfigOverride() failed with unexpected error: %v", err)
339339
}
@@ -371,7 +371,7 @@ func (s) TestParseFilterConfigOverride_Failure(t *testing.T) {
371371
t.Run(tt.name, func(t *testing.T) {
372372
t.Log(tt.desc)
373373
b := builder{}
374-
if _, err := b.ParseFilterConfigOverride(tt.override); err == nil || !strings.Contains(err.Error(), tt.wantErr) {
374+
if _, err := b.ParseFilterConfigOverride(tt.override, httpfilter.ParseOptions{}); err == nil || !strings.Contains(err.Error(), tt.wantErr) {
375375
t.Fatalf("ParseFilterConfigOverride() returned error = %v, wantErr containing %v", err, tt.wantErr)
376376
}
377377
})

internal/xds/httpfilter/extproc/config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (s) TestParseFilterConfig_Success(t *testing.T) {
219219
for _, tt := range tests {
220220
t.Run(tt.name, func(t *testing.T) {
221221
b := builder{}
222-
got, err := b.ParseFilterConfig(tt.cfg)
222+
got, err := b.ParseFilterConfig(tt.cfg, httpfilter.ParseOptions{})
223223
if err != nil {
224224
t.Fatalf("ParseFilterConfig() returned unexpected error: %v", err)
225225
}
@@ -427,7 +427,7 @@ func (s) TestParseFilterConfig_Errors(t *testing.T) {
427427
for _, tt := range tests {
428428
t.Run(tt.name, func(t *testing.T) {
429429
builder := builder{}
430-
_, err := builder.ParseFilterConfig(tt.cfg)
430+
_, err := builder.ParseFilterConfig(tt.cfg, httpfilter.ParseOptions{})
431431
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
432432
t.Fatalf("ParseFilterConfig() returned error = %v, wantErr %v", err, tt.wantErr)
433433
}
@@ -498,7 +498,7 @@ func (s) TestParseFilterConfigOverride_Success(t *testing.T) {
498498
for _, tt := range tests {
499499
t.Run(tt.name, func(t *testing.T) {
500500
builder := builder{}
501-
got, err := builder.ParseFilterConfigOverride(tt.override)
501+
got, err := builder.ParseFilterConfigOverride(tt.override, httpfilter.ParseOptions{})
502502
if err != nil {
503503
t.Fatalf("ParseFilterConfigOverride() returned unexpected error: %v", err)
504504
}
@@ -591,7 +591,7 @@ func (s) TestParseFilterConfigOverride_Errors(t *testing.T) {
591591
for _, tt := range tests {
592592
t.Run(tt.name, func(t *testing.T) {
593593
builder := builder{}
594-
_, err := builder.ParseFilterConfigOverride(tt.override)
594+
_, err := builder.ParseFilterConfigOverride(tt.override, httpfilter.ParseOptions{})
595595
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
596596
t.Fatalf("ParseFilterConfigOverride() returned error = %v, wantErr %v", err, tt.wantErr)
597597
}

internal/xds/httpfilter/extproc/ext_proc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func validateBodyProcessingMode(mode *v3procfilterpb.ProcessingMode) error {
107107
return nil
108108
}
109109

110-
func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, error) {
110+
func (builder) ParseFilterConfig(cfg proto.Message, _ httpfilter.ParseOptions) (httpfilter.FilterConfig, error) {
111111
m, ok := cfg.(*anypb.Any)
112112
if !ok {
113113
return nil, fmt.Errorf("extproc: error parsing config %v: unknown type %T, want *anypb.Any", cfg, cfg)
@@ -171,7 +171,7 @@ func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, er
171171
}, nil
172172
}
173173

174-
func (builder) ParseFilterConfigOverride(ov proto.Message) (httpfilter.FilterConfig, error) {
174+
func (builder) ParseFilterConfigOverride(ov proto.Message, _ httpfilter.ParseOptions) (httpfilter.FilterConfig, error) {
175175
m, ok := ov.(*anypb.Any)
176176
if !ok {
177177
return nil, fmt.Errorf("extproc: error parsing override %v: unknown type %T, want *anypb.Any", ov, ov)

internal/xds/httpfilter/fault/fault.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ func parseConfig(cfg proto.Message) (httpfilter.FilterConfig, error) {
9393
return config{config: msg}, nil
9494
}
9595

96-
func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, error) {
96+
func (builder) ParseFilterConfig(cfg proto.Message, _ httpfilter.ParseOptions) (httpfilter.FilterConfig, error) {
9797
return parseConfig(cfg)
9898
}
9999

100-
func (builder) ParseFilterConfigOverride(override proto.Message) (httpfilter.FilterConfig, error) {
100+
func (builder) ParseFilterConfigOverride(override proto.Message, _ httpfilter.ParseOptions) (httpfilter.FilterConfig, error) {
101101
return parseConfig(override)
102102
}
103103

internal/xds/httpfilter/gcp_authn/gcp_authn_filter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (builder) TypeURLs() []string {
5959
return []string{"type.googleapis.com/envoy.extensions.filters.http.gcp_authn.v3.GcpAuthnFilterConfig"}
6060
}
6161

62-
func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, error) {
62+
func (builder) ParseFilterConfig(cfg proto.Message, _ httpfilter.ParseOptions) (httpfilter.FilterConfig, error) {
6363
m, ok := cfg.(*anypb.Any)
6464
if !ok {
6565
return nil, fmt.Errorf("gcpauthn: invalid filter config type %T", cfg)
@@ -83,8 +83,8 @@ func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, er
8383
//
8484
// Note that we don't support overrides for this filter configuration,
8585
// but still validate it as part of the normal resource validation.
86-
func (b builder) ParseFilterConfigOverride(cfg proto.Message) (httpfilter.FilterConfig, error) {
87-
return b.ParseFilterConfig(cfg)
86+
func (b builder) ParseFilterConfigOverride(cfg proto.Message, opts httpfilter.ParseOptions) (httpfilter.FilterConfig, error) {
87+
return b.ParseFilterConfig(cfg, opts)
8888
}
8989

9090
func (builder) IsTerminal() bool {

internal/xds/httpfilter/gcp_authn/gcp_authn_filter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (s) TestParseFilterConfig(t *testing.T) {
8787
}
8888
for _, tc := range testCases {
8989
t.Run(tc.name, func(t *testing.T) {
90-
gotCfg, err := builder{}.ParseFilterConfig(tc.config)
90+
gotCfg, err := builder{}.ParseFilterConfig(tc.config, httpfilter.ParseOptions{})
9191
if err != nil {
9292
if tc.wantErr == "" || !strings.Contains(err.Error(), tc.wantErr) {
9393
t.Fatalf("ParseFilterConfig() failed with error = %v; want error %q", err, tc.wantErr)
@@ -207,7 +207,7 @@ func (s) TestInterceptor_NewStream_Errors(t *testing.T) {
207207
CacheSize: &wrapperspb.UInt64Value{Value: 10},
208208
},
209209
})
210-
filterConfig, err := builder.ParseFilterConfig(cfg)
210+
filterConfig, err := builder.ParseFilterConfig(cfg, httpfilter.ParseOptions{})
211211
if err != nil {
212212
t.Fatalf("Failed to parse filter config: %v", err)
213213
}

internal/xds/httpfilter/httpfilter.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"google.golang.org/grpc"
2727
estats "google.golang.org/grpc/experimental/stats"
2828
iresolver "google.golang.org/grpc/internal/resolver"
29+
"google.golang.org/grpc/internal/xds/bootstrap"
2930
"google.golang.org/protobuf/proto"
3031
)
3132

@@ -35,6 +36,17 @@ type FilterConfig interface {
3536
isFilterConfig()
3637
}
3738

39+
// ParseOptions contains additional information passed to the HTTP filter's
40+
// config parsing methods.
41+
type ParseOptions struct {
42+
// BootstrapConfig contains the complete bootstrap configuration used by the
43+
// xDS client that received the resource being parsed.
44+
BootstrapConfig *bootstrap.Config
45+
// ServerConfig contains the configuration of the xDS management server that
46+
// sent the resource being parsed.
47+
ServerConfig *bootstrap.ServerConfig
48+
}
49+
3850
// DisabledFilterConfig represents a disabled filter override. It implements the
3951
// FilterConfig interface and can be returned by ParseFilterConfigOverride to
4052
// indicate that the filter should be disabled. It is not used as a config for
@@ -58,13 +70,13 @@ type Builder interface {
5870
// udpa.type.v1.TypedStruct, or an xds.type.v3.TypedStruct for filters that
5971
// do not accept a custom type. The resulting FilterConfig will later be
6072
// passed to Build.
61-
ParseFilterConfig(proto.Message) (FilterConfig, error)
73+
ParseFilterConfig(proto.Message, ParseOptions) (FilterConfig, error)
6274
// ParseFilterConfigOverride parses the provided override configuration
6375
// proto.Message from the RDS override configuration of this filter. This
6476
// may be an anypb.Any, a udpa.type.v1.TypedStruct, or an
6577
// xds.type.v3.TypedStruct for filters that do not accept a custom type.
6678
// The resulting FilterConfig will later be passed to Build.
67-
ParseFilterConfigOverride(proto.Message) (FilterConfig, error)
79+
ParseFilterConfigOverride(proto.Message, ParseOptions) (FilterConfig, error)
6880
// IsTerminal returns whether this Filter is terminal or not (i.e. it must
6981
// be last filter in the filter chain).
7082
IsTerminal() bool

internal/xds/httpfilter/rbac/rbac.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func normalizeHeaderMatcher(header *v3routepb.HeaderMatcher) error {
182182
return nil
183183
}
184184

185-
func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, error) {
185+
func (builder) ParseFilterConfig(cfg proto.Message, _ httpfilter.ParseOptions) (httpfilter.FilterConfig, error) {
186186
if cfg == nil {
187187
return nil, fmt.Errorf("rbac: nil configuration message provided")
188188
}
@@ -197,7 +197,7 @@ func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, er
197197
return parseConfig(msg)
198198
}
199199

200-
func (builder) ParseFilterConfigOverride(override proto.Message) (httpfilter.FilterConfig, error) {
200+
func (builder) ParseFilterConfigOverride(override proto.Message, _ httpfilter.ParseOptions) (httpfilter.FilterConfig, error) {
201201
if override == nil {
202202
return nil, fmt.Errorf("rbac: nil configuration message provided")
203203
}

internal/xds/httpfilter/router/router.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type builder struct {
4848

4949
func (builder) TypeURLs() []string { return []string{TypeURL} }
5050

51-
func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, error) {
51+
func (builder) ParseFilterConfig(cfg proto.Message, _ httpfilter.ParseOptions) (httpfilter.FilterConfig, error) {
5252
// The gRPC router filter does not currently use any fields from the
5353
// config. Verify type only.
5454
if cfg == nil {
@@ -65,7 +65,7 @@ func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, er
6565
return config{}, nil
6666
}
6767

68-
func (builder) ParseFilterConfigOverride(override proto.Message) (httpfilter.FilterConfig, error) {
68+
func (builder) ParseFilterConfigOverride(override proto.Message, _ httpfilter.ParseOptions) (httpfilter.FilterConfig, error) {
6969
if override != nil {
7070
return nil, fmt.Errorf("router: unexpected config override specified: %v", override)
7171
}

0 commit comments

Comments
 (0)