fix: gitea runners
This commit is contained in:
@@ -93,7 +93,9 @@ gcr_record_del 9001 1
|
||||
test "$(wc -l < "$calls" | tr -d ' ')" = '3'
|
||||
jq -e 'select(.server_type == "ccx53" and .location == "nbg1" and
|
||||
(.user_data | startswith("#cloud-config\n")) and
|
||||
(.user_data | contains("/etc/ssh/ssh_host_ed25519_key")) and
|
||||
(.user_data | contains("ssh_deletekeys: true")) and
|
||||
(.user_data | contains("ssh_genkeytypes: [ed25519]")) and
|
||||
(.user_data | contains("ed25519_private: |")) and
|
||||
.labels["gcr.arch"] == "amd64" and
|
||||
.labels["gcr.image-id"] == "424242" and
|
||||
.labels["gcr.label"] == "gross-nix-x86-highmem" and
|
||||
|
||||
@@ -204,7 +204,9 @@ gcr_hcloud_req() {
|
||||
POST:/servers/71/actions/rebuild)
|
||||
jq -e 'select(.image == "424242" and
|
||||
(.user_data | startswith("#cloud-config\n")) and
|
||||
(.user_data | contains("/etc/ssh/ssh_host_ed25519_key")) and
|
||||
(.user_data | contains("ssh_deletekeys: true")) and
|
||||
(.user_data | contains("ssh_genkeytypes: [ed25519]")) and
|
||||
(.user_data | contains("ed25519_private: |")) and
|
||||
keys == ["image", "user_data"])' <<EOF >/dev/null
|
||||
$body
|
||||
EOF
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
#!/bin/dash
|
||||
set -eu
|
||||
|
||||
. "$LOG_SH"
|
||||
. "$STATE_SH"
|
||||
. "$DECIDE_SH"
|
||||
. "$HCLOUD_SH"
|
||||
|
||||
gcr_state_init
|
||||
export GCR_LOG=warn
|
||||
|
||||
key_path="$(gcr_vm_host_key_path 940 1)"
|
||||
other_key_path="$GCR_STATE_DIR/other-host-key"
|
||||
gcr_vm_host_key_prepare 940 1
|
||||
test "$(stat -c '%a' "$key_path")" = 600
|
||||
test "$(stat -c '%a' "$key_path.pub")" = 644
|
||||
gcr_vm_host_key_pair_valid "$key_path"
|
||||
|
||||
ssh-keygen -q -t ed25519 -N '' -C '' -f "$other_key_path"
|
||||
cp "$other_key_path.pub" "$key_path.pub"
|
||||
if gcr_vm_host_key_prepare 940 1; then
|
||||
printf 'mismatched existing host-key pair must fail closed\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
if gcr_vm_host_key_userdata 940 1 >/dev/null; then
|
||||
printf 'invalid host-key pair must not enter cloud-init user-data\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
if gcr_vm_known_hosts_file 940 1 192.0.2.94 >/dev/null; then
|
||||
printf 'invalid host-key pair must not create a known_hosts pin\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
ssh-keygen -y -f "$key_path" > "$key_path.pub"
|
||||
chmod 0644 "$key_path.pub"
|
||||
gcr_vm_host_key_pair_valid "$key_path"
|
||||
host_key_userdata="$(gcr_vm_host_key_userdata 940 1)"
|
||||
public_key_line="$(awk 'NR == 1 {print $1 " " $2}' "$key_path.pub")"
|
||||
printf '%s\n' "$host_key_userdata" | grep -Eq '^ssh_deletekeys: true$'
|
||||
printf '%s\n' "$host_key_userdata" | grep -Eq '^ssh_genkeytypes: \[ed25519\]$'
|
||||
printf '%s\n' "$host_key_userdata" | grep -Fq ' ed25519_private: |'
|
||||
printf '%s\n' "$host_key_userdata" | grep -Fq " ed25519_public: $public_key_line"
|
||||
rendered_private_key="$(printf '%s\n' "$host_key_userdata" \
|
||||
| sed -n '/^ ed25519_private: |$/,/^ ed25519_public:/p' \
|
||||
| sed '1d;$d;s/^ //')"
|
||||
test "$rendered_private_key" = "$(cat "$key_path")"
|
||||
printf '%s\n' "$host_key_userdata" \
|
||||
| grep -Fq 'systemctl restart sshd.service 2>/dev/null || systemctl restart ssh.service'
|
||||
|
||||
known_hosts_file="$(gcr_vm_known_hosts_file 940 1 192.0.2.94)"
|
||||
test "$(stat -c '%a' "$known_hosts_file")" = 600
|
||||
grep -Eq '^192\.0\.2\.94 ssh-ed25519 [A-Za-z0-9+/=]+$' "$known_hosts_file"
|
||||
long_error_file="$GCR_STATE_DIR/long-ssh-error"
|
||||
large_stderr_called="$GCR_STATE_DIR/large-stderr-called"
|
||||
large_stderr() {
|
||||
printf 'called\n' > "$large_stderr_called"
|
||||
awk 'BEGIN { for (i = 0; i < 10000; i++) printf "x" }' >&2
|
||||
return 255
|
||||
}
|
||||
if gcr_ssh_run_captured "$long_error_file" large_stderr 2>/dev/null; then
|
||||
printf 'SSH error capture must preserve command failure\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
test "$(cat "$large_stderr_called")" = called
|
||||
test "$(wc -c < "$long_error_file" | tr -d ' ')" -le 4096
|
||||
|
||||
export GCR_SSH_PRIVKEY_FILE="$GCR_STATE_DIR/ssh-client-key"
|
||||
printf 'test-only private key placeholder\n' > "$GCR_SSH_PRIVKEY_FILE"
|
||||
chmod 0600 "$GCR_SSH_PRIVKEY_FILE"
|
||||
export GCR_NIX_VERSION=2.24.11
|
||||
export GCR_NIX_TARBALL_SHA256=sha256
|
||||
export GCR_ARM_NIX_TARBALL_SHA256=sha256
|
||||
export GCR_ACT_RUNNER_VERSION=0.2.11
|
||||
export GCR_ACT_RUNNER_SHA256=sha256
|
||||
export GCR_GITEA_URL=https://gitea.example.test
|
||||
|
||||
sleep_calls_file="$GCR_STATE_DIR/sleep-calls"
|
||||
sleep() {
|
||||
test "$1" = 5
|
||||
printf '5\n' >> "$sleep_calls_file"
|
||||
}
|
||||
|
||||
ssh_mode=host-key
|
||||
ssh_calls_file="$GCR_STATE_DIR/ssh-calls"
|
||||
strict_pin_file="$GCR_STATE_DIR/strict-pin-seen"
|
||||
temp_paths="$GCR_STATE_DIR/bootstrap-temp-paths"
|
||||
mktemp() {
|
||||
created_temp="$(command mktemp "$@")" || return 1
|
||||
printf '%s\n' "$created_temp" >> "$temp_paths"
|
||||
printf '%s' "$created_temp"
|
||||
}
|
||||
assert_bootstrap_temps_removed() {
|
||||
while IFS= read -r temp_path; do
|
||||
test ! -e "$temp_path"
|
||||
done < "$temp_paths"
|
||||
}
|
||||
printf '0\n' > "$ssh_calls_file"
|
||||
ssh() {
|
||||
ssh_calls="$(cat "$ssh_calls_file")"
|
||||
ssh_calls=$((ssh_calls + 1))
|
||||
printf '%s\n' "$ssh_calls" > "$ssh_calls_file"
|
||||
case "$*" in
|
||||
*StrictHostKeyChecking=yes*"UserKnownHostsFile=$known_hosts_file"*)
|
||||
printf '1\n' > "$strict_pin_file"
|
||||
;;
|
||||
*)
|
||||
printf 'SSH bootstrap did not use strict per-job host-key pinning\n' >&2
|
||||
return 99
|
||||
;;
|
||||
esac
|
||||
case "$ssh_mode" in
|
||||
host-key)
|
||||
printf '%s\n' \
|
||||
'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!' \
|
||||
'Host key verification failed.' \
|
||||
'REGISTRATION_TOKEN=secret-value' \
|
||||
'Authorization: token secret-value' >&2
|
||||
return 255
|
||||
;;
|
||||
retry)
|
||||
if [ "$ssh_calls" -le 2 ]; then
|
||||
printf 'ssh: connect to host 192.0.2.94 port 22: Connection refused\n' >&2
|
||||
return 255
|
||||
fi
|
||||
if [ "$ssh_calls" -eq 3 ]; then
|
||||
return 0
|
||||
fi
|
||||
cat >/dev/null
|
||||
printf 'bootstrap\n' >> "$retry_script_calls"
|
||||
return 0
|
||||
;;
|
||||
remote-failure)
|
||||
if [ "$ssh_calls" -eq 1 ]; then
|
||||
return 0
|
||||
fi
|
||||
cat >/dev/null
|
||||
printf '%s\n' 'REGISTRATION_TOKEN=secret-value' \
|
||||
'Authorization: token secret-value' 'cloud-init status: error' >&2
|
||||
return 1
|
||||
;;
|
||||
transport-failure)
|
||||
if [ "$ssh_calls" -eq 1 ]; then
|
||||
return 0
|
||||
fi
|
||||
cat >/dev/null
|
||||
printf '%s\n' 'Connection reset by peer' 'REGISTRATION_TOKEN=secret-value' >&2
|
||||
return 255
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
host_key_log="$GCR_STATE_DIR/host-key.log"
|
||||
: > "$temp_paths"
|
||||
if gcr_vm_bootstrap_ssh 192.0.2.94 gross-x86 fresh-token gcr-940-1 \
|
||||
"$known_hosts_file" 940 1 994 > /dev/null 2> "$host_key_log"; then
|
||||
printf 'host-key mismatch must block SSH bootstrap\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -q 'category=host-key-verification' "$host_key_log"
|
||||
if grep -Eq 'REMOTE HOST IDENTIFICATION|Host key verification failed|REGISTRATION_TOKEN|Authorization:|secret-value' "$host_key_log"; then
|
||||
printf 'raw SSH stderr leaked into controller log\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
test "$(cat "$strict_pin_file")" = 1
|
||||
test "$(cat "$ssh_calls_file")" = 180
|
||||
test "$(wc -l < "$sleep_calls_file" | tr -d ' ')" = 179
|
||||
assert_bootstrap_temps_removed
|
||||
if grep -Eq 'StrictHostKeyChecking=(no|accept-new)|sshd never came up' "$host_key_log"; then
|
||||
printf 'unsafe SSH policy or stale failure message found\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ssh_mode=retry
|
||||
printf '0\n' > "$ssh_calls_file"
|
||||
rm -f "$sleep_calls_file"
|
||||
retry_script_calls="$GCR_STATE_DIR/retry-script-calls"
|
||||
: > "$temp_paths"
|
||||
if ! gcr_vm_bootstrap_ssh 192.0.2.94 gross-x86 fresh-token gcr-940-1 \
|
||||
"$known_hosts_file" 940 1 994 > /dev/null 2> "$GCR_STATE_DIR/retry.log"; then
|
||||
printf 'SSH readiness should succeed after two transient failures\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
test "$(cat "$ssh_calls_file")" = 4
|
||||
test "$(wc -l < "$sleep_calls_file" | tr -d ' ')" = 2
|
||||
test "$(wc -l < "$retry_script_calls" | tr -d ' ')" = 1
|
||||
assert_bootstrap_temps_removed
|
||||
|
||||
diag_calls="$GCR_STATE_DIR/diagnostics-called"
|
||||
gcr_vm_collect_diagnostics() {
|
||||
printf '%s\n' "$*" >> "$diag_calls"
|
||||
}
|
||||
ssh_mode=remote-failure
|
||||
printf '0\n' > "$ssh_calls_file"
|
||||
remote_failure_log="$GCR_STATE_DIR/remote-bootstrap.log"
|
||||
: > "$temp_paths"
|
||||
if gcr_vm_bootstrap_ssh 192.0.2.94 gross-x86 fresh-token gcr-940-1 \
|
||||
"$known_hosts_file" 940 1 994 > /dev/null 2> "$remote_failure_log"; then
|
||||
printf 'remote bootstrap command failure must be reported\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -q 'category=remote-bootstrap-command-failed' "$remote_failure_log"
|
||||
if grep -Eq 'REGISTRATION_TOKEN|Authorization:|secret-value|cloud-init status: error' "$remote_failure_log"; then
|
||||
printf 'remote bootstrap stderr leaked into controller log\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
test "$(wc -l < "$diag_calls" | tr -d ' ')" = 1
|
||||
test "$(cat "$diag_calls")" = '994 192.0.2.94 940 bootstrap-command-failed 1'
|
||||
assert_bootstrap_temps_removed
|
||||
|
||||
ssh_mode=transport-failure
|
||||
printf '0\n' > "$ssh_calls_file"
|
||||
: > "$temp_paths"
|
||||
transport_failure_log="$GCR_STATE_DIR/transport-failure.log"
|
||||
if gcr_vm_bootstrap_ssh 192.0.2.94 gross-x86 fresh-token gcr-940-1 \
|
||||
"$known_hosts_file" 940 1 994 > /dev/null 2> "$transport_failure_log"; then
|
||||
printf 'SSH transport failure after readiness must be reported\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -q 'category=connectivity-or-sshd' "$transport_failure_log"
|
||||
if grep -Eq 'Connection reset|REGISTRATION_TOKEN|secret-value' "$transport_failure_log"; then
|
||||
printf 'transport stderr leaked into controller log\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
test "$(wc -l < "$diag_calls" | tr -d ' ')" = 2
|
||||
grep -q '994 192.0.2.94 940 bootstrap-transport-failed 1' "$diag_calls"
|
||||
assert_bootstrap_temps_removed
|
||||
Reference in New Issue
Block a user