Describe the bug
User password is not saved when creating with redis-cli setuser testuser on >testpassword (non-interactive mode) and > is not escaped. It works fine in the following conditions:
* if redis-cli is started in interactive mode
* if > is escaped
* The user is created in ACLFILE instead of using redis-cli
To reproduce
Terminal #1:
docker run --rm --name=redis redis
Terminal #2:
docker exec -it redis bash
redis-cli ACL SETUSER testuser on >testpassword
redis-cli ACL GETUSER testuser
This yields the following result - notice that the password is not set:
1) "flags"
2) 1) "on"
2) "allchannels"
3) "passwords"
4) (empty array)
5) "commands"
6) "-@all"
7) "keys"
8) (empty array)
9) "channels"
10) 1) "*"
Expected behavior
The user should have set the password, such that redis-cli ACL GETUSER testuser will yield the following result:
1) "flags"
2) 1) "on"
2) "allchannels"
3) "passwords"
4) 1) "9f735e0df9a1ddc702bf0a1a7b83033f9f7153a00c29de82cedadc9957289b05"
5) "commands"
6) "-@all"
7) "keys"
8) (empty array)
9) "channels"
10) 1) "*"
Additional information
It works fine if the password section is put in quotes or > is escaped:
redis-cli ACL SETUSER testuser on ">testpassword"
redis-cli ACL SETUSER testuser on \>testpassword
It also works fine if redis-cli is run in interactive mode:
redis-cli
ACL SETUSER testuser on >testpassword
This inconsistent behaviour is very confusing - if it cannot be fixed, then it should at least be documented for e.g. redis-cli. Btw. many thanks for this awesome software :)
Comment From: zuiderkwast
> is shell syntax. The documentation for this is displayed if you type man sh in your shell. You will find that it means "Redirect standard output to file".
So if you type redis-cli ACL SETUSER testuser on >testpassword in a shell, it means you run the command redis-cli ACL SETUSER testuser on and the output of the command is saved in a file called "testpassword" in the current directory. There is nothing Redis or redis-cli can do about it.
Comment From: andersaaberg
@zuiderkwast : Many thanks for quick reply! Users are likely to run into this problem, specially with the introduction of ACL in Redis 6 where ">" is used for password. It would be very helpful with a little documentation at https://redis.io/docs/manual/cli/ about how to avoid these problems - is there a bulletproof way so I do not have to remember to escape every single piece of shell syntax individually?
Comment From: zuiderkwast
Well, we could add examples with special characters on the CLI page or on the ACL page. Maybe you can suggest something in a PR?
But IMHO if you're writing shell scripts or even commands in the shell, you're expected to know which characters need to be escaped. I think it's a fair requirement. (Theoretically, it can also depend on the shell. If you're using some completely different shell, it may be other characters that need to be escaped.)
Comment From: zuiderkwast
Actually, there is already an example with '>' on the CLI page:
$ redis-cli INCR mycounter > /tmp/output.txt
$ cat /tmp/output.txt
8