[Twisted-Python] ldaptor and bind
Hello everybody, I'm developing an application based on ldaptor and I need some help. My scenario is a public address book, let's say ou=Addressbook,dc=domain,dc=com and some private address books, suppose ou=John,ou=Addressbook,dc=domain,dc=com , ou=Peter,ou=Addressbook,dc=domain,dc=com and so on. So, I need to specify that ou=John,ou=Addressbook,dc=domain,dc=com can be accessed by cn=John,dc=domain,dc=com , so that by binding with a user I can look both in the public address book and in the private one. Do you have some examples or documentation explaining that? By now I'm stuck while trying to bind to do non-anonymous requests, but whatever I do I always get invalid credentials. Which objectClass do I need to be able to bind? Thanks, Ottavio -- Non c'e' piu' forza nella normalita', c'e' solo monotonia.
Can you post a stripped down example demonstrating what you're trying to do, and indicate where in the code you're encountering failures (invalid credentials)? On Jan 7, 2008 1:48 PM, Ottavio Campana <ottavio@campana.vi.it> wrote:
Hello everybody,
I'm developing an application based on ldaptor and I need some help.
My scenario is a public address book, let's say ou=Addressbook,dc=domain,dc=com and some private address books, suppose ou=John,ou=Addressbook,dc=domain,dc=com , ou=Peter,ou=Addressbook,dc=domain,dc=com and so on.
So, I need to specify that ou=John,ou=Addressbook,dc=domain,dc=com can be accessed by cn=John,dc=domain,dc=com , so that by binding with a user I can look both in the public address book and in the private one.
Do you have some examples or documentation explaining that?
By now I'm stuck while trying to bind to do non-anonymous requests, but whatever I do I always get invalid credentials. Which objectClass do I need to be able to bind?
Thanks,
Ottavio
-- Non c'e' piu' forza nella normalita', c'e' solo monotonia.
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- \\\\\/\"/\\\\\\\\\\\ \\\\/ // //\/\\\\\\\ \\\/ \\// /\ \/\\\\ \\/ /\/ / /\/ /\ \\\ \/ / /\/ /\ /\\\ \\ / /\\\ /\\\ \\\\\/\ \/\\\\\/\\\\\/\\\\\\ d.p.s
Drew Smathers ha scritto:
Can you post a stripped down example demonstrating what you're trying to do, and indicate where in the code you're encountering failures (invalid credentials)?
sure, I have set up a server with twisted, so my .tac file has def getLdapService (): db = ldiftree.LDIFTreeEntry ('/dev/shm/ldap/') class LDAPServerFactory (protocol.ServerFactory): protocol = ldapserver.LDAPServer def __init__ (self, root): self.root = root ldapserver.LDAPServer.debug= True components.registerAdapter (lambda x: x.root, LDAPServerFactory, interfaces.IConnectedLDAPEntry) factory = LDAPServerFactory (db) return internet.TCPServer (10389, factory) ... ldapservice = getLdapService () ldapservice.setServiceParent (application) after that, I have populated /dev/shm/ldap and it works for anonymous requests. If I run ldapsearch I get bott@laplace:~$ ldapsearch -x -p 10389 -h localhost -b dc=domain,dc=com -w pippo -D cn=ottavio,dc=domain,dc=com ldap_bind: Invalid credentials (49) and in logs I have 2008/01/07 22:21 CET [LDAPServer,0,127.0.0.1] /usr/lib/python2.4/site-packages/ldaptor/protocols/ldap/ldapserver.py:114: exceptions.DeprecationWarning: Use log.msg(..., debug=True), not log.debug(). 2008/01/07 22:21 CET [LDAPServer,0,127.0.0.1] S<-C LDAPMessage(id=1L, value=LDAPBindRequest(version=3, dn='cn=ottavio,dc=domain,dc=com', auth='pippo')) 2008/01/07 22:21 CET [LDAPServer,0,127.0.0.1] /usr/lib/python2.4/site-packages/ldaptor/protocols/ldap/ldapserver.py:67: exceptions.DeprecationWarning: Use log.msg(..., debug=True), not log.debug(). 2008/01/07 22:21 CET [LDAPServer,0,127.0.0.1] S->C LDAPMessage(id=1L, value=LDAPBindResponse(resultCode=49)) I tried several objectclasses combinations for the file /dev/shm/ldap/dc=com.dir/dc=domain.dir/cn=ottavio.ldif but it never worked. Thus I suspect that this file is the problem. Do you have a working example? -- Non c'e' piu' forza nella normalita', c'e' solo monotonia.
On Mon, Jan 07, 2008 at 10:28:34PM +0100, Ottavio Campana wrote:
class LDAPServerFactory (protocol.ServerFactory):
Oh, using ldaptor as a server with authentication is a bit pointless, as it has no access control whatsoever. Unless you are going to implement that yourself. The server part is not intended for production use, as is. -- :(){ :|:&};:
Tommi Virtanen ha scritto:
On Mon, Jan 07, 2008 at 10:28:34PM +0100, Ottavio Campana wrote:
class LDAPServerFactory (protocol.ServerFactory):
Oh, using ldaptor as a server with authentication is a bit pointless, as it has no access control whatsoever. Unless you are going to implement that yourself. The server part is not intended for production use, as is.
mmm... so, to summarize: 1) does it support bind? I think so, even though I'm not able to make it work by now. 2) it doesn't support access control, but for what I've seen class LDAPServer has a handle_LDAPSearchRequest method. I think I have to modify its behavior, especially when it calls root.lookup(dn). Do think that subclassing LDAPServer might be a good way of doing it? -- Non c'e' piu' forza nella normalita', c'e' solo monotonia.
On Mon, Jan 07, 2008 at 11:05:10PM +0100, Ottavio Campana wrote:
1) does it support bind? I think so, even though I'm not able to make it work by now.
The unit test in ldaptor.test.test_server.LDAPServerTest.test_bind_success says it does.
2) it doesn't support access control, but for what I've seen class LDAPServer has a handle_LDAPSearchRequest method. I think I have to modify its behavior, especially when it calls root.lookup(dn). Do think that subclassing LDAPServer might be a good way of doing it?
Yup, but don't think that's the only thing you'd need to change. Really, if you don't know LDAP already you probably will not be able to make it secure. -- :(){ :|:&};:
Tommi Virtanen ha scritto:
On Mon, Jan 07, 2008 at 11:05:10PM +0100, Ottavio Campana wrote:
1) does it support bind? I think so, even though I'm not able to make it work by now.
The unit test in ldaptor.test.test_server.LDAPServerTest.test_bind_success says it does.
I'll give a look at it
2) it doesn't support access control, but for what I've seen class LDAPServer has a handle_LDAPSearchRequest method. I think I have to modify its behavior, especially when it calls root.lookup(dn). Do think that subclassing LDAPServer might be a good way of doing it?
Yup, but don't think that's the only thing you'd need to change. Really, if you don't know LDAP already you probably will not be able to make it secure.
Yes, I agree with you, it's everything but easy. I'm thinking about other solutions because I don't need full acl as in openldap. Since each inetOrgPerson class has the userPassword field, I could add it to each element of the address book and I can check it in LDAPServer._cbSearchGotBase by modifying the filter object and adding a check to match the password in the inetOrgPerson classes with the password that the user gave to bind to the server. In this case I just need to know 1) how do I get the username and password used to bind in function def _cbSearchGotBase(self, base, dn, request, reply): ? with request.dn and request.auth? 2) how do I modify request.filter? can I just append text? In this case, after having biding working I would be done. It's not full acl support, but it would be enough. What do you think about it? -- Non c'e' piu' forza nella normalita', c'e' solo monotonia.
On Mon, Jan 07, 2008 at 11:52:52PM +0100, Ottavio Campana wrote:
1) how do I get the username and password used to bind in function def _cbSearchGotBase(self, base, dn, request, reply): ? with request.dn and request.auth?
LDAPServer's self.boundUser. And the password isn't stored any longer than is required to process the LDAPBindRequest.
2) how do I modify request.filter? can I just append text?
It's an LDAPFilter instance. No, it's not a string.
In this case, after having biding working I would be done. It's not full acl support, but it would be enough.
Umm, if you didn't even realize you need to protect against modification, do you really think you can manage to implement it securely? -- :(){ :|:&};:
Tommi Virtanen ha scritto:
On Mon, Jan 07, 2008 at 11:52:52PM +0100, Ottavio Campana wrote:
1) how do I get the username and password used to bind in function def _cbSearchGotBase(self, base, dn, request, reply): ? with request.dn and request.auth?
LDAPServer's self.boundUser. And the password isn't stored any longer than is required to process the LDAPBindRequest.
2) how do I modify request.filter? can I just append text?
It's an LDAPFilter instance. No, it's not a string.
In this case, after having biding working I would be done. It's not full acl support, but it would be enough.
Umm, if you didn't even realize you need to protect against modification, do you really think you can manage to implement it securely?
well, considering that data provided through ldap is for readonly use, that ldap exports information saved in a database which is protected, that clients access the ldap server only read only and the network is not hostile, I think it could be acceptable. I can't run openldap on that hardware and I need a way to separate public and private address books and I need to be able to look in both address books with only one search, so they have to be nested. I know acls would do the job, I know the solution is not perfect, but do you have any other idea? PS: going on with my idea, I could overwrite handle_LDAPModifyDNRequest by always rising ldaperrors.LDAPUnwillingToPerform. The same for all other add/delete/modify request... -- Non c'e' piu' forza nella normalita', c'e' solo monotonia.
Phil Mayers ha scritto:
I can't run openldap on that hardware and I need a way to separate
I would be surprised if that were true. Why can't you run openldap?
* strict hardware resources. By adopting twisted I was able to remove apache,php and I hope to be able to remove also openldap. * the fact that in case of power failure openldap database gets too often corrupted. I repeat, in this case I have all the informations in a db whose backups are regular, so I just need an ldap server to let the clients access the information in read only. * it doesn't integrate as well as ldaptor with the rest of the software I am developing. -- Non c'e' piu' forza nella normalita', c'e' solo monotonia.
On Tue, Jan 08, 2008 at 12:34:29AM +0100, Ottavio Campana wrote:
Umm, if you didn't even realize you need to protect against modification, do you really think you can manage to implement it securely? well, considering that data provided through ldap is for readonly use, that ldap exports information saved in a database which is protected, that clients access the ldap server only read only and the network is not hostile, I think it could be acceptable.
Yes but unless you do something to prevent writes anonymous can overwrite anyones password. That sort of makes any read restrictions pointless, doesn't it?
PS: going on with my idea, I could overwrite handle_LDAPModifyDNRequest by always rising ldaperrors.LDAPUnwillingToPerform. The same for all other add/delete/modify request...
Ah, good. You realize they are there ;) That was my point, earlier you spoke only of filtering search requests. To implement ACLs, you need way more than that. -- :(){ :|:&};:
Tommi Virtanen ha scritto:
PS: going on with my idea, I could overwrite handle_LDAPModifyDNRequest by always rising ldaperrors.LDAPUnwillingToPerform. The same for all other add/delete/modify request...
Ah, good. You realize they are there ;) That was my point, earlier you spoke only of filtering search requests. To implement ACLs, you need way more than that.
thanks for making me realize that. :-) I just need to understand how I can modify an LDAPFilter instance and I'll be done. You said it is not a string, so is there a way to easily change it? Otherwise, where is the filter converted from string to LDAPFilter? It's not acls, but I'll get the same effect for my application. Bye -- Non c'e' piu' forza nella normalita', c'e' solo monotonia.
On Tue, Jan 08, 2008 at 01:06:31AM +0100, Ottavio Campana wrote:
I just need to understand how I can modify an LDAPFilter instance and I'll be done. You said it is not a string, so is there a way to easily change it? Otherwise, where is the filter converted from string to LDAPFilter?
Filters don't travel on the wire as strings at all. It's a structured data type. Look around in pureldap.py, LDAPFilter_and etc. Ldaptor also includes a brief introduction to LDAP, including the filters; look in doc, or see http://eagain.net/temp/ldap-intro/ It sounds like you might be more intersted in request.attributes than the filter, though. -- :(){ :|:&};:
Tommi Virtanen ha scritto:
On Mon, Jan 07, 2008 at 11:05:10PM +0100, Ottavio Campana wrote:
1) does it support bind? I think so, even though I'm not able to make it work by now.
The unit test in ldaptor.test.test_server.LDAPServerTest.test_bind_success says it does.
ok, I made bind work. -- Non c'e' piu' forza nella normalita', c'e' solo monotonia.
participants (4)
-
Drew Smathers -
Ottavio Campana -
Phil Mayers -
Tommi Virtanen