feat: Add ldap-auth plugin #3894
Conversation
|
|
||
| `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. |
| ok, err = core.schema.check(schema, conf) | ||
| end | ||
|
|
||
| if not ok then |
| end | ||
|
|
||
| -- 3. Retreive consumer for authorization plugin | ||
| if conf.auto_create_consumer then |
There was a problem hiding this comment.
Better to avoid creating temporary consumers. The temporary consumer may be broken somewhere else.
There was a problem hiding this comment.
Ok remove this feature .
It was more to act like the oidc plugin , that does not require a consumer to be created , but i see your point
| | basedn | string | required | | | the base dn of the `ldap` server (example : `ou=users,dc=example,dc=org`) | | ||
| | ldapuri | string | required | | | the uri of the ldap server | | ||
| | usetls | boolean | optional | `true` | | Boolean flag indicating if Transport Layer Security (TLS) should be used. | | ||
| | uid | string | optional | `cn` | | the user's password | |
There was a problem hiding this comment.
No indeed it's the uid attribute that changes depending of the ldap server solution
| properties = { | ||
| basedn = { type = "string" }, | ||
| ldapuri = { type = "string" }, | ||
| usetls = { type = "boolean" }, |
There was a problem hiding this comment.
Would you use a snake case for the field name, like base_dn / ldap_uri?
|
@jp-gouin And the libldap in: apisix/utils/linux-install-openresty.sh Line 43 in 654b1a9 |
| "luasec = 0.9-1", | ||
| "lua-resty-consul = 0.3-2", | ||
| "penlight = 1.9.2-1", | ||
| "lualdap = 1.2.3-1", |
There was a problem hiding this comment.
Why not use the latest release: 1.2.6?
https://github.com/lualdap/lualdap does not declare the license, the author needs to declare the license first, otherwise APISIX cannot use this open-source project. |
|
@membphis there is a licence in their website https://lualdap.github.io/lualdap/license |
IMHO, it seems we can use it after adding the copyright notice. There is the raw file of the License page: https://github.com/lualdap/lualdap/blob/master/docs/license.md. |
https://github.com/lualdap/lualdap there is no information about I created a new issue right now: lualdap/lualdap#21 |
…, update rockspec to add libldap, update readme, remove auto_createconsumer feature
The CI doesn't seems to install libldap2-dev before installing apisix. Am i missing something ? |
|
@jp-gouin |
Some ci cases have their own way to install the library, like: Line 25 in 4156a73 apisix/ci/linux_tengine_runner.sh Line 218 in 4156a73 |
|
@jp-gouin hi, are you still interested in continuing this PR? |
|
I am , however there is still the licence issue on the lualdap/lualdap#21 |
|
@membphis is the information provided in the lualdap/lualdap#21 enough for the use of lualdap in Apisix ? |
cool, I think you can continue this PR, it fine now. |
|
I think you need to resolve the conflicting files ^_^ |
…on for ldap-auth.t, merge apisix-master-0.rockspec conflict
|
Failed tests do not seems to be related to |
| local decoded = ngx.decode_base64(m[1]) | ||
|
|
||
| local res | ||
| res, err = ngx_re.split(decoded, ":") |
There was a problem hiding this comment.
Better to check if decoded is not nil and the split result has two elements.
There was a problem hiding this comment.
Actually it’s a copy paste from
apisix/apisix/plugins/basic-auth.lua
Line 83 in 34df010
There was a problem hiding this comment.
Feel free to submit another PR to update basic-auth.
| }' | ||
| ``` | ||
|
|
||
| you can visit Dashboard `http://127.0.0.1:9080/apisix/dashboard/` and add a Consumer through the web console. |
There was a problem hiding this comment.
We can remove this part now. The dashboard is not shipped by default.
There was a problem hiding this comment.
Ok will remove , actually it’s a copy paste from
Look like they are just flaky test results. |
|
Needs to install the |
| return nil, "split authorization err:" .. err | ||
| end | ||
| if #res < 2 then | ||
| return nil, "split authorization length is invalid" |
There was a problem hiding this comment.
| return nil, "split authorization length is invalid" | |
| return nil, "split authorization err: invalid decoded data: " .. decoded |
|
|
||
| if err then | ||
| return nil, "failed to decode authentication header" | ||
| end |
There was a problem hiding this comment.
if not decoded then
return nil, "failed to decode authentication header: " .. m[1]
end
|
@membphis , the chaos mesh test is using the apisix-docker project to build apisix : apisix/.github/workflows/chaos.yml Line 41 in aa375ab I submitted a PR to add the library in the apisix-docker apache/apisix-docker#222 |
|
@jp-gouin |
Done :) |
|
LGTM |
|
@jp-gouin, |
|
Thanks for the effort. |
What this PR does / why we need it:
This PR add a new authentication plugin that use a LDAP server to authenticate the user
This add a new type of
consumerThis plugin can also automatically create a consumer upon request if
auto_create_consumer = trueThis fixes : #3861 and #1128
Test cases are not fully operational yet.
Help needed
Also need help to add the deployment of an Openldap server on Github Action.
FYI i used the (bitnami/openldap:2)(https://hub.docker.com/r/bitnami/openldap/) docker image
Next feature
Add a group variable in the consumer , this group would come from the
memberOf (configurable)attribute of the ldap user and add it in the consumer.Then plugins such as
consumer_restrictioncould be updated to take into account groups -> (which can also be used onbasic-auth (and more)plugin where aconsumercan also be part of a group)Pre-submission checklist: