Interview › Scripting (Bash, Groovy)
Why should you avoid putting secrets on the command line, and what leaks them? [Advanced]
Answer
Secrets on the command line can leak through process listings, shell history, CI logs, audit logs, error messages, and monitoring agents. I prefer stdin, protected files, environment bindings from a secret manager, or native credential mechanisms.
Technical explanation
Commands like ps can expose arguments to other users on the system depending on permissions and OS settings.
set -x can print expanded command lines containing secrets.
Some tools log full command invocations on failure, so command-line secrets are easy to leak accidentally.
Hands-on example
# Bad: password visible in command arguments
# mysql -u app -pSuperSecret
# Better: protected option file or env/secret manager
cat > "$HOME/.my.cnf" <<EOF
[client]
user=app
password=$MYSQL_PASSWORD
EOF
chmod 600 "$HOME/.my.cnf"
mysql -e 'select 1'Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Scripting (Bash, Groovy) interview questions
- How do you securely handle secrets in a shell script (avoid hardcoding, use env or a vault)? [Advanced]
- What is idempotency, and how do you make a script safe to run repeatedly? [Advanced]
- What is the difference between a cron job and a systemd timer? [Advanced]
- How do you define and call a function (or step) in a Jenkins Groovy pipeline? [Advanced]
- How would you write a health-check script that polls a URL until it returns 200? [Advanced]
- How do you handle errors and retries in a Groovy pipeline (try/catch, retry, timeout)? [Advanced]
- How do you run stages in parallel in a Jenkins Groovy pipeline? [Advanced]
- What is the difference between Groovy and Java for scripting purposes? [Advanced]