ldap-auth

Description

ldap-auth is an authentication plugin that can works with consumer. Add Ldap Authentication to a service or route.

The consumer then authenticate against the Ldap server using Basic authentication.

For more information on Basic authentication, refer to Wiki for more information.

This authentication plugin use lualdap plugin to connect against the ldap server

Attributes

For consumer side:

NameTypeRequirementDefaultValidDescription
user_dnstringrequiredthe user dn of the ladp client (example: cn=user01,ou=users,dc=example,dc=org)

For route side:

NameTypeRequirementDefaultValidDescription
base_dnstringrequiredthe base dn of the ldap server (example : ou=users,dc=example,dc=org)
ldap_uristringrequiredthe uri of the ldap server
use_tlsbooleanoptionaltrueBoolean flag indicating if Transport Layer Security (TLS) should be used.
uidstringoptionalcnthe uid attribute

How To Enable

1. set a consumer and config the value of the ldap-auth option

  1. curl http://127.0.0.1:9080/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "username": "foo",
  4. "plugins": {
  5. "ldap-auth": {
  6. "user_dn": "cn=user01,ou=users,dc=example,dc=org"
  7. }
  8. }
  9. }'

2. add a Route or add a Service, and enable the ldap-auth plugin

  1. curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "methods": ["GET"],
  4. "uri": "/hello",
  5. "plugins": {
  6. "ldap-auth": {
  7. "base_dn": "ou=users,dc=example,dc=org",
  8. "ldap_uri": "localhost:1389",
  9. "uid": "cn"
  10. },
  11. },
  12. "upstream": {
  13. "type": "roundrobin",
  14. "nodes": {
  15. "127.0.0.1:1980": 1
  16. }
  17. }
  18. }'

Test Plugin

  • missing Authorization header
  1. $ curl -i http://127.0.0.1:9080/hello
  2. HTTP/1.1 401 Unauthorized
  3. ...
  4. {"message":"Missing authorization in request"}
  • user is not exists:
  1. $ curl -i -uuser:password1 http://127.0.0.1:9080/hello
  2. HTTP/1.1 401 Unauthorized
  3. ...
  4. {"message":"Invalid user key in authorization"}
  • password is invalid:
  1. $ curl -i -uuser01:passwordfalse http://127.0.0.1:9080/hello
  2. HTTP/1.1 401 Unauthorized
  3. ...
  4. {"message":"Password is error"}
  • success:
  1. $ curl -i -uuser01:password1 http://127.0.0.1:9080/hello
  2. HTTP/1.1 200 OK
  3. ...
  4. hello, world

Disable Plugin

When you want to disable the ldap-auth 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:

  1. $ curl http://127.0.0.1:2379/apisix/admin/routes/1 -X PUT -d value='
  2. {
  3. "methods": ["GET"],
  4. "uri": "/hello",
  5. "plugins": {},
  6. "upstream": {
  7. "type": "roundrobin",
  8. "nodes": {
  9. "127.0.0.1:1980": 1
  10. }
  11. }
  12. }'