Kong 自定义身份验证层和速率限制

Kong custom auth layer and rate limiting

我想用Kong来保护一些服务。但是我已经用了一个idm来管理用户。

用户在请求kong网关时从idm中获取一个token并放入header中。为此,我会编写一个插件来执行此操作。然后插件会请求 idm。如果允许用户发出此请求以及用户在 idm 中拥有的用户 ID,则您会从 idm 获得答案。所以用户只是在idm中注册,并不是Kong中的消费者。如果我现在想使用速率限制,插件描述说 If the underlying Service/Route (or deprecated API entity) has no authentication layer, the client IP address will be used, otherwise the Consumer will be used if an authentication plugin has been configured.

现在可以使用idm中的用户id来限制速率吗?

我已经找到了:

但我找不到问题的答案。

您可以将 config.limit_by 设置为 header 并将 config.header_name 设置为自定义名称 (configuration). So the plugin needs to set a custom header e.g. 'x-user-id' to the id given from the idm. You have to make sure, that your plugin runs before the rate limiting plugin. You can look this up here ( > 901)。现在只需将 config.header_name 到 x-user-id 并且速率限制有效。我找不到其他解决方案。