Skip to content

Commit 1c1becf

Browse files
committed
fix(deploy): source .env.local in subshell before invoking sealed-env unseal
The sealed-env CLI doesn't auto-discover .env.local when invoked from a script (vs interactive shell). Sourcing it inside a subshell keeps the master keys out of the child docker compose process while still providing them to the unseal call. Also extract just the JWS string from sealed-env unseal output (the command prints a banner + the token + a CI hint paragraph; we want just the token bytes for the env var).
1 parent e85484f commit 1c1becf

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

deploy.sh

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,34 @@ if [[ ! "${TOTP_CODE}" =~ ^[0-9]{6}$ ]]; then
8080
exit 1
8181
fi
8282

83+
# ── Source .env.local so sealed-env CLI sees SEALED_ENV_KEY etc.
84+
# The CLI doesn't auto-discover .env.local when invoked from a script
85+
# (different from interactive use). `set -a` exports every var defined
86+
# in the file; we scope this to a subshell so the master keys don't
87+
# leak into the child docker compose process below.
88+
if [[ ! -f .env.local ]]; then
89+
echo "✗ .env.local not found in $(pwd) — copy it from the operator's laptop:"
90+
echo " scp ~/.../.env.local root@$(hostname):/opt/zentryx/status/.env.local"
91+
exit 1
92+
fi
93+
8394
# ── Mint the unseal token ────────────────────────────────────────
8495
echo "▸ Minting unseal token (TTL 60s, bound to ${DEPLOY_ID_SHORT})..."
85-
SEALED_ENV_UNSEAL_TOKEN="$(sealed-env unseal \
86-
--file src/main/resources/.env.sealed \
87-
--totp "${TOTP_CODE}" \
88-
--deploy-id "${DEPLOY_ID}" \
89-
--ttl 60)"
96+
SEALED_ENV_UNSEAL_TOKEN="$(
97+
set -a
98+
# shellcheck disable=SC1091
99+
. ./.env.local
100+
set +a
101+
sealed-env unseal \
102+
--file src/main/resources/.env.sealed \
103+
--totp "${TOTP_CODE}" \
104+
--deploy-id "${DEPLOY_ID}" \
105+
--ttl 60 \
106+
| grep -oE 'usl_[A-Za-z0-9._-]+' | head -1
107+
)"
90108

91109
if [[ -z "${SEALED_ENV_UNSEAL_TOKEN}" ]]; then
92-
echo "✗ unseal failed — check TOTP code and try again"
110+
echo "✗ unseal failed — check TOTP code (rotates every 30s) and try again"
93111
exit 1
94112
fi
95113

0 commit comments

Comments
 (0)