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: add resource labels to audit logs #2354

Conversation

davis-haba
Copy link
Contributor

@davis-haba davis-haba commented Oct 21, 2022

Signed-off-by: davis-haba [email protected]

What this PR does / why we need it:

When logging violations, also log the labels of the violating resource

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 #1977

Special notes for your reviewer:

Example of violation with labels (note the new resource_labels key):

{
  "level": "info",
  "ts": 1666389653.6440504,
  "logger": "controller",
  "msg": "you must provide labels: {\"geo\"}",
  "process": "audit",
  "audit_id": "2022-10-21T22:00:52Z",
  "details": {
    "missing_labels": [
      "geo"
    ]
  },
  "event_type": "violation_audited",
  "constraint_group": "constraints.gatekeeper.sh",
  "constraint_api_version": "v1beta1",
  "constraint_kind": "K8sRequiredLabels",
  "constraint_name": "ns-must-have-geo",
  "constraint_namespace": "",
  "constraint_action": "deny",
  "resource_group": "",
  "resource_api_version": "v1",
  "resource_kind": "Namespace",
  "resource_namespace": "",
  "resource_name": "my-ns",
  "resource_labels": {  
    "env": "prod",
    "kubernetes.io/metadata.name": "my-ns",
    "status": "happy"
  }
}

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

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.

small nit, otherwise LGTM!
Thanks @davis-haba !

Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@davis-haba davis-haba force-pushed the add-labels-to-audit-log-issue-1977 branch from f4c3d02 to b2a9f43 Compare October 25, 2022 21:43
@codecov-commenter
Copy link

codecov-commenter commented Oct 25, 2022

Codecov Report

Base: 53.40% // Head: 53.25% // Decreases project coverage by -0.15% ⚠️

Coverage data is based on head (c6a01db) compared to base (1ead7a8).
Patch coverage: 0.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2354      +/-   ##
==========================================
- Coverage   53.40%   53.25%   -0.16%     
==========================================
  Files         116      116              
  Lines       10198    10199       +1     
==========================================
- Hits         5446     5431      -15     
- Misses       4336     4348      +12     
- Partials      416      420       +4     
Flag Coverage Δ
unittests 53.25% <0.00%> (-0.16%) ⬇️

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

Impacted Files Coverage Δ
pkg/audit/manager.go 0.00% <0.00%> (ø)
pkg/readiness/list.go 79.41% <0.00%> (-11.77%) ⬇️
...onstrainttemplate/constrainttemplate_controller.go 55.50% <0.00%> (-2.64%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@sozercan sozercan merged commit aaa94e3 into open-policy-agent:master Oct 25, 2022
@davis-haba davis-haba deleted the add-labels-to-audit-log-issue-1977 branch October 25, 2022 23:56
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.

Add labels and metadata in audit logs of resource against which audits run
5 participants