Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Governance

Manage Open Policy Agent (OPA) policies, policy sets, and evaluations with the Harness Governance API.

The Governance API manages policy as code in Harness. Policies are written in Rego, the Open Policy Agent (OPA) language, and Harness evaluates them when someone saves or runs a resource.

Request basics

  • API key token: Send it in the x-api-key header on every request. Go to Manage API keys to create a key and token.

  • Account, organization, and project IDs: Send accountIdentifier as a query parameter. Add orgIdentifier and projectIdentifier for policies and policy sets at those levels. Go to Organizations and projects to find these identifiers.

  • Base URL: Send requests to https://app.harness.io/gateway/pm, followed by the endpoint path.

Example request

List the policies in a project:

curl "https://app.harness.io/gateway/pm/api/v1/policies?accountIdentifier=ACCOUNT_ID&orgIdentifier=ORG_ID&projectIdentifier=PROJECT_ID" \
  -H "x-api-key: $HARNESS_API_KEY"

Replace ACCOUNT_ID, ORG_ID, and PROJECT_ID with your own values, and set HARNESS_API_KEY to your API key token.

Find an endpoint

Endpoint paths are relative to the base URL.

  • Policies: Rules written in Rego, such as "every pipeline must include an approval stage". List policies with GET /api/v1/policies, create one with POST /api/v1/policies, and test one against sample input with POST /api/v1/policies/dry-run. Go to Harness Policy As Code overview to write your first policy.

  • Policy sets: Groups of policies tied to an entity type and an event, such as pipelines on save, with a warn or error action. List policy sets with GET /api/v1/policysets and create one with POST /api/v1/policysets. Go to Enable/Disable a policy set to enable or disable a policy set.

  • Evaluations: The recorded result each time Harness checks a resource against a policy set. List evaluations with GET /api/v1/evaluations and read one with GET /api/v1/evaluations/{id}. Go to Policy evaluations retention to understand how long evaluations are kept.

  • Policy packs: Built-in sets of policies for common compliance standards. List the available packs with GET /api/v1/policy-packs.

Last updated

Was this helpful?