-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"authenticates"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes corrected
apisix/plugins/ldap-auth.lua
Outdated
ok, err = core.schema.check(schema, conf) | ||
end | ||
|
||
if not ok then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ok, err
is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok added
apisix/plugins/ldap-auth.lua
Outdated
end | ||
|
||
-- 3. Retreive consumer for authorization plugin | ||
if conf.auto_create_consumer then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to avoid creating temporary consumers. The temporary consumer may be broken somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
docs/en/latest/plugins/ldap-auth.md
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the password?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No indeed it's the uid
attribute that changes depending of the ldap server solution
apisix/plugins/ldap-auth.lua
Outdated
properties = { | ||
basedn = { type = "string" }, | ||
ldapuri = { type = "string" }, | ||
usetls = { type = "boolean" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you use a snake case for the field name, like base_dn
/ ldap_uri
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok changed
@jp-gouin
And the libldap in: apisix/utils/linux-install-openresty.sh Line 43 in 654b1a9
|
rockspec/apisix-master-0.rockspec
Outdated
@@ -66,6 +66,7 @@ dependencies = { | |||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to check if decoded is not nil and the split result has two elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it’s a copy paste from
apisix/apisix/plugins/basic-auth.lua
Line 83 in 34df010
local decoded = ngx.decode_base64(m[1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to submit another PR to update basic-auth.
docs/en/latest/plugins/ldap-auth.md
Outdated
}' | ||
``` | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this part now. The dashboard is not shipped by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok will remove , actually it’s a copy paste from
you also can add a Consumer through the web console: |
Look like they are just flaky test results. |
Needs to install the https://github.com/apache/apisix/pull/3894/checks?check_run_id=3788501510#step:5:1004
|
apisix/plugins/ldap-auth.lua
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
consumer
This plugin can also automatically create a consumer upon request if
auto_create_consumer = true
This 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_restriction
could be updated to take into account groups -> (which can also be used onbasic-auth (and more)
plugin where aconsumer
can also be part of a group)Pre-submission checklist: