google / cloud-forensics-utils

Python library to carry out DFIR analysis on the Cloud
Apache License 2.0
453 stars 89 forks source link

GKE log query strings for k8s_cluster/k8s_container #405

Closed zkck closed 2 years ago

zkck commented 2 years ago

Example script:

from libcloudforensics.providers.gcp.internal import gke

cluster = gke.GkeCluster('project-id', 'us-central1-f', 'cluster-id')

print(cluster.ClusterLogsQuery())
print()
print(cluster.ContainerLogsQuery())
print()

workloads = [
    cluster.GetPod('nginx-pod', 'default'),
    cluster.GetDeployment('nginx', 'default'),
    cluster.GetReplicaSet('nginx-replicaset', 'default'),
]

for workload in workloads:
  print(type(workload))
  print()
  print(cluster.ContainerLogsQuery(workload))
  print()
  print(cluster.ClusterLogsQuery(workload))
  print()

Output:

resource.type="k8s_cluster"
resource.labels.project_id="project-id"
resource.labels.cluster_name="cluster-id"
resource.labels.location="us-central1-f"

resource.type="k8s_container"
resource.labels.project_id="project-id"
resource.labels.cluster_name="cluster-id"
resource.labels.location="us-central1-f"

<class 'libcloudforensics.providers.kubernetes.base.K8sPod'>

resource.type="k8s_container"
resource.labels.project_id="project-id"
resource.labels.cluster_name="cluster-id"
resource.labels.location="us-central1-f"
resource.labels.namespace_name="default"
resource.labels.pod_name="nginx-pod"

resource.type="k8s_cluster"
resource.labels.project_id="project-id"
resource.labels.cluster_name="cluster-id"
resource.labels.location="us-central1-f"
protoPayload.resourceName=~"\bnginx-pod$"
protoPayload.methodName:"pods."

<class 'libcloudforensics.providers.kubernetes.workloads.K8sDeployment'>

resource.type="k8s_container"
resource.labels.project_id="project-id"
resource.labels.cluster_name="cluster-id"
resource.labels.location="us-central1-f"
resource.labels.namespace_name="default"
labels.k8s-pod/app="nginx"

resource.type="k8s_cluster"
resource.labels.project_id="project-id"
resource.labels.cluster_name="cluster-id"
resource.labels.location="us-central1-f"
protoPayload.resourceName=~"\bnginx$"
protoPayload.methodName:"deployments."

<class 'libcloudforensics.providers.kubernetes.workloads.K8sReplicaSet'>

resource.type="k8s_container"
resource.labels.project_id="project-id"
resource.labels.cluster_name="cluster-id"
resource.labels.location="us-central1-f"
resource.labels.namespace_name="default"
labels.k8s-pod/app="nginx"
labels.k8s-pod/pod-template-hash="<HASH>"

resource.type="k8s_cluster"
resource.labels.project_id="project-id"
resource.labels.cluster_name="cluster-id"
resource.labels.location="us-central1-f"
protoPayload.resourceName=~"\bnginx-replicaset$"
protoPayload.methodName:"replicasets."
codecov-commenter commented 2 years ago

Codecov Report

:exclamation: No coverage uploaded for pull request base (main@11af9ed). Click here to learn what that means. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #405   +/-   ##
=======================================
  Coverage        ?   57.82%           
=======================================
  Files           ?       48           
  Lines           ?     3801           
  Branches        ?        0           
=======================================
  Hits            ?     2198           
  Misses          ?     1603           
  Partials        ?        0           
Flag Coverage Δ
nosetests 57.82% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 11af9ed...2568577. Read the comment docs.