From ab63a13b728c718ec673ee77ebc1debfd72da3a7 Mon Sep 17 00:00:00 2001 From: Sanja Kosier Date: Mon, 20 May 2024 16:30:50 +0200 Subject: [PATCH] feat(plugins/k8saudit): extract pod name Signed-off-by: Sanja Kosier --- plugins/k8saudit/pkg/k8saudit/extract.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/k8saudit/pkg/k8saudit/extract.go b/plugins/k8saudit/pkg/k8saudit/extract.go index 46400721..945efa08 100644 --- a/plugins/k8saudit/pkg/k8saudit/extract.go +++ b/plugins/k8saudit/pkg/k8saudit/extract.go @@ -172,6 +172,15 @@ func (e *Plugin) ExtractFromJSON(req sdk.ExtractRequest, jsonValue *fastjson.Val return e.extractFromKeys(req, jsonValue, "objectRef", "resource") case "ka.target.subresource": return e.extractFromKeys(req, jsonValue, "objectRef", "subresource") + case "ka.target.pod.name": + resource := string(jsonValue.Get("objectRef").Get("resource").GetStringBytes()) + if resource == "pods" { + subresource := string(jsonValue.Get("objectRef").Get("subresource").GetStringBytes()) + if subresource == "" { + // if pods; return pod name + return e.extractFromKeys(req, jsonValue, "responseObject", "metadata", "name") + } + } case "ka.req.binding.subjects": return e.extractFromKeys(req, jsonValue, "requestObject", "subjects") case "ka.req.binding.role":