{"id":21970797,"url":"https://github.com/kingluo/lua-resty-ffi-ldap","last_synced_at":"2026-04-10T20:58:11.565Z","repository":{"id":185026106,"uuid":"611845032","full_name":"kingluo/lua-resty-ffi-ldap","owner":"kingluo","description":"The openresty ldap client library that encapsulates bonsai","archived":false,"fork":false,"pushed_at":"2023-03-13T14:31:52.000Z","size":16,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-22T22:44:02.298Z","etag":null,"topics":["coroutines","kerberos","ldap","luajit","nginx","openresty","sasl"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kingluo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-09T16:57:16.000Z","updated_at":"2024-01-05T03:52:21.000Z","dependencies_parsed_at":"2023-07-31T12:49:48.262Z","dependency_job_id":null,"html_url":"https://github.com/kingluo/lua-resty-ffi-ldap","commit_stats":null,"previous_names":["kingluo/lua-resty-ffi-ldap"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kingluo/lua-resty-ffi-ldap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingluo%2Flua-resty-ffi-ldap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingluo%2Flua-resty-ffi-ldap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingluo%2Flua-resty-ffi-ldap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingluo%2Flua-resty-ffi-ldap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kingluo","download_url":"https://codeload.github.com/kingluo/lua-resty-ffi-ldap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingluo%2Flua-resty-ffi-ldap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31658964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-10T17:19:37.612Z","status":"ssl_error","status_checked_at":"2026-04-10T17:19:13.364Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coroutines","kerberos","ldap","luajit","nginx","openresty","sasl"],"created_at":"2024-11-29T14:43:10.352Z","updated_at":"2026-04-10T20:58:11.515Z","avatar_url":"https://github.com/kingluo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lua-resty-ffi-ldap\n\nThe openresty ldap client library that encapsulates [bonsai](https://github.com/noirello/bonsai).\n\n## Background\n\nLDAP is commonly used to do authentication and authorization.\n\nBut OpenResty does not have a fully functional LDAP library.\n\nLet's have a look at the current alternatives:\n\n* [lualdap](https://lualdap.github.io/lualdap/manual/)\n  * No SASL auth, simple bind only\n  * Not based on cosocket, i.e. not async\n* [lua-resty-ldap](https://github.com/api7/lua-resty-ldap)\n  * No SASL auth, simple bind only\n\nWhat about other programming lanuages?\n\n* [go-ldap](https://github.com/go-ldap/ldap)\n  * [No GSSAPI/Kerberos support](https://github.com/go-ldap/ldap/pull/340#issuecomment-1460021435)\n* [rust-ldap3](https://github.com/inejge/ldap3)\n  * depends on `kinit` to get service ticket first\n  * no keytab, no ad-hoc credential support\n* [python-ldap](https://www.python-ldap.org/en/python-ldap-3.4.3/reference/ldap-sasl.html#ldap.sasl.gssapi)\n  * depends on `kinit` to get service ticket first\n  * no keytab, no ad-hoc credential support\n  * not async\n\nAfter investigation, I think [bonsai](https://bonsai.readthedocs.io/en/latest/index.html) is the best choice,\nwhich is a popular and active python ldap client library.\n\nHighlights:\n\n* asyncio support\n* Full SASL support\n  * DIGEST-MD5 and NTLM\n  * GSSAPI and GSS-SPNEGO (keytab, ad-hoc credential support)\n  * EXTERNAL\n* simple pythonic design\n* based on robust and time-tested C libraries, e.g. libldap2, libsasl2, libkrb5\n\nWhy not encapsulate it so that we could reuse it in openresty?\n\n[lua-resty-ffi](https://github.com/kingluo/lua-resty-ffi) provides an efficient and generic API to do hybrid programming\nin openresty with mainstream languages (Go, Python, Java, Rust, Nodejs).\n\n`lua-resty-ffi-ldap = lua-resty-ffi + bonsai`\n\nI already tested this library on:\n\n* openldap + MIT KDC\n* Windows AD (Kerberos enabled)\n\n## Synopsis\n\n```lua\nlocal ldap = require(\"resty.ffi.ldap\")\n\nlocal client = ldap.new({\n    url = \"ldap://bonsai.test\",\n    maxconn = 2,\n    auth = {\n        mechanism=\"GSSAPI\",\n        user=\"chuck\",\n        password=\"Foo2023@\",\n        realm=\"BONSAI.TEST\",\n    }\n})\nassert(client)\n\nlocal ok, res = client:search({\n    base = \"cn=chuck,dc=bonsai,dc=test\",\n    scope = ldap.SCOPE_SUB,\n    filter_exp = \"(objectclass=user)\",\n    attrlist = {'memberOf', 'sAMAccountName'},\n})\nassert(ok)\nres = res[1]\nassert(res.dn == \"CN=chuck,DC=bonsai,DC=test\", \"dn mismatch\")\nassert(res.memberOf[1] == \"CN=foobar,DC=bonsai,DC=test\", \"memberOf mismatch\")\nassert(res.sAMAccountName[1] == \"chuck\", \"sAMAccountName mismatch\")\n\nlocal ok = client:close()\nassert(ok)\n```\n\n## Demo\n\nCheck this blog for detail:\n\nhttp://luajit.io/posts/access-windows-adds-kerberos-from-openresty/\n\n```bash\n# install lua-resty-ffi and lua-resty-ffi-python\n# https://github.com/kingluo/lua-resty-ffi#install-lua-resty-ffi-via-luarocks\n# set `OR_SRC` to your openresty source path\nluarocks config variables.OR_SRC /tmp/tmp.Z2UhJbO1Si/openresty-1.21.4.1\nluarocks install lua-resty-ffi-python\n\napt install libldap2-dev libsasl2-dev heimdal-dev\n\npip3 install bonsai\n\ncd /opt\ngit clone https://github.com/kingluo/lua-resty-ffi-ldap\n\ncd /opt/lua-resty-ffi-ldap/demo\n\n# run nginx\nKRB5_CONFIG=\"$PWD/krb5.conf\" \\\nLD_LIBRARY_PATH=/usr/local/lib/lua/5.1 \\\nPYTHONPATH=/opt/lua-resty-ffi-ldap \\\nnginx -p $PWD -c nginx.conf\n\n# set up a Windows AD...\n\n# in another terminal, trigger demo\ncurl localhost:20000/demo\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingluo%2Flua-resty-ffi-ldap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkingluo%2Flua-resty-ffi-ldap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingluo%2Flua-resty-ffi-ldap/lists"}