Skip to content

Commit e774f97

Browse files
Merge pull request #3093 from OctopusDeploy/policies-documentation-uplift
Update policies documentation for Platform Hub
2 parents 522a1bb + 0ffcbc8 commit e774f97

5 files changed

Lines changed: 1100 additions & 722 deletions

File tree

src/pages/docs/platform-hub/policies/best-practices.md

Lines changed: 120 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,160 @@
22
layout: src/layouts/Default.astro
33
pubDate: 2025-09-11
44
modDate: 2025-09-25
5-
title: Policies best practices
6-
subtitle: Best practices for creating policies within Platform Hub
5+
title: Policy best practices
6+
subtitle: Guidance on naming, rollout, and writing reliable policies
77
icon: fa-solid fa-lock
8-
navTitle: Best Practices
8+
navTitle: Best practices
99
navSection: Policies
10-
description: Best practices for creating policies within Platform Hub
10+
description: Best practices for creating and managing policies in Platform Hub.
1111
navOrder: 165
1212
---
1313

14-
## Policies administration
14+
This page covers the practices that will save you time and prevent problems as you build and roll out policies across your organization. If you're writing your first policy, start with the [getting started guide](/docs/platform-hub/policies) first.
1515

16-
### Establish a naming standard
16+
## Naming your policies
1717

18-
Use a [ Prefix ] - [ Policy Name ] that is easy for everyone to understand the policy's purpose. The [ Prefix ] should reflect when the policy will run.
18+
A consistent naming standard makes it easy for everyone to understand what a policy does and when it runs, without having to open it.
1919

20-
For example:
20+
Use the format **[Scope] - [Policy name]**, where the scope prefix reflects what type of execution the policy applies to:
2121

22-
- Deployments - [ Policy Name ] for policies designed to run during deployments only.
23-
- Runbook Runs - [ Policy Name ] for policies designed to run during runbooks runs only.
24-
- Deployments and Runbook Runs - [ Policy Name ] for policies for designed to run for deployments or runbooks runs.
22+
| Scope prefix | Use when |
23+
| --- | --- |
24+
| Deploy | The policy only applies to deployments |
25+
| Run | The policy only applies to runbook runs |
26+
| Global | The policy applies to both |
2527

26-
### Turn on SIEM audit log streaming
28+
For example: `Deploy - Manual intervention required` or `Run - Main branch only`.
2729

28-
All policy evaluations are logged to the audit log. Ensure [audit log streaming](/docs/security/users-and-teams/auditing/audit-stream) is enabled to log those evaluations to Splunk, SumoLogic, or an OpenTelemetry collector. SIEM tools can provide alerting and visualizations that you can customize to your requirements.
30+
## Use warn before block
2931

30-
## Creating and Updating Policies
32+
Every new policy should start with `"action": "warn"` in the default result. A warning lets the execution proceed but records the violation in the task log, dashboard, and audit log. This gives you a chance to verify the policy is evaluating the right executions before it starts blocking anyone.
3133

32-
### Start restrictive, then make generic
34+
Once you've confirmed the policy is working as expected, switch to `"action": "block"`.
3335

34-
Consider a policy that will block the execution of deployments and runbook runs. By default, that policy applies to all deployments and runbook runs.
36+
```ruby
37+
# Start here while testing
38+
default result := {"allowed": false, "action": "warn"}
3539

36-
When creating a new policy, be as restrictive as possible by limiting it to:
40+
# Switch to this once confirmed
41+
default result := {"allowed": false, "action": "block"}
42+
```
3743

