redis-commander icon indicating copy to clipboard operation
redis-commander copied to clipboard

readonly mode commands

Open skaravad opened this issue 2 years ago • 4 comments

Hello,

We plan to use info and select commands in readonly mode , I'm not a nodeJs expert, any files that I can modify to make this happen ? currently when READ_ONLY is enabled, the INFO and SELECT commands return this

info keyspace
"ERROR: Command not read-only"
select 13
"ERROR: Command not read-only"

skaravad avatar Oct 01 '23 21:10 skaravad

I attempted modifying node_modules/@ioredis/commands/built/commands.json node_modules/@ioredis/commands/commands.json

   "info": {
        "arity": -1,
        "flags": [
            "readonly",
            "loading",
            "stale"
        ],
        "keyStart": 0,
        "keyStop": 0,
        "step": 0
    },

skaravad avatar Oct 01 '23 21:10 skaravad

Hello, the list of read-only commands is (where ever allowed by the server) queried directly from the server itself after connect. "COMMAND" is send and the output parsed for all commands having the property "readonly"

Example output for some commands:

61) 1) "select"
     2) (integer) 2
     3) 1) loading
        2) fast
     4) (integer) 0
     5) (integer) 0
     6) (integer) 0
...
86) 1) "dbsize"
     2) (integer) 1
     3) 1) readonly
        2) fast
     4) (integer) 0
     5) (integer) 0
     6) (integer) 0
...
137) 1) "cluster"
     2) (integer) -2
     3) 1) admin
     4) (integer) 0
     5) (integer) 0
     6) (integer) 0
138) 1) "flushdb"
     2) (integer) -1
     3) 1) write
     4) (integer) 0
     5) (integer) 0
     6) (integer) 0
...
140) 1) "info"
     2) (integer) -1
     3) 1) random
        2) loading
        3) stale
     4) (integer) 0
     5) (integer) 0
     6) (integer) 0

That is why (from this list) "dbsize" only is allowed but not "select" or "flushdb".

Maybe the selection criteria should be evaluated to allow info or similar too. But must be make sure to not open up to more dangerous commands...

sseide avatar Oct 10 '23 15:10 sseide

thank you , will give it a try.

skaravad avatar Oct 18 '23 06:10 skaravad

Hello, i just added these two commands to a special list set as read-only on dynamic evaluation too. Its done in master branch and "latest" docker image.

Can you give it a try? And are there more commands missing as read-only?

Now the list is defined as a configuration option and can be overwritten with whatever you like inside your local.json file. The fallback/default is defined in the default.json config.

sseide avatar Nov 22 '23 09:11 sseide