Skip to content

Commit

Permalink
fix default values and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
kingluo committed Aug 3, 2022
1 parent ef84a13 commit dd4e2a3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
16 changes: 7 additions & 9 deletions apisix/plugins/ldap-auth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ local schema = {
properties = {
base_dn = { type = "string" },
ldap_uri = { type = "string" },
use_tls = { type = "boolean" },
verify_ldap_host = { type = "boolean" },
uid = { type = "string" }
use_tls = { type = "boolean", default = false },
tls_verify = { type = "boolean", default = false },
uid = { type = "string", default = "cn" }
},
required = {"base_dn","ldap_uri"},
}
Expand Down Expand Up @@ -137,25 +137,23 @@ function _M.rewrite(conf, ctx)
end

-- 2. try authenticate the user against the ldap server
local uid = conf.uid or "cn"

local ldap_host, ldap_port = core.utils.parse_addr(conf.ldap_uri)

local userdn = uid .. "=" .. user.username .. "," .. conf.base_dn
local userdn = conf.uid .. "=" .. user.username .. "," .. conf.base_dn
local ldapconf = {
timeout = 10000,
start_tls = false,
ldap_host = ldap_host,
ldap_port = ldap_port or 389,
ldaps = conf.use_tls,
verify_ldap_host = conf.verify_ldap_host,
tls_verify = conf.tls_verify,
base_dn = conf.base_dn,
attribute = uid,
attribute = conf.uid,
keepalive = 60000,
}
local res, err = ldap.ldap_authenticate(user.username, user.password, ldapconf)
if not res then
core.log.warn("ldap-auth: ", err)
core.log.warn("ldap-auth failed: ", err)
return 401, { message = "Invalid user authorization" }
end

Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/plugins/ldap-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ For Route:
| base_dn | string | True | | Base dn of the LDAP server. For example, `ou=users,dc=example,dc=org`. |
| ldap_uri | string | True | | URI of the LDAP server. |
| use_tls | boolean | False | `false` | If set to `true` uses TLS. |
| verify_ldap_host| boolean | False | `false` | Whether to verify the server certificate when `use_tls` is enabled; If set to `true`, you must set `ssl_trusted_certificate` in `config.yaml`, and make sure the host of `ldap_uri` matches the host in server certificate. |
| tls_verify| boolean | False | `false` | Whether to verify the server certificate when `use_tls` is enabled; If set to `true`, you must set `ssl_trusted_certificate` in `config.yaml`, and make sure the host of `ldap_uri` matches the host in server certificate. |
| uid | string | False | `cn` | uid attribute. |

## Enabling the plugin
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/latest/plugins/ldap-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Route 端:
| base_dn | string || | LDAP 服务器的 dn,例如:`ou=users,dc=example,dc=org`|
| ldap_uri | string || | LDAP 服务器的 URI。 |
| use_tls | boolean || false | 如果设置为 `true` 则表示启用 TLS。 |
| verify_ldap_host| boolean || false | 是否校验 LDAP 服务器的证书。如果设置为 `true`,你必须设置 `config.yaml` 里面的 `ssl_trusted_certificate`,并且确保 `ldap_uri` 里的 host 和服务器证书中的 host 匹配。 |
| tls_verify| boolean || false | 是否校验 LDAP 服务器的证书。如果设置为 `true`,你必须设置 `config.yaml` 里面的 `ssl_trusted_certificate`,并且确保 `ldap_uri` 里的 host 和服务器证书中的 host 匹配。 |
| uid | string || cn | UID 属性。 |

## 启用插件
Expand Down
6 changes: 3 additions & 3 deletions t/plugin/ldap-auth.t
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ find consumer user01
ngx.HTTP_GET,
nil,
[[
{"title":"work with route or service object","required":["base_dn","ldap_uri"],"properties":{"base_dn":{"type":"string"},"ldap_uri":{"type":"string"},"use_tls":{"type":"boolean"},"verify_ldap_host":{"type":"boolean"},"disable":{"type":"boolean"},"uid":{"type":"string"}},"type":"object"}
{"title":"work with route or service object","required":["base_dn","ldap_uri"],"properties":{"base_dn":{"type":"string"},"ldap_uri":{"type":"string"},"use_tls":{"type":"boolean"},"tls_verify":{"type":"boolean"},"disable":{"type":"boolean"},"uid":{"type":"string"}},"type":"object"}
]]
)
ngx.status = code
Expand Down Expand Up @@ -340,7 +340,7 @@ find consumer user01
ngx.HTTP_GET,
nil,
[[
{"title":"work with route or service object","required":["base_dn","ldap_uri"],"properties":{"base_dn":{"type":"string"},"ldap_uri":{"type":"string"},"use_tls":{"type":"boolean"},"verify_ldap_host":{"type":"boolean"},"disable":{"type":"boolean"},"uid":{"type":"string"}},"type":"object"} ]]
{"title":"work with route or service object","required":["base_dn","ldap_uri"],"properties":{"base_dn":{"type":"string"},"ldap_uri":{"type":"string"},"use_tls":{"type":"boolean"},"tls_verify":{"type":"boolean"},"disable":{"type":"boolean"},"uid":{"type":"string"}},"type":"object"} ]]
)
ngx.status = code
}
Expand Down Expand Up @@ -411,7 +411,7 @@ find consumer user01
"ldap_uri": "localhost:1636",
"uid": "cn",
"use_tls": true,
"verify_ldap_host": true
"tls_verify": true
}
},
"upstream": {
Expand Down

0 comments on commit dd4e2a3

Please sign in to comment.