@mandateops/cli-linux-x64 0.0.0-stage → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +55 -0
- package/README.md +175 -2
- package/audit-lab/README.md +194 -0
- package/audit-lab/bin/mandateops +0 -0
- package/audit-lab/contracts/contact-plain-text.vectors.json +85 -0
- package/audit-lab/contracts/history-reading.md +185 -0
- package/audit-lab/contracts/history-reading.vectors.json +284 -0
- package/audit-lab/contracts/profiles.md +161 -0
- package/audit-lab/contracts/properties.md +512 -0
- package/audit-lab/contracts/sdk-config.md +155 -0
- package/audit-lab/contracts/system-under-test.md +385 -0
- package/audit-lab/contracts/test-provider.md +350 -0
- package/audit-lab/lab/compose.audit.yml +181 -0
- package/audit-lab/lab/config/fault-control.json +14 -0
- package/audit-lab/lab/examples/agents/Dockerfile +28 -0
- package/audit-lab/lab/examples/agents/codeloc.cjs +199 -0
- package/audit-lab/lab/examples/agents/load.cjs +9 -0
- package/audit-lab/lab/examples/agents/package-lock.json +2840 -0
- package/audit-lab/lab/examples/agents/package.json +9 -0
- package/audit-lab/lab/examples/agents/python/mandateops_codeloc.py +271 -0
- package/audit-lab/lab/examples/agents/python/sitecustomize.py +51 -0
- package/audit-lab/lab/examples/agents/requirements-python.txt +522 -0
- package/audit-lab/lab/examples/agents/telemetry-router.cjs +272 -0
- package/audit-lab/lab/examples/test-provider/.dockerignore +4 -0
- package/audit-lab/lab/examples/test-provider/Dockerfile +28 -0
- package/audit-lab/lab/examples/test-provider/bun.lock +405 -0
- package/audit-lab/lab/examples/test-provider/package.json +42 -0
- package/audit-lab/lab/examples/test-provider/src/amount.ts +32 -0
- package/audit-lab/lab/examples/test-provider/src/app.ts +538 -0
- package/audit-lab/lab/examples/test-provider/src/auth.ts +30 -0
- package/audit-lab/lab/examples/test-provider/src/barrier.ts +262 -0
- package/audit-lab/lab/examples/test-provider/src/codeloc.ts +27 -0
- package/audit-lab/lab/examples/test-provider/src/config.ts +311 -0
- package/audit-lab/lab/examples/test-provider/src/connect.ts +204 -0
- package/audit-lab/lab/examples/test-provider/src/declaration.ts +270 -0
- package/audit-lab/lab/examples/test-provider/src/declared.ts +198 -0
- package/audit-lab/lab/examples/test-provider/src/domain.ts +193 -0
- package/audit-lab/lab/examples/test-provider/src/egress.ts +396 -0
- package/audit-lab/lab/examples/test-provider/src/flow.ts +263 -0
- package/audit-lab/lab/examples/test-provider/src/gate.ts +301 -0
- package/audit-lab/lab/examples/test-provider/src/main.ts +31 -0
- package/audit-lab/lab/examples/test-provider/src/notify.ts +157 -0
- package/audit-lab/lab/examples/test-provider/src/owner.ts +60 -0
- package/audit-lab/lab/examples/test-provider/src/payment.ts +103 -0
- package/audit-lab/lab/examples/test-provider/src/profile.ts +417 -0
- package/audit-lab/lab/examples/test-provider/src/request.ts +201 -0
- package/audit-lab/lab/examples/test-provider/src/rows.ts +173 -0
- package/audit-lab/lab/examples/test-provider/src/schema.ts +114 -0
- package/audit-lab/lab/examples/test-provider/src/signature.ts +86 -0
- package/audit-lab/lab/examples/test-provider/src/staged.ts +318 -0
- package/audit-lab/lab/examples/test-provider/src/store.ts +432 -0
- package/audit-lab/lab/examples/test-provider/src/traffic.ts +50 -0
- package/audit-lab/lab/examples/test-provider/src/webauthn.d.ts +11 -0
- package/audit-lab/lab/examples/test-provider/src/wire.ts +153 -0
- package/audit-lab/lab/examples/test-provider/tsconfig.build.json +9 -0
- package/audit-lab/lab/examples/test-provider/tsconfig.json +24 -0
- package/audit-lab/lab/images/capture/Dockerfile +15 -0
- package/audit-lab/lab/images/capture/LICENSE +201 -0
- package/audit-lab/lab/images/fault-control/Dockerfile +13 -0
- package/audit-lab/lab/images/fault-control/LICENSE +21 -0
- package/audit-lab/lab/images/provider-store/Dockerfile +4 -0
- package/audit-lab/lab/images/provider-store/LICENSE +23 -0
- package/audit-lab/lab/images/telemetry/Dockerfile +14 -0
- package/audit-lab/lab/images/telemetry/LICENSE +201 -0
- package/audit-lab/lab/scripts/compose-down.sh +143 -0
- package/audit-lab/lab/scripts/compose-lib.sh +632 -0
- package/audit-lab/lab/scripts/compose-up.sh +240 -0
- package/package.json +16 -4
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Starts one isolated lab deployment and records its loopback ports and
|
|
3
|
+
# provenance. Any value that cannot be established fails the script, so a
|
|
4
|
+
# written ports.env or provenance.json is complete and valid.
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
# shellcheck source=scripts/compose-lib.sh
|
|
7
|
+
source "$(dirname "$0")/compose-lib.sh"
|
|
8
|
+
lab_run "$@"
|
|
9
|
+
# The provider signs its notifications with a secret of this deployment
|
|
10
|
+
# alone: generated here unless the host generated one for its session, held
|
|
11
|
+
# only in this environment and the two containers that use it, and redacted
|
|
12
|
+
# from every kept log.
|
|
13
|
+
if [[ -z "${MANDATEOPS_NOTIFY_SECRET:-}" ]]; then
|
|
14
|
+
MANDATEOPS_NOTIFY_SECRET="$(LC_ALL=C od -An -tx1 -N32 /dev/urandom | tr -d ' \n')"
|
|
15
|
+
export MANDATEOPS_NOTIFY_SECRET
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
# Before anything else: an occupied project is another run's, so this one
|
|
19
|
+
# leaves nothing behind and asks for nothing it could then be blamed for.
|
|
20
|
+
if [[ -n "$(lab_compose ps --all --quiet)$(sut_compose_named ps --all --quiet)" ]]; then
|
|
21
|
+
rm -f "$customer_env"
|
|
22
|
+
echo "project $project already has containers; run compose-down.sh $run_id $deployment first" >&2
|
|
23
|
+
exit "$occupied_exit_code"
|
|
24
|
+
fi
|
|
25
|
+
# Recovery finds the project here: the name depends on where runs live, and the
|
|
26
|
+
# directory can move.
|
|
27
|
+
printf '%s\n' "$project" > "$run_dir/project"
|
|
28
|
+
printf '%s\n' "$sut_project" > "$run_dir/customer-project"
|
|
29
|
+
lab_customer_project
|
|
30
|
+
lab_egress_setup || exit 1
|
|
31
|
+
lab_write_override
|
|
32
|
+
lab_write_limits "$limits_file" lab_compose > /dev/null
|
|
33
|
+
startup="${MANDATEOPS_STARTUP_TIMEOUT_S:-$default_startup_timeout_s}"
|
|
34
|
+
# A customer build runs arbitrary steps outside the internal network, so it
|
|
35
|
+
# finishes before any lab service exists for it to reach.
|
|
36
|
+
# --wait returns only once every healthcheck passes, or fails at the deadline.
|
|
37
|
+
# Docker's own refusals (a mount, a missing image, a name in use) say why a
|
|
38
|
+
# container never ran, which no container log can; Compose may wrap them, as
|
|
39
|
+
# for a network it could not create. They are kept beside
|
|
40
|
+
# compose.log, redacted of every lab secret, so the failure names them; when
|
|
41
|
+
# the secrets cannot be listed nothing is kept. stdout passes through fd 3.
|
|
42
|
+
startup_stderr="$run_dir/startup.stderr"
|
|
43
|
+
startup_errors="$run_dir/startup-errors.log"
|
|
44
|
+
rm -f "$startup_errors"
|
|
45
|
+
# Unredacted until the failure path filters it: readable by the owner alone.
|
|
46
|
+
(umask 077 && : > "$startup_stderr")
|
|
47
|
+
# With a prebuilt image source, images are tagged for this run, not built.
|
|
48
|
+
build_images=(sut_compose_run build)
|
|
49
|
+
lab_build=--build
|
|
50
|
+
build_phase="building your images"
|
|
51
|
+
if lab_image_source; then
|
|
52
|
+
build_images=(lab_tag_prebuilt)
|
|
53
|
+
lab_build=--no-build
|
|
54
|
+
build_phase="tagging prebuilt images for this run"
|
|
55
|
+
fi
|
|
56
|
+
lab_phase "$build_phase"
|
|
57
|
+
exec 3>&1
|
|
58
|
+
if ! { "${build_images[@]}" &&
|
|
59
|
+
lab_phase "starting the test provider and fault injector and waiting for their health checks" &&
|
|
60
|
+
lab_compose up --detach "$lab_build" --wait --wait-timeout "$startup" &&
|
|
61
|
+
lab_start_customer "$startup"; } 2>&1 >&3 | tee "$startup_stderr" >&2; then
|
|
62
|
+
if secret_values="$(lab_secret_values)"; then
|
|
63
|
+
{ grep -a 'Error response from daemon: ' "$startup_stderr" || true; } |
|
|
64
|
+
lab_redact "$secret_values" | head -c 8192 > "$startup_errors"
|
|
65
|
+
fi
|
|
66
|
+
unset secret_values
|
|
67
|
+
rm -f "$startup_stderr"
|
|
68
|
+
echo "deployment $project did not start; collect evidence with compose-down.sh $run_id $deployment" >&2
|
|
69
|
+
exit 1
|
|
70
|
+
fi
|
|
71
|
+
exec 3>&-
|
|
72
|
+
rm -f "$startup_stderr"
|
|
73
|
+
|
|
74
|
+
# Prints the loopback host port published for service $1, container port $2;
|
|
75
|
+
# fails unless Docker reports exactly 127.0.0.1:<1..65535>. Docker can answer
|
|
76
|
+
# "invalid IP:0" just after `up` while it publishes the mapping, so the read
|
|
77
|
+
# is retried for a bounded time; the port itself is never guessed.
|
|
78
|
+
published_port() {
|
|
79
|
+
local address="" port="" attempt
|
|
80
|
+
for ((attempt = 1; attempt <= ${MANDATEOPS_PORT_READS:-$default_port_reads}; attempt++)); do
|
|
81
|
+
address="$(lab_compose port "$1" "$2")" || address=""
|
|
82
|
+
port="${address#127.0.0.1:}"
|
|
83
|
+
if [[ "$address" == "127.0.0.1:$port" && "$port" =~ ^[1-9][0-9]{0,4}$ ]] && ((port <= 65535)); then
|
|
84
|
+
echo "$port"
|
|
85
|
+
return 0
|
|
86
|
+
fi
|
|
87
|
+
sleep "$port_read_interval_s"
|
|
88
|
+
done
|
|
89
|
+
echo "$1:$2 is not published on a loopback port after $attempt reads: '$address'" >&2
|
|
90
|
+
lab_compose ps --all >&2 || true
|
|
91
|
+
return 1
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
# Docker occasionally starts a container healthy with its requested mapping
|
|
95
|
+
# empty, and more reads never fill it: `inspect` shows the binding asked for and
|
|
96
|
+
# no port. No traffic has reached the lab yet, so that one service restarts
|
|
97
|
+
# once, and provenance names it.
|
|
98
|
+
restarted_for_ports="$run_dir/restarted-for-ports"
|
|
99
|
+
: > "$restarted_for_ports"
|
|
100
|
+
service_port() {
|
|
101
|
+
published_port "$1" "$2" && return 0
|
|
102
|
+
lab_compose restart "$1" >&2 || return 1
|
|
103
|
+
lab_compose up --detach --no-build --no-recreate --no-deps --wait \
|
|
104
|
+
--wait-timeout "$startup" "$1" >&2 || return 1
|
|
105
|
+
echo "$1" >> "$restarted_for_ports"
|
|
106
|
+
published_port "$1" "$2"
|
|
107
|
+
}
|
|
108
|
+
backend_port="$(service_port gate "$MANDATEOPS_GATE_INGRESS_CONTAINER_PORT")" || exit 1
|
|
109
|
+
provider_port="$(service_port provider "$MANDATEOPS_PROVIDER_CONTAINER_PORT")" || exit 1
|
|
110
|
+
toxiproxy_port="$(service_port mandateops-relay "$MANDATEOPS_FAULT_CONTROL_CONTAINER_PORT")" || exit 1
|
|
111
|
+
ports_file="$run_dir/ports.env"
|
|
112
|
+
printf 'MANDATEOPS_PROJECT=%s\nMANDATEOPS_BACKEND_ADAPTER=%s\nMANDATEOPS_BACKEND_PORT=%s\nMANDATEOPS_PROVIDER_PORT=%s\nMANDATEOPS_FAULT_CONTROL_PORT=%s\n' \
|
|
113
|
+
"$sut_project" "$MANDATEOPS_BACKEND_ADAPTER" "$backend_port" "$provider_port" "$toxiproxy_port" > "$ports_file.partial"
|
|
114
|
+
# The service the runner may kill and restart, when the deployment names one.
|
|
115
|
+
if [[ -n "${MANDATEOPS_PROCESS_SERVICE:-}" ]]; then
|
|
116
|
+
printf 'MANDATEOPS_PROCESS_SERVICE=%s\n' "$MANDATEOPS_PROCESS_SERVICE" >> "$ports_file.partial"
|
|
117
|
+
fi
|
|
118
|
+
# What the deployment declares about how to observe it, when it does.
|
|
119
|
+
for setting in MANDATEOPS_QUIESCENCE_MS MANDATEOPS_RETRY_DELAY_MS MANDATEOPS_WORKER_LEASE_MS MANDATEOPS_WORKER_DEADLINE_MS MANDATEOPS_DEFECT_STIMULUS MANDATEOPS_PROVIDER_MAPPING MANDATEOPS_REPLY_HOLD_LIMIT MANDATEOPS_REPLY_HOLD_MS MANDATEOPS_EGRESS_PINS MANDATEOPS_CONTROL_TIMEOUT_MS MANDATEOPS_PROCESS_TIMEOUT_MS; do
|
|
120
|
+
if [[ -n "${!setting:-}" ]]; then
|
|
121
|
+
printf '%s=%s\n' "$setting" "${!setting}" >> "$ports_file.partial"
|
|
122
|
+
fi
|
|
123
|
+
done
|
|
124
|
+
mv "$ports_file.partial" "$ports_file"
|
|
125
|
+
|
|
126
|
+
# Provenance: what this deployment ran. Every image ID comes from the
|
|
127
|
+
# project's containers themselves (`.Image`), the one source also behind
|
|
128
|
+
# containers.json; each container also records Compose's
|
|
129
|
+
# com.docker.compose.image label, whose value depends on the image store.
|
|
130
|
+
# Tags and registry digests come from Docker; toolchain versions and the
|
|
131
|
+
# source revision from the host. Every value is collected into a variable
|
|
132
|
+
# first, so a failed command stops the script instead of leaving a gap.
|
|
133
|
+
|
|
134
|
+
# Prints $1 as a JSON string; rejects control characters rather than
|
|
135
|
+
# escaping them, since no recorded value should contain one.
|
|
136
|
+
json_string() {
|
|
137
|
+
if [[ "$1" =~ [[:cntrl:]] ]]; then
|
|
138
|
+
echo "provenance: control character in value" >&2
|
|
139
|
+
return 1
|
|
140
|
+
fi
|
|
141
|
+
local value="${1//\\/\\\\}"
|
|
142
|
+
printf '"%s"' "${value//\"/\\\"}"
|
|
143
|
+
}
|
|
144
|
+
# Prints the first line of a host tool's version output as a JSON string,
|
|
145
|
+
# or "unavailable" when the tool is absent or fails.
|
|
146
|
+
tool_version() {
|
|
147
|
+
local output
|
|
148
|
+
output="$("$@" 2>/dev/null)" || output="unavailable"
|
|
149
|
+
json_string "${output%%$'\n'*}"
|
|
150
|
+
}
|
|
151
|
+
container_ids="$( (lab_compose ps --all --quiet && sut_compose_named ps --all --quiet) | sort)" || exit 1
|
|
152
|
+
[[ -n "$container_ids" ]] || {
|
|
153
|
+
echo "provenance: project $project lists no containers" >&2
|
|
154
|
+
exit 1
|
|
155
|
+
}
|
|
156
|
+
containers=""
|
|
157
|
+
for container_id in $container_ids; do
|
|
158
|
+
container="$(docker container inspect --format \
|
|
159
|
+
'{"service":{{json (index .Config.Labels "com.docker.compose.service")}},"image_reference":{{json .Config.Image}},"image_id":{{json .Image}},"compose_image_label":{{json (index .Config.Labels "com.docker.compose.image")}}}' \
|
|
160
|
+
"$container_id")" || exit 1
|
|
161
|
+
containers+="${containers:+,}$container"
|
|
162
|
+
done
|
|
163
|
+
# shellcheck disable=SC2086 # container IDs are hex words
|
|
164
|
+
image_ids="$(docker container inspect --format '{{.Image}}' $container_ids | sort -u)" || exit 1
|
|
165
|
+
images=""
|
|
166
|
+
# The identity is the container's own .Image, read with the container, so no
|
|
167
|
+
# tag is ever resolved again here. Every image the lab builds is held under
|
|
168
|
+
# this run's tag until teardown; a pulled image another run re-pulls can
|
|
169
|
+
# still leave the engine with no record under this ID, and then only its
|
|
170
|
+
# tags and digests are unknown (null), never its identity.
|
|
171
|
+
inspect_errors="$run_dir/image-inspect.stderr"
|
|
172
|
+
for image_id in $image_ids; do
|
|
173
|
+
if ! image="$(docker image inspect --format \
|
|
174
|
+
'{"id":{{json .Id}},"tags":{{json .RepoTags}},"digests":{{json .RepoDigests}}}' \
|
|
175
|
+
"$image_id" 2> "$inspect_errors")"; then
|
|
176
|
+
if ! grep -q 'No such image' "$inspect_errors"; then
|
|
177
|
+
cat "$inspect_errors" >&2
|
|
178
|
+
exit 1
|
|
179
|
+
fi
|
|
180
|
+
image_json="$(json_string "$image_id")" || exit 1
|
|
181
|
+
image="{\"id\":$image_json,\"tags\":null,\"digests\":null}"
|
|
182
|
+
fi
|
|
183
|
+
images+="${images:+,}$image"
|
|
184
|
+
done
|
|
185
|
+
rm -f "$inspect_errors"
|
|
186
|
+
compose_images="$(sut_compose_named images --format json)" || exit 1
|
|
187
|
+
# A failed git command records an unknown head and a null (unknown) tree
|
|
188
|
+
# state, never a clean one.
|
|
189
|
+
git_head="$(git -C "$lab_root" rev-parse --verify --quiet HEAD 2>/dev/null)" || git_head="unknown"
|
|
190
|
+
if git_status="$(git -C "$lab_root" status --porcelain 2>/dev/null)"; then
|
|
191
|
+
if [[ -n "$git_status" ]]; then git_dirty=true; else git_dirty=false; fi
|
|
192
|
+
else
|
|
193
|
+
git_dirty=null
|
|
194
|
+
fi
|
|
195
|
+
project_json="$(json_string "$project")" || exit 1
|
|
196
|
+
deployment_json="$(json_string "$deployment")" || exit 1
|
|
197
|
+
wire_json=null
|
|
198
|
+
if [[ -n "${MANDATEOPS_PROVIDER_WIRE:-}" ]]; then
|
|
199
|
+
wire_json="$(json_string "$MANDATEOPS_PROVIDER_WIRE")" || exit 1
|
|
200
|
+
fi
|
|
201
|
+
# The run's provider names in list order; one default provider when unset.
|
|
202
|
+
names_json=""
|
|
203
|
+
IFS=, read -r -a provider_names <<< "${MANDATEOPS_PROVIDER_NAMES:-provider}"
|
|
204
|
+
for name in "${provider_names[@]}"; do
|
|
205
|
+
name_json="$(json_string "$name")" || exit 1
|
|
206
|
+
names_json+="${names_json:+,}$name_json"
|
|
207
|
+
done
|
|
208
|
+
restarted_json=""
|
|
209
|
+
while IFS= read -r service; do
|
|
210
|
+
service_json="$(json_string "$service")" || exit 1
|
|
211
|
+
restarted_json+="${restarted_json:+,}$service_json"
|
|
212
|
+
done < "$restarted_for_ports"
|
|
213
|
+
rm -f "$restarted_for_ports"
|
|
214
|
+
head_json="$(json_string "$git_head")" || exit 1
|
|
215
|
+
cargo_json="$(tool_version cargo --version)" || exit 1
|
|
216
|
+
rustc_json="$(tool_version rustc --version)" || exit 1
|
|
217
|
+
bun_json="$(tool_version bun --version)" || exit 1
|
|
218
|
+
docker_json="$(tool_version docker --version)" || exit 1
|
|
219
|
+
compose_json="$(tool_version docker compose version --short)" || exit 1
|
|
220
|
+
|
|
221
|
+
provenance_file="$run_dir/provenance.json"
|
|
222
|
+
{
|
|
223
|
+
printf '{"project":%s,"deployment":%s,' "$project_json" "$deployment_json"
|
|
224
|
+
printf '"provider_wire":%s,"provider_names":[%s],"restarted_for_ports":[%s],' \
|
|
225
|
+
"$wire_json" "$names_json" "$restarted_json"
|
|
226
|
+
printf '"compose_images":%s,"containers":[%s],"images":[%s],' \
|
|
227
|
+
"$compose_images" "$containers" "$images"
|
|
228
|
+
printf '"git":{"head":%s,"uncommitted_changes":%s},' "$head_json" "$git_dirty"
|
|
229
|
+
printf '"tools":{"cargo":%s,"rustc":%s,"bun":%s,"docker":%s,"compose":%s}}\n' \
|
|
230
|
+
"$cargo_json" "$rustc_json" "$bun_json" "$docker_json" "$compose_json"
|
|
231
|
+
} > "$provenance_file.partial"
|
|
232
|
+
# Docker's JSON is spliced in unparsed, so the whole record is parsed once
|
|
233
|
+
# before it is kept.
|
|
234
|
+
if ! lab_json_valid "$provenance_file.partial"; then
|
|
235
|
+
echo "provenance: $provenance_file.partial is not valid JSON; kept for inspection" >&2
|
|
236
|
+
exit 1
|
|
237
|
+
fi
|
|
238
|
+
mv "$provenance_file.partial" "$provenance_file"
|
|
239
|
+
lab_phase "deployment ready"
|
|
240
|
+
echo "$project healthy; ports and provenance written to $run_dir/"
|
package/package.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mandateops/cli-linux-x64",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.7.1",
|
|
4
|
+
"description": "The mandateops binary and lab for linux-x64, installed by @mandateops/cli.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://getmandateops.com",
|
|
7
|
+
"os": [
|
|
8
|
+
"linux"
|
|
9
|
+
],
|
|
10
|
+
"cpu": [
|
|
11
|
+
"x64"
|
|
12
|
+
],
|
|
13
|
+
"files": [
|
|
14
|
+
"audit-lab",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
]
|
|
18
|
+
}
|