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

Make CRDs optional #443

Open
JimBugwadia opened this issue Jun 29, 2023 · 0 comments
Open

Make CRDs optional #443

JimBugwadia opened this issue Jun 29, 2023 · 0 comments

Comments

@JimBugwadia
Copy link
Member

The CLI does not require CRDs:

Here is a resource that represents a TF plan:

apiVersion: nirmata.io/terraform
kind: Plan
metadata:
  annotations:
  labels:
    run: pod
  name: aws-instance
spec:
  outputs:
    private_ip:
      value: 192.168.3.2
      type: string
      sensitive: false
  root_module:
    resources:
    - address: aws_instance.example[1]
      mode: managed
      type: aws_instance
      name: example
      index: 1
      provider_name: aws
      schema_version: 2
      values:
        id: i-abc123
        instance_type: t2.micro
      sensitive_values:
        id: true
    child_modules:
    - address: module.child
      resources:
      - address: module.child.aws_instance.foo
      child_modules: []

Here is a policy that validates the Plan:

apiVersion: kyverno.io/v1
kind: Policy
metadata:
  name: validate-instance
spec:
  validationFailureAction: audit
  rules:
  - name: check-instance-type
    match:
      any:
      - resources:
          kinds:
          - nirmata.io/terraform/Plan
    context:
    - name: instanceTypes
      variable:
        jmesPath: "request.object.spec.root_module.resources[].values[].instance_type"
    validate:
      message: "invalid instance type"
      deny:
        conditions:
          all:
          - key: "{{ instanceTypes }}"
            operator: AllNotIn
            value: ["m5.large", "m4.large	"]
            message: "{{instanceTypes}} not allowed"

The CLI processes as follows:

./cmd/cli/kubectl-kyverno/kubectl-kyverno apply  /tmp/policy.yaml -r /tmp/resource.yaml

Applying 1 policy rule to 1 resource...

policy validate-instance -> resource default/Plan/aws-instance failed:
1. check-instance-type: invalid instance type; ["t2.micro"] not allowed

pass: 0, fail: 2, warn: 0, error: 0, skip: 0

However, on the Playground I get this error:

ServerError: failed to locate OpenAPI spec for GV: nirmata.io/terraform

Here is a link:

https://playground.kyverno.io/#/?content=N4IgDg9gNglgx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QBIh2NsdAAiOBzHwyr3qdM5wF4xj4DdwlxG9ICKWYYCBK9qAgFaQA===

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

No branches or pull requests

1 participant