Skip to content

Kubernetes audit logs: improve field mapping - #3414

Merged
tetianakravchenko merged 7 commits into
elastic:mainfrom
tetianakravchenko:kubernetes_audit_logs
Jun 13, 2022
Merged

Kubernetes audit logs: improve field mapping#3414
tetianakravchenko merged 7 commits into
elastic:mainfrom
tetianakravchenko:kubernetes_audit_logs

Conversation

@tetianakravchenko

@tetianakravchenko tetianakravchenko commented May 23, 2022

Copy link
Copy Markdown
Contributor

Signed-off-by: Tetiana Kravchenko tetiana.kravchenko@elastic.co

What does this PR do?

Audit logs are missing important fields, needed for security team to create detection rules.

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.

Author's Checklist

  • [ ]

How to test this PR locally

  1. Run the kind cluster with audit.policy, create audit-policy.yaml with:
apiVersion: audit.k8s.io/v1
kind: Policy
rules:
- level: RequestResponse

kind config:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: ClusterConfiguration
    apiServer:
        # enable auditing flags on the API server
        extraArgs:
          audit-log-path: /var/log/kubernetes/kube-apiserver-audit.log
          audit-policy-file: /etc/kubernetes/policies/audit-policy.yaml
        # mount new files / directories on the control plane
        extraVolumes:
          - name: audit-policies
            hostPath: /etc/kubernetes/policies
            mountPath: /etc/kubernetes/policies
            readOnly: true
            pathType: "DirectoryOrCreate"
          - name: "audit-logs"
            hostPath: "/var/log/kubernetes"
            mountPath: "/var/log/kubernetes"
            readOnly: false
            pathType: DirectoryOrCreate
  # mount the local file on the control plane
  extraMounts:
  - hostPath: ./audit-policy.yaml
    containerPath: /etc/kubernetes/policies/audit-policy.yaml
    readOnly: true

create cluster:

kind create cluster --config kind-config.yaml
  1. create stack:
cd  package/kubernetes
elastic-package build
elastic-package stack up -d -v --version 8.1.0-f479a40a-SNAPSHOT
  1. connect network:
docker network connect elastic-package-stack_default kind-control-plane
  1. Add kubernetes audit logs integration, for simplicity can be used a different log path, like /var/log/kubernetes/kube-apiserver-audit-1.log
  2. run, event below is used as an example
docker exec -it kind-control-plane bash
touch /var/log/kubernetes/kube-apiserver-audit-1.log
echo '{"annotations":{"authorization_k8s_io/decision":"allow","authorization_k8s_io/reason":""},"apiVersion":"audit.k8s.io/v1","auditID":"ad54d32c-9ed3-449f-9ea6-0e6665e58861","kind":"Event","level":"RequestResponse","objectRef":{"apiGroup":"rbac.authorization.k8s.io","apiVersion":"v1","name":"read-secrets-global","resource":"clusterrolebindings"},"requestObject":{"apiVersion":"rbac.authorization.k8s.io/v1","kind":"ClusterRoleBinding","metadata":{"name":"read-secrets-global"},"roleRef":{"apiGroup":"rbac.authorization.k8s.io","kind":"ClusterRole","name":"get-secrets-clusterrole"},"subjects":[{"kind":"ServiceAccount","name":"iammai-serviceaccount","namespace":"kube-public"}]},"requestReceivedTimestamp":"2022-05-20T21:09:03.480563Z","requestURI":"/apis/rbac.authorization.k8s.io/v1/clusterrolebindings?fieldManager=kubectl-create","responseObject":{"apiVersion":"rbac.authorization.k8s.io/v1","kind":"ClusterRoleBinding","metadata":{"creationTimestamp":"2022-05-20T21:09:03Z","managedFields":[{"apiVersion":"rbac.authorization.k8s.io/v1","fieldsType":"FieldsV1","fieldsV1":{"f:roleRef":{},"f:subjects":{}},"manager":"kubectl-create","operation":"Update","time":"2022-05-20T21:09:03Z"}],"name":"read-secrets-global","resourceVersion":"1888","uid":"325a14ed-f382-4dbc-99ac-10e7af55d291"},"roleRef":{"apiGroup":"rbac.authorization.k8s.io","kind":"ClusterRole","name":"get-secrets-clusterrole"},"subjects":[{"kind":"ServiceAccount","name":"iammai-serviceaccount","namespace":"kube-public"}]},"responseStatus":{"code":201,"metadata":{}},"sourceIPs":["172.18.0.5"],"stage":"ResponseComplete","stageTimestamp":"2022-05-20T21:09:03.482953Z","user":{"groups":["system:masters","system:authenticated"],"username":"system:admin"},"userAgent":"kubectl1.22.7/v1.22.7 (linux/amd64) kubernetes/b56e432","verb":"create"}' >> /var/log/kubernetes/kube-apiserver-audit-1.log

