Add LDAP Bind Authentication to a Route 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 IAM before or after a request has been proxied to the upstream API.Service
: the IAM entity representing an external upstream API or microservice.Route
: the IAM entity representing a way to map downstream requests to upstream services.upstream service
: this refers to your own API/service sitting behind IAM, to which client requests are forwarded.
Configuration
This plugin is compatible with requests with the following protocols:
http
https
This plugin is compatible with DB-less mode.
Enabling the plugin on a Route
With a database
Configure this plugin on a Route with:
$ curl -X POST http://localhost:8001/routes/{route}/plugins \
--data "name=ldap-auth" \
--data "config.hide_credentials=true" \
--data "config.ldap_host=ldap.example.com" \
--data "config.ldap_port=389" \
--data "config.start_tls=false" \
--data "config.base_dn=dc=example,dc=com" \
--data "config.verify_ldap_host=false" \
--data "config.attribute=cn" \
--data "config.cache_ttl=60" \
--data "config.header_type=ldap"
Without a database
Configure this plugin on a Route by adding this section do your declarative configuration file:
plugins:
- name: ldap-auth
route: {route}
config:
hide_credentials: true
ldap_host: ldap.example.com
ldap_port: 389
start_tls: false
base_dn: dc=example,dc=com
verify_ldap_host: false
attribute: cn
cache_ttl: 60
header_type: ldap
In both cases, {route}
is the id
or name
of the Route that this plugin configuration will target.
Global plugins
- Using a database, all plugins can be configured using the
http://localhost:8001/plugins/
endpoint. - Without a database, all plugins can be configured via the
plugins:
entry on the declarative configuration file.
A plugin which is not associated to any Service, Route or Consumer (or API, if you are using an older version of IAM) 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 parameter | description |
---|---|
name | The name of the plugin to use, in this case ldap-auth |
route_id | The id of the Route which this plugin will target. |
enabled default value: true | Whether this plugin will be applied. |
config.hide_credentials
optional default value:
|
An optional boolean value telling the plugin to hide the credential to the upstream server. It will be removed by IAM before proxying the request. |
config.ldap_host
|
Host on which the LDAP server is running. |
config.ldap_port
|
TCP port where the LDAP server is listening. |
config.start_tls
default value:
|
Set it to |
config.base_dn
|
Base DN as the starting point for the search. |
config.verify_ldap_host
default value:
|
Set it to |
config.attribute
|
Attribute to be used to search the user. |
config.cache_ttl
default value:
|
Cache expiry time in seconds. |
config.timeout
optional default value:
|
An optional timeout in milliseconds when waiting for connection with LDAP server. |
config.keepalive
optional default value:
|
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 |
config.header_type
optional default value:
|
An optional string to use as part of the Authorization header. By default, a valid Authorization header looks like this: |
config.header_type
option was introduced in IAM 0.12.0. Previous versions of this plugin behave as if ldap
was set for this value. 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
, theusername
of the Credential (only if the consumer is not the ‘anonymous' consumer)X-Anonymous-Consumer
, will be set totrue
when authentication failed, and the ‘anonymous' consumer was set instead.X-Consumer-ID
, the ID of the ‘anonymous' consumer on IAM (only if authentication failed and ‘anonymous' was set)X-Consumer-Custom-ID
, thecustom_id
of the ‘anonymous' consumer (only if authentication failed and ‘anonymous' was set)X-Consumer-Username
, theusername
of the ‘anonymous' consumer (only if authentication failed and ‘anonymous' was set)