Why is passing secrets as command-line arguments a problem?
AdvancedConceptShellCheck, debugging, testing, portability and security
Answer
Any local user can read every process's arguments via ps aux or /proc/PID/cmdline while it runs, and they end up in shell history, set -x traces and audit logs.
mysql -u app -p"$DB_PASS" ... # visible in ps
MYSQL_PWD="$DB_PASS" mysql -u app ... # env: readable only by the same user/root
curl -K <(printf 'header = "Authorization: Bearer %s"\n' "$TOKEN") "$url"
docker login -u ci --password-stdin <<<"$REGISTRY_TOKEN"
Prefer stdin (--password-stdin), config files with mode 0600, or file descriptors via process substitution.
More on ShellCheck, debugging, testing, portability and security
What is ShellCheck and how do you use it in a team?BeginnerHow do you disable a ShellCheck warning, and when is that acceptable?IntermediateName the ShellCheck warnings you see most and what each means.IntermediateHow do you debug a Bash script?BeginnerHow do you make `set -x` output more useful with `PS4`?IntermediateWhat is bats, and how do you test a script that calls external commands?Intermediate