Cloud 开放策略代理-错误与无
试图理解OPA中虚假的概念。我的情况就是这样——我需要验证所有云资源是否都在AWS允许的区域内。我现在得到的是:Cloud 开放策略代理-错误与无,cloud,open-policy-agent,rego,Cloud,Open Policy Agent,Rego,试图理解OPA中虚假的概念。我的情况就是这样——我需要验证所有云资源是否都在AWS允许的区域内。我现在得到的是: allowed_locations := ["eastus", "westus"] exists(array, value) { array[_] == value } all_resources_in_allowed_regions { not any_resource_not_in_allowed_regions }
allowed_locations := ["eastus", "westus"]
exists(array, value) {
array[_] == value
}
all_resources_in_allowed_regions {
not any_resource_not_in_allowed_regions
}
any_resource_not_in_allowed_regions {
some index
exists(allowed_locations, input.planned_values.root_module.resources[index].values.location) != true
}
问题是,我认为我遗漏了一些关于策略/函数结果的错误信息——例如,存在的结果(允许的位置,“西欧”)
不是错误的,而是某种类型的“未定义”,这意味着存在的结果(允许的位置,“西欧”)!=true
也是“未定义的”,这意味着允许的\u区域中的所有\u资源\u都被分配而不是“未定义的”
这是true
您将如何使用OPA解决此问题?我是否遗漏了正确使用它的方法?查看文档中的“全部”部分:
更多关于正在发生的事情的解释:
快速示例:
根据您的回复,更新后的策略如下所述:
allowed_locations := ["eastus", "westus"]
exists(array, value) {
array[_] == value
}
not_exists(array, value) {
not exists(array, value)
}
all_resources_in_region {
not any_resource_not_in_region
}
any_resource_not_in_region {
not_exists(allowed_locations, input.planned_values.root_module.resource[_].values.location)
}
操场示例:我找到了一些解决方案:定义一个
not\u exists
函数,它只是not exists(数组,值)
,然后配置一个any\u resource\u not\u in\u region{not\u exists(allowed\u locations,resource[\uu].region)}/code>的策略,然后在\u region{not any\u resource\u not u\u in\u region}u这个答案似乎很好,请考虑接受。