Debian Codegraph @

test/integration/targets/secret_masking_secret_input/runme.sh

raw
1 #!/usr/bin/env bash
2
3 set -eux -o pipefail
4
5 LOG="${OUTPUT_DIR}/input.log"
6
7 # YAML source, with the duplicate value repeated within the list to prove intra-file duplicates are ignored.
8 YAML_SEED='version: 1
9 secrets:
10 - Inputyaml0030Secret
11 - Inputdup0033Secret
12 - Inputdup0033Secret
13 '
14
15 # JSON source; JSON is valid YAML so it loads through the same parser. Repeats the duplicate value that
16 # also appears in the YAML source to prove cross-file duplicates are ignored.
17 JSON_SEED="${OUTPUT_DIR}/seed_input.json"
18 echo '{"version": 1, "secrets": ["Inputjson0031Secret", "Inputdup0033Secret"]}' > "${JSON_SEED}"
19
20 # Executable source: the loader runs files with the executable bit and parses their stdout.
21 EXEC_SEED="${OUTPUT_DIR}/seed_exec.sh"
22 cat > "${EXEC_SEED}" <<'EOF'
23 #!/usr/bin/env bash
24 echo '{"version": 1, "secrets": ["Inputexec0032Secret", "Inputdup0033Secret"]}'
25 EOF
26 chmod +x "${EXEC_SEED}"
27
28 # YAML is fed as a pipe to exercise the read-once path; JSON as file, and an executable output
29 _ANSIBLE_SECRETS_INPUT_FILES=<(printf '%s' "${YAML_SEED}"),${JSON_SEED},"${EXEC_SEED}" \
30 ansible-playbook input.yml -i ../../inventory "$@" 2>&1 | tee "${LOG}"
31
32 registered_secrets=(
33 Inputyaml0030Secret
34 Inputjson0031Secret
35 Inputexec0032Secret
36 Inputdup0033Secret
37 )
38 for secret in "${registered_secrets[@]}"; do
39 if grep -q -- "${secret}" "${LOG}"; then
40 echo "FAIL: registered secret '${secret}' leaked in plaintext" >&2
41 exit 1
42 fi
43 done
44
45 markers=(
46 "MARKER input_yaml: \$REDACTED\$"
47 "MARKER input_json: \$REDACTED\$"
48 "MARKER input_exec: \$REDACTED\$"
49 "MARKER input_dup: \$REDACTED\$"
50 )
51 for marker in "${markers[@]}"; do
52 if ! grep -qF -- "${marker}" "${LOG}"; then
53 echo "FAIL: expected redacted marker not found: '${marker}'" >&2
54 exit 1
55 fi
56 done
57
58 expect_failure() {
59 local description="$1" seed="$2" expected="$3" leaked="$4" out
60 if out=$(_ANSIBLE_SECRETS_INPUT_FILES=<(printf '%s' "${seed}") \
61 ansible-playbook input.yml -i ../../inventory 2>&1); then
62 echo "FAIL: ${description} was expected to abort but the command succeeded" >&2
63 echo "${out}" >&2
64 exit 1
65 fi
66 if ! grep -qF -- "${expected}" <<<"${out}"; then
67 echo "FAIL: ${description} did not produce the expected error: ${expected}" >&2
68 echo "${out}" >&2
69 exit 1
70 fi
71 if grep -qF -- "${leaked}" <<<"${out}"; then
72 echo "FAIL: ${description} disclosed the secret value '${leaked}' in its error output" >&2
73 echo "${out}" >&2
74 exit 1
75 fi
76 }
77
78 expect_failure "unsupported version" 'version: 2
79 secrets:
80 - Inputbadver0034Secret
81 ' "has an unsupported version 2;" "Inputbadver0034Secret"
82
83 expect_failure "boolean version" 'version: true
84 secrets:
85 - Inputbadbool0035Secret
86 ' "has an unsupported version True;" "Inputbadbool0035Secret"
87
88 expect_failure "non-mapping structure" '- version: 1
89 - secrets:
90 - Inputbadstruct0036Secret
91 ' "must contain a mapping, not a list" "Inputbadstruct0036Secret"
92
93 expect_failure "non-string secret entry" 'version: 1
94 secrets:
95 - some secret
96 - 1234567
97 ' "entry secrets[1] must be a string, not a int" "1234567"
98
99 echo "All secret masking secret input scenarios passed."