mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-04 08:48:45 +00:00
`container exec -e NAME=VALUE` puts VALUE in the argv of the host-side
process, where ps shows it to every local account for as long as the call runs.
no_log cannot mask a process table. The credentials that travel this way are
live: platform_administrator and every secrets.credentials.* value rotate
between the two passes of a matrix-deploy round.
tests/lint/ansible/shell/container/test_exec_env_passes_no_value.py rejects the
form for credential-bearing values, recognised by either the variable's name or
a credential source in the expression behind it. The second signal is what
keeps it from being a name denylist, which would be no protection on its own: a
secret handed over as -e FOO={{ lookup('users','x').password }} is caught by its
source although its name says nothing. Literal values pass; ports, paths and
model names are not worth moving.
The 24 sites it found now pass the name alone and bind the value in the task's
environment. Value-shaping filters stay, because the container needs the shaped
form; the shell-quoting | quote goes, and that is safe: shlex.quote builds
armour the host shell consumes while parsing argv, so what docker receives is
byte-identical either way, checked with a password of @, space, apostrophe
and $.
Three sites needed more than the pattern. set_postgres_superuser_password.sh
took the password as $2, so it stood in the argv of the script and of three
container exec calls; it now reads POSTGRES_SUPERUSER_PASSWORD, and both callers
follow. svc-db-elasticsearch built an exec prefix with the password inside it for
five tasks, so the binding moved to the two include sites and is inherited.
web-app-taiga had its upsert as a semicolon-chained one-liner inside the command;
it is a file read on stdin now, which took the name and the e-mail out of the
argv too.
What this does not do, stated because the docstring first claimed otherwise:
with ansible.builtin.script the value reaches no argv, but with shell and
command ansible-core still prefixes NAME='value' onto the module wrapper's own
line, from Shell.env_prefix in build_module_command. The window shrinks from the
whole container call, re-executed on every pass of an until: loop, to the
module's runtime. It does not vanish.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
49 lines
1.5 KiB
Bash
49 lines
1.5 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Usage:
|
|
# realign_admin_password.sh <container> <run_as_user> <admin_username> <occ_path>
|
|
# OC_PASS: the declared password, read from the environment only.
|
|
#
|
|
# Exit: 0 with [CHANGED] or [UNCHANGED] on stdout, 1 with [FAIL] on stderr.
|
|
|
|
container="${1:-}"
|
|
run_as="${2:-}"
|
|
admin_user="${3:-}"
|
|
occ="${4:-}"
|
|
|
|
if [[ -z "$container" || -z "$run_as" || -z "$admin_user" || -z "$occ" ]]; then
|
|
echo "Usage: $0 <container> <run_as_user> <admin_username> <occ_path>" >&2
|
|
exit 2
|
|
fi
|
|
|
|
if [[ -z "${OC_PASS:-}" ]]; then
|
|
echo "[FAIL] OC_PASS is empty; refusing to set an empty administrator password." >&2
|
|
exit 1
|
|
fi
|
|
|
|
marker="/var/www/html/config/.admin_password_sha256"
|
|
declared_sha="$(printf '%s' "$OC_PASS" | sha256sum | cut -d' ' -f1)"
|
|
|
|
current_sha="$(container exec -u "$run_as" "$container" \
|
|
sh -c "cat '$marker' 2>/dev/null || true")"
|
|
|
|
if [[ "$current_sha" == "$declared_sha" ]]; then
|
|
echo "[UNCHANGED] Administrator password already matches the declared one."
|
|
exit 0
|
|
fi
|
|
|
|
if ! container exec -u "$run_as" -e OC_PASS "$container" \
|
|
php "$occ" user:resetpassword --password-from-env "$admin_user" >/dev/null; then
|
|
echo "[FAIL] occ user:resetpassword failed for '$admin_user'." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! container exec -u "$run_as" -e "SHA=$declared_sha" "$container" \
|
|
sh -c "printf '%s' \"\$SHA\" > '$marker'"; then
|
|
echo "[FAIL] Password was reset but the marker could not be written." >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "[CHANGED] Administrator password did not match the declared one, and does now."
|