-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move foreman LDAP functionality to ldap_fluff #26
Conversation
@@ -1,6 +1,6 @@ | |||
Gem::Specification.new do |s| | |||
s.name = 'ldap_fluff' | |||
s.version = '0.2.5' | |||
s.version = '0.2.6' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will definitely be 0.3 :)
return false | ||
end | ||
return true | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be simplified to:
def user_exists?(uid)
@member_service.find_user(uid)
true
rescue self.class::MemberService::UIDNotFoundException
false
end
please look also for other usages.
I like creation of the Generic classes 👍 Thanks. |
@@ -0,0 +1,67 @@ | |||
require 'net/ldap' | |||
|
|||
class Generic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the gem should not pollute global space!
Thanks for the comments 😄, I've fixed them and tested it with ActiveDirectory which gave me a couple of hints:
I also fixed I need the & in |
# return string will be something like | ||
# CN=bros,OU=bropeeps,DC=jomara,DC=redhat,DC=com | ||
def get_groups(grouplist) | ||
grouplist.map(&:downcase).collect(&(proc { |g| g.sub(/.*?cn=(.*?),.*/, '\1') } )) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what you mean.
grouplist.map(&:downcase).collect(&(proc { |g| g.sub(/.*?cn=(.*?),.*/, '\1') } ))
#equals
grouplist.map(&:downcase).collect { |g| g.sub(/.*?cn=(.*?),.*/, '\1') }
Thanks for the updates, exceptions are looking much better now 👍 I noticed one more thing, could you create a common |
def find_user(uid) | ||
user = @ldap.search(:filter => name_filter(uid), :base => @group_base) | ||
raise self.class::UIDNotFoundException if (user.nil? || user.empty?) | ||
user | ||
end | ||
|
||
# return an ldap user with groups attached |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is giving me problems I think when testing against OpenLDAP, as it's returning the user's CN rather than their groups.
@domcleal It still doesn't recurse to bring the nested users, ideally I think Foreman should try to return all users directly in the specified GID (users_for_gid takes care of that), and after that, it should check for nested user groups, and create a external user group in Foreman for each of these nested groups found in it. Does this make sense to you? Say we have a group: "foremaners", with a direct member "dcleal", a subgroup "katellers", with a member "bk". The flow would work like this:
|
Sounds a little clunky and more work than using the LDAP server's memberOf determination to me, but if that's what you want to do, do it. |
This PR resolves #27 (this should auto close 27 when this PR is merged) |
@pitr-ch @domcleal I've pushed changes needed to recursive search groups for all 3 implementations and the Generic. Summing up:
Tests will follow soon, but I thought it'd be helpful to put this out early if you want to test. |
@pitr-ch I've just updated this with some tests for the nested usergroups and an easy refactor of some methods used in tests. After this PR is merged I think a rewrite of the test suite should follow at some point. |
@elobato could you fix travis tests? |
Thanks for updating. ACK Ruby wise, I would defer to @domcleal to ack the LDAP part. |
@pitr-ch sorry, I can't, I'm not at all familiar with this project |
I've tested it successfully with OpenLDAP, I'm happy. Please feel free to merge & release 0.3.0. 👍 |
I have to say @vintagepenguin 's comment on #28 worries me a bit, although I could not reproduce it. |
@elobato what are the possible objects returned by |
true if authentication was successful |
remove debugger Addressed Petr issues during review Removed domains and tested with ADLS LdapError class and OpenLDAP memberuid get_logins fix Relax activesupport dependency and add authors Recursive OU, posixgroups search Refactored tests and added nested groups tests Make travis pick up different activesupport for ruby 1.8 Booleanize authenticate? result
@domcleal @pitr-ch |
@elobato thanks |
Move foreman LDAP functionality to ldap_fluff
Most logic comes from here: https://github.com/theforeman/foreman/blob/develop/app/models/auth_sources/auth_source_ldap.rb
and theforeman/foreman#529 , which this PR is meant to facilitate.