Skip to content

Commit 24272cf

Browse files
committed
chore: add tests
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 12fefdf commit 24272cf

File tree

5 files changed

+22
-65
lines changed

5 files changed

+22
-65
lines changed

docs/opa-middleware.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,20 @@ Example:
4646

4747
## Comprehensive API Path Protection
4848

49-
When writing Rego policies, it's crucial to implement thorough path matching to prevent unintended access to APIs. The daemon processes API paths without strict prefix validation, which could lead to security bypasses.
49+
When writing Rego policies, use pattern matching for API paths to prevent unauthorized access. Simple string matching can be bypassed by adding prefixes to API paths.
50+
51+
Consider this potentially vulnerable policy that tries to restrict access to a specific container:
52+
```
53+
# INCORRECT: Can be bypassed
54+
allow if {
55+
not (input.Path == "/v1.43/containers/sensitive-container/json")
56+
}
57+
```
58+
This policy can be bypassed in multiple ways:
59+
1. Using container ID instead of name: `/v1.43/containers/abc123.../json`
60+
2. Adding path prefixes: `/custom/v1.43/containers/sensitive-container/json`
61+
62+
Follow the path matching best practices below to properly secure your resources.
5063

5164
## Path Matching Best Practices
5265

docs/sample-rego-policies/case1-incompatible_API.rego

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/sample-rego-policies/default.rego

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ is_plugins if {
3333
}
3434

3535
is_forbidden_container if {
36-
intpu.Method == "GET"
36+
input.Method == "GET"
3737
glob.match("/**/container/1f576a797a486438548377124f6cb7770a5cb7c8ff6a11c069cb4128d3f59462/json", ["/"], input.Path)
3838
}

docs/sample-rego-policies/test.rego

Lines changed: 0 additions & 39 deletions
This file was deleted.

e2e/e2e_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,15 @@ func TestRun(t *testing.T) {
3333
} else {
3434
t.Skip("E2E tests skipped. Set TEST_E2E=1 to run regular E2E tests or MIDDLEWARE_E2E=1 to run OPA middleware tests")
3535
}
36+
}
3637

38+
func runOPATests(t *testing.T) {
3739
if err := parseTestFlags(); err != nil {
3840
log.Println("failed to parse go test flags", err)
3941
os.Exit(1)
4042
}
4143

4244
opt, _ := option.New([]string{*Subject, "--namespace", "finch"})
43-
}
44-
45-
func runOPATests(t *testing.T) {
46-
opt, _ := option.New([]string{*Subject, "--namespace", "finch"})
4745

4846
ginkgo.SynchronizedBeforeSuite(func() []byte {
4947
tests.SetupLocalRegistry(opt)
@@ -67,6 +65,11 @@ func runOPATests(t *testing.T) {
6765
}
6866

6967
func runE2ETests(t *testing.T) {
68+
if err := parseTestFlags(); err != nil {
69+
log.Println("failed to parse go test flags", err)
70+
os.Exit(1)
71+
}
72+
7073
opt, _ := option.New([]string{*Subject, "--namespace", "finch"})
7174

7275
ginkgo.SynchronizedBeforeSuite(func() []byte {

0 commit comments

Comments
 (0)