Related issues

Screenshots

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
@elasticmachine

elasticmachine commented May 23, 2022

Copy link
Copy Markdown

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-06-08T16:25:03.985+0000

  • Duration: 31 min 13 sec

Test stats 🧪

Test Results
Failed 0
Passed 116
Skipped 0
Total 116

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@imays11 imays11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey, great work. A few things I noticed:

Missing field:
requestObject.spec.containers.securityContext.runasuser
type: integer

These fields should be nested under spec., not spec.container. :

  • requestObject.spec.HostNetwork
  • requestObject.spec.HostIPC
  • requestObject.spec.HostPID

These may need to be flattened so that I can search on the whole object (hope I'm understanding flattened correctly):

  • requestObject.spec.volumes.hostPath.path
  • responseObject.spec.volumes.hostPath.path

These may need to be nested objects instead of arrays so that I can search for specific 'resources' that are attached to 'verbs'; I'm not sure how best to do this though. Can we flatten the fields first and then link them together? I'm not sure if that's an option but maybe we can use the rules.apiGroup field as the link between each rules.resources and rules.verbs pairing? I would want to be able to search for something like requestObject.rules.resources: pods/exec and requestObject.rules.verbs: create but would only want a hit back if those two groups were linked to the same rules.apiGroup. Because it's possible to have the rules.verb: create but it's attached to a different group of resources like "cronjobs" under a different apiGroups.

requestObject.rules.resources
requestObject.rules.verbs
responseObject.rules.resources
responseObject.rules.verbs

      "kubernetes":{
        "audit":{
          "annotations":{
            "authorization_k8s_io/decision":"allow",
            "authorization_k8s_io/reason":"RBAC: allowed by ClusterRoleBinding \"system:controller:clusterrole-aggregation-controller\" of ClusterRole \"system:controller:clusterrole-aggregation-controller\" to ServiceAccount \"clusterrole-aggregation-controller/kube-system\""
          },
          "apiVersion":"audit.k8s.io/v1",
          "auditID":"492ef3d2-698a-4529-ada4-6ac0e3a9246e",
          "kind":"Event",
          "level":"RequestResponse",
          "objectRef":{
            "apiGroup":"rbac.authorization.k8s.io",
            "apiVersion":"v1",
            "name":"admin",
            "resource":"clusterroles"
          },
          "requestObject":{
            "apiVersion":"rbac.authorization.k8s.io/v1",
            "kind":"ClusterRole",
            "metadata":{
              "name":"admin"
            },
            "rules":[
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "pods/attach",
                  "pods/exec",
                  "pods/portforward",
                  "pods/proxy",
                  "secrets",
                  "services/proxy"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "serviceaccounts"
                ],
                "verbs":[
                  "impersonate"
                ]
              },
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "pods",
                  "pods/attach",
                  "pods/exec",
                  "pods/portforward",
                  "pods/proxy"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "configmaps",
                  "events",
                  "persistentvolumeclaims",
                  "replicationcontrollers",
                  "replicationcontrollers/scale",
                  "secrets",
                  "serviceaccounts",
                  "services",
                  "services/proxy"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "apps"
                ],
                "resources":[
                  "daemonsets",
                  "deployments",
                  "deployments/rollback",
                  "deployments/scale",
                  "replicasets",
                  "replicasets/scale",
                  "statefulsets",
                  "statefulsets/scale"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "autoscaling"
                ],
                "resources":[
                  "horizontalpodautoscalers"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "batch"
                ],
                "resources":[
                  "cronjobs",
                  "jobs"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "extensions"
                ],
                "resources":[
                  "daemonsets",
                  "deployments",
                  "deployments/rollback",
                  "deployments/scale",
                  "ingresses",
                  "networkpolicies",
                  "replicasets",
                  "replicasets/scale",
                  "replicationcontrollers/scale"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "policy"
                ],
                "resources":[
                  "poddisruptionbudgets"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "networking.k8s.io"
                ],
                "resources":[
                  "ingresses",
                  "networkpolicies"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "metrics.k8s.io"
                ],
                "resources":[
                  "pods",
                  "nodes"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "configmaps",
                  "endpoints",
                  "persistentvolumeclaims",
                  "persistentvolumeclaims/status",
                  "pods",
                  "replicationcontrollers",
                  "replicationcontrollers/scale",
                  "serviceaccounts",
                  "services",
                  "services/status"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "bindings",
                  "events",
                  "limitranges",
                  "namespaces/status",
                  "pods/log",
                  "pods/status",
                  "replicationcontrollers/status",
                  "resourcequotas",
                  "resourcequotas/status"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "namespaces"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "discovery.k8s.io"
                ],
                "resources":[
                  "endpointslices"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "apps"
                ],
                "resources":[
                  "controllerrevisions",
                  "daemonsets",
                  "daemonsets/status",
                  "deployments",
                  "deployments/scale",
                  "deployments/status",
                  "replicasets",
                  "replicasets/scale",
                  "replicasets/status",
                  "statefulsets",
                  "statefulsets/scale",
                  "statefulsets/status"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "autoscaling"
                ],
                "resources":[
                  "horizontalpodautoscalers",
                  "horizontalpodautoscalers/status"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "batch"
                ],
                "resources":[
                  "cronjobs",
                  "cronjobs/status",
                  "jobs",
                  "jobs/status"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "extensions"
                ],
                "resources":[
                  "daemonsets",
                  "daemonsets/status",
                  "deployments",
                  "deployments/scale",
                  "deployments/status",
                  "ingresses",
                  "ingresses/status",
                  "networkpolicies",
                  "replicasets",
                  "replicasets/scale",
                  "replicasets/status",
                  "replicationcontrollers/scale"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "policy"
                ],
                "resources":[
                  "poddisruptionbudgets",
                  "poddisruptionbudgets/status"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "networking.k8s.io"
                ],
                "resources":[
                  "ingresses",
                  "ingresses/status",
                  "networkpolicies"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "authorization.k8s.io"
                ],
                "resources":[
                  "localsubjectaccessreviews"
                ],
                "verbs":[
                  "create"
                ]
              },
              {
                "apiGroups":[
                  "rbac.authorization.k8s.io"
                ],
                "resources":[
                  "rolebindings",
                  "roles"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "get",
                  "list",
                  "patch",
                  "update",
                  "watch"
                ]
              }
            ]
          },
          "requestReceivedTimestamp":"2022-05-20T20:53:43.652860Z",
          "requestURI":"/apis/rbac.authorization.k8s.io/v1/clusterroles/admin?fieldManager=clusterrole-aggregation-controller\u0026force=true",
          "responseObject":{
            "aggregationRule":{
              "clusterRoleSelectors":[
                {
                  "matchLabels":{
                    "rbac.authorization.k8s.io/aggregate-to-admin":"true"
                  }
                }
              ]
            },
            "apiVersion":"rbac.authorization.k8s.io/v1",
            "kind":"ClusterRole",
            "metadata":{
              "annotations":{
                "rbac.authorization.kubernetes.io/autoupdate":"true"
              },
              "creationTimestamp":"2022-05-20T20:53:29Z",
              "labels":{
                "kubernetes.io/bootstrapping":"rbac-defaults"
              },
              "managedFields":[
                {
                  "apiVersion":"rbac.authorization.k8s.io/v1",
                  "fieldsType":"FieldsV1",
                  "fieldsV1":{
                    "f:rules":{
                      
                    }
                  },
                  "manager":"clusterrole-aggregation-controller",
                  "operation":"Apply",
                  "time":"2022-05-20T20:53:43Z"
                },
                {
                  "apiVersion":"rbac.authorization.k8s.io/v1",
                  "fieldsType":"FieldsV1",
                  "fieldsV1":{
                    "f:aggregationRule":{
                      ".":{
                        
                      },
                      "f:clusterRoleSelectors":{
                        
                      }
                    },
                    "f:metadata":{
                      "f:annotations":{
                        ".":{
                          
                        },
                        "f:rbac.authorization.kubernetes.io/autoupdate":{
                          
                        }
                      },
                      "f:labels":{
                        ".":{
                          
                        },
                        "f:kubernetes.io/bootstrapping":{
                          
                        }
                      }
                    }
                  },
                  "manager":"k3s",
                  "operation":"Update",
                  "time":"2022-05-20T20:53:29Z"
                }
              ],
              "name":"admin",
              "resourceVersion":"509",
              "uid":"ee78f4af-1057-454f-b0a3-d9d2e963162e"
            },
            "rules":[
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "pods/attach",
                  "pods/exec",
                  "pods/portforward",
                  "pods/proxy",
                  "secrets",
                  "services/proxy"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "serviceaccounts"
                ],
                "verbs":[
                  "impersonate"
                ]
              },
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "pods",
                  "pods/attach",
                  "pods/exec",
                  "pods/portforward",
                  "pods/proxy"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "configmaps",
                  "events",
                  "persistentvolumeclaims",
                  "replicationcontrollers",
                  "replicationcontrollers/scale",
                  "secrets",
                  "serviceaccounts",
                  "services",
                  "services/proxy"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "apps"
                ],
                "resources":[
                  "daemonsets",
                  "deployments",
                  "deployments/rollback",
                  "deployments/scale",
                  "replicasets",
                  "replicasets/scale",
                  "statefulsets",
                  "statefulsets/scale"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "autoscaling"
                ],
                "resources":[
                  "horizontalpodautoscalers"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "batch"
                ],
                "resources":[
                  "cronjobs",
                  "jobs"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "extensions"
                ],
                "resources":[
                  "daemonsets",
                  "deployments",
                  "deployments/rollback",
                  "deployments/scale",
                  "ingresses",
                  "networkpolicies",
                  "replicasets",
                  "replicasets/scale",
                  "replicationcontrollers/scale"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "policy"
                ],
                "resources":[
                  "poddisruptionbudgets"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "networking.k8s.io"
                ],
                "resources":[
                  "ingresses",
                  "networkpolicies"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "patch",
                  "update"
                ]
              },
              {
                "apiGroups":[
                  "metrics.k8s.io"
                ],
                "resources":[
                  "pods",
                  "nodes"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "configmaps",
                  "endpoints",
                  "persistentvolumeclaims",
                  "persistentvolumeclaims/status",
                  "pods",
                  "replicationcontrollers",
                  "replicationcontrollers/scale",
                  "serviceaccounts",
                  "services",
                  "services/status"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "bindings",
                  "events",
                  "limitranges",
                  "namespaces/status",
                  "pods/log",
                  "pods/status",
                  "replicationcontrollers/status",
                  "resourcequotas",
                  "resourcequotas/status"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  ""
                ],
                "resources":[
                  "namespaces"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "discovery.k8s.io"
                ],
                "resources":[
                  "endpointslices"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "apps"
                ],
                "resources":[
                  "controllerrevisions",
                  "daemonsets",
                  "daemonsets/status",
                  "deployments",
                  "deployments/scale",
                  "deployments/status",
                  "replicasets",
                  "replicasets/scale",
                  "replicasets/status",
                  "statefulsets",
                  "statefulsets/scale",
                  "statefulsets/status"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "autoscaling"
                ],
                "resources":[
                  "horizontalpodautoscalers",
                  "horizontalpodautoscalers/status"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "batch"
                ],
                "resources":[
                  "cronjobs",
                  "cronjobs/status",
                  "jobs",
                  "jobs/status"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "extensions"
                ],
                "resources":[
                  "daemonsets",
                  "daemonsets/status",
                  "deployments",
                  "deployments/scale",
                  "deployments/status",
                  "ingresses",
                  "ingresses/status",
                  "networkpolicies",
                  "replicasets",
                  "replicasets/scale",
                  "replicasets/status",
                  "replicationcontrollers/scale"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "policy"
                ],
                "resources":[
                  "poddisruptionbudgets",
                  "poddisruptionbudgets/status"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "networking.k8s.io"
                ],
                "resources":[
                  "ingresses",
                  "ingresses/status",
                  "networkpolicies"
                ],
                "verbs":[
                  "get",
                  "list",
                  "watch"
                ]
              },
              {
                "apiGroups":[
                  "authorization.k8s.io"
                ],
                "resources":[
                  "localsubjectaccessreviews"
                ],
                "verbs":[
                  "create"
                ]
              },
              {
                "apiGroups":[
                  "rbac.authorization.k8s.io"
                ],
                "resources":[
                  "rolebindings",
                  "roles"
                ],
                "verbs":[
                  "create",
                  "delete",
                  "deletecollection",
                  "get",
                  "list",
                  "patch",
                  "update",
                  "watch"
                ]
              }
            ]
          },
          "responseStatus":{
            "code":200,
            "metadata":{
              
            }
          },
          "sourceIPs":[
            "127.0.0.1"
          ],
          "stage":"ResponseComplete",
          "stageTimestamp":"2022-05-20T20:53:43.655728Z",
          "user":{
            "groups":[
              "system:serviceaccounts",
              "system:serviceaccounts:kube-system",
              "system:authenticated"
            ],
            "uid":"08f61082-e1cd-412d-8f2c-87fbd3d1f400",
            "username":"system:serviceaccount:kube-system:clusterrole-aggregation-controller"
          },
          "userAgent":"k3s/v1.22.7+k3s1 (linux/amd64) kubernetes/8432d7f/system:serviceaccount:kube-system:clusterrole-aggregation-controller",
          "verb":"patch"
        }
Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
@tetianakravchenko tetianakravchenko changed the title Audit logs: field mapping exception May 26, 2022
@tetianakravchenko
tetianakravchenko marked this pull request as ready for review May 26, 2022 11:37
@tetianakravchenko
tetianakravchenko requested a review from a team as a code owner May 26, 2022 11:37
Comment thread packages/kubernetes/data_stream/audit_logs/manifest.yml
Comment thread packages/kubernetes/data_stream/audit_logs/agent/stream/stream.yml.hbs Outdated
Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
@elasticmachine

