Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
d0g0x01 committed Aug 11, 2023
1 parent e5fbf8e commit ae28c39
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
7 changes: 5 additions & 2 deletions scripts/kubehound.bat
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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"=="" (
Expand Down
26 changes: 19 additions & 7 deletions scripts/kubehound.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit ae28c39

Please sign in to comment.