Skip to content
This repository was archived by the owner on Oct 25, 2026. It is now read-only.

Only warn about a command line password when -a or -u set it - #107

Closed
madolson wants to merge 1 commit into
upstream-unstable-8f67ab136from
fix-cli-env-auth-warning
Closed

madolson wants to merge 1 commit into
upstream-unstable-8f67ab136from
fix-cli-env-auth-warning

Conversation

@madolson

Copy link
Copy Markdown
Owner

Since #3402, valkey-cli reads environment variables before it parses command line options, so options can override them. The "Using a password with '-a' or '-u' option on the command line interface may not be safe" warning only checks that a password is set, so a password from VALKEYCLI_AUTH or REDISCLI_AUTH alone now prints it, even though nothing was on the command line. The fix warns only when -a or -u replaced the password the environment provided. -a still warns and still overrides the environment variable.

AI generated details

Problem

Based on upstream unstable 8f67ab136, so the base branch here is upstream-unstable-8f67ab136. Line numbers are at that commit.

baa5a48 (#3402) moved parseEnv() ahead of parseOptions() in main() (src/valkey-cli.c:10165) so that -h/-p override VALKEYCLI_HOST/VALKEYCLI_PORT. parseEnv() now writes VALKEYCLI_AUTH into config.conn_info.auth first (src/valkey-cli.c:2942), and the warning at the end of parseOptions() fires on any non-NULL password (src/valkey-cli.c:2906):

if (!config.no_auth_warning && config.conn_info.auth != NULL) {

Before #3402 the order was reversed, so auth was still NULL at that check unless -a or -u had set it. Affects 9.2.0-rc1. 9.1.x and earlier run parseEnv() after parseOptions().

$ VALKEYCLI_AUTH=envpass valkey-cli -p 26601 ping
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
PONG

Fix

parseOptions() records the auth pointer it starts with, which is whatever parseEnv() set, and warns only if the pointer changed. -a and -u with a password always allocate a new sds (src/valkey-cli.c:2620, src/cli_common.c:359), so they still warn. --askpass runs after parseOptions() and never warned. The parseEnv() ordering is unchanged, so command line options still override every environment variable.

Input Before #3402 9.2.0-rc1 This PR
VALKEYCLI_AUTH only no warning warning no warning
REDISCLI_AUTH only no warning warning no warning
-u without password, plus VALKEYCLI_AUTH no warning warning no warning
-a only warning warning warning
-u with password warning warning warning
wrong VALKEYCLI_AUTH, right -a warning, -a used warning, -a used warning, -a used
VALKEYCLI_AUTH with --no-auth-warning no warning no warning no warning

The "before #3402" column is from a build of baa5a48^.

Alternative considered

Moving the auth part of parseEnv() back after parseOptions() with the old auth == NULL guard would also work, but it splits parseEnv() and puts auth on a different precedence path from user, host, and port. Comparing the pointer leaves #3402's ordering alone.

Testing

The existing tests missed it because they don't check stderr: run_cli reads only stdout, and the VALKEYCLI_USER test passes --no-auth-warning. The new test merges stderr into the result. It also checks that -a still warns and still overrides a wrong VALKEYCLI_AUTH.

With the test in the tree and src/valkey-cli.c reverted to the base:

[err]: Non-interactive non-TTY CLI: VALKEYCLI_AUTH does not trigger the command line password warning in tests/integration/valkey-cli.tcl
Expected 'OK' to be equal to 'Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
OK' (context: type eval line 6 cmd {assert_equal "OK" [exec env VALKEYCLI_AUTH=mypass {*}$cmd set envkey envval 2>@1]} proc ::test)

Not run locally with --tls. The TLS test harness is broken on the machine this was written on, for every test file and not just this one.

This was generated by AI but verified, with love, by a human.

Since #3402, parseEnv() runs before parseOptions() so command line
arguments override environment variables. The password warning at the
end of parseOptions() checks only that auth is non-NULL, so a password
from VALKEYCLI_AUTH or REDISCLI_AUTH now prints "Using a password with
'-a' or '-u' option on the command line interface may not be safe",
even though no password was on the command line.

Remember the auth value parseEnv() left behind and warn only when
parseOptions() replaced it. -a and -u still warn and still override the
environment variable.

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

promoted Change has been promoted upstream

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant