이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 7. Implementing 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.
OPA, or Open Policy Agent, 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.
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.
7.1. Configuring policy enforcement settings 링크 복사링크가 클립보드에 복사되었습니다!
You can specify how your Ansible Automation Platform instance interacts with OPA by modifying your global settings.
Prerequisites
- 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
-
From the navigation panel, select
. - Click Edit policy settings.
On the Policy Settings page, fill out the following fields:
- OPA Server hostname
- Enter the name of the host that connects to the OPA service.
- OPA server port
- Enter the port that connects to the OPA service.
- OPA authentication type
- Select the OPA authentication type.
- OPA custom authentication header
- Enter a custom header to append to request headers for OPA authentication.
- OPA request timeout
- Enter the number of seconds until the connection times out.
- OPA request retry count
- Enter a figure for the number of times a request can attempt to connect to the OPA service before failing.
Depending on your authentication type, you might need to fill out the following fields.
If you selected Token as your authentication type:
- OPA authentication token
- Enter the OPA authentication token.
If you selected Certificate as your authentication type:
- OPA client certificate content
- Enter content of the CA certificate for mTLS authentication.
- OPA client key content
- Enter the client key for mTLS authentication.
- OPA CA certificate content
- Enter the content of the CA certificate for mTLS authentication.
Beneath the heading labeled Options:
- Use SSL for OPA connection
- Check this box to enable an SSL connection to the OPA service.
- Click .
7.2. Understanding OPA packages and rules 링크 복사링크가 클립보드에 복사되었습니다!
An OPA policy is organized in packages, which are namespaced collections of rules. The basic structure of an OPA policy looks like this:
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 comprise the OPA policy name, which is formatted as [package]/[rule]
. You will enter the OPA policy name when you configure enforcement points.
7.3. Configuring enforcement points 링크 복사링크가 클립보드에 복사되었습니다!
After you have set up your Ansible Automation Platform instance to communicate with the OPA server, you can set up enforcement points where you want the policy to be applied.
You can associate a policy with a job template, an inventory, or an organization. Enforcement then occurs in the following ways:
- Organization
- Jobs launched from a template owned by an organization will fail if the policy is violated. This configuration provides broad control over automation within organizational boundaries.
- Inventory
- Jobs using an inventory associated with a policy fail if the policy is violated. This configuration allows you to control access to specific infrastructure resources.
- Job template
- Jobs launched from a template associated with a policy fail if the job violates the associated policy. This configuration provides granular control over specific automation tasks.
If you do not associate a policy with a resource, policy evaluation will not occur when you run the related job.
7.3.1. Associating a policy with an organization 링크 복사링크가 클립보드에 복사되었습니다!
To associate a policy with an organization, take the following steps.
Procedure
-
From the navigation panel, select
. On the Organizations page:
-
To edit an existing organization, find the organization you want to edit and click the pencil icon
to go to the editing screen.
- To create a new organization, click .
-
To edit an existing organization, find the organization you want to edit and click the pencil icon
-
In the field labeled Policy enforcement, enter the query path associated with the policy you want to implement. You must format the query path as
package/rule
. - Click and then to save your settings.
7.3.2. Associating a policy with an inventory 링크 복사링크가 클립보드에 복사되었습니다!
To associate a policy with an inventory, take the following steps:
Procedure
-
From the navigation panel, select
. On the Inventories page:
-
To edit an existing inventory, find the inventory you want to edit and click the pencil icon
to go to the editing screen.
- To create a new inventory, click .
-
To edit an existing inventory, find the inventory you want to edit and click the pencil icon
-
In the field titled Policy enforcement, enter the query path associated with the policy you want to implement. You must format the query path as
package/rule
. - Click if you are editing an existing inventory, or click if you are creating a new inventory.
7.3.3. Associating a policy with a job template 링크 복사링크가 클립보드에 복사되었습니다!
To associate a policy with a job template, take the following steps:
Procedure
-
From the navigation panel, select
. On the Automation Templates page:
-
To edit an existing job template, find the job template you want to edit and click the pencil icon
to go to the editing screen.
- To create a new job template, click .
-
To edit an existing job template, find the job template you want to edit and click the pencil icon
-
In the field titled Policy enforcement, enter the query path associated with the policy you want to implement. You must format the query path as
package/rule
. - Click if you are editing an existing job template, or click if you are creating a new job template.
7.4. Policy enforcement inputs and outputs 링크 복사링크가 클립보드에 복사되었습니다!
Use the following inputs and outputs to craft policies for use in policy enforcement.
Input | Type | Description |
---|---|---|
| Integer | The job’s unique identifier. |
| String | Job template name. |
| Datetime (ISO 8601) | Timestamp indicating when the job was created. |
| Object | Information about the user who created the job.
|
| List of objects | Credentials associated with job execution.
|
| Object | Details about the execution environment used for the job.
|
| JSON | Extra variables provided for job execution. |
| Integer | The number of parallel processes used for job execution. |
| Integer | The number of hosts targeted by the job. |
| Object | Information about the instance group handling the job, including:
|
| Object | Inventory details used in the job execution, including:
|
| Object | Information about the job template, including:
|
| Choice (String) | Type of job execution. Allowed values are:
|
| String | Human-readable name for the job type. |
| List of objects | Labels associated with the job, including:
|
| Choice (String) | How the job was launched. Allowed values include:
|
| String | The limit applied to the job execution. |
| Object | Information about the user who launched the job, including:
|
| Object | Information about the organization associated with the job, including:
|
| String | The playbook used in the job execution. |
| Object | Details about the project associated with the job, including:
|
| String | The specific branch to use for SCM. |
| String | SCM revision used for the job. |
| Object | Workflow job details, if the job is part of a workflow. |
| Object | Workflow job template details. |
The following code block shows example input data from a demo job template launch:
Input | Type | Description |
---|---|---|
| Boolean | Indicates whether the action is permitted |
| List of strings | Reasons why the action is not permitted |
The following code block shows an example of expected output from the OPA policy query: