34
34
SHOULD_FAIL=false
35
35
for PIPELINE_IDX in " ${! SIGNED_PIPELINES[@]} " ; do
36
36
PIPELINE_PATH=" ${SIGNED_PIPELINES[${PIPELINE_IDX}]} "
37
+ SANITIZED_PIPELINE_PATH=" $( basename " ${PIPELINE_PATH} " | tr ' /' ' -' | tr ' .' ' -' | tr ' ' ' _' ) "
38
+
39
+ # Perform sanity checks such as ensuring that this pipeline will receive the key
40
+ if [[ -z " $( grep " BUILDKITE_PLUGIN_CRYPTIC_BASE64_SIGNED_JOB_ID_SECRET" " ${PIPELINE_PATH} " ) " ]]; then
41
+ (die " Pipeline ${PIPELINE_PATH} does not contain an env mapping for BUILDKITE_PLUGIN_CRYPTIC_BASE64_SIGNED_JOB_ID_SECRET!" ; ) || true
42
+ SHOULD_FAIL=true
43
+ continue
44
+ fi
37
45
38
46
# Hash up the inputs
39
47
readarray -d ' ' -t PIPELINE_INPUTS < <( collect_buildkite_array " BUILDKITE_PLUGIN_CRYPTIC_SIGNED_PIPELINES_${PIPELINE_IDX} _INPUTS" )
@@ -66,12 +74,31 @@ for PIPELINE_IDX in "${!SIGNED_PIPELINES[@]}"; do
66
74
base64dec <<< " ${!SIGNATURE_VAR}" > " ${SIGNATURE_FILE} "
67
75
fi
68
76
if [[ " $( decrypt_aes " ${UNENCRYPTED_REPO_KEY_PATH} " < " ${SIGNATURE_FILE} " ) " != " ${FULL_TREEHASH} " ]]; then
69
- echo " Pipeline '${PIPELINE_PATH} ' fails treehash siganture check! You may need to re-run cryptic/bin/sign_treehashes!"
77
+ SIGNATURE_FAIL_MSG=" Pipeline '${PIPELINE_PATH} ' fails treehash siganture check! You may need to re-run cryptic/bin/sign_treehashes!"
78
+ echo " ${SIGNATURE_FAIL_MSG} " >&2
70
79
71
80
HASH_OVERRIDE_VAR=" BUILDKITE_PLUGIN_CRYPTIC_SIGNED_PIPELINES_${PIPELINE_IDX} _ALLOW_HASH_OVERRIDE"
72
81
if [[ -v " ${HASH_OVERRIDE_VAR} " ]] && [[ " ${! HASH_OVERRIDE_VAR} " == " true" ]]; then
73
82
# If we allow committers to override the failing hash check, create a `block` step, then still launch it.
74
- cat " ${PIPELINE_PATH} " | sed -e " s&^steps:\(.*\)&steps:\\ 1\\ n - block: \" Bypass failed signature check for '${PIPELINE_PATH} '?\"\\ n blocked_state: \" running\"\\ n&" > " ${PIPELINE_PATH} .block"
83
+ # To do so, we require each of the pipeline's steps to contain a `depends_on` node:
84
+ NUM_STEPS=$( (grep -E " ^ - " " ${PIPELINE_PATH} " || true) | wc -l)
85
+ NUM_DEPENDS_ON=$( (grep -E " ^ depends_on:" " ${PIPELINE_PATH} " || true) | wc -l)
86
+ if [[ " ${NUM_DEPENDS_ON} " -lt " ${NUM_STEPS} " ]]; then
87
+ (die " Refusing to continue execution; pipeline '${PIPELINE_PATH} ' looks like it lacks some 'depends_on' nodes!" ; ) || true
88
+ SHOULD_FAIL=true
89
+ fi
90
+
91
+ # Notify the user that they probably need to re-sign something
92
+ BLOCK_KEY=" cryptic-block-${SANITIZED_PIPELINE_PATH} "
93
+ buildkite-agent annotate --style=warning --context=" ${BLOCK_KEY} " " ${SIGNATURE_FAIL_MSG} "
94
+
95
+ cat " ${PIPELINE_PATH} " |
96
+ # Insert a block step as the first step in this pipeline
97
+ sed -e " s&^steps:\(.*\)&steps:\\ 1\n - block: \" Bypass failed signature check for '${PIPELINE_PATH} '?\" \n blocked_state: \" running\" \n key: \" ${BLOCK_KEY} \" &" |
98
+ # Each other step in the secure pipeline _must_ have a `depends_on`, which we then add to:
99
+ sed -e " s&^ depends_on:& depends_on:\n - \" ${BLOCK_KEY} \" \n&" > " ${PIPELINE_PATH} .block"
100
+ echo " Printing out altered pipeline:"
101
+ cat " ${PIPELINE_PATH} .block"
75
102
PIPELINE_PATH=" ${PIPELINE_PATH} .block"
76
103
else
77
104
# Execute `die` in a subshell so that we can print out failure messages for each pipeline,
@@ -82,7 +109,7 @@ for PIPELINE_IDX in "${!SIGNED_PIPELINES[@]}"; do
82
109
fi
83
110
fi
84
111
85
- # If we passed, launch the pipeline!
112
+ # If we passed, try to launch the pipeline!
86
113
echo " -> Launching ${PIPELINE_PATH} "
87
114
buildkite-agent pipeline upload " ${PIPELINE_PATH} "
88
115
done
0 commit comments