Use Harness Policy As Code to enforce policies on steps
important
Currently, this feature is behind the feature flags OPA_PIPELINE_GOVERNANCE
, CUSTOM_POLICY_STEP
, and OPA_FF_GOVERNANCE
. Contact Harness Support to enable the feature.
This topic explains steps to create policies using the Harness Policy As Code and apply them to your pipeline steps. Harness Policy As Code uses the Open Policy Agency (OPA) to store policies on the Harness Platform. For more information, go to Harness Policy As Code Overview.
Before you begin
- See Harness Policy As Code Overview.
- Make sure you have set up a project and a working pipeline in the Harness platform.
- Policies use OPA authoring language Rego. For more information, go to:
- OPA Policy Authoring.
- Policy Language from OPA.
- Rego Cheat Sheet.
Video of using policies with Harness steps
Sample pipeline
Here is a sample YAML of a pipeline with steps:
pipeline:
name: OPA Policy Pipeline
identifier: OPA_Policy_Pipeline
projectIdentifier: ## YOUR PROJECT ID
orgIdentifier: ## YOUR ORG ID
tags: {}
stages:
- stage:
name: OPA Sandbox
identifier: OPA_Sandbox
description: ""
type: Custom
spec:
execution:
steps:
- step:
type: ShellScript
name: Compute Variable
identifier: Compute_Variable
timeout: 10m
spec:
shell: Bash
onDelegate: true
source:
type: Inline
spec:
script: |-
export serviceMsg=<+pipeline.variables.msg>
echo serviceMsg
environmentVariables: []
outputVariables:
- name: serviceMsg
type: String
value: serviceMsg
enforce:
policySets:
- Variable_Sanitization
tags: {}
variables:
- name: msg
type: String
description: ""
value: <+input>