fix: prepare sshd runtime directory before validation
All checks were successful
Bash syntax / syntax (push) Successful in 18s
Bash syntax / syntax (pull_request) Successful in 19s

This commit is contained in:
ochenstarik-ui 2026-10-23 14:31:21 +07:00
parent 47d5e030df
commit 9e8f024b89
3 changed files with 34 additions and 0 deletions

View file

@ -59,3 +59,6 @@ jobs:
- name: Test initial backup policy and upload retry - name: Test initial backup policy and upload retry
run: bash tests/test-backup-initial-retry.sh run: bash tests/test-backup-initial-retry.sh
- name: Test step 3 socket activation runtime directory
run: bash tests/test-step3-runtime-directory.sh

View file

@ -73,6 +73,12 @@ is_valid_port() {
(( 10#$port >= 1 && 10#$port <= 65535 )) (( 10#$port >= 1 && 10#$port <= 65535 ))
} }
prepare_sshd_runtime_directory() {
# Socket-activated Ubuntu can have no active ssh.service after an upgrade.
# Its RuntimeDirectory then does not exist, but standalone sshd -t needs it.
install -d -o root -g root -m 755 /run/sshd
}
read_ip_mode() { read_ip_mode() {
local mode=both local mode=both
if [[ -e "$IP_FAMILY_CONFIG" ]]; then if [[ -e "$IP_FAMILY_CONFIG" ]]; then
@ -517,6 +523,7 @@ UsePAM yes
EOF EOF
chmod 644 "$SSHD_DROPIN" chmod 644 "$SSHD_DROPIN"
prepare_sshd_runtime_directory
sshd -t || die "sshd syntax validation failed" sshd -t || die "sshd syntax validation failed"
# Capture the complete output once. With pipefail enabled, piping `sshd -T` # Capture the complete output once. With pipefail enabled, piping `sshd -T`
# into an awk program that exits after the first match can terminate sshd with # into an awk program that exits after the first match can terminate sshd with

View file

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -Eeuo pipefail
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
source <(awk '/^\[\[ "\$EUID"/{exit} {print}' ochenstarik-server-user-3.sh)
test_dir="$(mktemp -d)"
trap 'rm -rf -- "$test_dir"' EXIT
# Relocate just the privileged filesystem boundary; use the real install
# binary to check first creation, idempotency and repair of unsafe modes.
install() {
[[ "$*" == '-d -o root -g root -m 755 /run/sshd' ]]
/usr/bin/install -d -m 755 "$test_dir/sshd"
}
prepare_sshd_runtime_directory
[[ -d "$test_dir/sshd" && "$(stat -c %a "$test_dir/sshd")" == 755 ]]
chmod 777 "$test_dir/sshd"
prepare_sshd_runtime_directory
[[ "$(stat -c %a "$test_dir/sshd")" == 755 ]]
# The runtime prerequisite must run before standalone configuration validation.
prepare_line="$(grep -n '^prepare_sshd_runtime_directory$' ochenstarik-server-user-3.sh | cut -d: -f1)"
validate_line="$(grep -n '^sshd -t ' ochenstarik-server-user-3.sh | cut -d: -f1)"
((prepare_line < validate_line))
printf 'Step 3 socket-activation runtime directory tests passed.\n'