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: log details on log denies #2813

Merged
merged 4 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
Mutator = "mutator"
DebugLevel = 2 // r.log.Debug(foo) == r.log.V(logging.DebugLevel).Info(foo)
ExecutionStats = "execution_stats"
ViolationMetadata = "violation_metadata"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be consistent with how audit handles the details field:

logging.Details, details,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I missed that! 🤦🏼

Deduping this comment with the audit logging. I figured that logging the details of the rego evaluations for every object for every audit run would be too noisy. At present, we only log details for a violation in audit so this should be consistent w the audit behavior now:

func logViolation(l logr.Logger,
constraint *unstructured.Unstructured,
enforcementAction util.EnforcementAction, resourceGroupVersionKind schema.GroupVersionKind, rnamespace, rname, message string, details interface{}, rlabels map[string]string,
) {
userConstraintAnnotations := constraint.GetAnnotations()
delete(userConstraintAnnotations, "kubectl.kubernetes.io/last-applied-configuration")
l.Info(
message,
logging.Details, details,
logging.EventType, "violation_audited",
logging.ConstraintGroup, constraint.GroupVersionKind().Group,
logging.ConstraintAPIVersion, constraint.GroupVersionKind().Version,
logging.ConstraintKind, constraint.GetKind(),
logging.ConstraintName, constraint.GetName(),
logging.ConstraintNamespace, constraint.GetNamespace(),
logging.ConstraintAction, enforcementAction,
logging.ConstraintAnnotations, userConstraintAnnotations,
logging.ResourceGroup, resourceGroupVersionKind.Group,
logging.ResourceAPIVersion, resourceGroupVersionKind.Version,
logging.ResourceKind, resourceGroupVersionKind.Kind,
logging.ResourceNamespace, rnamespace,
logging.ResourceName, rname,
logging.ResourceLabels, rlabels,
)
}

)

func LogStatsEntries(client *constraintclient.Client, logger logr.Logger, entries []*instrumentation.StatsEntry, msg string) {
Expand Down
1 change: 1 addition & 0 deletions pkg/webhook/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func (h *validationHandler) getValidationMessages(res []*rtypes.Result, req *adm
logging.ConstraintAPIVersion, r.Constraint.GroupVersionKind().Version,
logging.ConstraintKind, r.Constraint.GetKind(),
logging.ConstraintAction, r.EnforcementAction,
logging.ViolationMetadata, r.Metadata,
logging.ResourceGroup, req.AdmissionRequest.Kind.Group,
logging.ResourceAPIVersion, req.AdmissionRequest.Kind.Version,
logging.ResourceKind, req.AdmissionRequest.Kind.Kind,
Expand Down