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

Merged
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
5 changes: 3 additions & 2 deletions pkg/audit/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ func (am *Manager) addAuditResponsesToUpdateLists(
}

totalViolationsPerEnforcementAction[ea]++
logViolation(am.log, r.Constraint, ea, gvk, namespace, name, r.Msg, details)
logViolation(am.log, r.Constraint, ea, gvk, namespace, name, r.Msg, details, r.obj.GetLabels())
if *emitAuditEvents {
emitEvent(r.Constraint, timestamp, ea, gvk, namespace, name, r.Msg, am.gkNamespace, am.eventRecorder)
}
Expand Down Expand Up @@ -1012,7 +1012,7 @@ func logConstraint(l logr.Logger, gvknn *util.KindVersionName, enforcementAction

func logViolation(l logr.Logger,
constraint *unstructured.Unstructured,
enforcementAction util.EnforcementAction, resourceGroupVersionKind schema.GroupVersionKind, rnamespace, rname, message string, details interface{},
enforcementAction util.EnforcementAction, resourceGroupVersionKind schema.GroupVersionKind, rnamespace, rname, message string, details interface{}, rlabels map[string]string,
) {
l.Info(
message,
Expand All @@ -1029,6 +1029,7 @@ func logViolation(l logr.Logger,
logging.ResourceKind, resourceGroupVersionKind.Kind,
logging.ResourceNamespace, rnamespace,
logging.ResourceName, rname,
logging.ResourceLabels, rlabels,
)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
ConstraintViolations = "constraint_violations"
ResourceGroup = "resource_group"
ResourceKind = "resource_kind"
ResourceLabels = "resource_labels"
davis-haba marked this conversation as resolved.
Show resolved Hide resolved
ResourceAPIVersion = "resource_api_version"
ResourceNamespace = "resource_namespace"
ResourceName = "resource_name"
Expand Down
4 changes: 4 additions & 0 deletions website/docs/audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ The audit pod emits JSON-formatted audit logs to stdout. The following is an exa
"resource_kind": "Pod",
"resource_namespace": "kube-system",
"resource_name": "kube-scheduler-kind-control-plane"
"resource_labels": {
"env": "prod",
"my-app-system": "true"
}
}
```

Expand Down