diff --git a/scripts/kubehound.bat b/scripts/kubehound.bat index dd1ee6c2..fe58de63 100644 --- a/scripts/kubehound.bat +++ b/scripts/kubehound.bat @@ -1,5 +1,7 @@ @echo off +REM Lightweight wrapper script to run KubeHound from a release archive + set KUBEHOUND_ENV=release set DOCKER_CMD=docker set DOCKER_COMPOSE_FILE_PATH=-f deployments\kubehound\docker-compose.yaml @@ -11,7 +13,7 @@ if not "%DD_API_KEY%"=="" ( set DOCKER_COMPOSE_PROFILE=--profile infra :run -REM TODO: run kubehound with config file + ./kubehound -c config.yaml goto :eof :backend-down @@ -28,9 +30,10 @@ goto :eof goto :eof :backend-reset-hard +call :backend-down %DOCKER_CMD% volume rm kubehound-%KUBEHOUND_ENV%_mongodb_data %DOCKER_CMD% volume rm kubehound-%KUBEHOUND_ENV%_janusgraph_data -call :backend-reset +call :backend-up goto :eof if "%1"=="" ( diff --git a/scripts/kubehound.sh b/scripts/kubehound.sh old mode 100644 new mode 100755 index b2cc6610..e27a854e --- a/scripts/kubehound.sh +++ b/scripts/kubehound.sh @@ -1,14 +1,24 @@ #!/bin/bash +# +# Lightweight wrapper script to run KubeHound from a release archive +# + +# Set the environment as the release environment KUBEHOUND_ENV="release" + +# Pull in the requisite compose files for the current setup DOCKER_COMPOSE_FILE_PATH="-f deployments/kubehound/docker-compose.yaml" DOCKER_COMPOSE_FILE_PATH+=" -f deployments/kubehound/docker-compose.release.yaml" if [ -n "${DD_API_KEY}" ]; then DOCKER_COMPOSE_FILE_PATH+=" -f deployments/kubehound/docker-compose.datadog.yaml" fi +# Set the environment variables for the compose DOCKER_COMPOSE_PROFILE="--profile infra" +DOCKER_HOSTNAME=$(hostname) +# Resolve the correct docker command for this environment (Linux requires sudo) UNAME_S=$(uname -s) if [ -z "${DOCKER_CMD}" ]; then if [ "${UNAME_S}" == "Linux" ]; then @@ -23,34 +33,36 @@ if [ -z "${DOCKER_CMD}" ]; then DOCKER_CMD="${DOCKER_CMD}" fi -DOCKER_HOSTNAME=$(hostname) -if [ -z "${CI}" ]; then - DOCKER_CMD="DOCKER_HOSTNAME=${DOCKER_HOSTNAME} ${DOCKER_CMD}" -fi - +# Run the kubehound binary run() { - # TODO run kubehound with config file + ./kubehound -c config.yaml } +# Shut down the kubehound backend backend_down() { ${DOCKER_CMD} compose ${DOCKER_COMPOSE_FILE_PATH} ${DOCKER_COMPOSE_PROFILE} rm -fvs } +# Bring up the kubehound backend backend_up() { ${DOCKER_CMD} compose ${DOCKER_COMPOSE_FILE_PATH} ${DOCKER_COMPOSE_PROFILE} up --force-recreate --build -d } +# Reset the kubehound backend backend_reset() { ${DOCKER_CMD} compose ${DOCKER_COMPOSE_FILE_PATH} ${DOCKER_COMPOSE_PROFILE} rm -fvs ${DOCKER_CMD} compose ${DOCKER_COMPOSE_FILE_PATH} ${DOCKER_COMPOSE_PROFILE} up --force-recreate --build -d } +# Reset the kubehound backend (WIPING ALL DATA) backend_reset_hard() { + backend_down ${DOCKER_CMD} volume rm kubehound-${KUBEHOUND_ENV}_mongodb_data ${DOCKER_CMD} volume rm kubehound-${KUBEHOUND_ENV}_janusgraph_data - backend_reset() + backend_up } +# Entrypoint case "$1" in run) run