Skip to content

Commit 4fb6822

Browse files
committed
plugin: allow selecting wasm target for evaluation
This turns the simple grpc tests scenario into a matrix test for both evaluation variants. Should wait for the next opa release so the inter query builtin cache is wired into the wasm eval. Signed-off-by: Stephan Renatus <[email protected]>
1 parent 570ca5d commit 4fb6822

File tree

7 files changed

+38
-9
lines changed

7 files changed

+38
-9
lines changed

Diff for: .github/workflows/checks.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ jobs:
9292
e2e-envoy-grpc:
9393
name: Envoy gRPC End-to-End Test
9494
runs-on: ubuntu-18.04
95+
strategy:
96+
matrix:
97+
include:
98+
- eval: wasm
99+
- eval: rego
95100
steps:
96101
- name: Check out code
97102
uses: actions/checkout@v2
@@ -104,7 +109,7 @@ jobs:
104109
working-directory: examples/grpc
105110

106111
- name: Run test
107-
run: make test-setup test
112+
run: make test-setup test EVAL_TARGET=${{ matrix.eval }}
108113
working-directory: examples/grpc
109114

110115
- name: Run test log dump and cleanup

Diff for: envoyauth/evaluation.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type EvalContext interface {
2121
Store() storage.Store
2222
Compiler() *ast.Compiler
2323
Runtime() *ast.Term
24+
Target() string
2425
PreparedQueryDoOnce() *sync.Once
2526
InterQueryBuiltinCache() iCache.InterQueryCache
2627
PreparedQuery() *rego.PreparedEvalQuery
@@ -83,7 +84,8 @@ func constructPreparedQuery(evalContext EvalContext, txn storage.Transaction, m
8384
rego.Compiler(evalContext.Compiler()),
8485
rego.Store(evalContext.Store()),
8586
rego.Transaction(txn),
86-
rego.Runtime(evalContext.Runtime()))
87+
rego.Runtime(evalContext.Runtime()),
88+
rego.Target(evalContext.Target()))
8789

8890
r := rego.New(opts...)
8991

Diff for: examples/grpc/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ SHELL:=bash
22
GRPCURL_IMAGE:=fullstorydev/grpcurl:v1.7.0
33
GRPCURL=docker run --network=host -i --rm -v $$(pwd)/testsrv.pb:/testsrv.pb $(GRPCURL_IMAGE) \
44
-d @ -plaintext -protoset /testsrv.pb 127.0.0.1:51051
5+
EVAL_TARGET?=rego
56

67
all: testsrv.pb testsrv-image test-setup test test-teardown
78

@@ -14,7 +15,7 @@ testsrv.pb: testsrv/test.proto
1415

1516
.PHONY: test-setup
1617
test-setup:
17-
docker-compose up -d
18+
EVAL_TARGET=$(EVAL_TARGET) docker-compose up -d
1819

1920
.PHONY: test-teardown
2021
test-teardown:

Diff for: examples/grpc/docker-compose.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ services:
1414
command:
1515
- run
1616
- --server
17-
- --config-file=/opa.yaml
17+
- --config-file=/opa-${EVAL_TARGET}.yaml
1818
- /policy.rego
1919
volumes:
2020
- ./testsrv.pb:/testsrv.pb
2121
- ./policy.rego:/policy.rego
22-
- ./opa.yaml:/opa.yaml
22+
- ./opa-wasm.yaml:/opa-wasm.yaml
23+
- ./opa-rego.yaml:/opa-rego.yaml
2324
testsrv:
2425
image: testsrv:latest
2526
ports:
File renamed without changes.

Diff for: examples/grpc/opa-wasm.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugins:
2+
envoy_ext_authz_grpc:
3+
addr: ":9191"
4+
path: envoy/authz/allow
5+
dry-run: false
6+
enable-reflection: true
7+
proto-descriptor: /testsrv.pb
8+
eval-target: wasm
9+
decision_logs:
10+
console: true

Diff for: internal/internal.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ import (
4141
"github.com/open-policy-agent/opa/util"
4242
)
4343

44-
const defaultAddr = ":9191"
45-
const defaultPath = "envoy/authz/allow"
46-
const defaultDryRun = false
47-
const defaultEnableReflection = false
44+
const (
45+
defaultAddr = ":9191"
46+
defaultPath = "envoy/authz/allow"
47+
defaultDryRun = false
48+
defaultEnableReflection = false
49+
defaultEvalTarget = "rego"
50+
)
4851

4952
// PluginName is the name to register with the OPA plugin manager
5053
const PluginName = "envoy_ext_authz_grpc"
@@ -58,6 +61,7 @@ func Validate(m *plugins.Manager, bs []byte) (*Config, error) {
5861
Addr: defaultAddr,
5962
DryRun: defaultDryRun,
6063
EnableReflection: defaultEnableReflection,
64+
EvalTarget: defaultEvalTarget,
6165
}
6266

6367
if err := util.Unmarshal(bs, &cfg); err != nil {
@@ -133,6 +137,7 @@ type Config struct {
133137
Path string `json:"path"`
134138
DryRun bool `json:"dry-run"`
135139
EnableReflection bool `json:"enable-reflection"`
140+
EvalTarget string `json:"eval-target"`
136141
parsedQuery ast.Body
137142
ProtoDescriptor string `json:"proto-descriptor"`
138143
protoSet *protoregistry.Files
@@ -167,6 +172,10 @@ func (p *envoyExtAuthzGrpcServer) Runtime() *ast.Term {
167172
return p.manager.Info
168173
}
169174

175+
func (p *envoyExtAuthzGrpcServer) Target() string {
176+
return p.cfg.EvalTarget
177+
}
178+
170179
func (p *envoyExtAuthzGrpcServer) PreparedQueryDoOnce() *sync.Once {
171180
return p.preparedQueryDoOnce
172181
}
@@ -243,6 +252,7 @@ func (p *envoyExtAuthzGrpcServer) listen() {
243252
"path": p.cfg.Path,
244253
"dry-run": p.cfg.DryRun,
245254
"enable-reflection": p.cfg.EnableReflection,
255+
"eval-target": p.cfg.EvalTarget,
246256
}).Info("Starting gRPC server.")
247257

248258
p.manager.UpdatePluginStatus(PluginName, &plugins.Status{State: plugins.StateOK})

0 commit comments

Comments
 (0)