Kong Enterprise only: This plugin is only available with a Kong Enterprise subscription.
Please inquire about Kong Enterprise by contacting us - or start a free trial today.

Add LDAP Bind Authentication with username and password protection. The plugin will check for valid credentials in the Proxy-Authorization and Authorization header (in this order).


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.
  • Consumer: the Kong entity representing a developer or machine using the API. When using Kong, a Consumer only communicates with Kong which proxies every call to the said upstream API.
  • Credential: a unique string associated with a Consumer, also referred to as an API key.
  • 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=ldap-auth-advanced" 

  • 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=ldap-auth-advanced" 

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

Enabling the plugin on a Consumer

You can use the http://localhost:8001/plugins endpoint to enable this plugin on specific Consumers:

$ curl -X POST http://kong:8001/plugins \
    --data "name=ldap-auth-advanced" \
    --data "consumer_id={consumer_id}" 

Where consumer_id is the id of the Consumer we want to associate with this plugin.

You can combine consumer_id and service_id

in the same request, to furthermore narrow the scope of the plugin.

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=ldap-auth-advanced" 

  • 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 ldap-auth-advanced
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.
consumer_idThe id of the Consumer which this plugin will target.
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.ldap_host

Host on which the LDAP server is running

config.ldap_port

TCP port where the LDAP server is listening

config.ldap_password

The password to the LDAP server

config.start_tls

false

Set it to true to issue StartTLS (Transport Layer Security) extended operation over ldap connection

config.base_dn

Base DN as the starting point for the search; e.g., “dc=example,dc=com”

config.verify_ldap_host

false

Set it to true to authenticate LDAP server. The server certificate will be verified according to the CA certificates specified by the lua_ssl_trusted_certificate directive.

config.attribute

Attribute to be used to search the user; e.g., “cn”

config.cache_ttl

60

Cache expiry time in seconds

config.timeout
optional

10000

An optional timeout in milliseconds when waiting for connection with LDAP server

config.keepalive
optional

10000

An optional value in milliseconds that defines for how long an idle connection to LDAP server will live before being closed

config.anonymous
optional

An optional string (consumer uuid) value to use as an “anonymous” consumer if authentication fails. If empty (default), the request will fail with an authentication failure 4xx. Please note that this value must refer to the Consumer id attribute which is internal to Kong, and not its custom_id.

config.header_type
optional

ldap

An optional string to use as part of the Authorization header. By default, a valid Authorization header looks like this: Authorization: ldap base64(username:password). If header_type is set to “basic” then the Authorization header would be Authorization: basic base64(username:password). Note that header_type can take any string, not just "ldap" and "basic".

config.consumer_optional
optional

false

Whether consumer is optional

config.consumer_by
optional

username

Whether to authenticate consumer based on username or custom_id

config.hide_credentials
optional

false

An optional boolean value telling the plugin to hide the credential to the upstream server. It will be removed by Kong before proxying the request.

config.bind_dn

The DN to bind to

Usage

In order to authenticate the user, client must set credentials in Proxy-Authorization or Authorization header in following format:

credentials := [ldap LDAP] base64(username:password)

The plugin will validate the user against the LDAP server and cache the credential for future requests for the duration specified in config.cache_ttl.

Upstream Headers

When a client has been authenticated, the plugin will append some headers to the request before proxying it to the upstream service, so that you can identify the consumer in your code:

  • X-Credential-Username, the username of the Credential (only if the consumer is not the ‘anonymous’ consumer)
  • X-Anonymous-Consumer, will be set to true when authentication failed, and the ‘anonymous’ consumer was set instead.
  • X-Consumer-ID, the ID of the ‘anonymous’ consumer on Kong (only if authentication failed and ‘anonymous’ was set)
  • X-Consumer-Custom-ID, the custom_id of the ‘anonymous’ consumer (only if authentication failed and ‘anonymous’ was set)
  • X-Consumer-Username, the username of the ‘anonymous’ consumer (only if authentication failed and ‘anonymous’ was set)