Questions tagged [rego]

Rego is a Query Language. To make a policy decision in Rego, you write logical tests on the data that comes in as input (such as the API or SSH data from the last section)

161 questions
0
votes
1 answer

Is there any way to store values in OPA

I have a usecase to do like, if a variable is already defined then return that value else invoke a rest endpoint to get the variable. get_value = value { data.value value }else = value { value := <> #invoke rest } I will be running OPA as…
Rithu
  • 79
  • 1
  • 6
0
votes
2 answers

Is there any way to validate if input is passed in REGO language?

In REGO language how can we validate if an input exists? I got one way to do this. package play default hello = false hello { input.message } But is this the right approach? Or is there a better way?
0
votes
1 answer

Why we are unable to evaluate comprehension if we have defined it inside a rule body in OPA?

The following is my sample code: https://play.openpolicyagent.org/p/oyY1GOsYaf Here when I try to evaluate names array, it is showing: error occurred: 1:1: rego_unsafe_var_error: var names is unsafe But when I define the same comprehension outside…
Rithu
  • 79
  • 1
  • 6
0
votes
1 answer

REGO how to get object (map) keys that match a pattern

Working with Rego, the Open Policy Agent (OPA) "rules" language, and given the following data: { "x-foo": "a", "x-bar": "b", "y-foo": "c", "y-bar": "d" } what is the correct Rego expression(s) or statement(s) to get just the keys…
0
votes
1 answer

rego opa policy to check if resources are provided for deployment in kubernetes

I'm checking if key resources.limits is provided in deployment kubernetes using OPA rego code. Below is the code, I'm trying to fetch the resources.limits key and it is always returning TRUE. Regardless of resources provided or not. package…
3br10ee032
  • 103
  • 2
  • 11
0
votes
2 answers

How to create OPA rego policy for a whitelist?

I am trying to implement a whitelist policy in OPA rego. The purpose of the policy is to block all attributes except for attributes that have been whitelisted. However, I cannot get it to work. Here is my rego policy: package…
Wayne
  • 1
  • 1
0
votes
1 answer

Testing k8s ConfigMap with nested dbless config for Kong

I've found really problematic to test Kong's config which is nested in such ConfigMap (it is a short version of this ConfigMap): apiVersion: v1 kind: ConfigMap metadata: name: "some_name" data: kong_config.yml: | _format_version: "2.1" …
0
votes
1 answer

OPA Rego issues counting

I am trying to write a rule but am running into an issue. I managed to extract the following from as my input: myData:= [{"Key": "use", "Value": "1"}, {"Key": "use", "Value": "2"}, {"Key": "att1", "Value": "3"}] I am trying to count the amount of…
SomeDutchGuy
  • 2,249
  • 4
  • 16
  • 42
0
votes
1 answer

Safely Evaluating Input of Multiple Types - OPA Gatekeeper/Rego

I'm trying to deploy a Constraint Template to my Kubernetes cluster for enforcing PodDisriptionBudgets contain a maxUnavailable percentage higher than a given percentage, and denying integer values. However, I'm unsure how to safely evaluate…
MattyKuzyk
  • 81
  • 2
  • 4
0
votes
1 answer

How to use simple hello world example on opa server

I have defined a file with name - play.rego package play default hello = false hello { m := input.message m == "world" } I also have file called -input.json { "message": "world"} I now want to use the policy to evaluate on input data using…
0
votes
1 answer

Rego: Given a list of regex and a list of strings create a set of all strings that don't match any of the regex

I have a list of strings and I want to remove each string from the list that matches any of the regex patterns from another list. I have solved it this way, however, I know there is a better way to do so. For example: Regex_list := ["^reg\ex1",…
SteelerKid
  • 304
  • 1
  • 4
  • 15
0
votes
2 answers

sprintf in opa rego policy

I have sprintf in one of the rule, but does not seem to be working. This is very basic but can someone tell me what am I doing wrong? Both online on https://play.openpolicyagent.org/ as well offline with opa version 0.32.0 does not seem to be…
Satish Burnwal
  • 487
  • 1
  • 4
  • 11
0
votes
1 answer

Transform { key: [values] } to {value: [keys]} in rego

Please help me write a rule on rego that returns a transformed object. My object: { "read": [ "server1", "server2" ], "write": [ "server2", "server3" ], "create": [ "server1", "server2", "server3" …
Sergey Bulavkin
  • 2,325
  • 2
  • 17
  • 26
0
votes
1 answer

Rego - assign array to existing array

I'm getting a weird behavior in Rego and I wonder why does it happen. Link to Rego Playground When I create an empty array, and than assign to it new array, the count of the first array is still zero: package play x[{"msg": msg}]{ c := [] a…
0
votes
1 answer

How to check if given string is contained in tags

Say I have the following test input, I would like to be able to write a test that checks if the string Application is contained in any of the tag keys. The idea being that this check would be able to match tags with different naming conventions…
jmreicha
  • 3,155
  • 7
  • 32
  • 39