我正在尝试在 OPA rego 中实施白名单策略。该策略的目的是阻止除已列入白名单的属性之外的所有属性。但是,我无法让它工作。
这是我的 rego 政策:
package play
whitelisted_attributes =
{
"foo.bar",
"hello.from.*.world"
}
default allow = false
default not_in_whitelist = true
not_in_whitelist {
whitelisted := {attr | attr := input.attributes[_]; glob.match(whitelisted_attributes[_], ["."], attr)}
count(whitelisted) == 0
}
allow {
not not_in_whitelist
}
这是我的输入:
{
"attributes": [
"foo.bar"
]
}
这是根据 Rego Playground 的输出:
{
"allow": false,
"not_in_whitelist": true,
"whitelisted_attributes": [
"foo.bar",
"hello.from.*.world"
]
}
如您所见,“允许”应该为真,因为在白名单中找到了输入。此外,“not_in_whitelist”应该为假,因为输入属性在白名单中。