-
Notifications
You must be signed in to change notification settings - Fork 125
support basic gRPC payload decoding #202
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 all commits
Commits
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
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 was deleted.
Oops, something went wrong.
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
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,29 @@ | ||
| SHELL:=bash | ||
| GRPCURL_IMAGE:=fullstorydev/grpcurl:v1.7.0 | ||
| GRPCURL=docker run --network=host -i --rm -v $$(pwd)/testsrv.pb:/testsrv.pb $(GRPCURL_IMAGE) \ | ||
| -d @ -plaintext -protoset /testsrv.pb 127.0.0.1:51051 | ||
|
|
||
| all: testsrv.pb testsrv-image test-setup test test-teardown | ||
|
|
||
| .PHONY: testsrv-image | ||
| testsrv-image: | ||
| docker build -t testsrv testsrv/ | ||
|
|
||
| testsrv.pb: testsrv/test.proto | ||
| protoc --include_imports -o "$@" "$<" | ||
|
|
||
| .PHONY: test-setup | ||
| test-setup: | ||
| docker-compose up -d | ||
|
|
||
| .PHONY: test-teardown | ||
| test-teardown: | ||
| docker-compose logs | ||
| docker-compose down | ||
|
|
||
| .PHONY: test | ||
| test: | ||
| $(GRPCURL) test.KitchenSink/Ping <<<"{}" | ||
| $(GRPCURL) test.KitchenSink/Exchange < message.json | ||
| if sed s/alice/arno/ message.json | $(GRPCURL) test.KitchenSink/Exchange; then \ | ||
| echo "expected 'Permission Denied'"; exit 1; fi |
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,82 @@ | ||
| # Envoy and gRPC example | ||
|
|
||
| The docker-compose.yaml file defines three services: | ||
| 1. testsrv, a gRPC server used for testing, created by [fullstorydev](https://github.com/fullstorydev/grpcui/tree/master/testing/cmd/testsvr) | ||
| 2. opa-envoy-plugin, equipped with the descriptor set for testsrv | ||
| 3. Envoy, configured to use opa-envoy-plugin as ext_authz service, using the v3 API, | ||
| and including the request payloads _as bytes_: | ||
| ```yaml | ||
| - name: envoy.ext_authz | ||
| typed_config: | ||
| '@type': type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthz | ||
| transport_api_version: V3 | ||
| failure_mode_allow: false | ||
| grpc_service: | ||
| envoy_grpc: | ||
| cluster_name: opa-envoy | ||
| with_request_body: | ||
| allow_partial_message: true | ||
| max_request_bytes: 1024 | ||
| pack_as_bytes: true | ||
| ``` | ||
|
|
||
| After spinning them up with `docker-compose up`, they can be exercised | ||
| using a gRPC client. | ||
|
|
||
| This is an example invocation using `grpcurl`: | ||
|
|
||
| ```interactive | ||
| $ grpcurl -plaintext -protoset testsrv.pb 127.0.0.1:51051 test.KitchenSink/Ping | ||
| { | ||
|
|
||
| } | ||
| $ grpcurl -plaintext -protoset testsrv.pb 127.0.0.1:51051 test.KitchenSink/Exchange | ||
| ERROR: | ||
| Code: PermissionDenied | ||
| Message: | ||
| $ grpcurl -d @ -plaintext -protoset testsrv.pb 127.0.0.1:51051 test.KitchenSink/Exchange < message.json | ||
| { | ||
| "person": { | ||
| "id": "123", | ||
| "name": "alice", | ||
| "parent": { | ||
| "id": "122", | ||
| "name": "bob" | ||
| } | ||
| }, | ||
| "state": "AWAITING_INPUT", | ||
| "neededNumA": 1.23, | ||
| "neededNumB": 1.23, | ||
| "opaqueId": "asdf", | ||
| "wk": { | ||
| "now": "2020-12-02T09:48:42.118723Z", | ||
| "period": "30s", | ||
| "neat": { | ||
| "@type": "googleapis.com/google.protobuf.StringValue", | ||
| "value": "Hithere" | ||
| }, | ||
| "object": { | ||
| "foo": "bar" | ||
| }, | ||
| "value": "string", | ||
| "list": [ | ||
| "zero", | ||
| "one", | ||
| "infinity" | ||
| ], | ||
| "bytes": "AAAA", | ||
| "string": "abcd", | ||
| "bool": true, | ||
| "double": 0.12, | ||
| "float": 0.12, | ||
| "smallInt": 1, | ||
| "bigInt": "2", | ||
| "smallId": 100, | ||
| "bigId": "101" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The policy used in this example, `policy.rego`, is quite artificial, but allows us | ||
| to show how different protobuf fields are going to look like when made available to | ||
| OPA. The service definition used can be found in `testsrv/test.proto`. |
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,26 @@ | ||
| version: '3' | ||
| services: | ||
| envoy: | ||
| image: envoyproxy/envoy:v1.16-latest | ||
| ports: | ||
| - "9901:9901" | ||
| - "51051:51051" | ||
| volumes: | ||
| - ./envoy.yaml:/etc/envoy/envoy.yaml | ||
| opa-envoy: | ||
| image: openpolicyagent/opa:latest-envoy | ||
| ports: | ||
| - "9191:9191" | ||
| command: | ||
| - run | ||
| - --server | ||
| - --config-file=/opa.yaml | ||
| - /policy.rego | ||
| volumes: | ||
| - ./testsrv.pb:/testsrv.pb | ||
| - ./policy.rego:/policy.rego | ||
| - ./opa.yaml:/opa.yaml | ||
| testsrv: | ||
| image: testsrv:latest | ||
| ports: | ||
| - "9090:9090" |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this could be flakey.
test-setuprundocker-compose up -d, and the tests start calling the service; there's a chance that envoy isn't ready yet.However, I haven't been able to trigger this so far locally,
and on github, we're more than likely to pull down the grpcurl image anyways, given envoy plenty of time. While I'm not happy with this arrangement, let's try to roll with it. We'll deal with it if it becomes a problem.