GitOps Integration with nctl

Deploy approved policy exceptions through GitOps by opening pull requests with nctl

NOTE: Nirmata Control Hub can open the pull requests or merge requests for approved exceptions automatically, without nctl. See Git Integration (Automatic PRs/MRs).

Policy exceptions can be managed and deployed using GitOps, similar to any other resource. Follow Nirmata Control Hub’s request and approval workflow for creating and approving exceptions. After approval, your team uses nctl to open a pull request that adds the exception to the GitOps repository, and your GitOps tool deploys it after the pull request is merged.

Managing Deployment Settings

An admin user can manage the deployment settings for Policy Exception Requests.

  1. Go to Settings -> Policy Exceptions and click on the Deployment tab. The Settings page for Policy Exceptions deployment opens with Automatic deployment set as the default.
  2. Click on the radio button beside GitOps deployment.
  3. Enter the Git repository URL under Git repository for policy exceptions to provide a path for mapping the available clusters to a repository branch.
  4. Optionally, enter a folder under Folder for policy exception files. The path is relative to the repository root, for example policy-exceptions, and must exist on each mapped branch. The path must not contain spaces or . or .. segments. Leave it empty to write exception files to the repository root.
  5. Map the clusters that are onboarded in Nirmata Control Hub to a branch in the Git repository. To do so: a. Under Cluster Expression to Branch Mappings, select cluster.label or cluster.name from the dropdown.
    b. If cluster.label is selected, choose the label from the dropdown.
    c. Select the operator type from the dropdown. The available options are in, exists, and contains.
    d. Select the operator value from the dropdown or enter it manually, then enter the repository branch name.
    e. If cluster.name is selected, choose the operator type from the dropdown. The available options are in and contains.
    f. Select the operator value from the dropdown or enter it manually, then enter the repository branch name.
    g. Click the + button to add more cluster mappings.

image

  1. Finally, click Save.

The other fields on this page (Create PRs/MRs automatically, Git account, Reviewers, and the repository exception settings) are described in Git Integration (Automatic PRs/MRs). Leave Create PRs/MRs automatically off to open pull requests with nctl.

GitOps Deployment of Policy Exceptions in Action

nctl is required for creating Pull Requests for Policy Exception Requests. Learn more about installing nctl and its commands in the official documentation.

To deploy Policy Exceptions through GitOps:

  1. Create a Policy Exception Request by following the steps here.
  2. After the request is approved, a Create Deploy PR message will appear under the Deploy Status section in Nirmata Control Hub.
  3. In your local terminal, verify the created Policy Exception Request by executing:
nctl get policyexceptionrequest

NOTE: Login using the nctl login nch command to fetch policy exception requests from Nirmata Control Hub.

  1. Now, create a pull request to deploy the Policy Exception by executing the following command. It creates PRs for all Policy Exception Requests that are in Approved state.
nctl create pull-request

To create a PR for a given Policy Exception Request, use the --per-name argument. See nctl create pull-request for all options.

nctl create pull-request --per-name <per-name>

NOTE: NCTL needs a Git Personal Access Token (PAT) to be able to create pull requests on behalf of the user. Use the nctl login git command to set the Git login credentials, for example nctl login git --provider gitlab --domain gitlab.example.com.

NOTE: The Git PAT should have write access to the repository. NCTL creates a temporary branch to commit the PolicyException YAML to the folder set in Folder for policy exception files and then creates a PR to the relevant branch mapped in Nirmata Control Hub.

NOTE: If Create PRs/MRs automatically is turned on, nctl create pull-request prints a message that Nirmata Control Hub opens the pull/merge requests for the tenant and exits without creating a PR.

  1. Once the PR is created, a team member can review and merge it into the repository. The Policy Exception will be deployed to the cluster according to your GitOps/pipeline workflow settings.
  2. Verify the deployment by checking the Policy Exceptions in Nirmata Control Hub - you should see a Merge Deploy PR message with a link to the PR under the Deploy Status section while the PR is open.
  3. When revoking a deployed Policy Exception, after revoking it from Nirmata Control Hub, create a PR using the same process to remove the PolicyException from the cluster.