Skip to content

feat: adding driver to export to disk #3832

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

Merged
merged 39 commits into from
May 6, 2025

Conversation

JaydipGabani
Copy link
Contributor

What this PR does / why we need it: Adding driver to export violation on disk.

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged):
Fixes ##1037

Special notes for your reviewer:

@JaydipGabani JaydipGabani requested a review from a team as a code owner March 1, 2025 03:22
@JaydipGabani
Copy link
Contributor Author

Working on docs still.

@codecov-commenter
Copy link

codecov-commenter commented Mar 1, 2025

Codecov Report

Attention: Patch coverage is 64.25532% with 84 lines in your changes missing coverage. Please review.

Project coverage is 48.04%. Comparing base (3350319) to head (f5d9bdc).
Report is 334 commits behind head on master.

Files with missing lines Patch % Lines
pkg/export/disk/disk.go 71.90% 39 Missing and 20 partials ⚠️
pkg/audit/manager.go 0.00% 22 Missing ⚠️
pkg/export/util/util.go 0.00% 2 Missing ⚠️
pkg/controller/export/export_config_controller.go 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (3350319) and HEAD (f5d9bdc). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (3350319) HEAD (f5d9bdc)
unittests 2 1
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3832      +/-   ##
==========================================
- Coverage   54.49%   48.04%   -6.46%     
==========================================
  Files         134      236     +102     
  Lines       12329    20124    +7795     
