Skip to content

Commit

Permalink
extend the output fields with talon specific fields, useful if the pa…
Browse files Browse the repository at this point in the history
…yload is forwarded to a third party like AWS Lambda (#195)

Signed-off-by: Thomas Labarussias <issif+github@gadz.org>
  • Loading branch information
Issif authored Mar 28, 2024
1 parent 3caadd2 commit 11682f4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
5 changes: 4 additions & 1 deletion actionners/actionners.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ func StartConsumer(eventsC <-chan string) {
metrics.IncreaseCounter(log)

for _, a := range i.GetActions() {
if err := runAction(i, a, event); err != nil && a.IgnoreErrors == falseStr {
e := new(events.Event)
*e = *event
i.ExtendOutputFields(e, a)
if err := runAction(i, a, e); err != nil && a.IgnoreErrors == falseStr {
break
}
if a.Continue == falseStr || a.Continue != trueStr && !GetDefaultActionners().FindActionner(a.GetActionner()).MustDefaultContinue() {
Expand Down
2 changes: 1 addition & 1 deletion internal/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func DecodeEvent(payload io.Reader) (*Event, error) {
}

if event.Source == "" {
event.Source = "syscalls"
event.Source = "syscall"
}

if event.TraceID == "" {
Expand Down
26 changes: 24 additions & 2 deletions internal/rules/rules.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rules

import (
"encoding/json"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -50,8 +51,9 @@ type outputfield struct {
}

const (
trueStr string = "true"
falseStr string = "false"
trueStr string = "true"
falseStr string = "false"
falcoTalonOutputField string = "falco-talon."
)

var rules *[]*Rule
Expand Down Expand Up @@ -527,3 +529,23 @@ func (rule *Rule) comparePriority(event *events.Event) bool {
}
return false
}

func (rule *Rule) ExtendOutputFields(event *events.Event, action *Action) {
event.OutputFields[falcoTalonOutputField+"rule"] = rule.Name
if rule.Continue != "" {
event.OutputFields[falcoTalonOutputField+"rule.continue"] = rule.Continue
}
if rule.DryRun != "" {
event.OutputFields[falcoTalonOutputField+"rule.dry_run"] = rule.DryRun
}
event.OutputFields[falcoTalonOutputField+"action"] = action.Name
if action.Continue != "" {
event.OutputFields[falcoTalonOutputField+"action.continue"] = action.Continue
}
if action.IgnoreErrors != "" {
event.OutputFields[falcoTalonOutputField+"action.ignore_errors"] = action.IgnoreErrors
}
j, _ := json.Marshal(action.Parameters)
event.OutputFields[falcoTalonOutputField+"action.parameters"] = string(j)
event.OutputFields[falcoTalonOutputField+"actionner"] = action.Actionner
}
32 changes: 15 additions & 17 deletions rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
aws_lambda_alias_or_version: $LATEST
aws_lambda_invocation_type: RequestResponse



- rule: Suspicious outbound connection
match:
rules:
Expand All @@ -41,22 +39,22 @@
actions:
- action: Labelize Pod as Suspicious

- rule: Test invoke lambda
match:
rules:
- Test invoke lambda
actions:
- action: Invoke Lambda function
# - rule: Test invoke lambda
# match:
# rules:
# - Test invoke lambda
# actions:
# - action: Invoke Lambda function

- rule: Delete unknown namespace
match:
rules:
- K8s Namespace Created
output_fields:
- ka.target.namespace=todelete
actions:
- action: Delete the namespace
actionner: kubernetes:delete
# - rule: Delete unknown namespace
# match:
# rules:
# - K8s Namespace Created
# output_fields:
# - ka.target.namespace=todelete
# actions:
# - action: Delete the namespace
# actionner: kubernetes:delete

- rule: Calico netpol
match:
Expand Down

0 comments on commit 11682f4

Please sign in to comment.