Skip to content

Commit

Permalink
[Kubehound] Jt-dd/fixes-logs-notebooks (#191)
Browse files Browse the repository at this point in the history
* fix logs config

* fix makefile

* fix notebooks

* revert
  • Loading branch information
jt-dd committed May 17, 2024
1 parent 96036fe commit 5597534
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 43 deletions.
42 changes: 21 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ HELP_MAKEFILE_LIST := $(MAKEFILE_LIST)
# Loading docker .env file if present
ifneq (,$(wildcard $(DOCKER_COMPOSE_ENV_FILE_PATH)))
include $(DOCKER_COMPOSE_ENV_FILE_PATH)
export
export
endif

# Loading docker .env file if present
ifneq (,$(wildcard $(DEV_ENV_FILE_PATH)))
include $(DEV_ENV_FILE_PATH)
export
export
endif

# Set default values if none of the above have set anything
Expand Down Expand Up @@ -55,24 +55,24 @@ endif
# if not we try again with sudo, and if that also fail we assume the docker setup is broken and cannot work
# so we abort
docker-check:
# exit early without error if custom docker cmd is provided
ifeq ("docker", ${DOCKER_CMD})
@echo "Using provided docker cmd: ${DOCKER_CMD}"
DOCKER_CMD := ${DOCKER_CMD}
else
ifeq ("docker", ${DOCKER_CMD})
@echo "Using provided docker cmd: ${DOCKER_CMD}"
DOCKER_CMD := ${DOCKER_CMD}
else

# exit early if docker is not found. No point in continuing
ifeq (, $(shell command -v docker))
$(error "Docker not found")
endif
ifeq (, $(shell command -v docker))
$(error "Docker not found")
endif

ifneq (, $(findstring Server Version,$(shell docker info)))
DOCKER_CMD := docker
else ifneq (, $(findstring Server Version,$(shell sudo docker info)))
DOCKER_CMD := sudo docker
else
$(error "We don't have the permission to run docker. Are you root or in the docker group?")
endif
endif
ifneq (, $(findstring Server Version,$(shell docker info)))
DOCKER_CMD := docker
else ifneq (, $(findstring Server Version,$(shell sudo docker info)))
DOCKER_CMD := sudo docker
else
$(error "We don't have the permission to run docker. Are you root or in the docker group?")
endif
endif


RACE_FLAG_SYSTEM_TEST := "-race"
Expand All @@ -82,7 +82,7 @@ endif

DOCKER_HOSTNAME := $(shell hostname)
ifneq (${CI},true)
DOCKER_CMD := DOCKER_HOSTNAME=$(DOCKER_HOSTNAME) $(DOCKER_CMD)
DOCKER_CMD := DOCKER_HOSTNAME=$(DOCKER_HOSTNAME) $(DOCKER_CMD)
endif

all: build
Expand Down Expand Up @@ -111,12 +111,12 @@ backend-up: | docker-check ## Spawn the kubehound stack
$(DOCKER_CMD) compose $(DOCKER_COMPOSE_FILE_PATH) $(DOCKER_COMPOSE_PROFILE) up --force-recreate --build -d

.PHONY: backend-reset
backend-reset: ## Restart the kubehound stack
backend-reset: | docker-check ## Restart the kubehound stack
$(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

.PHONY: backend-wipe
backend-wipe: # Wipe the persisted backend data
backend-wipe: | docker-check ## Wipe the persisted backend data
ifndef KUBEHOUND_ENV
$(error KUBEHOUND_ENV is undefined)
endif
Expand Down
2 changes: 1 addition & 1 deletion deployments/kubehound/notebook/BlueTeam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"source": [
"%%graph_notebook_config\n",
"{\n",
" \"host\": \"host.docker.internal\",\n",
" \"host\": \"kubegraph\",\n",
" \"port\": 8182,\n",
" \"ssl\": false,\n",
" \"gremlin\": {\n",
Expand Down
2 changes: 1 addition & 1 deletion deployments/kubehound/notebook/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ENV WORKING_DIR="/root"
ENV NOTEBOOK_DIR="${WORKING_DIR}/notebooks"
ENV NODE_VERSION=14.x
ENV GRAPH_NOTEBOOK_AUTH_MODE="DEFAULT"
ENV GRAPH_NOTEBOOK_HOST="localhost"
ENV GRAPH_NOTEBOOK_HOST="kubegraph"
ENV GRAPH_NOTEBOOK_PORT="8182"
ENV NOTEBOOK_PORT="8888"
ENV LAB_PORT="8889"
Expand Down
2 changes: 1 addition & 1 deletion deployments/kubehound/notebook/InsomniHackDemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"source": [
"%%graph_notebook_config\n",
"{\n",
" \"host\": \"host.docker.internal\",\n",
" \"host\": \"kubegraph\",\n",
" \"port\": 8182,\n",
" \"ssl\": false,\n",
" \"gremlin\": {\n",
Expand Down
2 changes: 1 addition & 1 deletion deployments/kubehound/notebook/KubeHound.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"source": [
"%%graph_notebook_config\n",
"{\n",
" \"host\": \"host.docker.internal\",\n",
" \"host\": \"kubegraph\",\n",
" \"port\": 8182,\n",
" \"ssl\": false,\n",
" \"gremlin\": {\n",
Expand Down
2 changes: 1 addition & 1 deletion deployments/kubehound/notebook/RedTeam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"source": [
"%%graph_notebook_config\n",
"{\n",
" \"host\": \"host.docker.internal\",\n",
" \"host\": \"kubegraph\",\n",
" \"port\": 8182,\n",
" \"ssl\": false,\n",
" \"gremlin\": {\n",
Expand Down
2 changes: 1 addition & 1 deletion deployments/kubehound/notebook/SecurityPosture.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"source": [
"%%graph_notebook_config\n",
"{\n",
" \"host\": \"host.docker.internal\",\n",
" \"host\": \"kubegraph\",\n",
" \"port\": 8182,\n",
" \"ssl\": false,\n",
" \"gremlin\": {\n",
Expand Down
2 changes: 1 addition & 1 deletion deployments/kubehound/notebook/shared/shared.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"source": [
"%%graph_notebook_config\n",
"{\n",
" \"host\": \"host.docker.internal\",\n",
" \"host\": \"kubegraph\",\n",
" \"port\": 8182,\n",
" \"ssl\": false,\n",
" \"gremlin\": {\n",
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
const (
DefaultProfilerPeriod time.Duration = 60 * time.Second
DefaultProfilerCPUDuration time.Duration = 15 * time.Second
DefaultTelemetryStatsdUrl = "127.0.0.1:8225"
DefaultTelemetryProfilerUrl = "127.0.0.1:8226"
DefaultTelemetryStatsdUrl = "" // 127.0.0.1:8225
DefaultTelemetryProfilerUrl = "" // 127.0.0.1:8226

TelemetryStatsdUrl = "telemetry.statsd.url"
TelemetryTracerUrl = "telemetry.tracer.url"
Expand Down
10 changes: 7 additions & 3 deletions pkg/telemetry/profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import (
)

func Initialize(cfg *config.KubehoundConfig) {
err := profiler.Start(
opts := []profiler.Option{
profiler.WithService(globals.DDServiceName),
profiler.WithEnv(globals.DDEnv),
profiler.WithVersion(config.BuildVersion),
profiler.WithAgentAddr(cfg.Telemetry.Tracer.URL),
profiler.WithProfileTypes(
profiler.CPUProfile,
profiler.HeapProfile,
Expand All @@ -28,7 +27,12 @@ func Initialize(cfg *config.KubehoundConfig) {
profiler.CPUDuration(cfg.Telemetry.Profiler.CPUDuration),
profiler.WithLogStartup(false),
profiler.WithTags(tag.GetBaseTags()...),
)
}
if cfg.Telemetry.Tracer.URL != "" {
opts = append(opts, profiler.WithAgentAddr(cfg.Telemetry.Tracer.URL))
}

err := profiler.Start(opts...)
if err != nil {
log.I.Errorf("start profiler: %v", err)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/telemetry/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ func init() {
func Setup(cfg *config.KubehoundConfig) error {
statsdURL := cfg.Telemetry.Statsd.URL
log.I.Infof("Using %s for statsd URL", statsdURL)
var err error
// In case we don't have a statsd url set, we just want to continue, but log that we aren't going to submit metrics.
if statsdURL == "" {
log.I.Warn("No metrics collector has been setup. All metrics submission are going to be NOOP.")

return nil
}
var err error
tags := tag.GetBaseTags()
for tk, tv := range cfg.Telemetry.Tags {
tags = append(tags, tag.MakeTag(tk, tv))
}

statsdClient, err = statsd.New(statsdURL,
statsd.WithTags(tags))
if err != nil {

// In case we don't have a statsd url set or DD_DOGSTATSD_URL env var, we just want to continue, but log that we aren't going to submit metrics.
if err != nil || statsdClient == nil {
log.I.Warn("No metrics collector has been setup. All metrics submission are going to be NOOPmmm.")
statsdClient = &NoopClient{}

return err
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/telemetry/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import (
)

func Initialize(cfg *config.KubehoundConfig) {
log.I.Infof("Using %s for tracer URL", cfg.Telemetry.Tracer.URL)

// Default options
opts := []tracer.StartOption{
tracer.WithEnv(globals.DDEnv),
tracer.WithService(globals.DDServiceName),
tracer.WithServiceVersion(config.BuildVersion),
tracer.WithAgentAddr(cfg.Telemetry.Tracer.URL),
tracer.WithLogStartup(false),
}
if cfg.Telemetry.Tracer.URL != "" {
log.I.Infof("Using %s for tracer URL", cfg.Telemetry.Tracer.URL)
opts = append(opts, tracer.WithAgentAddr(cfg.Telemetry.Tracer.URL))
}

// Add the base tags
for _, t := range tag.GetBaseTags() {
Expand Down

0 comments on commit 5597534

Please sign in to comment.