==========================================
+ Hits         6719     9669    +2950     
- Misses       5116     9544    +4428     
- Partials      494      911     +417     
Flag Coverage Δ
unittests 48.04% <64.25%> (-6.46%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

if path, ok := cfg["path"].(string); ok {
if conn.Path != path {
if err := os.RemoveAll(conn.Path); err != nil {
cleanUpErr = fmt.Errorf("connection updated but failed to remove content form old path: %w", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be an error or log?

@@ -280,17 +259,28 @@ func (am *Manager) audit(ctx context.Context) error {
timestamp := startTime.UTC().Format(time.RFC3339)
am.log = log.WithValues(logging.AuditID, timestamp)
logStart(am.log)
exportErrorMap := make(map[string]error)
if err := am.exportSystem.Publish(context.Background(), *auditConnection, *auditChannel, exportutil.ExportMsg{Message: "audit is started", ID: timestamp}); err != nil {
exportErrorMap[err.Error()] = err
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can lead to memory consumption if by any chance driver returns unique error for all violations instead of returning one. Instead, we can modify returned error type to ExportError and use error type as keys to limit the number of errors we are storing in map. Do folks think this is a way to go about limiting the number of errors stored? I am open to other suggestions.

I will make the change if we agree to use ExportError because that may need updating interface.

Copy link
Member

Choose a reason for hiding this comment

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

agreed, your suggestion make sense. if we want to avoid interface changes, another idea might be to extract error category by checking with regex or before : for example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Parsing the error message and using the string before : as key to store errors.

@JaydipGabani JaydipGabani self-assigned this Mar 3, 2025
@JaydipGabani JaydipGabani changed the title chore: adding driver to export to disk feat: adding driver to export to disk Mar 5, 2025
@sozercan sozercan requested a review from Copilot March 5, 2025 23:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR adds a new disk export driver for persisting audit violations to the file system and updates related configuration, tests, and documentation.

  • Introduces a new disk driver under pkg/export/disk.
  • Adds GitHub workflow and test configuration to exercise the disk export.
  • Updates documentation to guide users through configuring and using the disk export driver.

Reviewed Changes

File Description
.github/workflows/disk-export.yaml Workflow definition to run disk export tests
test/export/fake-reader/.yaml,.go Test configuration and a fake-reader to simulate exports
website/docs/export.md Documentation updates for the disk export driver
pkg/export/disk/disk.go New disk export driver implementation
pkg/export/util/util.go Utility types updated for export messages
pkg/audit/manager.go Audit manager updates to integrate disk export; error map
pkg/export/system.go Updated export system to include the disk driver

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

pkg/export/disk/disk.go:69

  • The variable 'err' is never updated in CreateConnection; consider returning 'nil' explicitly to avoid confusion.
return err

pkg/audit/manager.go:263

  • [nitpick] Consider defining and using constants for the audit trigger messages ("audit is started" and "audit is completed") to avoid typos and ensure consistency across the codebase.
am.exportSystem.Publish(context.Background(), *auditConnection, *auditChannel, exportutil.ExportMsg{Message: "audit is started", ID: timestamp})

@sozercan sozercan self-requested a review March 6, 2025 00:01
return fmt.Errorf("missing or invalid values in config for connection: %s", connectionName)
}
var err error
maxResults, maxResultsOk := cfg["maxAuditResults"].(float64)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why float?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the inherent value is stored in float64 when the object is getting unpacked, so checking and converting to int64 does not work here.

egress-policy: audit

- name: Check out code into the Go module directory
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

maxAllowedAuditRuns = 5
)

const (
Copy link
Member

Choose a reason for hiding this comment

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

nit: merge these

ARG BUILDERIMAGE="golang:1.22-bookworm"
ARG BASEIMAGE="gcr.io/distroless/static-debian12:nonroot"

FROM --platform=$BUILDPLATFORM $BUILDERIMAGE as builder
Copy link
Member

Choose a reason for hiding this comment

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

let's add it here instead of using an arg, and dependabot can bump it. please make sure its covered in dependabot config


RUN go build -o main

FROM $BASEIMAGE
Copy link
Member

Choose a reason for hiding this comment

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

same here

return fmt.Errorf("invalid data type, cannot convert data to exportMsg")
}

if violation.Message == "audit is started" {
Copy link
Member

Choose a reason for hiding this comment

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

can we use a const for these to avoid issues?

return fmt.Errorf("error writing message to disk: %w", err)
}

if violation.Message == "audit is completed" {
Copy link
Member

Choose a reason for hiding this comment

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

same here

return fmt.Errorf("missing or invalid 'path' for connection: %s", connectionName)
}

if maxResults, ok := cfg["maxAuditResults"].(float64); ok {
Copy link
Member

Choose a reason for hiding this comment

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

const these?

}

var cleanUpErr error
if path, ok := cfg["path"].(string); ok {
Copy link
Member

Choose a reason for hiding this comment

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

same here

2. Update `gatekeeper-audit` deployment to add `emptyDir` volume.

```yaml
volumes:
Copy link
Member

Choose a reason for hiding this comment

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

do we want to add this to helm chart with conditional?

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 found it to be more complecated to add a whole sidecar container and its config because unlike adding dapr annotation which adds a container with specification required for dapr sidecar to run. A sidecar reader for purposes beyond just reading and logging would require specific customizations. We can add it but the chart will get more complicated and I do not see the value since we might not be able to make it completly customizable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to add helm variables for volume, volumeMount and sidecar as well.


```yaml
...
- --enable-violation-export=true
Copy link
Member

Choose a reason for hiding this comment

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

same for these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above comment.

@ritazh ritazh added this to the v3.19.0 milestone Mar 17, 2025
You can use below command that uses a rule defined in [Makefile](https://github.com/open-policy-agent/gatekeeper/blob/master/Makefile) to deploy gatekeeper that mounts emptyDir with sidecar reader container.


make deploy IMG=gatekeeper-e2e:latest IMG=<gatekeeper_image> EXPORT_BACKEND=disk FAKE_READER_IMAGE=<your_reader_image>
Copy link
Member

Choose a reason for hiding this comment

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

i am confused, isn't this going to add the sidecar to audit automatically? instructions in the prereqs are saying to do this manually

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made it more clear a bit.

3. Create connection config to establish a connection.

```shell
kubectl apply -f - <<EOF
Copy link
Member

Choose a reason for hiding this comment

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

this might be okay on the website, but copy pasting this have some formatting issues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah this is happening due to indentation. I tested copying from website and I am not seeing any formatting issues.


```log
kubectl logs -l gatekeeper.sh/operation=audit -c go-sub -n gatekeeper-system
2025/03/05 00:37:16 {"id":"2025-03-05T00:37:13Z","details":{"missing_labels":["test"]},"eventType":"violation_audited","group":"constraints.gatekeeper.sh","version":"v1beta1","kind":"K8sRequiredLabels","name":"pod-must-have-test","message":"you must provide labels: {\"test\"}","enforcementAction":"deny","resourceAPIVersion":"v1","resourceKind":"Pod","resourceNamespace":"nginx","resourceName":"nginx-deployment-2-79479fc6db-7qbnm","resourceLabels":{"app":"nginx-ingress","app.kubernetes.io/component":"controller","pod-template-hash":"79479fc6db"}}
Copy link
Member

Choose a reason for hiding this comment

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

I am seeing this \u003, not sure if this is something on my side

2025/03/24 04:25:27 {"id":"2025-03-24T04:24:27Z","details":{},"eventType":"violation_audited","group":"constraints.gatekeeper.sh","version":"v1beta1","kind":"K8sAllowedRepos","name":"repo-is-mcr","message":"container \u003ccoredns\u003e has an invalid image repo \u003cregistry.k8s.io/coredns/coredns:v1.11.3\u003e, allowed repos are [\"quay.io/\"]","enforcementAction":"dryrun","resourceAPIVersion":"v1","resourceKind":"Pod","resourceNamespace":"kube-system","resourceName":"coredns-668d6bf9bc-57xm9","resourceLabels":{"k8s-app":"kube-dns","pod-template-hash":"668d6bf9bc"}}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I have not run into similar issues. How are you testing this?

Copy link
Member

Choose a reason for hiding this comment

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

using the instructions here on a kind cluster. might be on my side, unless @ritazh can repro too

@@ -280,17 +259,28 @@ func (am *Manager) audit(ctx context.Context) error {
timestamp := startTime.UTC().Format(time.RFC3339)
am.log = log.WithValues(logging.AuditID, timestamp)
logStart(am.log)
exportErrorMap := make(map[string]error)
if err := am.exportSystem.Publish(context.Background(), *auditConnection, *auditChannel, exportutil.ExportMsg{Message: "audit is started", ID: timestamp}); err != nil {
exportErrorMap[err.Error()] = err
Copy link
Member

Choose a reason for hiding this comment

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

agreed, your suggestion make sense. if we want to avoid interface changes, another idea might be to extract error category by checking with regex or before : for example

Copy link
Member

@sozercan sozercan left a comment

Choose a reason for hiding this comment

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

LGTM with a few more suggestions


```yaml
audit:
exportVolume:
Copy link
Member

Choose a reason for hiding this comment

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

indent issue i think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1, fixed it.


```log
kubectl logs -l gatekeeper.sh/operation=audit -c go-sub -n gatekeeper-system
2025/03/05 00:37:16 {"id":"2025-03-05T00:37:13Z","details":{"missing_labels":["test"]},"eventType":"violation_audited","group":"constraints.gatekeeper.sh","version":"v1beta1","kind":"K8sRequiredLabels","name":"pod-must-have-test","message":"you must provide labels: {\"test\"}","enforcementAction":"deny","resourceAPIVersion":"v1","resourceKind":"Pod","resourceNamespace":"nginx","resourceName":"nginx-deployment-2-79479fc6db-7qbnm","resourceLabels":{"app":"nginx-ingress","app.kubernetes.io/component":"controller","pod-template-hash":"79479fc6db"}}
Copy link
Member

Choose a reason for hiding this comment

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

using the instructions here on a kind cluster. might be on my side, unless @ritazh can repro too

if err != nil {
return fmt.Errorf("failed to acquire lock: %w", err)
}
log.Info("Writing latest violations at ")
Copy link
Member

Choose a reason for hiding this comment

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

is this missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the log statement,

Comment on lines 186 to 171
dir := path.Join(conn.Path, topic)
if err := os.MkdirAll(dir, 0o755); err != nil {
return fmt.Errorf("failed to create directories: %w", err)
}

file, err := os.OpenFile(path.Join(dir, appendExtension(conn.currentAuditRun, "txt")), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o644)
if err != nil {
return fmt.Errorf("failed to open file: %w", err)
}
Copy link
Contributor

@nreisch nreisch Mar 25, 2025

Choose a reason for hiding this comment

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

Readers might want to truncate and remove files after processing, but this seems to only grant write if the sidecar container runs as the same user id of the main container. But sidecars might need to run as root or other users. How can we support if sidecar needs to run as root, should we handle this in the permissions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the permissions issue by setting file and dir permissions to allow reader to modify the same if needed.


```shell
helm upgrade --install gatekeeper gatekeeper/gatekeeper --namespace gatekeeper-system \
...
Copy link
Member

Choose a reason for hiding this comment

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

remove this ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it


#### Configure Gatekeeper with Export enabled to Disk

1. Build `fake-reader` image from [gatekeeper/test/export/fake-reader](https://github.com/open-policy-agent/gatekeeper/tree/master/test/export/fake-reader)
Copy link
Member

Choose a reason for hiding this comment

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

instead of having users do this, can this image be published as one of the Gatekeeper images? built/released/tagged like other GK images.

Copy link
Member

Choose a reason for hiding this comment

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

To clarify, I'm suggesting to add this as part of the makefile and publish it to the registry so we can use it as a default value in the values.yaml. this is to ensure users have an easy way to test things. they can always replace with their own image.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Published fake-reader image on ghcr - https://github.com/open-policy-agent/gatekeeper/pkgs/container/fake-reader. This should improve experience trying out this feature with defaults for the first time.

1. Build `fake-reader` image from [gatekeeper/test/export/fake-reader](https://github.com/open-policy-agent/gatekeeper/tree/master/test/export/fake-reader)

```bash
docker buildx build -t <your_img_name:tag> --load -f test/export/fake-reader/Dockerfile test/export/fake-reader
Copy link
Member

Choose a reason for hiding this comment

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

this can be part of the makefile like docker-buildx-crds

<your-side-car>
```

Here is the default `values.yaml` that you can use.
Copy link
Member

Choose a reason for hiding this comment

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

can this be deployed as part of the chart but conditional on a field in values.yaml? e.g. audit.enableExportToDisk

--values /path/to/values.yaml
```

4. Create connection config to establish a connection.
Copy link
Member

Choose a reason for hiding this comment

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

same, can this be part of the chart but conditionally install only if the feature is enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this to helm charts.

@@ -905,7 +902,7 @@ func (am *Manager) addAuditResponsesToUpdateLists(
if *exportController.ExportEnabled {
err := am.exportSystem.Publish(context.Background(), *auditConnection, *auditChannel, violationMsg(constraint, ea, r.ScopedEnforcementActions, gvk, namespace, name, msg, details, labels, timestamp))
if err != nil {
am.log.Error(err, "error exporting audit violation")
Copy link
Member

Choose a reason for hiding this comment

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

this should still be logged in the audit pod log

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was removed to prevent flood of logs with the same error for each violation in favor of only logging unique errors - https://github.com/open-policy-agent/gatekeeper/pull/3832/files#diff-2a233457fc5c89cf0dd91c044d7582aa1cc0c835feabf4638882ac54ba3ca63aR286.

@JaydipGabani JaydipGabani modified the milestones: v3.19.0, v3.20.0 Mar 27, 2025
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Copy link
Member

@sozercan sozercan left a comment

Choose a reason for hiding this comment

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

lgtm

timeout-minutes: 15
steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
Copy link
Member

Choose a reason for hiding this comment

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

please double check these GitHub action versions to ensure they are the latest

| audit.connection | (alpha) Connection name for exporting audit violation messages | `audit-connection` |
| audit.channel | (alpha) Channel name for exporting audit violation messages | `audit-channel` |
| audit.exportVolume | (alpha) Volume for audit pod to export violations. | `{"name":"tmp-violations","emptyDir":{}}` |
| audit.exportVolumeMount.path | (alpha) VolumeMount for audit pod manager container to export violations and sidecar container to read from. | `/tmp/violations` |
| audit.exportSidecar | (alpha) Sidecar container to read violations from disk. | `{"name":"reader","image":"ghcr.io/open-policy-agent/fake-reader:latest","imagePullPolicy":"Always","securityContext":{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"readOnlyRootFilesystem":true,"runAsGroup":999,"runAsNonRoot":true,"runAsUser":1000,"seccompProfile":{"type":"RuntimeDefault"}},"volumeMounts":[{"mountPath":"/tmp/violations","name":"tmp-violations"}]}` |
Copy link
Member

Choose a reason for hiding this comment

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

where is the code that pushes ghcr.io/open-policy-agent/fake-reader

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now I have pushed them manually before building a CI for that.

Copy link
Member

Choose a reason for hiding this comment

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

As a follow up, please add this to CI. I can see maybe it could have CVEs in the future that we may need to patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 This should be added for all sample images as follow up.

@@ -0,0 +1,31 @@
FROM --platform=$BUILDPLATFORM golang:1.23-bookworm@sha256:462f68e1109cc0415f58ba591f11e650b38e193fddc4a683a3b77d29be8bfb2c AS builder
Copy link
Member

Choose a reason for hiding this comment

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

Please check this is the latest


RUN go build -o main

FROM gcr.io/distroless/static-debian12@sha256:8dd8d3ca2cf283383304fd45a5c9c74d5f2cd9da8d3b077d720e264880077c65
Copy link
Member

Choose a reason for hiding this comment

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

same

1. Deploy Gatekeeper with disk export configurations.

```shell
helm upgrade --install gatekeeper gatekeeper/gatekeeper --namespace gatekeeper-system \
Copy link
Member

Choose a reason for hiding this comment

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

should we move this step after user has updated their values yaml?

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 am not sure, in quickstart steps user doesnt need to create values.yaml to try it out. So the yaml of variables in values is just a guide and not a requirement for users to try this. By that flow I think this is fine 🤔

Copy link
Member

Choose a reason for hiding this comment

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

We shouldnt encourage users to use the fake-reader container image in production. IMO we should move this up and then add a warning to replace fake-reader for any production use since its just for demo purpose. WDYT?

Copy link
Contributor Author

@JaydipGabani JaydipGabani May 5, 2025

Choose a reason for hiding this comment

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

Oh yeah from that point of view moving it down makes sense. I am updating docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated docs to move up default values before installing Gk with added warning about production use.

--set audit.channel=audit-channel \
--set audit.exportConfig.maxAuditResults=3 \
--set exportBackend=disk \
--set audit.exportSidecar.image=ghcr.io/open-policy-agent/fake-reader:latest \
Copy link
Member

@ritazh ritazh Apr 24, 2025

Choose a reason for hiding this comment

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

since this is the default value, should this be removed assuming users have updated their values.yaml or add a comment here to --set audit.exportSidecar.image to override the default?

Copy link
Contributor Author

@JaydipGabani JaydipGabani Apr 25, 2025

Choose a reason for hiding this comment

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

+1, removed these values.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new disk driver for exporting audit violations to disk and integrates it into the existing export system. Key changes include:

  • A new disk driver implementation (pkg/export/disk/disk.go) with connection, publishing, and file handling logic.
  • Integration of the disk driver into the supported drivers map and updates to export configuration and audit manager.
  • Updates to Helm charts and documentation to support configuration of the disk export backend.

Reviewed Changes

Copilot reviewed 20 out of 26 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/export/util/util.go Added export message and error types used by both drivers and audit manager.
pkg/export/system.go Included the disk driver into the SupportedDrivers map.
pkg/export/disk/disk.go New implementation of the disk driver with file and connection management.
pkg/controller/export/export_config_controller.go Updated to lower-case the driver value for consistency.
pkg/audit/manager.go Propagated export error mapping and adjusted audit response handling.
manifest_staging/charts/gatekeeper/*.yaml and README.md Updated configuration values and documentation for the disk export backend.
cmd/build/helmify/* Adjusted templating to support the export disk configuration.
.github/workflows/*.yaml Added CI jobs to run tests for the disk export functionality.
.github/dependabot.yml Added updates for docker package ecosystems related to export testing.
Files not reviewed (6)
  • Makefile: Language not supported
  • cmd/build/helmify/static/templates/gatekeeper-audit-violation-export-config.yaml: Language not supported
  • cmd/build/helmify/static/values.yaml: Language not supported
  • test/bats/helpers.bash: Language not supported
  • test/bats/test.bats: Language not supported
  • test/export/fake-reader/Dockerfile: Language not supported
Comments suppressed due to low confidence (1)

pkg/export/disk/disk.go:160

  • There is a stray backtick in the error message format string; remove it to correctly format the error message.
if err := os.MkdirAll(dir, 0o777); err != nil { return fmt.Errorf("failed to create directories:` %w", err) }


dir := path.Join(conn.Path, topic)
if err := os.MkdirAll(dir, 0o777); err != nil {
return fmt.Errorf("failed to create directories:` %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

Remove ` before %w

@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.24-bookworm@sha256:fa1a01d362a7b9df68b021d59a124d28cae6d99ebd1a876e3557c4dd092f1b1d AS builder
Copy link
Member

Choose a reason for hiding this comment

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

this will prob get bumped by dependabot to use the latest and to avoid CVEs. hence my question that maybe we would need to publish these in the future like all other GK images.

Copy link
Contributor Author

@JaydipGabani JaydipGabani Apr 28, 2025

Choose a reason for hiding this comment

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

+1. I will raise a PR as follow up.

Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
@JaydipGabani JaydipGabani requested a review from ritazh April 28, 2025 21:04
Copy link
Member

@ritazh ritazh left a comment

Choose a reason for hiding this comment

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

LGTM

@JaydipGabani JaydipGabani merged commit 5cb924f into open-policy-agent:master May 6, 2025
25 checks passed
@JaydipGabani JaydipGabani deleted the disk-driver branch May 6, 2025 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants