Skip to content

Commit 0383e20

Browse files
authored
fix(policies): Set proper host on policy engine (#1403)
Signed-off-by: Javier Rodriguez <[email protected]>
1 parent f1d4092 commit 0383e20

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

pkg/policies/engine/rego/rego.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ var builtinFuncNotAllowed = []*ast.Builtin{
5757
// allowedNetworkDomains is a list of network domains that are allowed for the compiler to access
5858
// when using http.send built-in function
5959
var allowedNetworkDomains = []string{
60-
"chainloop.dev",
61-
"cisa.gov",
60+
"www.chainloop.dev",
61+
"www.cisa.gov",
6262
}
6363

6464
// Force interface

pkg/policies/engine/rego/rego_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func TestRego_VerifyInvalidPolicy(t *testing.T) {
195195
})
196196
}
197197

198-
func TestRego_WithRestrictiveMOde(t *testing.T) {
198+
func TestRego_WithRestrictiveMode(t *testing.T) {
199199
t.Run("forbidden functions", func(t *testing.T) {
200200
regoContent, err := os.ReadFile("testfiles/restrictive_mode.rego")
201201
require.NoError(t, err)
@@ -229,6 +229,20 @@ func TestRego_WithRestrictiveMOde(t *testing.T) {
229229
assert.Contains(t, err.Error(), "eval_builtin_error: http.send: unallowed host: example.com")
230230
assert.Len(t, violations, 0)
231231
})
232+
233+
t.Run("allowed network requests", func(t *testing.T) {
234+
regoContent, err := os.ReadFile("testfiles/restricted_mode_networking_allowed_host.rego")
235+
require.NoError(t, err)
236+
237+
r := &Rego{}
238+
policy := &engine.Policy{
239+
Name: "policy",
240+
Source: regoContent,
241+
}
242+
243+
_, err = r.Verify(context.TODO(), policy, []byte(`{}`), nil)
244+
assert.NoError(t, err)
245+
})
232246
}
233247

234248
func TestRego_WithPermissiveMode(t *testing.T) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import rego.v1
4+
5+
violations contains msg if {
6+
kev := http.send({"method": "GET", "url": "https://www.chainloop.dev", "cache": true}).body
7+
8+
msg := ""
9+
}

0 commit comments

Comments
 (0)