You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "bzp2010 (via GitHub)" <gi...@apache.org> on 2023/03/07 07:58:43 UTC
[GitHub] [apisix] bzp2010 opened a new pull request, #9022: feat: add ldap-auth-advanced plugin
bzp2010 opened a new pull request, #9022:
URL: https://github.com/apache/apisix/pull/9022
### Description
<!-- Please include a summary of the change and which issue is fixed. -->
<!-- Please also include relevant motivation and context. -->
According to the Proposal in #8958, this PR implements a new LDAP authentication plugin that is more standardized and flexible.
New #8958
### Checklist
- [x] I have explained the need for this PR and the problem it solves
- [x] I have explained the changes or the new features added to this PR
- [x] I have added tests corresponding to this change
- [x] I have updated the documentation to reflect this change
- [x] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
<!--
Note
1. Mark the PR as draft until it's ready to be reviewed.
2. Always add/update tests for any changes unless you have a good reason.
3. Always update the documentation to reflect the changes made in the PR.
4. Make a new commit to resolve conversations instead of `push -f`.
5. To resolve merge conflicts, merge master instead of rebasing.
6. Use "request review" to notify the reviewer after making changes.
7. Only a reviewer can mark a conversation as resolved.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] soulbird commented on a diff in pull request #9022: feat: add ldap-auth-advanced plugin
Posted by "soulbird (via GitHub)" <gi...@apache.org>.
soulbird commented on code in PR #9022:
URL: https://github.com/apache/apisix/pull/9022#discussion_r1147252229
##########
apisix/plugins/ldap-auth-advanced.lua:
##########
@@ -0,0 +1,308 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local core = require("apisix.core")
+local consumer_mod = require("apisix.consumer")
+local ok, ldap_cli = pcall(require, "resty.ldap.client")
+local ldap_proto = require("resty.ldap.protocol")
+
+local pcall = pcall
+local ipairs = ipairs
+local str_find = core.string.find
+local str_format = string.format
+local decode_base64 = ngx.decode_base64
+local ngx_re_match = ngx.re.match
+local ngx_re_gsub = ngx.re.gsub
+local ngx_re_split = require("ngx.re").split
+
+local LDAP_SEARCH_SCOPE_BASE_OBJECT = ldap_proto.SEARCH_SCOPE_BASE_OBJECT
+local LDAP_SEARCH_DEREF_ALIASES_ALWAYS = ldap_proto.SEARCH_DEREF_ALIASES_ALWAYS
+
+local auth_header_lrucache = core.lrucache.new({
+ ttl = 300, count = 512
+})
+
+local schema = {
+ type = "object",
+ properties = {
+ ldap_uri = { type = "string" },
+ use_ldaps = {
+ type = "boolean",
+ default = false
+ },
+ use_starttls = {
+ type = "boolean",
+ default = false
+ },
+ ssl_verify = {
+ type = "boolean",
+ default = true,
+ },
+ timeout = {
+ type = "integer",
+ minimum = 1,
+ maximum = 60000,
+ default = 3000,
+ description = "timeout in milliseconds",
+ },
+ keepalive = {type = "boolean", default = true},
+ keepalive_timeout = {type = "integer", minimum = 1000, default = 60000},
+ keepalive_pool_size = {type = "integer", minimum = 1, default = 5},
+ keepalive_pool_name = {type = "string", default = nil},
+ ldap_debug = {
+ type = "boolean",
+ default = false,
+ },
+ hide_credentials = {
+ type = "boolean",
+ default = false,
+ },
+ consumer_required = {
+ type = "boolean",
+ default = true,
+ },
+ user_dn_template = {
+ type = "string",
+ },
+ user_membership_attribute = {
+ type = "string",
+ default = "memberOf",
+ }
+ },
+ required = {"ldap_uri", "user_dn_template"}
+}
+
+
+local consumer_schema = {
+ type = "object",
+ properties = {
+ user_dn = { type = "string" },
+ group_dn = { type = "string" },
+ },
+ oneOf = {
+ {required = {"user_dn"}},
+ {required = {"group_dn"}},
+ }
+}
+
+local plugin_name = "ldap-auth-advanced"
+
+local _M = {
+ version = 0.1,
+ priority = 2541,
+ type = "auth",
+ name = plugin_name,
+ schema = schema,
+ consumer_schema = consumer_schema,
+}
+
+
+function _M.check_schema(conf, schema_type)
+ if schema_type == core.schema.TYPE_CONSUMER then
+ return core.schema.check(consumer_schema, conf)
+ end
+
+ local ok, err = core.schema.check(schema, conf)
+ if not ok then
+ return ok, err
+ end
+
+ -- ensure %s in template
+ if not str_find(conf.user_dn_template, "%s") or not ok then
+ return false, "User DN template doesn't contain " ..
+ "the %s placeholder for the uid variable"
+ end
+
+ -- ensure only one %s in template
+ if not pcall(str_format, conf.user_dn_template, "username") then
+ return false, "User DN template has more than one " ..
+ "placeholder %s for the username variable."
+ end
+
+ if conf.use_starttls and conf.use_ldaps then
+ return false, "STARTTLS and LDAPS cannot be open at the same time"
+ end
+
+ return true
+end
+
+
+local function extract_auth_header(authorization)
Review Comment:
This function is used multiple times in different plugins, can we put them in a unified location. Maybe record a todo
##########
apisix/plugins/ldap-auth-advanced.lua:
##########
@@ -0,0 +1,308 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local core = require("apisix.core")
+local consumer_mod = require("apisix.consumer")
+local ok, ldap_cli = pcall(require, "resty.ldap.client")
+local ldap_proto = require("resty.ldap.protocol")
+
+local pcall = pcall
+local ipairs = ipairs
+local str_find = core.string.find
+local str_format = string.format
+local decode_base64 = ngx.decode_base64
+local ngx_re_match = ngx.re.match
+local ngx_re_gsub = ngx.re.gsub
+local ngx_re_split = require("ngx.re").split
+
+local LDAP_SEARCH_SCOPE_BASE_OBJECT = ldap_proto.SEARCH_SCOPE_BASE_OBJECT
+local LDAP_SEARCH_DEREF_ALIASES_ALWAYS = ldap_proto.SEARCH_DEREF_ALIASES_ALWAYS
+
+local auth_header_lrucache = core.lrucache.new({
+ ttl = 300, count = 512
+})
+
+local schema = {
+ type = "object",
+ properties = {
+ ldap_uri = { type = "string" },
+ use_ldaps = {
+ type = "boolean",
+ default = false
+ },
+ use_starttls = {
+ type = "boolean",
+ default = false
+ },
+ ssl_verify = {
+ type = "boolean",
+ default = true,
+ },
+ timeout = {
+ type = "integer",
+ minimum = 1,
+ maximum = 60000,
+ default = 3000,
+ description = "timeout in milliseconds",
+ },
+ keepalive = {type = "boolean", default = true},
+ keepalive_timeout = {type = "integer", minimum = 1000, default = 60000},
+ keepalive_pool_size = {type = "integer", minimum = 1, default = 5},
+ keepalive_pool_name = {type = "string", default = nil},
+ ldap_debug = {
+ type = "boolean",
+ default = false,
+ },
+ hide_credentials = {
+ type = "boolean",
+ default = false,
+ },
+ consumer_required = {
+ type = "boolean",
+ default = true,
+ },
+ user_dn_template = {
+ type = "string",
+ },
+ user_membership_attribute = {
+ type = "string",
+ default = "memberOf",
+ }
+ },
+ required = {"ldap_uri", "user_dn_template"}
+}
+
+
+local consumer_schema = {
+ type = "object",
+ properties = {
+ user_dn = { type = "string" },
+ group_dn = { type = "string" },
+ },
+ oneOf = {
+ {required = {"user_dn"}},
+ {required = {"group_dn"}},
+ }
+}
+
+local plugin_name = "ldap-auth-advanced"
+
+local _M = {
+ version = 0.1,
+ priority = 2541,
+ type = "auth",
+ name = plugin_name,
+ schema = schema,
+ consumer_schema = consumer_schema,
+}
+
+
+function _M.check_schema(conf, schema_type)
+ if schema_type == core.schema.TYPE_CONSUMER then
+ return core.schema.check(consumer_schema, conf)
+ end
+
+ local ok, err = core.schema.check(schema, conf)
+ if not ok then
+ return ok, err
+ end
+
+ -- ensure %s in template
+ if not str_find(conf.user_dn_template, "%s") or not ok then
+ return false, "User DN template doesn't contain " ..
+ "the %s placeholder for the uid variable"
+ end
+
+ -- ensure only one %s in template
+ if not pcall(str_format, conf.user_dn_template, "username") then
+ return false, "User DN template has more than one " ..
+ "placeholder %s for the username variable."
+ end
+
+ if conf.use_starttls and conf.use_ldaps then
+ return false, "STARTTLS and LDAPS cannot be open at the same time"
+ end
+
+ return true
+end
+
+
+local function extract_auth_header(authorization)
+ local function do_extract(auth)
+ local obj = { username = "", password = "" }
+
+ local m, err = ngx_re_match(auth, "Basic\\s(.+)", "jo")
+ if err then
+ -- error authorization
+ return nil, err
+ end
+
+ if not m then
Review Comment:
These two judgments can be combined
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] soulbird commented on pull request #9022: feat: add ldap-auth-advanced plugin
Posted by "soulbird (via GitHub)" <gi...@apache.org>.
soulbird commented on PR #9022:
URL: https://github.com/apache/apisix/pull/9022#issuecomment-1482388244
Missing doc?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add ldap-auth-advanced plugin [apisix]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9022:
URL: https://github.com/apache/apisix/pull/9022#issuecomment-1817465271
This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add ldap-auth-advanced plugin [apisix]
Posted by "bzp2010 (via GitHub)" <gi...@apache.org>.
bzp2010 closed pull request #9022: feat: add ldap-auth-advanced plugin
URL: https://github.com/apache/apisix/pull/9022
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org