> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/harness-platform/3.0/harness-cli/cli/harness-cli-commands/governance.md).

# Governance

Use the Harness CLI to manage OPA policies, policy sets, and policy evaluation records.

Use the Harness CLI to manage the Governance module, including OPA policies written in Rego, policy sets, and policy evaluation records.

Harness Governance enforces Open Policy Agent (OPA) policies across your account. You author policies in Rego, group them into policy sets, and Harness evaluates those sets when a pipeline runs or a resource changes. The CLI lets you manage policies and policy sets as code and review the evaluations that Harness recorded.

This page covers all Governance resources and actions available in the CLI.

## What you will learn in this topic

By the end of this page, you will know how to:

* List, create, update, and delete OPA policies.
* Inspect the Rego source of a policy.
* Group policies into policy sets and control when those sets are evaluated.
* Review recorded policy evaluations.

## Before you begin

* **Harness CLI installed and authenticated:** Go to [Install and upgrade](https://developer.harness.io/harness-platform/3.0/harness-cli/cli/overview.md) and [Authenticate](https://developer.harness.io/harness-platform/3.0/harness-cli/cli/authenticate-the-harness-cli.md) for setup steps.
* **Scope configured:** Governance resources resolve against the scope in your profile. Pass `--account`, `--org`, or `--project` to override it for a single command.
* **Rego knowledge:** Policies are written in Rego. Go to [Harness Governance](https://developer.harness.io/harness-platform/use-harness-platform/governance/policy-as-code/harness-governance-overview) for the policy model.

### Policies

A policy is a single Rego module that inspects a resource or pipeline payload and returns violations. A policy on its own does nothing until it belongs to a policy set.

#### List policies

```bash
harness list policy 
harness list policy --all --format json 
harness list policy --columns "name,id,updated"
```

#### Get policy details

The response includes the Rego source of the policy.

```bash
harness get policy <policy_id>
harness get policy <policy_id> --format json
```

#### Create a policy

Supply the name and the Rego source inline, or pass the whole definition in a YAML file.

```bash
harness create policy <policy_id> \ 
  --set name="<policy_name>" \ 
  --set rego='package main 

deny[msg] { 
  msg := "<violation_message>" 
}' 

harness create policy <policy_id> -f <policy_file>.yaml
```

#### Update a policy

Update the name, the Rego source, or both.

```bash
harness update policy <policy_id> --set name="<policy_name>" 
harness update policy <policy_id> -f <policy_file>.yaml
```

#### Delete a policy

```bash
harness delete policy <policy_id>
```

### Policy sets

A policy set groups policies and binds them to an entity type and an action, which is what makes them run. A set that is not enabled is stored but never evaluated.

#### List and get policy sets

```bash
harness list policy_set 
harness list policy_set --all --format json 
harness get policy_set <policy_set_id>
```

#### Create a policy set

The `type` field names the entity the set applies to, and `action` names the event that triggers evaluation.

```bash
harness create policy_set <policy_set_id> \ 
  --set name="<policy_set_name>" \ 
  --set type=pipeline \ 
  --set action=onrun \ 
  --set enabled=true
```

#### Update a policy set

Update the name, the enabled state, or the member policies.

```bash
harness update policy_set <policy_set_id> --set name="<policy_set_name>" 
harness update policy_set <policy_set_id> --set enabled=false
```

#### Delete a policy set

```bash
harness delete policy_set <policy_set_id>
```

### Policy evaluations

Every time Harness evaluates a policy set against a resource it records the result. Use evaluations to audit which policies passed or failed and why.

```bash
harness list policy_evaluation 
harness list policy_evaluation --all --format json 
harness list policy_evaluation --limit 20
```

### Troubleshooting

* **A policy set never evaluates:** Confirm the policy set is enabled, since a disabled set is stored but never evaluated.
* **A policy change does not take effect:** Policy sets evaluate the policies currently bound to them, since updating a policy's Rego source applies immediately to every set that references it. Confirm you updated the correct `policy_id`.
* **`create policy` fails with a Rego syntax error:** Validate the Rego source independently before passing it inline, since the CLI does not lint Rego before submitting it.

### Related concepts

* [Audit](https://developer.harness.io/harness-platform/3.0/harness-cli/cli/harness-cli-commands/audit.md): Review the audit trail for policy changes.
* [Continuous Delivery](https://developer.harness.io/harness-platform/3.0/harness-cli/cli/harness-cli-commands/continuous-delivery.md): Manage the pipelines that policy sets evaluate.
* [Platform](https://developer.harness.io/harness-platform/3.0/harness-cli/cli/harness-cli-commands/platform.md): Manage account resources, connectors, and secrets.
