-
Notifications
You must be signed in to change notification settings - Fork 4.7k
extproc: register filter and parse base and override config #9073
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
11a461a
add ext_proc parsing
eshitachandwani acce672
add env config
eshitachandwani 04b7720
Merge branch 'master' into parsing_proc
eshitachandwani 2eac09b
formatting
eshitachandwani 4473a5d
check error in tes
eshitachandwani ac256fd
add regex validation and proc per route
eshitachandwani 96536f2
review comments
eshitachandwani 2d2895c
change the base and override cfg
eshitachandwani 60eff96
change creds to json.Rawmsg, move config to new file common for proc
eshitachandwani db6dac5
remove validation
eshitachandwani 83a64d6
add optional type
eshitachandwani 617824c
use optional type in override config
eshitachandwani ac98798
comments fix
eshitachandwani 83df378
minor fixes
eshitachandwani d222084
minor fixes
eshitachandwani d922e76
address review comments
eshitachandwani f20b9ce
fixes
eshitachandwani 435b1e4
review comments
eshitachandwani fb8fab2
review comments
eshitachandwani 9c30b51
add testgrpcparse string
eshitachandwani 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
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,34 @@ | ||
| /* | ||
| * | ||
| * Copyright 2026 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package extproc | ||
|
|
||
| import ( | ||
| pb "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ext_proc/v3" | ||
| "google.golang.org/grpc/internal/xds/httpfilter" | ||
| ) | ||
|
|
||
| type baseConfig struct { | ||
| httpfilter.FilterConfig | ||
|
easwars marked this conversation as resolved.
|
||
| config *pb.ExternalProcessor | ||
| } | ||
|
|
||
| type overrideConfig struct { | ||
| httpfilter.FilterConfig | ||
| config *pb.ExtProcOverrides | ||
| } | ||
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,120 @@ | ||
| /* | ||
| * | ||
| * Copyright 2026 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| // Package extproc implements the Envoy external processing filter. | ||
| package extproc | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "google.golang.org/grpc/internal/envconfig" | ||
| "google.golang.org/grpc/internal/xds/httpfilter" | ||
| "google.golang.org/protobuf/proto" | ||
| "google.golang.org/protobuf/types/known/anypb" | ||
|
|
||
| fpb "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ext_proc/v3" | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
| func init() { | ||
| if envconfig.XDSClientExtProcEnabled { | ||
| httpfilter.Register(builder{}) | ||
| } | ||
| } | ||
|
|
||
| type builder struct{} | ||
|
|
||
| func (builder) TypeURLs() []string { | ||
| return []string{"type.googleapis.com/envoy.extensions.filters.http.ext_proc.v3.ExternalProcessor"} | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| // validateBodyProcessingMode ensures that the body processing mode is either | ||
| // NONE or GRPC. | ||
| func validateBodyProcessingMode(pMode *fpb.ProcessingMode) error { | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| if reqMode := pMode.GetRequestBodyMode(); reqMode != fpb.ProcessingMode_NONE && reqMode != fpb.ProcessingMode_GRPC { | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| return fmt.Errorf("ext_proc: invalid request body mode %v: want 'NONE' or 'GRPC'", reqMode) | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| } | ||
| if resMode := pMode.GetResponseBodyMode(); resMode != fpb.ProcessingMode_NONE && resMode != fpb.ProcessingMode_GRPC { | ||
| return fmt.Errorf("ext_proc: invalid response body mode %v: want 'NONE' or 'GRPC'", resMode) | ||
| } | ||
|
eshitachandwani marked this conversation as resolved.
Outdated
|
||
| return nil | ||
| } | ||
|
|
||
| func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, error) { | ||
| if cfg == nil { | ||
| return nil, fmt.Errorf("ext_proc: nil base configuration message provided") | ||
| } | ||
| m, ok := cfg.(*anypb.Any) | ||
| if !ok { | ||
| return nil, fmt.Errorf("ext_proc: error parsing config %v: unknown type %T", cfg, cfg) | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| } | ||
|
eshitachandwani marked this conversation as resolved.
|
||
| msg := new(fpb.ExternalProcessor) | ||
| if err := m.UnmarshalTo(msg); err != nil { | ||
| return nil, fmt.Errorf("ext_proc: failed to unmarshal config %v: %v", cfg, err) | ||
| } | ||
| if msg.GetGrpcService() == nil { | ||
| return nil, fmt.Errorf("ext_proc: empty grpc_service provided in config %v", cfg) | ||
| } | ||
| if msg.GetGrpcService().GetGoogleGrpc() == nil { | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| return nil, fmt.Errorf("ext_proc: only google_grpc grpc_service is supported, got %v in config %v", msg.GrpcService.GetTargetSpecifier(), cfg) | ||
| } | ||
| if msg.GetProcessingMode() == nil { | ||
| return nil, fmt.Errorf("ext_proc: missing processing_mode in config %v", cfg) | ||
| } | ||
| if err := validateBodyProcessingMode(msg.GetProcessingMode()); err != nil { | ||
| return nil, err | ||
| } | ||
| if mr := msg.GetMutationRules(); mr != nil { | ||
| if err := mr.GetAllowExpression().Validate(); err != nil { | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| return nil, fmt.Errorf("ext_proc: %v", err) | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| } | ||
| if err := mr.GetDisallowExpression().Validate(); err != nil { | ||
| return nil, fmt.Errorf("ext_proc: %v", err) | ||
| } | ||
| } | ||
|
easwars marked this conversation as resolved.
|
||
| return baseConfig{config: msg}, nil | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| func (builder) ParseFilterConfigOverride(ov proto.Message) (httpfilter.FilterConfig, error) { | ||
| if ov == nil { | ||
| return nil, fmt.Errorf("ext_proc: nil override configuration provided") | ||
| } | ||
| m, ok := ov.(*anypb.Any) | ||
| if !ok { | ||
| return nil, fmt.Errorf("ext_proc: error parsing override %v: unknown type %T", ov, ov) | ||
| } | ||
| msg := new(fpb.ExtProcPerRoute) | ||
| if err := m.UnmarshalTo(msg); err != nil { | ||
| return nil, fmt.Errorf("ext_proc: failed to unmarshal override %v: %v", ov, err) | ||
| } | ||
| override := msg.GetOverrides() | ||
| // GrpcService can be optionally provided in the override config. If | ||
| // provided, it must be of type google_grpc. | ||
| if override.GetGrpcService() != nil && override.GrpcService.GetGoogleGrpc() == nil { | ||
| return nil, fmt.Errorf("ext_proc: only google_grpc grpc_service is supported, got %v in override %v", override.GrpcService.GetTargetSpecifier(), override) | ||
| } | ||
| if pm := override.GetProcessingMode(); pm != nil { | ||
|
eshitachandwani marked this conversation as resolved.
|
||
| if err := validateBodyProcessingMode(pm); err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| return overrideConfig{config: override}, nil | ||
| } | ||
|
|
||
| func (builder) IsTerminal() bool { | ||
| return false | ||
| } | ||
Oops, something went wrong.
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.