38-
- A specific hook - such a deployment or a runbook run (not both)
39-
- A specific project
44+
You can also use the `action` field in individual rules to block in production while warning elsewhere. See the [block in production, warn elsewhere](/docs/platform-hub/policies/examples#block-in-production-warn-elsewhere) example.
4045

41-
That will limit a policy's "blast radius." Once you are confident the policy is working as intended, extend the policy to cover more projects or tenants. When acceptable, switch the policy to project groups or spaces.
46+
## Start narrow, then broaden
4247

43-
### Provide a verbose failure reason
48+
When you create a new policy, limit its scope as tightly as possible:
4449

45-
A policy violation will be the first experience for must users with policies within Octopus Deploy. For example, when a policy blocks a deployment or runbook run. Provide a verbose failure reason to help the user self-service the solution.
50+
1. **Start with a single project and execution type.** For example, scope to one project and deployments only. This limits the blast radius if the policy behaves unexpectedly.
51+
2. **Extend to more projects or tenants** once you're confident the policy is correct.
52+
3. **Extend to project groups or spaces** once you're satisfied with behaviour across multiple projects.
53+
54+
This progression also gives teams time to fix violations before the policy scope reaches them, rather than discovering a blocked deployment with no warning.
55+
56+
## Write a clear violation reason
57+
58+
A policy violation is often the first time a user encounters the policies feature. The violation reason is the message they see when a deployment or runbook run fails. Make it specific enough for them to understand what's wrong and what to do about it.
59+
60+
Avoid generic messages like "Policy violation" or "Deployment blocked". Instead, explain what was expected:
4661

4762
:::figure
48-
![An example of a verbose policy violation error message to help users self-service](/docs/img/platform-hub/policies/policy-violation-user-message.png)
63+
![An example of a clear, actionable policy violation message](/docs/img/platform-hub/policies/policy-violation-user-message.png)
4964
:::
5065

51-
### Check for both the existence of steps and if they’ve been skipped
66+
You can set a default violation reason in the policy UI, and override it per rule using the `reason` property in your conditions Rego:
67+
68+
```ruby
69+
result := {"allowed": false, "reason": "A manual intervention step is required and cannot be skipped in this environment"} if {
70+
manual_intervention_skipped
71+
}
72+
```
5273

53-
Policies can be written to check for the existence of specific steps within a deployment or runbook process. It's important to remember that in many cases those deployments and runbook processes have existed for years. Octopus Deploy has the capability to require a step and prevent it from being skipped. But it is unlikely that _all_ of those required steps in _all_ of your deployment and runbook processes have been configured to prevent them from being skipped.
74+
## Check for both existence and skipping
5475

55-
It is not enough for a policy to simply check for the existence of a specific step. The policy must also ensure users don't elect to skip the required step (for whatever reason).
76+
It's not enough to check that a required step exists in the process. Users can skip steps when scheduling a deployment or runbook run, even if the step is present.
5677

5778
:::figure
58-
![An example of a step that can be skipped before scheduling a deployment or runbook run](/docs/img/platform-hub/policies/a-step-that-can-be-skipped-violating-a-policy.png)
79+
![An example of a step that can be skipped when scheduling a deployment](/docs/img/platform-hub/policies/a-step-that-can-be-skipped-violating-a-policy.png)
5980
:::
6081

61-
The resulting policy will have two conditions.
82+
Your policy conditions should check both that the step is present and that it hasn't been skipped:
83+
84+
```ruby
85+
result := {"allowed": true} if {
86+
some step in input.Steps
87+
step.Source.SlugOrId == "<step-slug>"
88+
not step.Id in input.SkippedSteps
89+
step.Enabled == true
90+
}
91+
```
6292

6393
:::figure
64-
![An example of a policy that has both the existence and that isn't skipped](/docs/img/platform-hub/policies/example-of-policy-with-two-conditions.png)
94+
![An example of a policy checking both step existence and that it is not skipped](/docs/img/platform-hub/policies/example-of-policy-with-two-conditions.png)
6595
:::
6696

67-
### Check for parallel execution
97+
See the [steps and skipping examples](/docs/platform-hub/policies/examples#ensure-required-steps-are-present) for complete patterns.
98+
99+
## Guard against conditional fields
100+
101+
Three input fields are not always present in the input object: `Tenant`, `Release`, and `Runbook`. Referencing them without checking for their existence first will cause a policy evaluation error. See [schema for policies](/docs/platform-hub/policies/schema) for the full list of available fields.
102+
103+
| Field | When it's present |
104+
| --- | --- |
105+
| Tenant | Tenanted deployments only |
106+
| Release | Deployments only |
107+
| Runbook | Runbook runs only |
108+
109+
Always guard against their absence in your scope or conditions:
110+
111+
```ruby
112+
# Safe: check Runbook exists before accessing its properties
113+
evaluate if {
114+
input.Runbook
115+
input.Runbook.Id == "<runbook-id>"
116+
}
117+
118+
# Unsafe: will error if Runbook is absent
119+
evaluate if {
120+
input.Runbook.Id == "<runbook-id>"
121+
}
122+
```
123+
124+
The simplest way to avoid this is to scope your policy to deployments only or runbook runs only when the policy is specific to one type. See the [scoping examples](/docs/platform-hub/policies/examples#scoping-examples).
125+
126+
## Check for parallel execution
127+
128+
Steps can be configured to run in parallel or sequentially. If your organization requires sequential execution for compliance or audit purposes, add a policy to enforce it.
129+
130+
Each item in the `Execution` input field has a `StartTrigger` property with one of two values:
131+
132+
- `StartAfterPrevious`: the step runs after the previous step completes
133+
- `StartWithPrevious`: the step runs at the same time as the previous step
134+
135+
To enforce sequential execution:
136+
137+
```ruby
138+
result := {"allowed": true} if {
139+
every execution in input.Execution {
140+
execution.StartTrigger != "StartWithPrevious"
141+
}
142+
}
143+
```
144+
145+
See the [prevent parallel execution](/docs/platform-hub/policies/examples#prevent-parallel-execution) example for the complete policy.
146+
147+
## Stream evaluations to your SIEM
148+
149+
All policy evaluations are recorded in the Octopus audit log. If your organization uses a SIEM tool such as Splunk, Sumo Logic, or an OpenTelemetry collector, set up [audit log streaming](/docs/security/users-and-teams/auditing/audit-stream) to forward those records automatically.
150+
151+
This gives your security team visibility into policy violations across your entire Octopus instance, and lets you build dashboards and alerts that match your compliance requirements.
68152

69-
Steps can be configured to run in parallel or sequentially. If your organization requires sequential execution for compliance or troubleshooting purposes, create a policy to check the `Execution` array in the input schema.
153+
## Testing your policy
70154

71-
Each execution phase has a `StartTrigger` property that indicates when it should run:
155+
Before extending a policy's scope or switching from warn to block, verify it's evaluating correctly:
72156

73-
- `StartAfterPrevious` - Steps run sequentially
74-
- `StartWithPrevious` - Steps run in parallel
157+
1. Run a deployment or runbook run that should fail the policy. Confirm the violation appears in the task log and project dashboard.
158+
2. Run a deployment or runbook run that should pass the policy. Confirm it proceeds without a violation.
159+
3. Check the audit log under **Configuration** > **Audit**, filtered by **Compliance Policy Evaluated**, to see the full evaluation history.
75160

76-
To enforce sequential execution, check that no execution phases have `StartTrigger` set to `StartWithPrevious`. See the [examples page](/docs/platform-hub/policies/examples) for a sample policy.
161+
To see the exact input object that was passed to the policy engine for a specific execution, turn on the verbose option in the task log. This is useful when a policy isn't evaluating as expected. See [Troubleshooting policies](/docs/platform-hub/policies/troubleshooting) for more detail.

0 commit comments

Comments
 (0)