Skip to content

Commit

Permalink
PolicyReport: determine resource name also from ka.resp.name
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <[email protected]>
  • Loading branch information
fjogeleit authored and poiana committed Aug 29, 2022
1 parent 7aba0b4 commit f9be9de
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions outputs/policyreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ const (
skip wgpolicy.PolicyResult = "skip"

targetNS = "ka.target.namespace"
targetName = "ka.target.name"
targetResource = "ka.target.resource"
targetName = "ka.target.name"
responseName = "ka.resp.name"
)

var (
Expand Down Expand Up @@ -408,14 +409,19 @@ func mapSeverity(event types.FalcoPayload) wgpolicy.PolicyResultSeverity {
}

func mapResource(event types.FalcoPayload, ns string) []*corev1.ObjectReference {
name, ok := event.OutputFields[targetName]
if !ok {
name := determineResourceName(event.OutputFields)
if name != "" {
return nil
}

targetResource, ok := event.OutputFields[targetResource]
if !ok {
return nil
return []*corev1.ObjectReference{
{
Namespace: ns,
Name: toString(name),
},
}
}

resource, ok := resourceMapping[toString(targetResource)]
Expand All @@ -433,6 +439,15 @@ func mapResource(event types.FalcoPayload, ns string) []*corev1.ObjectReference
}
}

func determineResourceName(outputFields map[string]interface{}) string {
name, ok := outputFields[targetName]
if ok {
return toString(name)
}

return toString(outputFields[responseName])
}

func toString(value interface{}) string {
return fmt.Sprintf("%v", value)
}

0 comments on commit f9be9de

Please sign in to comment.