forked from SpecterOps/BloodHound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
193 lines (157 loc) · 8.09 KB
/
justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
_default:
@just --list --unsorted
golangci-lint-version := "v1.53.3"
host_os := if os() == "macos" { "darwin" } else { os() }
host_arch := if arch() == "x86" { "386" } else { if arch() == "x86_64" { "amd64" } else { if arch() == "aarch64" { "arm64" } else { arch() } } }
export CGO_ENABLED := "0"
export GOOS := env_var_or_default("GOOS", host_os)
export GOARCH := env_var_or_default("GOARCH", host_arch)
export INTEGRATION_CONFIG_PATH := env_var_or_default("INTEGRATION_CONFIG_PATH", absolute_path("./local-harnesses/integration.config.json"))
set positional-arguments
# Initialize your dev environment (use "just init clean" to reset your config files)
init wipe="":
#!/usr/bin/env bash
echo "Init BloodHound CE"
echo "Make local copies of configuration files"
if [[ -f "./local-harnesses/build.config.json" ]] && [[ "{{wipe}}" != "clean" ]]; then
echo "Not copying build.config.json since it already exists"
elif [[ -f "./local-harnesses/build.config.json" ]]; then
echo "Backing up build.config.json and resetting"
mv ./local-harnesses/build.config.json ./local-harnesses/build.config.json.bak
cp ./local-harnesses/build.config.json.template ./local-harnesses/build.config.json
else
cp ./local-harnesses/build.config.json.template ./local-harnesses/build.config.json
fi
if [[ -f "./local-harnesses/integration.config.json" ]] && [[ "{{wipe}}" != "clean" ]]; then
echo "Not copying integration.config.json since it already exists"
elif [[ -f "./local-harnesses/integration.config.json" ]]; then
echo "Backing up integration.config.json and resetting"
mv ./local-harnesses/integration.config.json ./local-harnesses/integration.config.json.bak
cp ./local-harnesses/integration.config.json.template ./local-harnesses/integration.config.json
else
cp ./local-harnesses/integration.config.json.template ./local-harnesses/integration.config.json
fi
if [[ -f "./.env" ]] && [[ "{{wipe}}" == "clean" ]]; then
echo "Backing up existing environment file"
mv ./.env ./.env.bak
fi
echo "Install additional Go tools"
go install github.com/golangci/golangci-lint/cmd/[email protected]
echo "Run modsync to ensure workspace is up to date"
just modsync
echo "Ensure containers have been rebuilt"
if [[ "{{wipe}}" != "clean" ]]; then
just bh-dev build
else
echo "Clear volumes and rebuild without cache"
just bh-clear-volumes
just bh-clean-docker-build
fi
echo "Start integration testing services"
if [[ "{{wipe}}" == "clean" ]]; then
echo "Clear volumes and restart testing services without cache"
just bh-testing-clear-volumes
just bh-testing build --no-cache
fi
echo "BloodHound CE Init Complete"
# Show available targets for this context.
show *FLAGS:
#!/usr/bin/env bash
set -euo pipefail
python3 packages/python/beagle/main.py show {{FLAGS}}
# Build a target. To list targets run 'just show'
build *FLAGS:
#!/usr/bin/env bash
set -euo pipefail
python3 packages/python/beagle/main.py build {{FLAGS}}
# Test a target. To list targets run 'just show'
test *FLAGS:
#!/usr/bin/env bash
set -euo pipefail
python3 packages/python/beagle/main.py test {{FLAGS}}
# sync modules in workspace
modsync:
@go run github.com/specterops/bloodhound/packages/go/stbernard modsync
# updates favicon.ico, logo192.png and logo512.png from logo.svg
update-favicon:
@just imagemagick convert -background none ./cmd/ui/public/logo-light.svg -define icon:auto-resize ./cmd/ui/public/favicon-light.ico
@just imagemagick convert -background none -size 192x192 cmd/ui/public/logo-light.svg cmd/ui/public/logo-light192.png
@just imagemagick convert -background none -size 512x512 cmd/ui/public/logo-light.svg cmd/ui/public/logo-light512.png
@just imagemagick convert -background none ./cmd/ui/public/logo-dark.svg -define icon:auto-resize ./cmd/ui/public/favicon-dark.ico
@just imagemagick convert -background none -size 192x192 cmd/ui/public/logo-dark.svg cmd/ui/public/logo-dark192.png
@just imagemagick convert -background none -size 512x512 cmd/ui/public/logo-dark.svg cmd/ui/public/logo-dark512.png
# run go commands in the context of the api project
go *ARGS:
@cd cmd/api/src && GODEBUG=cgocheck=2 go {{ARGS}}
# run yarn commands in the context of the workspace root
yarn-local *ARGS="":
@yarn {{ARGS}}
# run yarn commands in the context of the workspace root and rebuild containers
yarn *ARGS="": && (bh-dev "build bh-ui")
@yarn {{ARGS}}
build-js-client *ARGS="":
@cd packages/javascript/js-client-library && yarn build
build-shared-ui *ARGS="":
@cd packages/javascript/bh-shared-ui && yarn build
# run the code generation from the cue schema
schemagen: yarn-local && check-license (yarn "format")
go run github.com/specterops/bloodhound/schemagen
# run imagemagick commands in the context of the project root
imagemagick *ARGS:
@docker run -it --rm -v {{justfile_directory()}}:/workdir -w /workdir --entrypoint magick cblunt/imagemagick {{ARGS}}
# run git pruning on merged branches to clean up local workspace (run with `nuclear` to clean up orphaned branches)
prune-my-branches nuclear='no':
#!/usr/bin/env bash
git branch --merged| egrep -v "(^\*|master|main|dev)" | xargs git branch -d
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git remote prune origin
if [ "{{nuclear}}" == 'nuclear' ]; then
echo Switching to main to remove orphans
git switch main
git branch -vv | grep ': gone]' | grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -D
git switch -
fi
echo "Remaining Git Branches:"
git --no-pager branch
# run linting for all Go modules
go-lint:
#!/usr/bin/env bash
echo 'ensuring golangci-lint@{{golangci-lint-version}} is installed'
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@{{golangci-lint-version}}
echo 'running golangci-lint on all detected modules in your go.work'
# grab all the module locations from go.work and run golangci-lint on each
golangci-lint run $(cat go.work | { cat | grep -E '\./' | awk 'NF{print $0 "/..."}'; } | tr '\n' ' ')
echo 'done'
# run docker compose commands for the BH dev profile (Default: up)
bh-dev *ARGS='up':
@docker compose --profile dev -f docker-compose.dev.yml {{ARGS}}
# run docker compose commands for the BH debug profile (Default: up)
bh-debug *ARGS='up':
@docker compose --profile debug-api -f docker-compose.dev.yml {{ARGS}}
# run docker compose commands for the BH api-only profile (Default: up)
bh-api-only *ARGS='up':
@docker compose --profile api-only -f docker-compose.dev.yml {{ARGS}}
# run docker compose commands for the BH ui-only profile (Default: up)
bh-ui-only *ARGS='up':
@docker compose --profile ui-only -f docker-compose.dev.yml {{ARGS}}
# run docker compose commands for the BH testing databases (Default: up)
bh-testing *ARGS='up -d':
@docker compose --project-name bh-testing -f docker-compose.testing.yml {{ARGS}}
# clear BH testing volumes
bh-testing-clear-volumes *ARGS='':
@docker compose --project-name bh-testing -f docker-compose.testing.yml down -v {{ARGS}}
# clear BH docker compose volumes (pass --remove-orphans if troubleshooting)
bh-clear-volumes target='dev' *ARGS='':
@docker compose --profile {{target}} -f docker-compose.dev.yml down -v {{ARGS}}
# build BH target cleanly (default profile dev with --no-cache flag)
bh-clean-docker-build target='dev' *ARGS='':
@docker compose --profile {{target}} -f docker-compose.dev.yml build --no-cache {{ARGS}}
# build local BHCE container image (ex: just build-bhce-container <linux/arm64|linux/amd64> edge v5.0.0)
build-bhce-container platform='linux/amd64' tag='edge' version='v5.0.0' *ARGS='':
@docker buildx build -f dockerfiles/bloodhound.Dockerfile -t specterops/bloodhound:{{tag}} --platform={{platform}} --load --build-arg version={{version}}-{{tag}} {{ARGS}} .
# run local BHCE container image (ex: just build-bhce-container <linux/arm64|linux/amd64> custom v5.0.0)
run-bhce-container platform='linux/amd64' tag='custom' version='v5.0.0' *ARGS='':
@just build-bhce-container {{platform}} {{tag}} {{version}} {{ARGS}}
@cd examples/docker-compose && BLOODHOUND_TAG={{tag}} docker compose up
check-license:
python3 license_check.py