Fix Redis DENIED Redis is running in protected mode
Redis DENIED running in protected mode means the default user has no password, so remote clients get blocked. Set a password; don't turn protected mode off.
DENIED Redis is running in protected mode because protected mode is enabled and no password is set for the default user. In this mode connections are only accepted from the loopback interface. …Protected mode is on and the default user has no password, so Redis answers any connection from outside loopback with this explanation instead of running commands. The connection itself works; no command is accepted. The message lists four fixes. The first three turn protected mode off, which opens a password-less Redis to the network. The last one, a password for the default user, is the right fix.
The official docs describe protected mode as a safeguard added in 3.2.0 because so many Redis instances were left exposed on the internet (Redis security — Protected mode).
[1] Check the conditions. On the Redis server itself (loopback is not refused), read three values:
$ redis-cli CONFIG GET protected-mode bind requirepassprotected-modeyesbind* -::*requirepass $ redis-cli ACL LISTuser default on nopass sanitize-payload ~* &* +@allprotected-mode yes plus nopass on default produces this error. On the server itself, PING still returns PONG.
[2] Give the default user a password. From loopback you can do it at runtime. Remote clients then get NOAUTH instead, and the password lets them in.
$ redis-cli CONFIG SET requirepass '<password>'OKFrom another host (a sidecar container in the test):
$ redis-cli -h redis pingNOAUTH Authentication required. $ redis-cli -h redis --no-auth-warning -a '<password>' pingPONGCONFIG SET is lost on restart, so also set requirepass in redis.conf. For putting the password into apps and for WRONGPASS, see Redis NOAUTH Authentication required. Use a long value, for example from ACL GENPASS as the docs recommend.
[3] If you created a separate ACL user, the default user must be closed too. In the test, logging in as a new user app with its password still hit protected mode, and so did setting default to off, because nopass was still on it.
$ redis-cli -h redis --user app --pass '<app password>' --no-auth-warning pingAUTH failed: DENIED Redis is running in protected mode because protected mode is enabled and no password is set for the default user. …Error: Connection reset by peerClearing the "no password" state of default lifts it. resetpass removes both the password list and nopass, so nobody can log in as default afterwards.
$ redis-cli ACL SETUSER default resetpassOK$ redis-cli -h redis --user app --pass '<app password>' --no-auth-warning pingPONG$ redis-cli -h redis pingNOAUTH Authentication required. From then on, redis-cli on the server also needs a user (--user app --pass …). Create an admin user first, then run resetpass. To undo, run ACL SETUSER default nopass as that admin user.
[4] Changing bind alone did not lift it. The docs describe the trigger as "the default configuration (binding all the interfaces) and no password", but in the test (7.4.12) an explicit --bind 0.0.0.0 still returned DENIED. bind decides which addresses Redis listens on; it does not replace a password. For a server that must accept remote clients, narrow bind to the private address (for example bind 127.0.0.1 -::1 192.0.2.10), allow only app servers in the firewall, and do [2] on top.
[5] Turn protected mode off only in a trusted segment where a password is impossible. The message's CONFIG SET protected-mode no (from loopback), protected-mode no in the config file and the --protected-mode no startup option all do the same. From that moment anyone who reaches the port can run every command without a password — the docs warn that a single FLUSHALL from an attacker deletes the whole data set. If you do it, restrict source addresses in the firewall first; to revert, run CONFIG SET protected-mode yes and fix the config file too.
[6] With the official Docker image you normally never see this error. The image is built with the protected-mode default changed to no, on the grounds that ports are not exposed automatically in Docker (docker-library/redis Dockerfile). The tested image behaved that way:
$ redis-cli CONFIG GET protected-modeprotected-modenoSo running the container with -p 6379:6379 publishes a password-less Redis on every host address. Give containers a password too (--requirepass or a config file) and publish only where needed, such as -p 127.0.0.1:6379:6379. Conversely, if you start the image with the source redis.conf, that file's protected-mode yes applies again.