consumer-restriction
Summary#
Introduction#
The consumer-restriction makes corresponding access restrictions based on different objects selected.
Attributes#
| Name | Type | Requirement | Default | Valid | Description |
|---|---|---|---|---|---|
| type | string | optional | consumer_name | ["consumer_name", "service_id"] | According to different objects, corresponding restrictions, support consumer_name, service_id. |
| whitelist | array[string] | required | Grant full access to all users specified in the provided list , has the priority over allowed_by_methods | ||
| blacklist | array[string] | required | Reject connection to all users specified in the provided list , has the priority over whitelist | ||
| rejected_code | integer | optional | 403 | [200,...] | The HTTP status code returned when the request is rejected. |
| allowed_by_methods | array[object] | optional | Set a list of allowed HTTP methods for the selected user , HTTP methods can be ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE"] |
For the type field is an enumerated type, it can be consumer_name or service_id. They stand for the following meanings:
- consumer_name: Add the
usernameofconsumerto a whitelist or blacklist (supporting single or multiple consumers) to restrict access to services or routes. - service_id: Add the
idof theserviceto a whitelist or blacklist (supporting one or more services) to restrict access to the service. It needs to be used in conjunction with authorized plugins.
Example#
How to restrict consumer_name#
The following is an example. The consumer-restriction plugin is enabled on the specified route to restrict consumer access.
Test Plugin
Requests from jack1:
Requests from jack2:
How to restrict allowed_by_methods#
This example restrict the user jack1 to only POST on the resource
Test Plugin
Requests from jack1:
Add the capability for jack1 to get the resource
Requests from jack1:
How to restrict service_id#
The service_id method needs to be used together with the authorization plug-in. Here, the key-auth authorization plug-in is taken as an example.
- Create two services.
- Bind the
consumer-restrictionplugin on theconsumer(need to cooperate with an authorized plugin to bind), and add theservice_idwhitelist list.
- Open the
key-authplugin on the route and bind theservice_idto1.
Test Plugin
The service_id in the whitelist column allows access, and the plug-in configuration takes effect.
- Open the
key-authplugin on the route and bind theservice_idto2.
Test Plugin
It means that the service_id that is not in the whitelist is denied access, and the plug-in configuration takes effect.
Disable Plugin#
When you want to disable the consumer-restriction plugin, it is very simple,
you can delete the corresponding json configuration in the plugin configuration,
no need to restart the service, it will take effect immediately:
The consumer-restriction plugin has been disabled now. It works for other plugins.