elasticmachine commented May 26, 2022

Copy link
Copy Markdown

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (0/0) 💚
Files 100.0% (0/0) 💚 3.432
Classes 100.0% (0/0) 💚 3.432
Methods 94.872% (74/78) 👍 5.983
Lines 100.0% (0/0) 💚 10.242
Conditionals 100.0% (0/0) 💚
type: flattened
- name: rules
dynamic: true
type: nested

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@imays11 fyi, with query as on the screenshot, it seems to give the desired result:
Screenshot 2022-05-25 at 21 21 09

Screenshot 2022-05-25 at 21 21 32

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice! Question, what would happen if another resource group had the verb "list" but secrets did not. Would running that query still capture those results?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would running that query still capture those results?

No.
I have 2 documents, first with

"resources": [
                    "services",
                    "endpoints",
                    "secrets"
                ],
                "verbs": [
                    "get",
                    "list",
                    "watch"
                ]

second with (no list):

"resources": [
                    "services",
                    "endpoints",
                    "secrets"
                ],
                "verbs": [
                    "get",
                    "watch"
                ]

query kubernetes.audit.requestObject.rules:{ resources : "secrets" and verbs : "watch"} capture 2 documents:
Screenshot 2022-06-08 at 10 35 03
query kubernetes.audit.requestObject.rules:{ resources : "secrets" and verbs : "list"} gives only 1:
Screenshot 2022-06-08 at 10 37 00

Is it expected outcome for you?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes that is perfect! Thank you @tetianakravchenko

- name: volumeMounts
type: flattened
- name: volumes.hostPath
type: flattened

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@imays11 fyi:
Screenshot 2022-05-26 at 10 47 33
Screenshot 2022-05-26 at 10 47 50

the same situation is with volumeMounts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

type: integer
- name: volumeMounts
type: flattened
- name: volumes.hostPath

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is one level up in the original:

Is that correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it should be on the same level, I've changed the fields ordering to make it clear - f4b6798

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice thanks

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
…t.metadata -> kubernetes.audit.requestObject.metadata

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
@gizas
gizas self-requested a review June 9, 2022 07:06
@tetianakravchenko
tetianakravchenko merged commit 9e79299 into elastic:main Jun 13, 2022
orestisfl pushed a commit to orestisfl/integrations that referenced this pull request May 15, 2026
* add fields

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* drop metadata field; disable dynamic mapping

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* rerun elastic-package build

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* add pr number

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* change order of fields

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* adjust changelog description; fix typo kubernetes.audit.responseObject.metadata ->  kubernetes.audit.requestObject.metadata

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* run elastic-package format

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants