Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(helm): support custom policies with built-in scanner #1144

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.10.4
version: 0.11.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
9 changes: 9 additions & 0 deletions deploy/helm/templates/policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,12 @@ data:
kubernetes.namespace]))\n\n\tres := {\n\t\t\"msg\": msg,\n\t\t\"id\": __rego_metadata__.id,\n\t\t\"title\":
__rego_metadata__.title,\n\t\t\"severity\": __rego_metadata__.severity,\n\t\t\"type\":
__rego_metadata__.type,\n\t}\n}\n"
{{- with .Values.additionalPolicies }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be interesting to try to prevent collisions here. Otherwise our beloved YAML will let the last instance of a duplicate key win, which might produce unexpected results.

{{- range $key, $val := .library }}
library.{{ $key }}: {{ $val | quote }}
{{- end }}
{{- range $key, $val := .policy }}
policy.{{ $key }}.rego: {{ $val.rego | quote }}
policy.{{ $key }}.kinds: {{ $val.kinds | quote }}
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions deploy/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,19 @@ nodeSelector: {}
tolerations: []

affinity: {}

additionalPolicies:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, the Conftest is deprecated and planned for removal. If that's not the case, perhaps it would be good to unify this with conftest.library and conftest.policy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not attached to this name, but it seems to follow in the tradition of other charts in the wild.

library: {}
# kubernetes.rego: |
# << REGO >>
# utils.rego: |
# << REGO >>
policy: {}
# access_to_host_pid:
# rego: |
# << REGO >>
# kinds: Workload
# configmap_with_sensitive_data:
# rego: |
# << REGO >>
# kinds: ConfigMap
11 changes: 11 additions & 0 deletions docs/tutorials/writing-custom-configuration-audit-policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ data:
}
```

When using the Helm chart, this can be accomplished as follows:

```yaml
additionalPolicies:
policy:
recommended_labels:
kinds: "*"
rego: |-
...
```

In this example, to add a new policy, you must define two data entries in the `starboard-policies-config`
ConfigMap:

Expand Down