Edit Policies and Open Merge Requests

Edit a policy of a GitLab-backed Policy Set in Nirmata Control Hub, run its Kyverno tests, open a merge request, follow it on the Changes tab until it is deployed, and delete a policy through a merge request.

You can change the policies of a Git Policy Set from Nirmata Control Hub (NCH) without leaving the UI. NCH never writes to your clusters directly: every change becomes a GitLab merge request, and your clusters get the new version only after the merge request is merged and the Kyverno operator syncs the new commit.

Before you begin

  • The Policy Set is on GitLab (gitlab.com or self-hosted) and has the repository type Policies. See Limits.
  • The Git Access state of the Policy Set is Connected. See Git Access and Policy History.
  • The Git provider account that NCH uses for the repository has the Developer role on the GitLab project and a token with the api scope. NCH makes the commits and opens the merge requests as this account. See Add a Git provider account.
  • You may change the Policy Set: admin and platform users can change any Policy Set, and devops users can change the team Policy Sets their team owns.

How a change reaches your clusters

StepWhereWhat happens
1. EditPolicy details drawer, Edit YAMLYou edit the policy and its Kyverno tests. NCH validates the YAML against the policy schema while you type.
2. DraftSave DraftNCH stores the policy file and its test files as a change in NCH. Nothing is written to Git.
3. TestRun TestsNCH runs the policy’s Kyverno tests.
4. Merge requestOpen Merge Request…NCH commits the files to a new branch and opens a merge request with the reviewers you picked.
5. ReviewGitLabReviewers review and approve in GitLab. NCH shows reviewers and approvals on the Changes tab.
6. MergedGitLabThe change shows Merged, and its deployment shows Waiting for sync.
7. DeployedKyverno operatorWhen the operator reports a commit that contains the merge, the change shows Deployed <sha>. Until then, your clusters keep the old version.

Edit a policy

  1. Go to Policies > Policy Sets and open the Policy Set.
  2. On the Deployed Policies tab, click ⋮ > Edit YAML in the policy’s row. You can also open the policy and click Edit YAML in the drawer.
  3. Edit the YAML. Below the editor, the Validation section shows the result of the schema check, for example “Schema valid · ClusterPolicy”. Click Validate Now to check again.

Edit mode with Current violations, the YAML editor, and validation

If Edit YAML is disabled, the reason is shown under it. Common reasons:

Reason shownWhat to do
“Editing and merge requests are available for GitLab repositories only.”The repository is on github.com. Edit the policy in Git directly.
“NCH can read this repository but cannot open merge requests. Give the Git provider account the Developer role and the api scope.”Update the Git provider account, then click Check access.
“NCH cannot access this repository. Check the Git provider account.”Fix the Git provider account, then click Check access.
“This policy is not in the Git repository, so there is no file to edit.”The policy runs on a cluster but isn’t in the repository.
“You do not have permission to edit this Policy Set.”Ask a user who may change the Policy Set.

If the file holds several YAML documents, NCH edits only the policy’s own document. A note above the editor says “Editing document N of M in <file>. The other documents of the file are saved unchanged.”

Check the current violations

Above the editor, Current violations shows what your clusters report for this policy today: the totals as N fail, N warn, and N error tags, “across X of Y clusters”, and one line per cluster. Click View Results to open the Results tab of the policy.

These numbers are for the deployed version of the policy. They change only after your merge request is merged and the operator syncs it. NCH matches results by policy name, so policies with the same name, for example in different namespaces, are counted together.

Edit and run tests

The Tests section below the editor holds the Kyverno test files of the policy. They live in a fixed folder next to the policy file:

<policy folder>/.kyverno-test/<policy file name without .yaml or .yml>/

For example, the tests of policies/require-labels.yaml are in policies/.kyverno-test/require-labels/.

Tests section with test files and run results

In the Tests section you can:

  • Edit a test file in its own tab.
  • Click Add File to add a test file inside the test folder. The name must end in .yaml or .yml.
  • Click Generate Missing Tests to have NCH generate tests for the policy. If a generated file would replace one of yours, choose Overwrite my files or Keep my files.
  • Click Run Tests to run the policy and all test files. The result shows a summary, such as “2 passed, 1 failed, 0 skipped of 3 tests”, and one row per test case. The result is marked Out of date as soon as you change the policy or a test file.

The policy file and its test files are committed together, in one merge request.

Save a draft

Click Save Draft to store your edits in NCH without writing to Git. An edit session keeps one draft: every later save, and opening the merge request, update the same draft. You can resume a draft from the Changes tab.

