-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] INS-1659: [docs] update kyverno plugin documentation #513
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
Open
jdesouza
wants to merge
6
commits into
main
Choose a base branch
from
js/kyverno
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,6 +225,181 @@ tracked in your Infrastructure-as-Code (IaC) repository. | |
| You can add the `--delete` flag to the `push policy-mappings` command, which | ||
| will delete any Policy Mappings from Insights that **do not exist** in your IaC repository. Adding the `--dry-run` flag will explain which Policy Mappings would be deleted without making changes to Insights. | ||
|
|
||
| ### Kyverno Policies | ||
|
|
||
| You can use the Insights CLI to manage Kyverno policies as code. | ||
|
|
||
| Check out the [Kyverno Policies](/features/kyverno-policies) documentation for more information about managing Kyverno policies in Insights. | ||
|
|
||
| #### Pushing Kyverno Policies | ||
|
|
||
| When pushing Kyverno policies to Insights, the CLI expects a directory structure like the following: | ||
|
|
||
| ``` | ||
| . | ||
| +-- kyverno-policies | ||
| || +-- require-resource-limits.yaml | ||
| || +-- require-resource-limits.success.yaml | ||
| || +-- require-resource-limits.failure.yaml | ||
| || +-- disallow-privileged.yaml | ||
| ``` | ||
|
|
||
| Each file should contain a complete Kyverno policy. The policy name in the file's `metadata.name` will be used as the policy name in Insights. | ||
|
|
||
| **Example policy file** (`kyverno-policies/require-resource-limits.yaml`): | ||
|
|
||
| ```yaml | ||
| apiVersion: kyverno.io/v1 | ||
| kind: ClusterPolicy | ||
| metadata: | ||
| name: require-resource-limits | ||
| annotations: | ||
| policies.kyverno.io/title: Require Resource Limits | ||
| policies.kyverno.io/category: Efficiency | ||
| policies.kyverno.io/severity: medium | ||
| policies.kyverno.io/description: All Pods must have resource limits set | ||
| spec: | ||
| validationFailureAction: Enforce | ||
| rules: | ||
| - name: check-resource-limits | ||
| match: | ||
| any: | ||
| - resources: | ||
| kinds: [Pod] | ||
| validate: | ||
| message: "Resource limits are required" | ||
| pattern: | ||
| spec: | ||
| containers: | ||
| - resources: | ||
| limits: | ||
| memory: "?*" | ||
| cpu: "?*" | ||
| ``` | ||
|
|
||
| **Basic push command:** | ||
|
|
||
| ```bash | ||
| insights-cli push kyverno-policies | ||
| ``` | ||
|
|
||
| **Push options:** | ||
|
|
||
| ```bash | ||
| # Push from a custom subdirectory | ||
| insights-cli push kyverno-policies -s custom-policies | ||
|
|
||
| # Push specific policies only | ||
| insights-cli push kyverno-policies -p require-labels,disallow-privileged | ||
|
|
||
| # Dry run to see what would be changed | ||
| insights-cli push kyverno-policies --dry-run | ||
|
|
||
| # Skip validation (not recommended) | ||
| insights-cli push kyverno-policies --skip-validation | ||
|
|
||
| # Force push even if validation fails (use with extreme caution) | ||
| insights-cli push kyverno-policies --force | ||
|
|
||
| # Delete policies that don't exist locally | ||
| insights-cli push kyverno-policies --delete | ||
| ``` | ||
|
|
||
| #### Downloading Kyverno Policies | ||
|
|
||
| If you were managing Kyverno policies via the Fairwinds Insights UI, you can download and sync those definitions using: | ||
|
|
||
| ```bash | ||
| # Download all policies from Insights | ||
| insights-cli download kyverno-policies -d . | ||
|
|
||
| # Download to custom subdirectory | ||
| insights-cli download kyverno-policies -d . --download-subdirectory my-policies | ||
|
|
||
| # Download to specific directory | ||
| insights-cli download kyverno-policies -d /path/to/my/project | ||
|
|
||
| # Download with override (overwrite existing local files) | ||
| insights-cli download kyverno-policies -d . --override | ||
| ``` | ||
|
|
||
| Note that the folder `kyverno-policies` (or your custom subdirectory) will be created automatically if it doesn't exist. | ||
|
|
||
| #### Listing Kyverno Policies | ||
|
|
||
| You can list Kyverno policies from local files or Insights: | ||
|
|
||
| ```bash | ||
| # List all policies from Insights | ||
| insights-cli list kyverno-policies | ||
|
|
||
| # List local policy files | ||
| insights-cli list kyverno-policies --local | ||
|
|
||
| # List policies for specific cluster (with app groups applied) | ||
| insights-cli list kyverno-policies --cluster production | ||
|
|
||
| # Export cluster policies as YAML | ||
| insights-cli list kyverno-policies --cluster production --format yaml | ||
| ``` | ||
|
|
||
| #### Validating Kyverno Policies | ||
|
|
||
| The CLI can validate Kyverno policies before pushing them. You can validate a single policy or a directory of policies with test cases. | ||
|
|
||
| **Test case files:** | ||
| - `.success.yaml` - Resources that should pass validation | ||
| - `.failure.yaml` - Resources that should fail validation | ||
| - `.testcase*.yaml` - Named test cases with expected outcomes | ||
|
|
||
| **Validate a single policy:** | ||
|
|
||
| ```bash | ||
| insights-cli validate kyverno-policies -r policy.yaml -k test-resource.yaml | ||
| ``` | ||
|
|
||
| **Validate a directory of policies:** | ||
|
|
||
| ```bash | ||
| # Validate all policies in directory | ||
| insights-cli validate kyverno-policies -b ./kyverno-policies | ||
|
|
||
| # Validate specific policies | ||
| insights-cli validate kyverno-policies -b ./kyverno-policies -p require-labels,disallow-privileged | ||
| ``` | ||
|
|
||
| **Validate policies for a specific cluster:** | ||
|
|
||
| ```bash | ||
| insights-cli validate kyverno-policies --cluster production | ||
| ``` | ||
|
|
||
| This validates all policies that would be deployed to the cluster (with app groups applied). | ||
|
|
||
| #### Namespaced Policies | ||
|
|
||
| For namespaced policy kinds (`Policy`, `NamespacedValidatingPolicy`), ensure the `metadata.namespace` field is set in your policy file: | ||
|
|
||
| ```yaml | ||
| apiVersion: kyverno.io/v1 | ||
| kind: Policy | ||
| metadata: | ||
| name: namespace-specific-policy | ||
| namespace: production # Required for namespaced policies | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this interact with policymappings & appGroups?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just for the cli |
||
| spec: | ||
| # ... policy spec | ||
| ``` | ||
|
|
||
| #### Policy Validation Details | ||
|
|
||
| The CLI validates policies before pushing them to Insights: | ||
| - **Security validation**: Prevents dangerous configurations | ||
jdesouza marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - **Kyverno CLI validation**: Ensures policy syntax is correct | ||
| - **Conflict detection**: Prevents conflicts with existing cluster policies | ||
| - **Test case validation**: Validates policies against test resources with expected outcomes | ||
|
|
||
| If validation fails, you'll see specific error messages to help fix the issue. | ||
|
|
||
| ### Teams Management | ||
|
|
||
| Teams in **Fairwinds Insights** can be managed in two ways: | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit confusing to me, what does it mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improved