使用python检查ldap访问权限
我正在为 LDAP 服务器编写一个 Web 前端 (django)。不同类型的人拥有不同类型的权限,因此我设置了 LDAP ACL 来控制谁可以查看或编辑特定属性。 现在可以轻松确定特定用户是否具有读取权限 - 尝试读取,您将看到您得到的内容。 但在我实际尝试编写一些更改之前,我没有看到一种区分读取和写入访问的优雅方法。也就是说,我想在界面中明确登录用户是否具有写入权限,或者只能读取。这样用户就不会尝试编辑他们无法编辑的属性。
我唯一想到的就是尝试暂时将某种虚拟对象写入属性中,看看是否成功。如果是这样,原始值将被恢复,并且我知道该用户具有写权限。然后我可以将此属性显示为可编辑。 这样做的问题是,如果服务器在写入虚拟值之后且在恢复原始值之前崩溃,我的 LDAP 服务器中就会留下虚拟值。
我需要的是某种方式来查询 ACL,其方式类似于我可以查询架构定义。但也许这被 LDAP“禁止”了?
有什么想法吗?
艾萨克
I am writing a web frontend (django) for an LDAP server. There are different kinds of people with different kinds of privileges, so I set up LDAP ACL to control who gets to see or edit a specific attribute.
Now its easy to determine if a specific user has read access - try to read, and you will see what you get.
But I don't see an elegant way to distinguish between read and write access before I actually try to write some changes. That is, I would like to make it clear in the interface, if the logged in user has write access, or can only read. So that users won't try to edit an attribute which they can not.
The only thing that came to my mind was to try to temporarily write some sort of dummy into an attribute, and see if that was successful. If so, the original value would be restored, and I know that this user has write access. I can then display this attribute as editable.
The problem with this is that if the server crashes after the dummy has been written and before the original value has been restored, I am left with dummy values in my LDAP server.
What I would need is some way to query the ACLs, in a way similar that I can query schema definitions. But maybe that is "forbidden" by LDAP?
Any ideas?
Isaac
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
openldap 上的 ACL 是通过 OU 和/或 DN 检查来组织的,使用正则表达式
ex :
因此,关于登录用户的 dn(
whoami_s
with python-ldap),您可以确定用户是否拥有某些权限。您不需要测试是否可以写入数据,只需在 django 应用程序中实现一个检查 DN 的函数即可。也许您是说 ACL 是动态生成的?
关于您的评论,如果您的 ACL 是静态的,要了解 ACL,更简单的方法是实现一个实现这些 ACL 的 python 工具。以我之前的例子:
目前,python-ldap 无法检索 slapd.conf 的 ACL...并且解析 slapd.conf 并不安全(因为 slapd.conf 可以位于系统和 ACL 声明的“任何位置”)解析起来可能很棘手),而且尝试在 LDAP 后端写入数据也会消耗大量时间。
我知道这不太令人满意。另一种解决方案是使用“服务用户”。只有该用户对 LDAP 后端具有写入权限。
它简化了 ACL 的编写:
然后,对于普通用户,您可以设置授权标志。
当您的登录用户想要执行某些操作时,您的应用程序会检查该标志。如果该标志为 OK,则服务用户将数据写入后端。
这是我们在我们的一个应用程序上部署的策略。
在这两种情况下,ACL 的检查都是由我们的应用程序完成的,而不是由 ldap 后端完成的。
ACL, on openldap are organized by OU and/or DN check with regexp
ex :
So, regarding, the dn of the logged user (
whoami_s
with python-ldap), you can determine if user has some rights. You don't need to test if you can write the data, implement a function in your django application that check the DN.Maybe are you saying that ACL are dinamically generated?
Regarding your comment, if your ACL are static, to know ACLs, the simpler way is to implement a python facility who's implement these ACLs. With my previous exemple :
For now, python-ldap can't retrieve the slapd.conf's ACLs... And it is not safe to parse the slapd.conf (because slapd.conf can be "anywhere" on the system and ACLs declaration might be tricky to parse), also it consumes lots of time to try to write data on the LDAP backend.
I know this is not very satisfactory. Another solution is to use a "service user". Only this user has write access on the LDAP backend.
It simplifies ACL's writing :
Then, on regular users, you set an authorisation's flag.
Your application checks the flag when your logged user want to do something. And if this flag is OK, the service user writes data on the Backend.
This is the strategy we deploy on one of our application.
In the both case, ACL's check is done by our application, not by the ldap backend.
我想我会尝试“测试”方法,如果它太慢,也许需要一些缓存。
我只想在 ldap 服务器上保留 ACL 定义的原因是,还有其他方式与服务器交互(会有 cli 工具,还有标准 ldap 工具),所以我想保留所有这些接口同步 ACL,只有一处定义 ACL
I think I will try the "test" approch, if its too slow maybe with some caching.
The reason why I want to keep the ACL definition only on the ldap server is that there are other ways to interact with the server (there will be cli tools, and also the standard ldap tools), so I'd like to keepall those interfaces in sync ACL wise, with just one place to define ACLs
在 OpenLDAP 中,ACL 定义位于 DIT 之外。
如果您想使用 ldap 查询访问 ACL,您可以使用 FedoraDS(389 目录服务器): http:// /directory.fedoraproject.org/wiki/Howto:AccessControl
您还可以查看 OpenDS (https://www.opends.org)
In OpenLDAP the ACL definitions is outside of DIT.
If you want to access to ACL with ldap query you may user FedoraDS (389 Directory server): http://directory.fedoraproject.org/wiki/Howto:AccessControl
You can see also OpenDS (https://www.opends.org)