Restrict access to a Service or a Route (or the deprecated API entity) by whitelisting or blacklisting consumers using arbitrary ACL group names. This plugin requires an [authentication plugin][faq-authentication] to have been already enabled on the Service or the Route (or API).


Terminology

  • plugin: a plugin executing actions inside Kong before or after a request has been proxied to the upstream API.
  • API: (deprecated) the Kong entity representing your upstream service placed behind Kong, for which Kong proxies requests to.
  • Service: the Kong entity representing an external upstream API or microservice.
  • Route: the Kong entity representing a way to map downstream requests to upstream services.
  • upstream service: this refers to your own API/service sitting behind Kong, to which client requests are forwarded.

Configuration

Enabling the plugin for a Service

Configure on top of a Service by executing the following request on your Kong server:

$ curl -X POST http://kong:8001/services/{service}/plugins \
    --data "name=acl"  \
    --data "config.whitelist=group1, group2"
  • service: the id or name of the Service that this plugin configuration will target.

Enabling the plugin for a Route

Configure on top of a Route with:

$ curl -X POST http://kong:8001/routes/{route_id}/plugins \
    --data "name=acl"  \
    --data "config.whitelist=group1, group2"
  • route_id: the id of the Route that this plugin configuration will target.

Enabling the plugin for an API

If you are using the deprecated API entity, you can configure on top of an API by executing the following request on your Kong server:

$ curl -X POST http://kong:8001/apis/{api}/plugins \
    --data "name=acl"  \
    --data "config.whitelist=group1, group2"
  • api: either id or name of the API that this plugin configuration will target.

Global plugins

All plugins can be configured using the http:/kong:8001/plugins/ endpoint. A plugin which is not associated to any API, Service, Route or Consumer is considered "global", and will be run on every request. Read the Plugin Reference and the Plugin Precedence sections for more information.

Parameters

Here's a list of all the parameters which can be used in this plugin's configuration:

form parameterdefaultdescription
nameThe name of the plugin to use, in this case acl
api_idThe id of the API which this plugin will target.
service_idThe id of the Service which this plugin will target.
route_idThe id of the Route which this plugin will target.
config.whitelist
semi-optional

Comma separated list of arbitrary group names that are allowed to consume the Service or the Route (or API). One of config.whitelist or config.blacklist must be specified.

config.blacklist
semi-optional

Comma separated list of arbitrary group names that are not allowed to consume the Service or the Route (or API). One of config.whitelist or config.blacklist must be specified.

Note that the whitelist and blacklist models are mutually exclusive in their usage, as they provide complimentary approaches. That is, you cannot configure an ACL with both whitelist and blacklist configurations. An ACL with a whitelist provides a positive security model, in which the configured groups are allowed access to the resources, and all others are inherently rejected. By contrast, a blacklist configuration provides a negative security model, in which certain groups are explicitly denied access to the resource (and all others are inherently allowed).

Usage

In order to use this plugin, you need to properly have configured your Service or Route (or API) with an authentication plugin so that the plugin can identify who is the client Consumer making the request.

Associating Consumers

Once you have added an authentication plugin to a Service or a Route (or API) and you have created your Consumers, you can now associate a group to a Consumer using the following request:

$ curl -X POST http://kong:8001/consumers/{consumer}/acls \
    --data "group=group1"

consumer: The id or username property of the Consumer entity to associate the credentials to.

form parameter default description
group The arbitrary group name to associate to the consumer.

You can have more than one group associated to a consumer.

Upstream Headers

When a consumer has been validated, the plugin will append a X-Consumer-Groups header to the request before proxying it to the upstream service, so that you can identify the groups associated with the consumer. The value of the header is a comma separated list of groups that belong to the consumer, like admin, pro_user.

Paginate through the ACLs

Note: This endpoint was introduced in Kong 0.11.2.

You can retrieve all the ACLs for all Consumers using the following request:

$ curl -X GET http://kong:8001/acls

{
    "total": 3,
    "data": [
        {
            "group": "foo-group",
            "created_at": 1511391159000,
            "id": "724d1be7-c39e-443d-bf36-41db17452c75",
            "consumer_id": "89a41fef-3b40-4bb0-b5af-33da57a7ffcf"
        },
        {
            "group": "bar-group",
            "created_at": 1511391162000,
            "id": "0905f68e-fee3-4ecb-965c-fcf6912bf29e",
            "consumer_id": "c0d92ba9-8306-482a-b60d-0cfdd2f0e880"
        },
        {
            "group": "baz-group",
            "created_at": 1509814006000,
            "id": "ff883d4b-aee7-45a8-a17b-8c074ba173bd",
            "consumer_id": "c0d92ba9-8306-482a-b60d-0cfdd2f0e880"
        }
    ]
}

You can filter the list using the following query parameters:

Attributes Description
id
optional
A filter on the list based on the ACL id field.
group
optional
A filter on the list based on the ACL group field.
consumer_id
optional
A filter on the list based on the ACL consumer_id field.
size
optional, default is 100
A limit on the number of objects to be returned.
offset
optional
A cursor used for pagination. offset is an object identifier that defines a place in the list.

Retrieve the Consumer associated with an ACL

Note: This endpoint was introduced in Kong 0.11.2.

It is possible to retrieve a Consumer associated with an ACL using the following request:

curl -X GET http://kong:8001/acls/{id}/consumer

{
   "created_at":1507936639000,
   "username":"foo",
   "id":"c0d92ba9-8306-482a-b60d-0cfdd2f0e880"
}

id: The id property of the ACL for which to get the associated Consumer.

Keep up with the latest features