Giter Site home page Giter Site logo

Comments (7)

jpreese avatar jpreese commented on August 17, 2024

This sounds reasonable to me. Let myself or @jalseth know if you need any help working on this if you decide to pick it up 👍

from konstraint.

Pierre-Mike avatar Pierre-Mike commented on August 17, 2024

very good tool and thanks a lot for it
I'm having the same issue here
with,

  excludedNamespaces:
      - gatekeeper-system
      - kube-system
      - istio-system

it overwrites all the file, I may be able to solve the problem by using Kustomize, but this feature will help me as well
I will stay updated

Update :

for now I'm using Kustomize

to over-overwrite the contraint.yaml

bases:
  - template.yaml
  - constraint.yaml
patches:
  - overwrite-exclude-namespace.yaml

from konstraint.

jalseth avatar jalseth commented on August 17, 2024

We now (as of a few minutes ago) support generating the OpenAPIV3Schema validation using the @parameter tag in the header comment block, so that is the preferred way forward for that item.

@Pierre-Mike Typically, when people want to exclude the *-system namespaces, they want to apply that for all of their policies, and not just one. In that case, it would be best to use the Config CRD for Gatekeeper (https://github.com/open-policy-agent/gatekeeper/#exempting-namespaces-from-gatekeeper) which will apply globally within the cluster. Does that work for your use case or are you trying to add these exemptions for individual policies?

from konstraint.

rawc0der avatar rawc0der commented on August 17, 2024

Hi @jalseth,
Can you please give an example of how to include the schema spec using @parameter annotation?
Currently in order to generate validation.openAPIV3Schema field for the constraint templates, I'm using scripting utilities like yq/jq to decorate the final resources (Schemas for a policy is extracted from external source).

Is it possible to allow passing a json string as a @schema annotation and merge the structural schema in the generated resource?

Example ./mypolicy.rego

# @title mypolicy 
#
# @kinds apps/DaemonSet apps/Deployment apps/StatefulSet core/Pod
# @parameter apiVersion string
# @parameter kind string
# @parameter metadata object
# @parameter spec object
$ @schema '{ \"properties\": {\"apiVersion\": {\"description\": \"...\",\"type\": \"string\"},\"kind\": {\"description\": \"...\",\"type\": \"string\"},\"metadata\": {\"type\": \"object\",\"properties\": {  \"labels\": { \"type\": \"object\" }}},\"spec\": {\"type\": \"object\",\"properties\": \"....\"} }}'
package mypolicy 

....

Generated ./template_Mypolicy.yaml

apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
  name: mypolicy
spec:
  crd:
    spec:
      names:
        kind: Mypolicy
      validation:
        openAPIV3Schema:
            properties:
                apiVersion:
                    description: "..."
                    type: string
                kind:
                    description: "..."
                    type: string
                metadata:
                    type: object
                    properties:
                        labels:
                            type: object
                spec:
                    type: object
                    properties:
                        ....

  targets:
    - libs:  ...

Any thoughts?

from konstraint.

rawc0der avatar rawc0der commented on August 17, 2024

Actually I just saw how the function getOpenAPISchemaProperties to extract parameters data types from the comment header..

from konstraint.

jalseth avatar jalseth commented on August 17, 2024

@rawc0der the documentation on using the @parameter tag is here https://github.com/plexsystems/konstraint/blob/main/docs/constraint_creation.md#using-input-parameters

from konstraint.

jalseth avatar jalseth commented on August 17, 2024

Now that Konstraint supports parameters and @skip-constraint, this issue has been addressed. If you want namespace targeting, exceptions, etc. for your policy to apply globally, you can include them in the Rego. Otherwise, it is expected that the Constraint resources are managed outside of Konstraint's flows.

from konstraint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.