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 to have been already enabled on the Service or the Route (or API).

Note: The functionality of this plugin as bundled with versions of Kong prior to 0.14.1 and Kong Enterprise prior to 0.34 differs from what is documented herein. Refer to the CHANGELOG for details.

Terminology

  • plugin: a plugin executing actions inside Kong before or after a request has been proxied to the upstream API.
  • 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.
  • API: a legacy entity used to represent your upstream services. Deprecated in favor of Services since CE 0.13.0 and EE 0.32.

Configuration

Enabling the plugin on a Service

Configure this plugin on a Service by making the following request:

$ curl -X POST http://kong:8001/services/{service}/plugins \
    --data "name=acl"  \
    --data "config.whitelist=group1, group2" \
    --data "config.hide_groups_header=true"

  • service: the id or name of the Service that this plugin configuration will target.

Enabling the plugin on a Route

Configure this plugin on a Route with:

$ curl -X POST http://kong:8001/routes/{route_id}/plugins \
    --data "name=acl"  \
    --data "config.whitelist=group1, group2" \
    --data "config.hide_groups_header=true"

  • route_id: the id of the Route that this plugin configuration will target.

Enabling the plugin on an API

If you are using an older version of Kong with the legacy API entity (deprecated in favor of Services since CE 0.13.0 and EE 0.32.), you can configure this plugin on top of such an API by making the following request:

$ curl -X POST http://kong:8001/apis/{api}/plugins \
    --data "name=acl"  \
    --data "config.whitelist=group1, group2" \
    --data "config.hide_groups_header=true"

  • 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 Service, Route or Consumer (or API, if you are using an older version of Kong) 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
service_idThe id of the Service which this plugin will target.
route_idThe id of the Route which this plugin will target.
enabledtrueWhether this plugin will be applied.
api_idThe id of the API which this plugin will target. Note: The API Entity is deprecated in favor of Services since CE 0.13.0 and EE 0.32.
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.

config.hide_groups_header
optional

false

Flag which if enabled (true), prevents the X-Consumer-Groups header to be sent in the request to the upstream service.

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.

This header will not be injected in the request to the upstream service if the hide_groups_header config flag is set to true.

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.