policy: allow array.flatten and template strings

Enable new builtins from OPA v1.14. The template_strings parser
feature was already active via ast.Features, but evaluating the
$"..." syntax also requires the internal.template_string builtin
to be present in the capabilities allowlist.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2026-07-06 16:53:49 -07:00
parent c74f522b8e
commit 03479f1a96
2 changed files with 33 additions and 0 deletions
+4
View File
@@ -55,6 +55,7 @@ func builtins() []*ast.Builtin {
// Arrays
ast.ArrayConcat,
ast.ArrayFlatten,
ast.ArraySlice,
ast.ArrayReverse,
@@ -196,6 +197,9 @@ func builtins() []*ast.Builtin {
// Printing
ast.Print,
ast.InternalPrint,
// Internal implementation for template strings.
ast.InternalTemplateString,
}
return b
}
+29
View File
@@ -917,6 +917,35 @@ decision := {
}, caps)
}
func TestPolicyOPA114Builtins(t *testing.T) {
p := NewPolicy(Opt{
Files: []File{{
Filename: "policy.rego",
Data: []byte(`
package docker
segments := array.flatten([["exec"], ["proxy"]])
decision := {
"allow": true,
"caps": {
"exec.proxy": true,
},
} if {
msg := $"execute {segments[0]}.{segments[1]}"
msg == "execute exec.proxy"
}
`),
}},
})
caps, err := p.CheckCaps(context.Background())
require.NoError(t, err)
require.Equal(t, Caps{
CapExecProxy: true,
}, caps)
}
func TestCheckCapsMalformedCaps(t *testing.T) {
p := NewPolicy(Opt{
Files: []File{{