MCPcopy Index your code
hub / github.com/DataDog/KubeHound

github.com/DataDog/KubeHound @v1.6.7

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.6.7 ↗ · + Follow
2,603 symbols 9,000 edges 364 files 952 documented · 37%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

KubeHound

KubeHound

A Kubernetes attack graph tool allowing automated calculation of attack paths between assets in a cluster.

Quick Start

Requirements

To run KubeHound, you need a couple dependencies + Docker >= 19.03 + Docker Compose V2

Install

From Release

Download binaries are available for Linux / Windows / Mac OS via the releases page or by running the following (Mac OS/Linux):

wget https://github.com/DataDog/KubeHound/releases/latest/download/kubehound-$(uname -o | sed 's/GNU\///g')-$(uname -m) -O kubehound
chmod +x kubehound

MacOS Notes

If downloading the releases via a browser you must run e.g xattr -d com.apple.quarantine kubehound before running to prevent MacOS blocking execution

With homebrew

KubeHound is available in homebrew-core and you can simply run

brew update && brew install kubehound

kubehound should now be in your path.

From source

If you wish to build KubeHound from source, you will need to checkout a tag before building

git clone https://github.com/DataDog/KubeHound.git
cd KubeHound
git checkout $(git describe --tags --abbrev=0)
make build

KubeHound binary will be output to ./bin/build/kubehound.

Run

Select a target Kubernetes cluster, either: * Using kubectx * Using specific kubeconfig file by exporting the env variable: export KUBECONFIG=/your/path/to/.kube/config

Then, simply run the kubehound binary:

# If you installed it from brew, it is in your path
kubehound

# If you installed it from release, it should be were you downloaded it
./kubehound

# If you installed it from source, it should be in the <repo_path>/bin/build folder
./bin/build/kubehound

For more advanced use case and configuration, see

Note: KubeHound can be deployed as a serivce (KHaaS), for more information.

Using KubeHound Data

To query the KubeHound graph data requires using the Gremlin query language via an API call or dedicated graph query UI. A number of fully featured graph query UIs are available (both commercial and open source), but we provide an accompanying Jupyter notebook based on the AWS Graph Notebook,to quickly showcase the capabilities of KubeHound. To access the UI:

  • Visit http://localhost:8888/notebooks/KubeHound.ipynb in your browser
  • Use the default password admin to login (note: this can be changed via the Dockerfile or by setting the NOTEBOOK_PASSWORD environment variable in the .env file)
  • Follow the initial setup instructions in the notebook to connect to the KubeHound graph and configure the rendering
  • Start running the queries and exploring the graph!

Example queries

We have documented a few sample queries to execute on the database in our documentation. A specific DSL has been developped to query the Graph for the most basic use cases (KubeHound DSL).

Sample Attack Path

Example Path

Sample Data

To view a sample graph demonstrating attacks in a very, very vulnerable cluster you can generate data via running the app against the provided kind cluster:

make sample-graph

To view the generated graph see the Using KubeHound Data section.

Query data from your scripts

If you expose the graph endpoint you can automate some queries to gather some KPI and metadata for instance.

Python

You can query the database data in your python script by using the following snippet:

#!/usr/bin/env python
import sys
from gremlin_python.driver.client import Client

KH_QUERY = "kh.containers().count()"
c = Client("ws://127.0.0.1:8182/gremlin", "kh")
results = c.submit(KH_QUERY).all().result()

You'll need to install gremlinpython as a dependency via: pip install gremlinpython

Further information

Acknowledgements

KubeHound was created by the Adversary Simulation Engineering (ASE) team at Datadog:

With additional support from:

We would also like to acknowledge the BloodHound team for pioneering the use of graph theory in offensive security and inspiring us to create this project.

Extension points exported contracts — how you extend this code

Collection (Interface)
Collection provides a common abstraction of a SQL database table or a NoSQL object collection to work with the storedb p [17 …
pkg/kubehound/store/collections/collections.go
NodeIngestor (Interface)
NodeIngestor defines the interface to allow an ingestor to consume node inputs from a collector. go:generate mockery -- [4 …
pkg/collector/collector.go
DumperWriter (Interface)
The DumperWriter handle multiple types of writer (file, tar, ...) It is used to centralized all writes and therefore han [4 …
pkg/dump/writer/writer.go
Notifier (Interface)
(no doc) [6 implementers]
pkg/ingestor/notifier/notifier.go
UnwrapJoin (Interface)
Interface to unwrap joined errors.Join https://pkg.go.dev/errors#Join [1 implementers]
pkg/telemetry/log/fields.go
WorkerPool (Interface)
WorkerPool provides a worker pool for parallelised processing tasks. [1 implementers]
pkg/worker/pool.go
Renderer (Interface)
Renderer is the interface for rendering reports. [1 implementers]
exp/khaudit/internal/infrastructure/renderer/api.go
DynamicOption (FuncType)
DynamicOption is a functional option for configuring the dynamic config.
pkg/config/dynamic.go

Core symbols most depended-on inside this repo

Errorf
called by 536
pkg/telemetry/log/logger.go
Get
called by 206
pkg/kubehound/storage/cache/provider.go
Return
called by 184
pkg/kubehound/ingestor/pipeline/mocks/object_ingest.go
Run
called by 166
pkg/kubehound/ingestor/ingestor.go
Info
called by 121
pkg/telemetry/log/logger.go
String
called by 114
pkg/config/run_id.go
Error
called by 105
pkg/telemetry/log/logger.go
run
called by 90
exp/khaudit/main.go

Shape

Method 1,422
Function 644
Struct 437
Interface 51
TypeAlias 24
FuncType 16
Class 8
Enum 1

Languages

Go98%
Java1%
Python1%
TypeScript1%

Modules by API surface

pkg/collector/mockcollector/collector_client.go76 symbols
pkg/telemetry/log/fields.go74 symbols
pkg/telemetry/log/kv.go59 symbols
pkg/kubehound/graph/edge/mocks/edge.go58 symbols
pkg/kubehound/storage/graphdb/mocks/graph_provider.go52 symbols
pkg/kubehound/storage/storedb/mocks/store_provider.go46 symbols
pkg/collector/collector.go41 symbols
pkg/kubehound/storage/cache/mocks/cache_provider.go40 symbols
pkg/ingestor/api/grpc/pb/api.pb.go40 symbols
test/system/graph_edge_test.go37 symbols
pkg/dump/writer/mockwriter/writer.go34 symbols
pkg/kubehound/storage/cache/mocks/cache_reader.go28 symbols

Datastores touched

(mongodb)Database · 1 repos
testdbDatabase · 1 repos

For agents

$ claude mcp add KubeHound \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page