-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a builtin function to render JSON templates #6371
Comments
Hi @RDVasavada 👋 I'd be curious to learn more about your use case! Is this for infrastructure policy, authorization, or something else? I'd also be curious to know why you'd need to parse JSON and insert variables. Can you not simply use the input JSON directly in your policy? That way you'll have access to loops, and whatever else you'd get from templating. The decision can of course be any valid JSON, so it feels like OPA and Rego would do well for this purpose, but perhaps there's something I'm not getting :) Some example policy with inputs/outputs might help shed some light here.
Now you've piqued my curiosity! 😃 You'd use OPA for templating but not as a decision engine? What would you use for that instead? |
Hey @anderseknert! Happy to provide more context as to my specific use case. Our OPA policies are used for infrastructure policy. Our policy bundle runs a number of decisioning checks against infrastructure configurations, one of them being IAM policies. For IAM policies, in certain cases we would be receiving templated JSON as an input, along with template variables. After injecting template variables, we would like to run a number of policy checks on our own side (e.g. character count, JSON format validation) as well as send the rendered JSON to a decoupled decision engine which accepts static IAM policies and runs additional validations. So the need for template handling comes from the fact that the templated JSON itself is the input for our policies. |
…ings Fixes open-policy-agent#6371 Signed-off-by: Rohan Vasavada <[email protected]>
…ings Fixes open-policy-agent#6371 Signed-off-by: Rohan Vasavada <[email protected]>
…ings Fixes open-policy-agent#6371 Signed-off-by: Rohan Vasavada <[email protected]>
… render templated strings This adds support for rendering of templated strings utilizing Golang's text/template library. For a given templated string and key/value mapping of template var inputs, this builtin will inject the values into the template where they are referenced by key. Fixes open-policy-agent#6371 Signed-off-by: Rohan Vasavada <[email protected]>
… render templated strings This adds support for rendering of templated strings utilizing Golang's text/template library. For a given templated string and key/value mapping of template var inputs, this builtin will inject the values into the template where they are referenced by key. Fixes open-policy-agent#6371 Signed-off-by: Rohan Vasavada <[email protected]>
… render templated strings This adds support for rendering of templated strings utilizing Golang's text/template library. For a given templated string and key/value mapping of template var inputs, this builtin will inject the values into the template where they are referenced by key. Fixes open-policy-agent#6371 Signed-off-by: Rohan Vasavada <[email protected]>
… render templated strings This adds support for rendering of templated strings utilizing Golang's text/template library. For a given templated string and key/value mapping of template var inputs, this builtin will inject the values into the template where they are referenced by key. Fixes open-policy-agent#6371 Signed-off-by: Rohan Vasavada <[email protected]>
… render templated strings This adds support for rendering of templated strings utilizing Golang's text/template library. For a given templated string and key/value mapping of template var inputs, this builtin will inject the values into the template where they are referenced by key. Fixes #6371 Signed-off-by: Rohan Vasavada <[email protected]>
… render templated strings This adds support for rendering of templated strings utilizing Golang's text/template library. For a given templated string and key/value mapping of template var inputs, this builtin will inject the values into the template where they are referenced by key. Fixes open-policy-agent#6371 Signed-off-by: Rohan Vasavada <[email protected]> Signed-off-by: Colin Lacy <[email protected]>
… render templated strings This adds support for rendering of templated strings utilizing Golang's text/template library. For a given templated string and key/value mapping of template var inputs, this builtin will inject the values into the template where they are referenced by key. Fixes open-policy-agent#6371 Signed-off-by: Rohan Vasavada <[email protected]>
What is the underlying problem you're trying to solve?
I have encountered a number of use cases that involve running policies against templated JSON. Some examples are:
For example, here's a scenario of what templating might look like:
Describe the ideal solution
Ideally, there could be a builtin function which takes in a templated JSON string representation and a mapping of template input variables, and returns the rendered JSON with the template variables injected. This can be done using the text/template standard library native to Go, which supports common templating syntax.
Describe a "Good Enough" solution
The current solution is to manually implement logic in rego to parse JSON and insert template variables. However, this becomes very complex when trying to extend to more advanced templating syntax, such as looping through multiple values.
Additional Context
I'd be happy to work on this issue if it's approved!
The text was updated successfully, but these errors were encountered: