Skip to content

Fail tests whose memtier runs get NOAUTH on a password-protected env - #863

Merged
fcostaoliveira merged 10 commits into
masterfrom
claude/noauth-guard-842
Oct 25, 2026
Merged

fcostaoliveira merged 10 commits into
masterfrom
claude/noauth-guard-842

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #842.

Problem

The "Single Endpoint: TCP Plaintext with auth" CI cell sets REDIS_PASSWORD, but a test that forgets to authenticate memtier still passes there. memtier counts -NOAUTH error replies as completed operations and exits 0. For example, dropping auth from test_sigpipe_immunity's command line on master still passes, while the server records 79,897 NOAUTH replies.

Change

NOAUTH guard (tests/include.py):

  • What it checks: when the env has a password, every RLTest function test is wrapped in a check of errorstat_NOAUTH on every server of the env: each shard's master and each replica. The counts are read before the test, and the test fails if any count grew, even if the test itself already failed. The message names the server and how many requests it answered -NOAUTH.
  • Snapshot instead of CONFIG RESETSTAT: comparing against the starting counts leaves the commandstats that tests assert on unchanged.
  • Why the server side: a stderr check in the run helpers would miss hand-built memtier command lines and redis-py clients. The server sees every client.
  • How it hooks in: include.py registers the check with RLTest.add_test_hook(), which runs it around every function test that takes the env. The hook is new in the pinned RLTest fork commit and proposed upstream as Add add_test_hook() to run a hook around each function test RedisLabsModules/RLTest#262. The pin also keeps Fixed build for tls v1.3 on openssl v1.0.2. Added CI check #253's cluster-aware replicas.
  • Opt-out: @allow_noauth(reason), with a required reason. Only the two test_cli_fuzz_phase1 tests that send memcache to Redis on purpose use it, because memcache cannot AUTH.

One password reader: a new env_password(env) feeds memtier_auth_args(), the password restores in test_retry_on_error and test_prometheus_redaction, the skip in test_cli_fuzz_phase1, and the replica clients. test_progress_interval and test_cluster_ask_asking no longer pass --authenticate twice, and test_cli_validation_count_flags drops its own copy, because add_required_env_arguments() already adds it.

Replica helpers. The guard surfaced these on its own:

  • get_cluster_replica_connections() created replica clients without the password. With OSS_CLUSTER_REPLICAS=1 and a password, every replica command got NOAUTH, and that error was swallowed, so test_read_preference_resp3.py failed 4 assertions.
  • _stop_one_replica() in test_read_preference_resp3.py and test_read_preference_failover.py treated any ConnectionError from SHUTDOWN NOSAVE as success. NOAUTH is a subclass of that error, so the replica was marked dead in RLTest while still running, and a redis-server leaked after every password run. A new shutdown_nosave() reports success only once the server stops answering.

Table test: tests/test_harness_auth.py has 21 rows of memtier_auth_args() skip rules and tests of the guard against a fake env.

Validation

  • Single mutation: with auth dropped from test_sigpipe_immunity, master passes and this PR fails with "shard 1 master answered 77040 request(s) -NOAUTH".
  • Broad mutation: with memtier_auth_args() returning nothing, the issue's 148-test file set has 23 failures on master and 90 with the guard, including all 27 test_prometheus tests.
  • Full standalone suite, serial, 864 tests (on intermediate commits of this branch; test_cli_validation_read_preference.py is left out because it hard-codes -p 6379): with REDIS_PASSWORD only the memcache-text test failed, and it is now opted out; without a password there were 0 failures. On the final head, test_harness_auth.py (with and without a password), 8 files standalone with a password (84/84, 3 by-design skips) and test_reconnections.py over a Unix socket with a password (32/32) pass.
  • 3-shard cluster sample with a password: 36/36 pass. An unauthenticated memtier aimed at the 3rd shard fails with "shard 3 master answered 20 request(s) -NOAUTH", so the guard covers every shard.
  • Read preference: test_read_preference_resp3.py and test_read_preference_failover.py under OSS_CLUSTER_REPLICAS=1 SHARDS=3, with and without a password, give 5 passes and 1 by-design skip, with no leaked redis-server.

Follow-up after review:

  • test_harness_auth.py runs a test through RLTest's hook runner and checks that the guard fails it.
  • If a password is set but no server can be read before the test, the test fails instead of passing unchecked. A server that goes away during the test is logged.
  • Passing checks print nothing, so a green CI log has no NOAUTH lines.
  • The guard's and shutdown_nosave()'s connections have redis-py retries off, including connections the client already has open, and a 5 s socket timeout (connections already open keep the one they were made with, which is redis-py's default of 5 s). A refused or successful SHUTDOWN on a replica client the test has already used now returns at once instead of after 4–8 s of retry backoff, and redis-py no longer resends it. The 3-shard replica failover file with a password takes 78 s instead of 132 s.
  • Fake-connection tests cover shutdown_nosave(), a restarted server, and a test with extra parameters.

Limits

  • The guard relies on add_test_hook() (RLTest#262) and the indexed getSlaveConnection() (RLTest#253). test_requirements.txt says so next to the pin, and two harness tests fail if a pin move drops either.
  • Class-based tests are not wrapped; the suite has none today.
  • No CI cell combines replicas with a password, so the replica-password half is covered by local runs and the fake-connection tests only.
  • A CONFIG RESETSTAT during a test clears errorstats and hides NOAUTH replies before it.
  • Run alone with --test, test_benchmark_logging.py has no guard because it doesn't import include.py; it talks to no server. In the full suite the guard is always installed.

Test-only change; no memtier code is touched.

🤖 Generated with Claude Code


Note

Low Risk
Changes are confined to the RLTest harness and dependencies; production memtier code is untouched, with moderate complexity in the global test hook and RLTest pin.

Overview
Fixes #842: on password-protected CI, memtier can exit 0 while every request gets -NOAUTH, so tests that omit auth still pass.

NOAUTH guard registers an RLTest hook that snapshots errorstat_NOAUTH on every shard master and replica before each test and fails if any count rises. Tests can opt out with @allow_noauth(reason) (used for intentional unauthenticated memcache-to-Redis cases). env_password(env) centralizes reading REDIS_PASSWORD / --oss_password; several suites drop duplicate manual --authenticate wiring and rely on add_required_env_arguments() / memtier_auth_args() instead.

Related harness fixes exposed while enabling the guard: cluster replica redis-py clients now authenticate; shutdown_nosave() only reports success after the server stops answering (avoids treating NOAUTH SHUTDOWN as a killed replica and leaking processes); bounded_client() disables redis-py retries for guard/shutdown paths. New test_harness_auth.py table-tests auth args and guard behavior. test_requirements.txt bumps redis-py ≥6.0 and the RLTest pin for add_test_hook (and existing cluster-replica support).

Test-only; no memtier binary changes.

Reviewed by Cursor Bugbot for commit 47da15e. Bugbot is set up for automated code reviews on this repo. Configure here.

memtier counts error replies as completed requests and exits 0, so in
the "TCP Plaintext with auth" CI cell a test whose memtier command line
forgets --authenticate still passes while every request is answered
-NOAUTH. Dropping the auth from test_sigpipe_immunity's command line,
for example, passes with 79897 NOAUTH replies recorded by the server.

When the env has a password, include.py now wraps each RLTest function
test that takes an env. Before the test it reads errorstat_NOAUTH from
INFO errorstats on every server of the env (each shard's master and its
replicas), and after the test, even one that failed, it asserts that no
count grew, naming the server and how many requests it answered NOAUTH.
Checking the servers catches every client: Benchmark runs, hand-built
Popen command lines and redis-py. RLTest has no per-test hook for
function tests, so the guard wraps the target that RLTest's loader
resolves before each test; include.py is imported while RLTest
discovers the test files, before any test runs and before the
--parallelism workers fork. It compares against the counts taken before
the test rather than running CONFIG RESETSTAT, so the commandstats that
tests assert on are left alone. A server that restarted during the test
counts from zero, and one the env's password cannot reach is skipped.

Tests that are unauthenticated on purpose opt out with
@allow_noauth(reason). Only test_cli_fuzz_phase1's two #426 item 3
tests need it: they send memcache_text and memcache_binary to Redis on
purpose, and memcache cannot AUTH. The other memcache-protocol runs
against Redis are rejected before they connect, and the wrong-credential
and fake-server tests do not talk to the env's servers.

The password is now read one way, with env_password(env) (the RLTest
node's "password"). test_retry_on_error and test_prometheus_redaction
restore requirepass from it, and test_progress_interval,
test_cluster_ask_asking and test_cli_validation_count_flags no longer
append a second --authenticate that add_required_env_arguments()
already adds.

The replica clients that get_cluster_replica_connections() builds now
carry that password too. Without it, on a password-protected env with
replicas, every replica command was answered NOAUTH and swallowed, so
test_read_preference_resp3 read 0 calls and failed. The replica
shutdown in test_read_preference_resp3 and test_read_preference_failover
also swallowed a NOAUTH reply to SHUTDOWN NOSAVE and still marked the
replica dead, so RLTest never stopped it and a redis-server leaked after
every such run. The new shutdown_nosave() reports success only once the
server stops answering, and only then is the replica marked dead.

test_harness_auth.py adds a table test of memtier_auth_args()'s skip
rules (-a, --authenticate, userinfo in the last --uri, memcache in the
last --protocol, no password) and tests of the guard against a fake
env.

Fixes #842

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

🤖 Automated first-pass review — a human maintainer's review is still required before merge.

Thanks for this. Reading errorstats on the server side instead of grepping memtier's stderr seems like the right call, since it also catches hand-built Popen lines and redis-py clients. The replica SHUTDOWN NOSAVE / leaked redis-server fix is a nice catch to come out of it. I read through all of it and have a few comments:

  • The harness now relies more heavily on the RLTest fork. Before this PR the pin was a temporary workaround until Fixed build for tls v1.3 on openssl v1.0.2. Added CI check #253 merged upstream. Now the guard also needs add_test_hook() (RLTest#262), which only exists in the fork. Separately, _install_noauth_guard() quietly returns on ImportError. That means that on upstream RLTest (or any pin without We should build and publish package to Ubuntu 24.04 (Noble Numbat) #262) the guard is just off, and the only signal is test_guard_is_installed_in_rltest failing on its own import. Did you consider making that case loud when REDIS_PASSWORD is set, e.g. printing a warning or failing? Otherwise a pin revert could switch off Test harness: the auth CI cell passes when memtier gets NOAUTH replies #842's protection without anyone noticing in the password cell. I may be wrong about how likely that revert is, so this may be worth a second look from whoever tracks the RLTest upstreaming.

  • I think noauth_guard() is only used by test_harness_auth.py. It also re-implements RLTest's "first positional parameter gets the env" rule, which is a second copy that can drift from the real one. Since test_guard_is_installed_in_rltest already drives run_with_hooks, could the fake-env tests go through that path too, so noauth_guard can be dropped from include.py? Do you confirm it's not needed elsewhere?

  • Nitpicking: test_bounded_client_turns_off_retries_on_open_connections appends to pool._available_connections, which is a private redis-py attribute. With redis>=6.0.0 and no upper bound, a future redis-py bump could break this test even if bounded_client() still works. Not a big deal, just flagging it.

  • The redis>=3.0.0 → >=6.0.0 bump looks fine for CI, since the workflows use Python 3.10. Local venvs that already exist will need a pip install -U, though. Maybe it's worth a line in the PR description.

The guard logic itself looks solid to me: the restart-to-zero handling, the check still running when the test fails, and failing instead of passing when no server can be read. The validation in the description covers the cases I'd want covered. Mostly I'd want the silent-disable question answered before this merges.

(would file this as a comment, not a formal block)

fcostaoliveira and others added 3 commits October 25, 2026 04:06
Follow-up to the NOAUTH guard (#842), from review.

The guard passed without checking anything when it could read no
server of the env before the test, for example after RLTest drift or a
password mismatch. It now fails the test, listing each server and its
error. A server that stops during the test, such as a replica a test
shuts down on purpose, is still not a failure, but the guard now prints
that it was not checked.

It asserts only when a count grew. In VERBOSE CI logs every passing test
used to print a "✅ (OK): 0 == 0 ... answered 0 request(s) -NOAUTH" line.

The guard's connections and shutdown_nosave() now use
bounded_client(): no redis-py retries and a 5 s socket timeout. A
stopped server used to cost about 4.5 s of retry backoff per guard read,
and a successful shutdown about 8 s. Both now return at once, a hung
server can no longer block the guard, and redis-py no longer resends
SHUTDOWN after the connection closes.

Tests whose first parameter takes the env are wrapped even if they have
more parameters, which is how RLTest decides to pass the env.

test_harness_auth.py gains:
- a check that RLTest's loader really wraps the tests it resolves (it
  fails if _install_noauth_guard() does nothing);
- fake-connection tests of shutdown_nosave(): a NOAUTH or other error
  reply to SHUTDOWN, or a server that keeps answering PING, is not a
  stop; a closed connection followed by a refused PING is;
- rows for no readable server, a server stopped mid-test, a restart back
  to 0 with no new NOAUTH, a passing test printing nothing, and a test
  with a defaulted second parameter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bounded_client only changed the pool's settings for new connections. The
replica clients shutdown_nosave gets from the read-preference tests have
already been used, and their pooled connections kept redis-py's default
retry, so a refused SHUTDOWN still took about 4 s and a successful one
about 8 s, and redis-py could resend the SHUTDOWN. Use the pool's
set_retry, which also reaches its existing connections, and drop them so
the next command reconnects with the socket timeout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Without pool.set_retry, a connection the client already opened keeps
redis-py's 10 retries, and test_harness_auth.py did not notice. The new
case puts such a connection in the pool and checks its retries are 0.
Also correct the comment: open connections keep the socket timeout they
were made with; only the retries reach them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7f1658c. Configure here.

Comment thread tests/include.py Resolved
fcostaoliveira and others added 2 commits October 25, 2026 06:08
_read_noauth caught every exception, so an RLTest API change, such as a
getSlaveConnection that takes no index, would have left that server
unchecked without a word. Catch only redis-py and socket errors, for a
server that is down or refuses us, and let anything else fail the test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ds from RLTest

bounded_client() and its test use Retry.get_retries() and
ConnectionPool.set_retry(), which redis>=3.0.0 did not promise. Next to
the RLTest pin, name the loader and replica APIs the guard relies on and
the tests that fail if a pin move changes them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks, answering the three points:

  • redis-py floor: raised to redis>=6.0.0 in a65c24c. One correction: include.py imports redis.backoff and redis.retry inside bounded_client(), not at module import, so an older redis-py wouldn't have broken the whole suite. On 5.x, bounded_client() works because the default is already 0 retries. Only test_bounded_client_turns_off_retries_on_open_connections errors there, because Retry.get_retries() needs 6.0. RLTest already needs redis>=5.0, and CI installs 8.1.0.
  • RLTest hook: I've kept the guard here for now. Adding a per-test hook would mean changing the fork's PR Fixed build for tls v1.3 on openssl v1.0.2. Added CI check #253 (RLTest) as well. a65c24c adds the note you suggested next to the pin: moving it has to keep TestFunction.initialize/target and the indexed getSlaveConnection. Two tests fail if either changes: test_guard_is_installed_in_loader and, since 56382cc, test_noauth_guard_raises_on_an_unexpected_error, now that the guard no longer swallows a TypeError.
  • pool._available_connections: I'm keeping it on purpose. It's the only way to give the test a connection that is already open without a server, and it is the same list in redis-py 5.0 through 8.1. If an upgrade renames it, the test fails loudly; it can't pass by mistake.

The TLS v1.2 cell on 56382cc lost its runner ("The hosted runner lost communication with the server") after 405 PASS and 0 FAIL. The new head reruns it.

Instead of wrapping RLTest.loader.TestFunction.initialize, register the
check as a test hook. add_test_hook() is new in the RLTest fork commit
pinned here (RedisLabsModules/RLTest#262, on top of #253). The hook gets
the test function, so @allow_noauth still opts a test out.
test_guard_is_installed_in_rltest now runs a test through RLTest's hook
runner and expects the guard to fail it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Following up on the RLTest hook suggestion: 3e00990 does it. RedisLabsModules/RLTest#262 adds add_test_hook(hook), where hook(env, test) returns a context manager run around each function test. The pin moves to fork commit 31b31e4, which is #253's commit plus that change. The guard now registers through the hook instead of wrapping TestFunction.initialize. End to end with a password, an unauthenticated memtier run fails with the NOAUTH message and the @allow_noauth copy passes. test_harness_auth.py passes 9/9 with and without a password, and the 3-shard replica failover file passes 3/3.

73c10b7 keeps one copy of a test hook that a test file adds again each
time RLTest re-imports it. memtier registers its hook from include.py,
which is imported once, so it was not affected; this keeps the pin on
the reviewed version of RedisLabsModules/RLTest#262.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

880af13 moves the RLTest pin to fork commit 73c10b7. Reviewers found that RLTest#262 only skipped a hook added a second time when it was the same function object, so a hook added at the top of a test file was added again each time RLTest re-imported the file. The hook now counts as the same when it has the same module and name, and a new flow test checks, through the runner, that it runs once per test. memtier wasn't affected, since include.py registers its hook once.

fcostaoliveira and others added 2 commits October 25, 2026 07:57
…ctions

09176c8 matches a re-added test hook by module and name only when it is
a top-level function, so distinct lambdas or closures are not merged.
memtier's hook is a top-level function in include.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Review summary for 47da15e. All 7 lenses approve (semantics, output, tests, lifecycle, interactions, maintainability, build). CI ran 15,875 tests with 0 failed. Every RLTest job installed fcostaoliveira/RLTest@09176c8, and every per-test result matches master. In Plaintext with auth the guard is live and adds no measurable time (23.5 vs 23.1 min).

Answering the updated review:

  1. Silent ImportError in _install_noauth_guard(): this is deliberate. include.py is also imported where RLTest isn't installed. A pin without RLTest#262 doesn't pass unnoticed either: test_guard_is_installed_in_rltest imports RLTest.test_hooks and checks that the registered hook fails a test, so it fails in all 14 cells. The note next to the pin names it.
  2. noauth_guard() repeating RLTest's env rule: only the harness tests use it, to drive noauth_check against a fake env. The real path is the hook, which RLTest calls only for tests it passes the env to.
  3. _available_connections: answered above.
  4. Existing venvs: yes, after redis>=6.0.0, run pip install -U -r tests/test_requirements.txt (or utils/install_test_requirements.sh). CI installs fresh each run.

@fcostaoliveira
fcostaoliveira merged commit 47814ae into master Oct 25, 2026
151 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test harness: the auth CI cell passes when memtier gets NOAUTH replies

1 participant