Skip to content

Commit 162084c

Browse files
author
nuwandi-wickramasinghe_zse
committed
eopa dependencies
1 parent ce21a33 commit 162084c

File tree

7 files changed

+1020
-113
lines changed

7 files changed

+1020
-113
lines changed

config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ type Config struct {
317317
OpenPolicyAgentControlLoopMaxJitter time.Duration `yaml:"open-policy-agent-control-loop-max-jitter"`
318318
EnableOpenPolicyAgentDataPreProcessingOptimization bool `yaml:"enable-open-policy-agent-data-preprocessing-optimization"`
319319
EnableOpenPolicyAgentPreloading bool `yaml:"enable-open-policy-agent-preloading"`
320+
EnableEnterpriseOpenPolicyAgentPlugins bool `yaml:"enable-enterprise-open-policy-agent-plugins"`
320321
OpenPolicyAgentConfigTemplate string `yaml:"open-policy-agent-config-template"`
321322
OpenPolicyAgentEnvoyMetadata string `yaml:"open-policy-agent-envoy-metadata"`
322323
OpenPolicyAgentCleanerInterval time.Duration `yaml:"open-policy-agent-cleaner-interval"`
@@ -571,6 +572,7 @@ func NewConfig() *Config {
571572
flag.Int64Var(&cfg.OpenPolicyAgentMaxRequestBodySize, "open-policy-agent-max-request-body-size", openpolicyagent.DefaultMaxRequestBodySize, "Maximum number of bytes from a http request body that are passed as input to the policy")
572573
flag.Int64Var(&cfg.OpenPolicyAgentRequestBodyBufferSize, "open-policy-agent-request-body-buffer-size", openpolicyagent.DefaultRequestBodyBufferSize, "Read buffer size for the request body")
573574
flag.Int64Var(&cfg.OpenPolicyAgentMaxMemoryBodyParsing, "open-policy-agent-max-memory-body-parsing", openpolicyagent.DefaultMaxMemoryBodyParsing, "Total number of bytes used to parse http request bodies across all requests. Once the limit is met, requests will be rejected.")
575+
flag.BoolVar(&cfg.EnableEnterpriseOpenPolicyAgentPlugins, "enable-enterprise-open-policy-agent-plugins", false, "Allowing open policy agent to load additional plugins which are available with EOPA. EOPA has been donated to the OPA community")
574576

575577
// TLS client certs
576578
flag.StringVar(&cfg.ClientKeyFile, "client-tls-key", "", "TLS Key file for backend connections, multiple keys may be given comma separated - the order must match the certs")
@@ -1041,6 +1043,7 @@ func (c *Config) ToOptions() skipper.Options {
10411043
OpenPolicyAgentControlLoopMaxJitter: c.OpenPolicyAgentControlLoopMaxJitter,
10421044
EnableOpenPolicyAgentDataPreProcessingOptimization: c.EnableOpenPolicyAgentDataPreProcessingOptimization,
10431045
EnableOpenPolicyAgentPreloading: c.EnableOpenPolicyAgentPreloading,
1046+
EnableEnterpriseOpenPolicyAgentPlugins: c.EnableEnterpriseOpenPolicyAgentPlugins,
10441047
OpenPolicyAgentConfigTemplate: c.OpenPolicyAgentConfigTemplate,
10451048
OpenPolicyAgentEnvoyMetadata: c.OpenPolicyAgentEnvoyMetadata,
10461049
OpenPolicyAgentCleanerInterval: c.OpenPolicyAgentCleanerInterval,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package eopa
2+
3+
import (
4+
"github.com/open-policy-agent/eopa/pkg/plugins/data"
5+
dl "github.com/open-policy-agent/eopa/pkg/plugins/decision_logs"
6+
"github.com/open-policy-agent/opa/v1/plugins"
7+
)
8+
9+
func All() map[string]plugins.Factory {
10+
return map[string]plugins.Factory{
11+
data.Name: data.Factory(),
12+
dl.DLPluginName: dl.Factory(),
13+
}
14+
}

filters/openpolicyagent/openpolicyagent.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"errors"
77
"fmt"
8+
"github.com/zalando/skipper/filters/openpolicyagent/internal/eopa"
89
"io"
910
"maps"
1011
"math/rand"
@@ -115,6 +116,8 @@ type OpenPolicyAgentRegistry struct {
115116
controlLoopInterval time.Duration
116117
controlLoopMaxJitter time.Duration
117118

119+
enableEopaPlugins bool
120+
118121
enableDataPreProcessingOptimization bool
119122

120123
valueCache iCache.InterQueryValueCache
@@ -200,6 +203,13 @@ func WithEnableCustomControlLoop(enabled bool) func(*OpenPolicyAgentRegistry) er
200203
}
201204
}
202205

206+
func WithEnableEopaPlugins(enabled bool) func(*OpenPolicyAgentRegistry) error {
207+
return func(cfg *OpenPolicyAgentRegistry) error {
208+
cfg.enableEopaPlugins = enabled
209+
return nil
210+
}
211+
}
212+
203213
func WithEnableDataPreProcessingOptimization(enabled bool) func(*OpenPolicyAgentRegistry) error {
204214
return func(cfg *OpenPolicyAgentRegistry) error {
205215
cfg.enableDataPreProcessingOptimization = enabled
@@ -690,7 +700,14 @@ func (registry *OpenPolicyAgentRegistry) new(store storage.Store, bundleName str
690700
return nil, err
691701
}
692702

693-
discoveryPlugin, err := discovery.New(manager, discovery.Factories(map[string]plugins.Factory{envoy.PluginName: envoy.Factory{}}), discovery.Hooks(configHooks))
703+
discoveryOpts := map[string]plugins.Factory{envoy.PluginName: envoy.Factory{}}
704+
if registry.enableEopaPlugins {
705+
for name, factory := range eopa.All() {
706+
discoveryOpts[name] = factory
707+
}
708+
}
709+
710+
discoveryPlugin, err := discovery.New(manager, discovery.Factories(discoveryOpts), discovery.Hooks(configHooks))
694711
if err != nil {
695712
return nil, err
696713
}

filters/openpolicyagent/openpolicyagent_test.go

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,44 @@ func mockControlPlaneWithDiscoveryBundle(discoveryBundle string) (*opasdktest.Se
121121
{"discovery":{"bundles":{"bundles/test":{"persist":false,"resource":"bundles/test","service":"test"}}}}
122122
`,
123123
}),
124+
opasdktest.MockBundle("/bundles/discovery-eopa-plugin", map[string]string{
125+
"data.json": `{
126+
"discovery": {
127+
"bundles": {
128+
"bundles/test": {
129+
"persist": false,
130+
"resource": "bundles/test",
131+
"service": "test"
132+
}
133+
},
134+
"decision_logs": {
135+
"plugin": "eopa_dl"
136+
},
137+
"plugins": {
138+
"eopa_dl": {
139+
"buffer": {
140+
"type": "memory",
141+
"max_bytes": 50000000
142+
},
143+
"output": {
144+
"type": "s3",
145+
"bucket": "logs",
146+
"endpoint": "https://example.s3.eu-central-1.amazonaws.com/",
147+
"force_path": true,
148+
"region": "eu-central-1",
149+
"access_key_id": "myid",
150+
"access_secret": "mysecret",
151+
"batching": {
152+
"at_bytes": 10000000,
153+
"at_period": "1s"
154+
}
155+
}
156+
}
157+
}
158+
}
159+
}
160+
`,
161+
}),
124162
opasdktest.MockBundle("/bundles/discovery-with-wrong-bundle", map[string]string{
125163
"data.json": `
126164
{"discovery":{"bundles":{"bundles/non-existing-bundle":{"persist":false,"resource":"bundles/non-existing-bundle","service":"test"}}}}
@@ -560,17 +598,24 @@ func TestOpaActivationSuccessWithDiscovery(t *testing.T) {
560598
{
561599
enableCustomControlLoop: true,
562600
discoveryBundle: "bundles/discovery",
601+
enableEopaPlugins: false,
563602
},
564603
{
565604
enableCustomControlLoop: false,
566605
discoveryBundle: "bundles/discovery",
606+
enableEopaPlugins: true,
607+
},
608+
{
609+
enableCustomControlLoop: false,
610+
discoveryBundle: "bundles/discovery-eopa-plugin",
611+
enableEopaPlugins: true,
567612
},
568613
}
569614
runWithTestCases(t, testCases,
570615
func(t *testing.T, tc opaInstanceStartupTestCase) {
571616
_, config := mockControlPlaneWithDiscoveryBundle(tc.discoveryBundle)
572617

573-
registry, err := NewOpenPolicyAgentRegistry(WithReuseDuration(1*time.Second), WithCleanInterval(1*time.Second), WithEnableCustomControlLoop(tc.enableCustomControlLoop), WithOpenPolicyAgentInstanceConfig(WithConfigTemplate(config)))
618+
registry, err := NewOpenPolicyAgentRegistry(WithReuseDuration(1*time.Second), WithCleanInterval(1*time.Second), WithEnableCustomControlLoop(tc.enableCustomControlLoop), WithOpenPolicyAgentInstanceConfig(WithConfigTemplate(config)), WithEnableEopaPlugins(tc.enableEopaPlugins))
574619
assert.NoError(t, err)
575620

576621
instance, err := registry.GetOrStartInstance("test")
@@ -1084,6 +1129,7 @@ type opaInstanceStartupTestCase struct {
10841129
expectedTriggerMode plugins.TriggerMode
10851130
discoveryBundle string
10861131
resourceBundle bool
1132+
enableEopaPlugins bool
10871133
}
10881134

10891135
func runWithTestCases(t *testing.T, cases []opaInstanceStartupTestCase, test func(t *testing.T, tc opaInstanceStartupTestCase)) {

0 commit comments

Comments
 (0)