I’m having this issue with redis, i have a node app that listens on a socket, it runs constantly with forever and uses redis to store data. After a couple of hours the node app crashes and it logs:
READONLY You can't write against a read only replica
The thing is, i don’t know why it randomly becomes read only, i only have a single instance of redis running inside a docker container with appendonlydir set to store all the data in a file. The path is fully accessible by the redis container and i can see the appendonlydir file on the host and inside the container.
There isn’t much more i can give, the error is above with no indication of why it’s randomly happening after the writing is working perfectly fine for a few hours.
If it helps my dockerfile:
FROM redis:7.0.0
RUN usermod --uid 1001 redis
RUN groupmod --gid 1001 redis
EXPOSE 6379
COPY ./docker/chat-redis/redis.conf /usr/local/etc/redis/redis.conf
CMD ["redis-server", "--include /usr/local/etc/redis/redis.conf"]
The folder on the host is owned by 1001:1001 and as i say can write to it perfectly fine when i first start up the redis container.
Please let me know if you need to see any of the redis.conf file, i haven’t much in there except the default for version 7 and appendonlydir turned on.
Thee permissions on the directory are also allowing writing of the owner which is 1001
drwx------ 2 1001 1001 4096 Jun 6 13:39 appendonlydir
2
Answers
For anyone running into this issue, what seems to have happened is that i hadn't yet closed the firewall ports while i was putting the server setup together and someone got into to the redis container and changed it to read only.
I didn't set a password on it as it was going to be used in a private network only, but clearly someone got in before i had chance to close the external port.
I have since set a password.
Be very careful with the
ports
definition in your docker compose file or the--publish/-p
option fordocker run
! If you only need to expose the container ports to the local host, I would always specify ports as127.0.0.1:<host-port>:<container-port>
. The<host-port>:<container-port>
syntax exposes the host port to the entire network even when you have some firewall rules, e.g. withufw
, set up. Unfortunately, this isn’t very clear in the Docker docs. See also How To Use Docker with a UFW Firewall:So I just ran into the same issue and had the same conclusion as @Glen: someone accessed my (unsecured) redis instance and turned it into a read-only replica:
From what I can tell they pushed (at least) the following keys onto my redis instance:
The base64 encoded values decode to the following:
At the time of this writing, the domain (
kiss.a-dog.top
) seems to be defunct now, so I hope that it didn’t actually download any shell scripts from there. But I will still recreate the host machine I guess.