Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request help: How to add password auth support for limit-count-redis #971

Closed
totemofwolf opened this issue Dec 13, 2019 · 3 comments · Fixed by #1150
Closed

request help: How to add password auth support for limit-count-redis #971

totemofwolf opened this issue Dec 13, 2019 · 3 comments · Fixed by #1150
Assignees

Comments

@totemofwolf
Copy link
Contributor

totemofwolf commented Dec 13, 2019

Issue description

We need to support auth password for redis in production env.
So i modified the file limit-count/limit-count-redis.lua as follows:

--- a/lua/apisix/plugins/limit-count/limit-count-redis.lua
+++ b/lua/apisix/plugins/limit-count/limit-count-redis.lua
@@ -51,6 +51,20 @@ function _M.incoming(self, key)
         return false, err
     end
 
+    if pass then
+        local ok, err = red:auth(conf.redis_pass)
+        if not ok then
+            return nil, redis_err(err)
+        end
+    end
+
+    if dbid then
+        local ok, err = red:select(conf.redis_dbid)
+        if not ok then
+            return nil, redis_err(err)
+        end
+    end
+
     local limit = self.limit
     local window = self.window
     local remaining

and

--- a/lua/apisix/plugins/limit-count.lua
+++ b/lua/apisix/plugins/limit-count.lua
@@ -45,6 +45,9 @@ local schema = {
         redis_port = {
             type = "integer", minimum = 1
         },
+        redis_pass = {
+            type = "string", minLength = 0
+        },
         redis_timeout = {
             type = "integer", minimum = 1
         },

when i do this request again, it says that:

$ curl -i 127.0.0.1:9180/apisix/admin/routes/00000000000000000075 -X PUT -H 'Content-Type: application/json' -d '
> {
>     "uris":[
>         "/api/admin/login"
>     ],
>     "hosts":[
>         "blog.nsa.work"
>     ],
>     "methods":[
>         "POST"
>     ],
>     "plugins":{
>         "limit-count":{
>             "count":2,
>             "time_window":60,
>             "rejected_code":503,
>             "key":"http_x_forwarded_for",
>             "policy":"redis",
>             "redis_host":"127.0.0.1",
>             "redis_port":6389,
>             "redis_pass":"xxxx",
>             "redis_timeout":1000
>         }
>     },
>     "vars":[
>         [
>             "scheme",
>             "==",
>             "https"
>         ]
>     ],
>     "upstream_id":"2",
>     "desc":"https://blog.nsa.work/api/admin/login"
> }'
HTTP/1.1 400 Bad Request
Date: Fri, 13 Dec 2019 10:36:41 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX web server

{"error_msg":"failed to check the configuration of plugin limit-count err: additional properties forbidden, found redis_pass"}

How to support this additional properties of plugin limit-count ?

Environment

  • apisix version (cmd: apisix version): 0.9
  • OS: alpine 3.7
@agile6v
Copy link
Member

agile6v commented Dec 14, 2019

Hi @totemofwolf

I can't reproduce your problem. You may need to confirm whether APISIX has been restarted and the code has passed.

@totemofwolf
Copy link
Contributor Author

Hi @totemofwolf

I can't reproduce your problem. You may need to confirm whether APISIX has been restarted and the code has passed.

So we can use redis_pass property for limit-count-redis plugin without modifying the related files now?

@agile6v
Copy link
Member

agile6v commented Dec 15, 2019

@totemofwolf Maybe I didn't make it clear.

I go through the APISIX code, found that the error you encountered was caused by the failure of the schema parsing. I also modified the local code according to your modification and then curl 127.0.0.1:9180/apisix/admin/routes/00000000000000000075 -X PUT, but it could not be reproduced.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants