You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is useful to have a debug command to indentify which Kubernetes
Identity Aware policies should be applied on a specific container. An
example can be found here:
Create a pod with "app: ubuntu" and "usage: dev" labels.
$ cat << EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: ubuntu
labels:
app: ubuntu
usage: dev
spec:
containers:
- name: ubuntu
image: ubuntu:24.10
command: ["/bin/sleep", "3650d"]
imagePullPolicy: IfNotPresent
restartPolicy: Always
EOF
And apply several policies where some of them match while others don't.
$ cat << EOF | kubectl apply -f -
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: "lseek-podfilter-app"
spec:
podSelector:
matchLabels:
app: "ubuntu"
kprobes:
[...]
EOF
$ cat << EOF | kubectl apply -f -
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: "lseek-podfilter-usage"
spec:
podSelector:
matchLabels:
usage: "dev"
kprobes:
[...]
EOF
$ cat << EOF | kubectl apply -f -
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: "lseek-podfilter-prod"
spec:
podSelector:
matchLabels:
prod: "true"
kprobes:
[...]
EOF
$ cat << EOF | kubectl apply -f -
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: "lseek-podfilter-info"
spec:
podSelector:
matchLabels:
info: "broken"
kprobes:
[...]
EOF
$ cat << EOF | kubectl apply -f -
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: "lseek-podfilter-global"
spec:
kprobes:
[...]
EOF
Based on the labels we expect that policies lseek-podfilter-app and
lseek-podfilter-usage to match on that pod. lseek-podfilter-global is
not a Kubernetes Identity Aware policy so this will be applied in all
cases and we do not report that.
First step is to find the container ID that we care about.
$ kubectl describe pod/ubuntu | grep containerd
Container ID: containerd://ff433e9e16467787a60ac853d9b313150091968731f620776d6d7c514b1e8d6c
And then use it to report all Kubernetes Identity Aware policies that
match.
$ kubectl exec -it ds/tetragon -n kube-system -c tetragon -- tetra policyfilter -r "unix:///procRoot/1/root/run/containerd/containerd.sock" listpolicies ff433e9e16467787a60ac853d9b313150091968731f620776d6d7c514b1e8d6c
ID NAME STATE FILTERID NAMESPACE SENSORS KERNELMEMORY
5 lseek-podfilter-usage enabled 5 (global) generic_kprobe 1.72 MB
1 lseek-podfilter-app enabled 1 (global) generic_kprobe 1.72 MB
We also provide --debug flag to provide more details i.e.:
$ kubectl exec -it ds/tetragon -n kube-system -c tetragon -- tetra policyfilter -r "unix:///procRoot/1/root/run/containerd/containerd.sock" listpolicies ff433e9e16467787a60ac853d9b313150091968731f620776d6d7c514b1e8d6c --debug
time="2024-12-13T09:47:38Z" level=info msg=cgroup path=/run/tetragon/cgroup2/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-pod189a8053_9f36_4250_bcae_9ed167172920.slice/cri-containerd-ff433e9e16467787a60ac853d9b313150091968731f620776d6d7c514b1e8d6c.scope
time="2024-12-13T09:47:38Z" level=info msg=cgroup id=5695
time="2024-12-13T09:47:39Z" level=debug msg="resolved server address using info file" InitInfoFile=/var/run/tetragon/tetragon-info.json ServerAddress="localhost:54321"
ID NAME STATE FILTERID NAMESPACE SENSORS KERNELMEMORY
1 lseek-podfilter-app enabled 1 (global) generic_kprobe 1.72 MB
5 lseek-podfilter-usage enabled 5 (global) generic_kprobe 1.72 MB
This uses a reverse policy filter map that introduced in a previous
commit and maps cgroupIds to policyIds.
Signed-off-by: Anastasios Papagiannis <[email protected]>
0 commit comments