Debian Codegraph @

test/integration/targets/secret_masking_display/runme.sh

raw
1 #!/usr/bin/env bash
2
3 set -eux -o pipefail
4
5 LOG="${OUTPUT_DIR}/display.log"
6 ANSIBLE_LOG="${OUTPUT_DIR}/ansible_log_path.log"
7 rm -f "${ANSIBLE_LOG}"
8
9 SEED='version: 1
10 secrets:
11 - Displaywarn0050Secret
12 - Displaydeprec0051Secret
13 - Displaybanner0052Secret
14 - Displayerror0053Secret
15 - Displayinvoke0054Secret
16 - Displayline0055Secret
17 '
18
19 _ANSIBLE_SECRETS_INPUT_FILES=<(printf '%s' "${SEED}") \
20 ANSIBLE_INJECT_INVOCATION=True \
21 ANSIBLE_DEPRECATION_WARNINGS=True \
22 ANSIBLE_DISPLAY_TRACEBACK=always \
23 ANSIBLE_LOG_PATH="${ANSIBLE_LOG}" \
24 ANSIBLE_LOG_VERBOSITY=3 \
25 ansible-playbook display.yml -i ../../inventory -vvv "$@" 2>&1 | tee "${LOG}"
26
27 registered_secrets=(
28 Displaywarn0050Secret
29 Displaydeprec0051Secret
30 Displaybanner0052Secret
31 Displayerror0053Secret
32 Displayinvoke0054Secret
33 Displayline0055Secret
34 )
35 sink_markers=(
36 "MARKERBANNER \$REDACTED\$"
37 "MARKERWARN \$REDACTED\$"
38 "MARKERDEPR \$REDACTED\$"
39 "MARKERINVOKE \$REDACTED\$"
40 "MARKERERROR \$REDACTED\$"
41 "MARKERLINE \$REDACTED\$"
42 )
43
44 # assert_masked FILE
45 # No registered plaintext secret may appear anywhere in FILE, each sink must have emitted a redacted
46 # marker, and the error sink must have rendered a real Python traceback (ANSIBLE_DISPLAY_TRACEBACK=always),
47 # proving the traceback egress path ran; the plaintext scan already guarantees nothing in it leaked.
48 assert_masked() {
49 local file="$1" secret marker
50
51 for secret in "${registered_secrets[@]}"; do
52 if grep -q -- "${secret}" "${file}"; then
53 echo "FAIL: registered secret '${secret}' leaked in plaintext (${file})" >&2
54 grep -n -- "${secret}" "${file}" >&2 || true
55 exit 1
56 fi
57 done
58
59 for marker in "${sink_markers[@]}"; do
60 if ! grep -qF -- "${marker}" "${file}"; then
61 echo "FAIL: expected redacted marker not found: '${marker}' (${file})" >&2
62 exit 1
63 fi
64 done
65
66 if ! grep -qF -- "Traceback (most recent call last):" "${file}"; then
67 echo "FAIL: expected a rendered traceback (ANSIBLE_DISPLAY_TRACEBACK=always) but found none (${file})" >&2
68 exit 1
69 fi
70 }
71
72 # stdout/stderr captured from the run
73 assert_masked "${LOG}"
74
75 # The ANSIBLE_LOG_PATH file is fed by the same Display sinks and must be masked in the same way.
76 cat "${ANSIBLE_LOG}"
77 assert_masked "${ANSIBLE_LOG}"