Skip to content
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

Enable Gatekeeper Rego Packages to be Imported From Outside of Template #3558

Open
bravurasteve opened this issue Sep 23, 2024 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@bravurasteve
Copy link

bravurasteve commented Sep 23, 2024

Describe the solution you'd like
Similar to how templates can import a library package defined within the template, allow the template to import a rego package defined outside the template.

e.g. common.rego:

package k8scommonaccess

in_approved_group {
   input.review.userInfo.groups[_] == input.parameters.approved_groups[_}
}

Anything else you would like to add:
As more and more templates are created, having to copy/paste the same common rego functions over and over becomes a maintenance nightmare; when/if the common function needs to be modified, having to make the changes in a single rego package file is highly desired over having to make it in multiple template files.

Environment:

  • Gatekeeper version: v3.17.1
  • Kubernetes version: v1.28:
@bravurasteve bravurasteve added the enhancement New feature or request label Sep 23, 2024
@maxsmythe
Copy link
Contributor

I'd suggest creating a pipeline that bakes the shared code into templates, similar to static linking when building a binary. That way shared code does not become a human maintenance burden. Using the libs keyword you cite should make this a fairly trivial pipeline to build.

See the below comment for why dynamically linking code from outside the template at runtime is operationally fraught:

#1204 (comment)

@bravurasteve
Copy link
Author

The problem w/ the pipeline approach is the dependency upon a pipeline which means no way to run/test via command line. Also, I wouldn't characterize the concept of reusable libraries as being dynamically linked since many other languages support the concept and statically link; e.g. Golang, Rust, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants