Team Policy Sets (Namespace-Scoped)

Let a team own a Policy Set that deploys only namespace-scoped policies into namespaces the team can access, from a GitLab source an admin approved.

A team Policy Set is a Policy Set that a team owns. It deploys only namespace-scoped policies, and only into namespaces the team can access. Devops users can create and manage the team Policy Sets their team owns, without platform help and without affecting other teams’ policies. The policies come from a GitLab repository under a source that an admin approved.

Policy Sets created before this feature, and Policy Sets created with Add Custom Policy Set, are cluster-scoped. The scope of a Policy Set can’t change after it is created.

Prerequisites

  • Enterprise Kyverno Operator 0.6.0 or later on every target cluster. NCH doesn’t deploy a team Policy Set to a cluster with an older operator. The operator enforces the same content rules as NCH and never overwrites a policy that another Policy Set deployed.
  • A Git provider account for the GitLab host of the repository. See Add a Git provider account. The account can be added even when the tenant uses Automatic deployment for policy exceptions; see Tenants that use Automatic deployment.
  • At least one allowed source configured by an admin. See Add allowed sources.
  • The devops user is a member of a team that has access to the target namespaces.

Add allowed sources (admin)

Admins and platform users decide which GitLab repositories team Policy Sets may use.

  1. Go to Settings > Policy Sets. The Settings - Policy Sets page lists the allowed Git sources for team (namespace-scoped) Policy Sets.
  2. Click Add source.
  3. In the Add allowed source dialog, enter:
    • Repository URL prefix: a host and group path, for example gitlab.example.com/payments. It matches whole path segments, so gitlab.example.com/payments matches gitlab.example.com/payments/policies but not gitlab.example.com/payments-old/policies.
    • Description: optional.
  4. Click Add.

To remove a source, click the delete icon in its row and confirm. Existing team Policy Sets keep working; new ones and edits must use another source.

While no source is configured, devops users see No allowed team sources on the add form and can’t create team Policy Sets.

Create a team Policy Set

  1. Go to Policies > Policy Sets.

  2. Click Add Team Policy Set. Devops users see this button. Admin and platform users find Add Team Policy Set in the Add Policy Set menu.

  3. Fill in the form:

    FieldDescription
    NameLowercase letters, numbers, and dashes.
    DescriptionOptional.
    Owning teamThe team that owns the Policy Set. Devops users can pick only their own teams.
    Repository URLThe GitLab repository. It must be under an allowed source. The allowed sources are listed under the field.
    Git provider accountThe account NCH uses to read the repository. If several accounts use the host, choose the one that can read the repository.
    BranchThe branch to deploy from.
    DirectoryThe folder that holds the policies. It must start with /.
    Credentials secretnamespace/secret/key of the Kubernetes secret that holds the Git token the operator uses. Leave it blank for a public repository.
    TargetsOne or more clusters, each with one or more namespaces. Only namespaces you can access are listed. Each policy must set one of these namespaces.
    SyncHow often the operator syncs the repository: every 5 minutes, every 15 minutes, or every hour.
    Deploy changes automaticallyDeploy new commits to the clusters without a manual deploy.
  4. Click Check repository to preview the content. NCH lists the policies it found and whether any of them can’t be deployed by a team Policy Set.

  5. Click Create. NCH checks the content again and doesn’t create the Policy Set if the content is rejected. Fix the rejected content in Git, then check again.

What a team Policy Set can contain

Each policy must be one of these kinds and must set metadata.namespace to one of the Policy Set’s target namespaces:

  • Policy
  • NamespacedValidatingPolicy
  • NamespacedMutatingPolicy
  • NamespacedImageValidatingPolicy

NCH and the operator reject:

  • Cluster-scoped kinds, such as ClusterPolicy or ValidatingPolicy.
  • PolicyException resources. To request an exception, use Policy Exceptions.
  • A Policy with a generate rule, or with a mutate rule that has targets.
  • A policy without metadata.namespace, or with a namespace that isn’t a target of the Policy Set.
  • A policy with the same namespace and name as a policy that another Policy Set already deployed.

NCH doesn’t copy a policy into several namespaces. To apply the same policy to two namespaces, add one copy per namespace, each with its own metadata.namespace.

When the repository holds rejected content, the Policy Set shows a red Content rejected chip next to its name in the list. Its details page shows a banner, “This Policy Set has content a namespace-scoped set can’t deploy”, that lists each rejected file and the reason. Fix those files in Git. Changes that add rejected content can’t be published.

Permissions

RoleCluster-scoped Policy SetsTeam Policy Sets
admin, platformCreate, edit, deleteCreate, edit, delete
securityView in the UIView
devopsViewCreate, edit, and delete the sets their team owns; view the others
readonlyViewView

Devops users can’t change a cluster-scoped Policy Set, set a team Policy Set as default, or create a team Policy Set for a team they aren’t a member of.

Team owners can also edit policies and open merge requests on their team Policy Sets. See Edit Policies and Open Merge Requests. For the roles, see Users and Roles.

Find team Policy Sets

The Policy Sets list has these columns for team Policy Sets:

  • Scope: Namespace for team Policy Sets, Cluster for the others.
  • Owner: the owning team.
  • Targets: the target clusters and namespaces.

If you are a member of a team, use the All policy sets / My team’s sets filter above the list to see only the sets your teams own.

On the details page of a team Policy Set, the Deployed Policies tab has a Namespace column. Git access, the policy history, and the policy editor work as for any GitLab Policy Set. See Git Access and Policy History.