Implement policy enforcement
Policy enforcement at automation runtime is a feature that uses encoded rules to define, manage, and enforce policies that govern how your users interact with your Ansible Automation Platform instance. Policy enforcement automates policy management, improving security, compliance, and efficiency.
Open Policy Agent, or OPA, is a policy engine that offloads policy decisions from your Ansible instance. When it is triggered, the policy enforcement feature connects to OPA to retrieve policies specified in your configuration, and applies policy rules to your automation content. If OPA detects a policy violation, it will stop the action and give your user information about the policy violation. For more information, see Open Policy Agent in the Related Links section.
Prerequisites
Before you can implement policy enforcement in your Ansible Automation Platform instance, you must have:
- Access to an OPA server that is reachable from your Ansible Automation Platform deployment.
- Configured Ansible Automation Platform with settings required for authenticating to your OPA server.
- Some familiarity with OPA and the Rego language, which is the language policies are written in.
For policy enforcement to work correctly, you must both configure the OPA server in your policy settings, and associate a specific policy with a particular resource. For example, a particular organization, inventory, or job template.
OPA API V1 is the only version currently supported in Ansible Automation Platform.
Configure policy enforcement settings Copy linkLink copied!
You can specify how your Ansible Automation Platform instance interacts with OPA by modifying your global settings.
Before you begin Copy linkLink copied!
- To configure policy enforcement, you must have administrative privileges.
If you do not configure the OPA server in your policy settings, policy evaluation will not occur when you run the job.
Procedure Copy linkLink copied!
Understand OPA packages and rules Copy linkLink copied!
An OPA policy is organized in packages, which are namespaced collections of rules. The basic structure of an OPA policy looks like this:
package aap_policy_examples # Package name
import rego.v1 # Import required for Rego v1 syntax
# Rules define the policy logic
allowed := {
"allowed": true,
"violations": []
}
The key components of the rule’s structure are:
- Package declaration
- This defines the namespace for your policy.
- Rules
- This defines the policy’s logic and the decision that it returns.
These components together form the OPA policy name, with the format [package]/[rule]. Enter the OPA policy name when you configure enforcement points.