Skip to content

Commit 5542d14

Browse files
CP-14167 - Make scheduled rake runner shell-safe on Alpine
What Hardens the one-shot rake task runner so it works under Alpine’s /bin/sh (busybox ash), not just bash. AWS CLI detection and Secrets Manager fetches now fail cleanly with portable redirects and explicit error handling. Why The webhook health check runs as a scheduled ECS task via this script. Bash-isms (&>) and dead $? checks under set -e could mis-handle errors on Alpine, so the periodic integrity check needs a portable, fail-closed startup path. How to test • sh -n bin/run_rake_task (syntax check) • Review that command -v aws uses >/dev/null 2>&1 and aws fetches use if ! VAR=$(aws ...); then • On staging after deploy: EventBridge/ECS one-shot still loads secrets and runs careerplug:check_webhooks
1 parent c536d2e commit 5542d14

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

bin/run_rake_task

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#
1515
# Migrations are intentionally NOT run here: the app service migrates on deploy,
1616
# and a periodic one-shot shouldn't race with it.
17+
#
18+
# POSIX sh only (Alpine /bin/sh is busybox ash, not bash): no bash-isms like &>.
1719

1820
RAKE_TASK="${1:-}"
1921
if [ -z "$RAKE_TASK" ]; then
@@ -41,7 +43,7 @@ check_aws_setup() {
4143
exit 1
4244
fi
4345

44-
if ! command -v aws &> /dev/null; then
46+
if ! command -v aws >/dev/null 2>&1; then
4547
echo "ERROR: AWS CLI is not installed. Please install it to proceed."
4648
exit 1
4749
fi
@@ -55,13 +57,11 @@ fetch_db_credentials() {
5557
exit 1
5658
fi
5759

58-
SECRET_JSON=$(aws secretsmanager get-secret-value \
60+
if ! SECRET_JSON=$(aws secretsmanager get-secret-value \
5961
--region "$AWS_REGION" \
6062
--secret-id "$DB_SECRETS_NAME" \
6163
--query SecretString \
62-
--output text)
63-
64-
if [ $? -ne 0 ]; then
64+
--output text); then
6565
echo "ERROR: Failed to retrieve secrets from AWS Secrets Manager"
6666
exit 1
6767
fi
@@ -90,13 +90,16 @@ fetch_encryption_key() {
9090

9191
ENCRYPTION_SECRET_NAME="cpdocuseal/encryption_key"
9292

93-
ENCRYPTION_KEY=$(aws secretsmanager get-secret-value \
93+
if ! ENCRYPTION_KEY=$(aws secretsmanager get-secret-value \
9494
--region "$AWS_REGION" \
9595
--secret-id "$ENCRYPTION_SECRET_NAME" \
9696
--query SecretString \
97-
--output text)
97+
--output text); then
98+
echo "ERROR: Failed to retrieve encryption key from AWS Secrets Manager"
99+
exit 1
100+
fi
98101

99-
if [ $? -ne 0 ] || [ -z "$ENCRYPTION_KEY" ] || [ "$ENCRYPTION_KEY" = "null" ]; then
102+
if [ -z "$ENCRYPTION_KEY" ] || [ "$ENCRYPTION_KEY" = "null" ]; then
100103
echo "ERROR: Failed to retrieve encryption key from AWS Secrets Manager"
101104
exit 1
102105
fi
@@ -114,13 +117,11 @@ fetch_env_variables() {
114117
exit 1
115118
fi
116119

117-
SECRET_JSON=$(aws secretsmanager get-secret-value \
120+
if ! SECRET_JSON=$(aws secretsmanager get-secret-value \
118121
--region "$AWS_REGION" \
119122
--secret-id "$CP_VARIABLES_NAME" \
120123
--query SecretString \
121-
--output text)
122-
123-
if [ $? -ne 0 ]; then
124+
--output text); then
124125
echo "ERROR: Failed to retrieve secrets from AWS Secrets Manager"
125126
exit 1
126127
fi

0 commit comments

Comments
 (0)