motiv-labs / janus

An API Gateway written in Go
https://hellofresh.gitbooks.io/janus
MIT License
2.79k stars 317 forks source link

Why ratelimit is required in oauth2 plugin? #285

Closed chendanshuang closed 6 years ago

chendanshuang commented 6 years ago

I add an api def as below with oauth2 plugin:

    {
        "name": "cdosapi-test-auth",
        "active": true,
        "proxy": {
            "preserve_host": false,
            "listen_path": "/test/*",
            "upstream_url": "",
            "upstreams": {
                "balancing": "roundrobin",
                "targets": [
                    {
                        "target": "http://10.18.6.126:91/",
                        "weight": 0
                    },
                    {
                        "target": "http://10.18.6.126:92/",
                        "weight": 0
                    }
                ]
            },
            "insecure_skip_verify": false,
            "strip_path": true,
            "append_path": false,
            "enable_load_balancing": false,
            "methods": [
                "ALL"
            ],
            "hosts": []
        },
        "plugins": [
            {
                "name": "oauth2",
                "enabled": true,
                "config": {
                    "server_name": "local"
                }
            }
        ]
    }

Unfornatelly, oauth2 is not loaded successully. I found a error in logs:

ERRO[1073] Not able to create rate limit error="incorrect format ''" name=local

I can not understand why ratelimit is required oauth2 plugin? I haven't found any case like this in all docs. If ratelimit is need, what's the correct format? Thx!

Below is detailed logs to handle this request.

DEBU[1073] Started request                               method=PUT path=/apis/cdosapi-test-auth
DEBU[1073] Resource added                                name=cdosapi-test-auth
DEBU[1073] Sending notification                          type=ApiUpdated
INFO[1073] Completed handling request                    code=200 duration=2 host="10.18.6.126:81" method=PUT referer= remote-addr="10.32.3.145:58193" request=/apis/cdosapi-test-auth user-agent=PostmanRuntime/7.1.1
DEBU[1073] Event triggered                               event_name=reload
DEBU[1073] Building token strategy                       name=jwt
DEBU[1073] Loading OAuth servers configurations         
DEBU[1073] Registering OAuth server                      name=local
DEBU[1073] Muted stats counter increment                 metric=error-log.error.-.-
DEBU[1073] Muted stats counter increment                 metric=total.error-log
ERRO[1073] Not able to create rate limit                 error="incorrect format ''" name=local
DEBU[1073] Endpoint not registered                      
DEBU[1073] Registering OAuth endpoint                    listen_path=/auth/token
DEBU[1073] Using a load balancing algorithm              balancing_alg=roundrobin
DEBU[1073] Registering a route                           listen_path=/auth/token
DEBU[1073] Endpoint registered                           listen_path=/auth/token
DEBU[1073] OAuth server registered                       name=local
DEBU[1073] Done loading OAuth servers configurations    
DEBU[1073] Using a load balancing algorithm              balancing_alg=roundrobin
DEBU[1073] Registering a route                           listen_path=/api
DEBU[1073] Registering a route                           listen_path="/api/*"
DEBU[1073] API registered                                api_name=cdosapi
DEBU[1073] Using a load balancing algorithm              balancing_alg=roundrobin
DEBU[1073] Registering a route                           listen_path=/admin
DEBU[1073] Registering a route                           listen_path="/admin/*"
DEBU[1073] API registered                                api_name=cdosapi-admin
DEBU[1073] Plugin enabled                                api_name=cdosapi-test-auth name=oauth2
DEBU[1073] Building token strategy                       name=jwt
DEBU[1073] Using a load balancing algorithm              balancing_alg=roundrobin
DEBU[1073] Registering a route                           listen_path=/test
DEBU[1073] Registering a route                           listen_path="/test/*"
DEBU[1073] API registered                                api_name=cdosapi-test-auth
italolelis commented 6 years ago

Hi @shuangstar,

This was a bug that we fixed recently. If you check this file https://github.com/hellofresh/janus/blob/master/pkg/plugin/oauth2/loader.go#L48 There is an option that you can define if you wanna use rate limit on this endpoint or not.

By default, it's not enabled. Also, in case you want to use the rate limit the correct format is 10-S (10 req/sec), 50-M (50 req/min) and so on.

Hope this helps.