[ASAP] Importing K8S objects to Neo4j using only Cypher
Mostly for fun, because I got lost on Neo4j’s docs for some reason, and also needed a quick graph visualisation+query of a complex OpenShift cluster, I tried to import K8s/OpenShift objects from the API to a Neo4j database. The goal was kind of to make a quick and dirty bloodhound for kubernetes, making a fully fledge replacement of KubeHound or IceKube was not in the cards.
Thanks to the apoc.load.json
and apoc.cypher.runFiles
functions, we can easily load a JSON resource (file and URL with auth bits) and execute some script while passing arguments to it. With this we can do a loop structure to factorize the cypher queries to import objects in a particular namespace.
This came together pretty quick (given that I’d never played with Cypher before): repo The most “annoying” thing to deal with in the input data is the optional arrays, possibly nested, so when in doubt apply this pattern.