Skip to content

Commit

Permalink
add opa example to docs - i don't like my phrasing here
Browse files Browse the repository at this point in the history
  • Loading branch information
mildwonkey committed Oct 1, 2024
1 parent e143c0d commit a86baf0
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions docs/reference/domains/file-domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ The file domain supports the following file formats for validation:
* YAML
## Validations
When writing validations against files, the filepath Name must be included as the top-level key in the validation, in this example below `check`:
When writing validations against files, the filepath Name must be included as
the top-level key in the validation. The placement varies between providers.
Given the following ini file:
```grafana.ini
[server]
# Protocol (http, https, socket)
protocol = http
```

The below Kyverno policy validates the protocol is https by including Grafana as the top-level key under "check":

```yaml
metadata:
Expand Down Expand Up @@ -68,8 +79,47 @@ provider:
protocol: https
```
```grafana.ini
[server]
# Protocol (http, https, socket)
protocol = http
```
While in an OPA policy, the filepath Name is the input key to access the config:
```yaml
metadata:
name: validate-grafana-config
uuid: ad38ef57-99f6-4ac6-862e-e0bc9f55eebe
domain:
type: file
file-spec:
filepaths:
- name: 'grafana'
path: 'custom.ini'
provider:
type: opa
opa-spec:
rego: |
package validate
import rego.v1
# Default values
default validate := false
default msg := "Not evaluated"
validate if {
check_grafana_config.result
}
msg = check_grafana_config.msg
config := input["grafana"]
protocol := config.server.protocol
check_grafana_config = {"result": true, "msg": msg} if {
protocol == "https"
msg := "Server protocol is set to https"
} else = {"result": false, "msg": msg} if {
protocol == "http"
msg := "Grafana protcol is insecure"
}
output:
validation: validate.validate
observations:
- validate.msg
```

0 comments on commit a86baf0

Please sign in to comment.