Skip to content

Commit 5e8e119

Browse files
authored
docs(policies): digest integrity checks (#1304)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent 737cbab commit 5e8e119

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

docs/docs/reference/policies.mdx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ before signing and sending it to Chainloop.
1212
Currently, policy violations won't block `attestation push` commands, but instead, we chose to include them in the attestation so that they can
1313
be used for building server side control gates.
1414

15-
### Policy specification
15+
## Policy specification
1616
A policy can be defined in a YAML document, like this:
1717

1818
<CodeBlock language="yaml" title="cyclonedx-licenses.yaml" showLineNumbers>
@@ -32,7 +32,7 @@ spec:
3232
path: my-script.rego
3333
```
3434
35-
### Applying policies to contracts
35+
## Applying policies to contracts
3636
When defining a contract, a new `policies` section can be specified. Policies can be applied to any material, but also to the attestation statement as a whole.
3737
```yaml
3838
schemaVersion: v1
@@ -46,8 +46,10 @@ materials:
4646
policies:
4747
materials: # policies applied to materials
4848
- ref: file://cyclonedx-licenses.yaml # (1)
49+
# or optionally with the digest appended, see integrity checks below
50+
# - ref: file://cyclonedx-licenses.yaml@sha256:5b40425cb7bcba16ac47e3d8a8d3af7288afeeb632096994e741decedd5d38b3
4951
attestation: # policies applied to the whole attestation
50-
- ref: https://github.com/chainloop/chainloop-dev/blob/main/docs/examples/policies/chainloop-commit.yaml # (2)
52+
- ref: https://raw.githubusercontent.com/chainloop-dev/chainloop/main/docs/examples/policies/chainloop-commit.yaml # (2)
5153
```
5254
Here we can see that:
5355
- (1) materials will be validated against `cyclonedx-licenses.yaml` policy. But, since that policy has a `type` property set to `SBOM_CYCLONEDX_JSON`, only SBOM materials (`sbom` and `another-sbom` in this case) will be evaluated.
@@ -68,7 +70,7 @@ Finally, note that material policies are evaluated during `chainloop attestation
6870

6971
### Embedding or referencing policies
7072
There are two ways to attach a policy to a contract:
71-
* **By referencing it**, as it can be seen in the examples above. `ref` property admits a local `file://`` (filesystem) or remote reference `https://`. For example:
73+
* **By referencing it**, as it can be seen in the examples above. `ref` property admits a local `file://` (filesystem) or remote reference `https://`. For example:
7274
```yaml
7375
policies:
7476
materials:
@@ -78,7 +80,7 @@ There are two ways to attach a policy to a contract:
7880
```yaml
7981
policies:
8082
materials:
81-
- ref: https://github.com/chainloop/chainloop-dev/blob/main/docs/examples/policies/cyclonedx-licenses.yaml
83+
- ref: https://raw.githubusercontent.com/chainloop-dev/chainloop/main/docs/examples/policies/sbom/cyclonedx-banned-licenses.yaml
8284
```
8385
are both equivalent. The advantage of having remote policies is that they can be easily reused, allowing organizations to create policy catalogs.
8486

@@ -127,7 +129,22 @@ policies:
127129
```
128130
(1) This is interpreted as a string, that's why we need to add `to_number` in the policy script
129131

130-
### Rego scripts
132+
### Integrity Checks
133+
134+
Optionally, you can append the sha256 hash of the policy file content to your policy attachment reference. By doing so, the policy engine will make sure the resolved policy matches the expected hash in the contract reference.
135+
136+
For example
137+
138+
```yaml
139+
policies:
140+
materials:
141+
# append digest to optionally check the integrity of the policy file during evaluation
142+
- ref: file://cyclonedx-banned-licenses.yaml@sha256:5b40425cb7bcba16ac47e3d8a8d3af7288afeeb632096994e741decedd5d38b3
143+
# It also works for http references
144+
- ref: https://raw.githubusercontent.com/chainloop-dev/chainloop/main/docs/examples/policies/sbom/cyclonedx-banned-licenses.yaml@sha256:5b40425cb7bcba16ac47e3d8a8d3af7288afeeb632096994e741decedd5d38b3
145+
```
146+
147+
## Policy scripts format (REGO)
131148
Currently, policy scripts are assumed to be written in [Rego language](https://www.openpolicyagent.org/docs/latest/policy-language/#learning-rego). Other policy engines might be implemented in the future.
132149
The only requirement of the policy is the existence of one or multiple `violations` rules, which evaluate to a **set of violation messages**.
133150
For example, this policy script:

0 commit comments

Comments
 (0)