Skip to content

Commit

Permalink
change the GetPodName/Namespace method to use k8s_audit source
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Labarussias <issif+github@gadz.org>
  • Loading branch information
Issif authored and poiana committed Jan 21, 2025
1 parent 8e08a8f commit 53c4519
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 25 deletions.
8 changes: 4 additions & 4 deletions actionners/cilium/networkpolicy/networkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ rules:
actionner: cilium:networkpolicy
parameters:
allow_cidr:
- "192.168.1.0/24"
- "172.17.0.0/16"
- "192.168.1.0/24"
- "172.17.0.0/16"
allow_namespaces:
- "green-ns"
- "blue-ns"
- "green-ns"
- "blue-ns"
`
)

Expand Down
6 changes: 3 additions & 3 deletions actionners/gcp/function/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ const (
AllowOutput bool = false
RequireOutput bool = false
Permissions string = `{
"cloudfunctions.functions.get",
"cloudfunctions.functions.invoke"
"cloudfunctions.functions.get",
"cloudfunctions.functions.invoke"
}`
Example string = `- action: Invoke GCP Cloud Function
actionner: gcp:function
parameters:
gcp_function_name: sample-function
gcp_function_location: us-central1
gcp_function_timeout: 10
`
`
)

var (
Expand Down
2 changes: 1 addition & 1 deletion actionners/kubernetes/annotation/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
Name string = "annotation"
Category string = "kubernetes"
Description string = "Add, modify or delete the annotations of the pod/node"
Source string = "syscalls"
Source string = "syscalls, k8s_audit"
Continue bool = true
UseContext bool = false
AllowOutput bool = false
Expand Down
2 changes: 1 addition & 1 deletion actionners/kubernetes/cordon/cordon.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
Name string = "cordon"
Category string = "kubernetes"
Description string = "Cordon a node"
Source string = "syscalls"
Source string = "syscalls, k8s_audit"
Continue bool = true
UseContext bool = false
AllowOutput bool = false
Expand Down
2 changes: 1 addition & 1 deletion actionners/kubernetes/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
Name string = "delete"
Category string = "kubernetes"
Description string = "Delete a resource"
Source string = "k8saudit"
Source string = "k8s_audit"
Continue bool = false
UseContext bool = false
AllowOutput bool = false
Expand Down
4 changes: 2 additions & 2 deletions actionners/kubernetes/drain/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
const (
Name string = "drain"
Category string = "kubernetes"
Description string = "Drain a pod"
Source string = "syscalls"
Description string = "Drain a node"
Source string = "syscalls, k8s_audit"
Continue bool = true
UseContext bool = false
AllowOutput bool = false
Expand Down
2 changes: 1 addition & 1 deletion actionners/kubernetes/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
Name string = "exec"
Category string = "kubernetes"
Description string = "Exec a command in a pod"
Source string = "syscalls"
Source string = "syscalls, k8s_audit"
Continue bool = true
UseContext bool = true
AllowOutput bool = false
Expand Down
2 changes: 1 addition & 1 deletion actionners/kubernetes/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
Name string = "label"
Category string = "kubernetes"
Description string = "Add, modify or delete the labels of the pod/node"
Source string = "syscalls"
Source string = "syscalls, k8s_audit"
Continue bool = true
UseContext bool = false
AllowOutput bool = false
Expand Down
2 changes: 1 addition & 1 deletion actionners/kubernetes/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
Name string = "log"
Category string = "kubernetes"
Description string = "Get logs from a pod"
Source string = "syscalls"
Source string = "syscalls, k8s_audit"
Continue bool = true
UseContext bool = false
AllowOutput bool = true
Expand Down
2 changes: 1 addition & 1 deletion actionners/kubernetes/script/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
Name string = "script"
Category string = "kubernetes"
Description string = "Run a script in a pod"
Source string = "syscalls"
Source string = "syscalls, k8s_audit"
Continue bool = true
UseContext bool = true
AllowOutput bool = false
Expand Down
10 changes: 1 addition & 9 deletions actionners/kubernetes/sysdig/sysdig.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
Name string = "sysdig"
Category string = "kubernetes"
Description string = "Capture the syscalls packets in a pod"
Source string = "syscalls, k8saudit"
Source string = "syscalls, k8s_audit"
Continue bool = false
UseContext bool = false
AllowOutput bool = false
Expand Down Expand Up @@ -123,14 +123,6 @@ func (a Actionner) Parameters() models.Parameters {
}

func (a Actionner) Checks(event *events.Event, _ *rules.Action) error {
if event.Source == "k8s_audit" {
event.OutputFields["k8s.ns.name"] = event.OutputFields["ka.target.namespace"]
if event.OutputFields["ka.target.pod.name"] != "" {
event.OutputFields["k8s.pod.name"] = event.OutputFields["ka.target.pod.name"]
} else {
event.OutputFields["k8s.pod.name"] = event.OutputFields["ka.target.name"]
}
}
return k8sChecks.CheckPodExist(event)
}

Expand Down
9 changes: 9 additions & 0 deletions internal/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,22 @@ func (event *Event) GetPodName() string {
if event.OutputFields["k8s.pod.name"] != nil {
return event.OutputFields["k8s.pod.name"].(string)
}
if event.OutputFields["ka.target.pod.name"] != nil {
return event.OutputFields["ka.target.pod.name"].(string)
}
if event.OutputFields["ka.target.name"] != nil {
return event.OutputFields["ka.target.name"].(string)
}
return ""
}

func (event *Event) GetNamespaceName() string {
if event.OutputFields["k8s.ns.name"] != nil {
return event.OutputFields["k8s.ns.name"].(string)
}
if event.OutputFields["ka.target.namespace"] != nil {
return event.OutputFields["ka.target.namespace"].(string)
}
return ""
}

Expand Down

0 comments on commit 53c4519

Please sign in to comment.