Open a merge request

  1. Click Open Merge Request…. The button is enabled when your edits pass the schema check.
  2. In the Open merge request dialog, fill in:
    • Title: required, at most 255 characters. It starts as “Update <policy>”.
    • Description: optional.
    • Reviewers: search the members of the GitLab project by name and pick up to 10. On GitLab Free you can pick one: “Only one reviewer can be assigned (GitLab Free).”
  3. Click Open Merge Request.

Open merge request dialog

NCH commits the policy file and its test files with the Git provider account of the Policy Set, on a new branch named nirmata/policyset/<set>/<change-id>, and opens a merge request against the branch of the Policy Set. When it’s open, click Open MR <number> in GitLab to review it there.

When tests haven’t passed

Schema errors always block the merge request. Tests block it too, unless someone overrides them. If no test run passed on exactly the current policy and test files, for example because the policy has no tests, the tests weren’t run, or a test failed, the dialog says why and asks for a Reason for opening it anyway. The button then reads Open Merge Request Anyway.

The role check for overrides allows admin, platform, and security users, but security users cannot edit Policy Sets, so in practice only admin and platform users can override failing or missing tests. NCH records the override in the merge request description as Validation override by <user>: <reason>, so reviewers see it. Devops users see “Only admins, platform or security users can override failing or missing tests. Fix the tests or ask one of them to publish.” and can open the merge request once the tests pass. The message names security users because of the role check; ask an admin or platform user.

Follow changes on the Changes tab

The Changes tab of the Policy Set lists the changes made in NCH (drafts, merge requests, merged and closed changes) and the merge requests opened directly in GitLab that touch the Policy Set’s folder. The tab refreshes itself while a merge request is open or waiting for the operator.

Changes tab

Use the Open, All, Merged, and Closed filters, or search with “Search title, file or author”. The table has the columns Change, Policy file, State, Validation, Merge request, Reviewers, Deployment, Author, Created, Updated, and Actions.

StateMeaning
DraftSaved in NCH, not validated or not passed.
ValidatedValidation passed. Not yet published.
Publishing…NCH is committing and opening the merge request.
MR openThe merge request is open. Review, merge, and close it in GitLab.
MergedThe merge request was merged.
ClosedThe merge request was closed without merging.
FailedThe last attempt failed. The error is shown under the tag.

For a merged change, the Deployment column shows:

  • Waiting for sync: merged, and the operator hasn’t synced the merge commit yet.
  • Deployed <sha>: the operator synced a commit that contains the merge. The SHA links to the commit in GitLab.
  • Deployment not tracked: no sync was seen within 24 hours of the merge, or the change was merged before NCH tracked deployments.

The Reviewers column shows the reviewers GitLab assigned and “Approved by N”. The Validation column shows the schema and test results and an Overridden tag when tests were overridden.

For Draft, Validated, and Failed changes, the Actions column offers Resume (open the draft in the editor), Open merge request, and Discard.

Merge requests opened outside NCH

Merge requests that someone opened directly in GitLab, from any branch, appear with an Opened outside NCH tag. They are read-only in NCH: click View diff to see the changed files. NCH doesn’t validate them or track their deployment.

Delete a policy

You delete a policy through a merge request, too.

  1. On the Deployed Policies tab, click ⋮ > Delete… in the policy’s row, or click Delete… in the policy drawer.
  2. Review what the merge request will remove. If the file holds only this policy, NCH removes the file and its test folder. If the file holds several policies, NCH removes only this policy’s document.
  3. Enter a Title (it starts as “Remove <kind>/<name>”), a Reason (required; it becomes the merge request description), and optionally Reviewers.
  4. Click Open merge request to delete.

Your clusters keep enforcing the policy until the merge request is merged and the operator syncs. The delete request appears on the Changes tab with a red Delete tag. You can open only one delete request per policy at a time: Delete… stays disabled until the open one is merged, closed, or discarded.

Limits

  • GitLab only. You can’t edit, open merge requests for, or see the Changes tab of github.com, Helm, Kustomize, or HelmChart Policy Sets.
  • No new policies. The editor changes one existing policy file (or one document of it) and its test files. To add a policy, add its file to the repository in Git.
  • Read-only after publishing. A change with an open merge request is read-only in NCH. Review, merge, and close it in GitLab.
  • Tests. A change holds at most 20 test files, 2 MiB of test content in total, and 1 MiB per file. The test runner has no network access, so policies that call a service or registry (for example apiCall.service, imageRegistry, or verifyImages) can’t be tested.
  • Reviewers. At most 10 reviewers. GitLab Free assigns one.
  • Outside merge requests. NCH lists merge requests opened outside NCH from the latest 100 updated merge requests of the project, so older ones may be missing.
  • Deployment tracking. NCH waits for the operator sync for 24 hours after the merge.
  • Current violations describe the deployed policy, not your edit, and are matched by policy name.