{"id":37100910,"url":"https://github.com/vmware-archive/pid2pod","last_synced_at":"2026-01-14T12:16:45.416Z","repository":{"id":57490732,"uuid":"130415173","full_name":"vmware-archive/pid2pod","owner":"vmware-archive","description":"A small demo/experiment that shows how Linux process IDs (PIDs) can be mapped to Kubernetes pod metadata.","archived":true,"fork":false,"pushed_at":"2018-05-11T14:12:46.000Z","size":34,"stargazers_count":44,"open_issues_count":0,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-12-19T00:04:33.922Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vmware-archive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-20T21:23:40.000Z","updated_at":"2023-11-23T08:55:06.000Z","dependencies_parsed_at":"2022-08-29T20:31:45.936Z","dependency_job_id":null,"html_url":"https://github.com/vmware-archive/pid2pod","commit_stats":null,"previous_names":["heptiolabs/pid2pod"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vmware-archive/pid2pod","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-archive%2Fpid2pod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-archive%2Fpid2pod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-archive%2Fpid2pod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-archive%2Fpid2pod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vmware-archive","download_url":"https://codeload.github.com/vmware-archive/pid2pod/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-archive%2Fpid2pod/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28419867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T12:16:44.647Z","updated_at":"2026-01-14T12:16:45.402Z","avatar_url":"https://github.com/vmware-archive.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pid2pod\n\nThis is a small demo/experiment that shows how Linux process IDs (PIDs) can be mapped to Kubernetes pod metadata.\n\nIt works by looking up the target process's [cgroup] metadata in `/proc/$PID/cgroup`.\nThis metadata contains the names of each cgroup assigned to the process.\nIn the case of Docker containers created using the `docker` CLI or created by the kubelet, these cgroup names contain the Docker container ID.\nWe can map this container ID to a Kubernetes pod by doing a lookup against the local [kubelet API][kubelet-api].\n\nThanks to the [SPIRE] implementation of [SPIFFE], which inspired this method ([see `k8s.go`][spiffe-impl]).\n\n## Example Use Cases\n\n- You want to enrich [audit][go-audit] or other host-level events with pod-level metadata.\n\n- You want to control access to a UNIX domain socket based on [the calling pod][uds-pid-lookup].\n\n## Caveats\n\n- Not well tested.\n  Please use this as an example but don't run this in production.\n\n- Only works for the Docker runtime.\n  Other container runtimes may use a different scheme for cgroup names or may not even have workload PIDs visible from the host.\n\n- Assumes the kubelet read-only API (`--read-only-port`) is running on `http://localhost:10255/`.\n  We could add token/certificate authentication to move past this assumption.\n\n- Has some inherent race conditions since a lookup from PID to pod metadata takes some time.\n  The PID may correspond to a different process by the time the data is used.\n\n  This may be avoided in some scenarios.\n  For example, if you have a server holding an open UNIX domain socket you know the client has had the same PID for the whole connection.\n\n## Usage\n\nThe demo lists all processes on the system that it can map back to a pod.\nIt must be run in privileged mode, in the host PID namespace, and in the host network namespace.\n\n```console\n$ docker run --rm --privileged --pid=host --net=host pid2pod:latest\nPID 4549 (kube-proxy): \u0026pid2pod.ID{Namespace:\"kube-system\", PodName:\"kube-proxy-mdnzr\", PodUID:\"6344523c-44b7-11e8-b7fb-b2d1d7d0d428\", PodLabels:map[string]string{\"controller-revision-hash\":\"1193416634\", \"k8s-app\":\"kube-proxy\", \"pod-template-generation\":\"1\"}, ContainerID:\"7d6ca8ec4775491b941aeb9d55fe52fe14236575c26b395f36d0afa8717bdaae\", ContainerName:\"kube-proxy\"}\nPID 4992 (dashboard): \u0026pid2pod.ID{Namespace:\"kube-system\", PodName:\"kubernetes-dashboard-5498ccf677-xk55s\", PodUID:\"63fe5f9d-44b7-11e8-b7fb-b2d1d7d0d428\", PodLabels:map[string]string{\"addonmanager.kubernetes.io/mode\":\"Reconcile\", \"app\":\"kubernetes-dashboard\", \"pod-template-hash\":\"1054779233\", \"version\":\"v1.8.1\"}, ContainerID:\"3d23b4ffce2f10bbcc10ffee5acc5bdb2446e48c9253bb51405d65ece5bf0dd2\", ContainerName:\"kubernetes-dashboard\"}\nPID 5079 (kube-dns): \u0026pid2pod.ID{Namespace:\"kube-system\", PodName:\"kube-dns-86f4d74b45-qfs6f\", PodUID:\"634ab7a3-44b7-11e8-b7fb-b2d1d7d0d428\", PodLabels:map[string]string{\"k8s-app\":\"kube-dns\", \"pod-template-hash\":\"4290830601\"}, ContainerID:\"8ae06d9c2b923cad2a3fd8f1c5ebaad18483d6af369f968209cc940e7f501b1a\", ContainerName:\"kubedns\"}\nPID 5173 (storage-provisi): \u0026pid2pod.ID{Namespace:\"kube-system\", PodName:\"storage-provisioner\", PodUID:\"640b24b0-44b7-11e8-b7fb-b2d1d7d0d428\", PodLabels:map[string]string{\"addonmanager.kubernetes.io/mode\":\"Reconcile\", \"integration-test\":\"storage-provisioner\"}, ContainerID:\"f22bff5ee043e33d952df17f9cf6d79d8b8de3b82d565566b0bef49d2a4fa809\", ContainerName:\"storage-provisioner\"}\nPID 5291 (dnsmasq-nanny): \u0026pid2pod.ID{Namespace:\"kube-system\", PodName:\"kube-dns-86f4d74b45-qfs6f\", PodUID:\"634ab7a3-44b7-11e8-b7fb-b2d1d7d0d428\", PodLabels:map[string]string{\"k8s-app\":\"kube-dns\", \"pod-template-hash\":\"4290830601\"}, ContainerID:\"07567b209503648459d7e5bd5ef1e943355dc479ca68c629a30cc139810a95ae\", ContainerName:\"dnsmasq\"}\nPID 5339 (dnsmasq): \u0026pid2pod.ID{Namespace:\"kube-system\", PodName:\"kube-dns-86f4d74b45-qfs6f\", PodUID:\"634ab7a3-44b7-11e8-b7fb-b2d1d7d0d428\", PodLabels:map[string]string{\"k8s-app\":\"kube-dns\", \"pod-template-hash\":\"4290830601\"}, ContainerID:\"07567b209503648459d7e5bd5ef1e943355dc479ca68c629a30cc139810a95ae\", ContainerName:\"dnsmasq\"}\nPID 5378 (sidecar): \u0026pid2pod.ID{Namespace:\"kube-system\", PodName:\"kube-dns-86f4d74b45-qfs6f\", PodUID:\"634ab7a3-44b7-11e8-b7fb-b2d1d7d0d428\", PodLabels:map[string]string{\"k8s-app\":\"kube-dns\", \"pod-template-hash\":\"4290830601\"}, ContainerID:\"fa1685e9e27b95556313641bd6b4e7f3db7893a8dcb6d85f5cc369d895be17db\", ContainerName:\"sidecar\"}\nPID 16962 (sh): \u0026pid2pod.ID{Namespace:\"default\", PodName:\"testcli-5b8d779dfd-vpwkw\", PodUID:\"a8c810f7-44d3-11e8-b7fb-b2d1d7d0d428\", PodLabels:map[string]string{\"pod-template-hash\":\"1648335898\", \"run\":\"testcli\"}, ContainerID:\"8fe33943cbef5cdc741b265cad4c061e6232ec6187b9e00e2c2e800df7fce4aa\", ContainerName:\"testcli\"}\n```\n\n[SPIFFE]: https://spiffe.io/\n[SPIRE]: https://github.com/spiffe/spire\n[cgroup]: https://en.wikipedia.org/wiki/Cgroups\n[kubelet-api]: https://stackoverflow.com/questions/35075195/is-there-api-documentation-for-kublet\n[spiffe-impl]: https://github.com/spiffe/spire/blob/719c696036a99c0cd918ff4747d5fd7f15c782e4/pkg/agent/plugin/workloadattestor/k8s/k8s.go#L61\n[go-audit]: https://github.com/slackhq/go-audit\n[uds-pid-lookup]: https://stackoverflow.com/questions/8104904/identify-program-that-connects-to-a-unix-domain-socket","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmware-archive%2Fpid2pod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvmware-archive%2Fpid2pod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmware-archive%2Fpid2pod/lists"}