Jenkins LDAP authentication for specific group members - jenkins

I need to setup authentication for our Jenkins via LDAP (AD). I was able to setup the authentication on a wide scale but I have to narrow it down to a certain members of a group and my LDAP filtering fails here.
This is the full DN that I want to target:
CN=jenkinsgroup,OU=App1,OU=Applications,OU=CompanyGroup,OU=Company,DC=my,DC=domain,DC=com
In the jenkinsgroup group I have the users stored as member attributes, only they should get access.
Jenkins LDAP plugin offers these fields:
Jenkis configuration
I'm not sure whether I should use a filter in on the User or the Group field, or which objectClass or category should I use for member attribute - I tried user and member as well.
Error message I get:
User lookup: user "username" does not exist.
Does the Manager Dn have permissions to perform user lookup?
Are the user search base and user search filter settings correct?
LDAP Group lookup: could not verify.
Please try with a user that is a member of at least one LDAP group.
Without the filtering, I can authenticate with a user from the group and it also confirms me its membership.
So I'm confused about how the write the proper query.
Thanks in advance!

As EricLavault commented:
(&(sAMAccountName={0})(memberOf=CN=jenkinsgroup,OU=App1,OU=Applications,OU=CompanyGroup,OU=Company,DC=my,DC=domain,DC=com))
I used this as the user search filter and worked.

Related

Spring Security Users With Same Name

If two users have same username in the database then how can spring security handle that?
I have two users with following login CREDENTIALS in database:-
1.Username:rohit password:1234
2.Username:rohit password:123
That means the user cannot be unique identified by the username only. So you have to think about the business requirements how to unique identify an user based on the information collected from the user request.
Enforcing the username to be unique across the system can definitely solve the problem. Ask the product owner if it is okay to do it .If not , ask him how to handle such case from the business 's point of view. Then based on the actual requirements of how to unique identify an user , you may need to customise the following classes (Assuming you are using the default username and password login form and authenticate against the user records from DB using JDBC) :
UsernamePasswordAuthenticationFilter
DaoAuthenticationProvider
UserDetailsService

Configuring group authorization in Jenkins using SAML

I am trying to setup group authorizations using my IDP (Identity Provider) with the Jenkins instance I have.
For individual users, I have been able to setup this up successfully by installing the SAML 2.0 plugin , sending up the Service Provider Metadata to my IDP and completing a successful registration.
I am able to login to my Jenkins successfully using my SAML credentials.
Further more I am able to give users certain roles using the Role Strategy Plugin. I have defined roles like "Job Reader" , "Job Admin" etc etc and assigned those roles to individual users.
All until here is done.
But what Im looking for is rather than having to assign roles to users on the Jenkins layer, I want Jenkins to pull groups defined in my IDP and assign those groups to roles that Ive defined rather than me having to assign roles to individual users.
On my IDP side, I have created groups (I have a group ID) and assigned users to those groups. All I want to do is to have my Jenkins reads those group IDs. Is there some documentation I can follow ?
Below are the steps Ive done so far with unsuccessful results.
In my IDP, Ive created a group jenkins-reader and assigned a user to the group.
When I curl on the data of the user, I can clearly see that my user P000002 is part of a particular group.
{
"uid": "P000002",
.
.
"companyGroups": [
"jenkins-reader"
],
.
.
. }
Now switching to Jenkins, I have the following config.
Under Manage Roles , ive configured Project Roles. Creating a jenkins-reader roles and assigning in Job Read permissions.
Under Assign Roles , I added the group jenkins-reader (same name as defined in IDP) and assigned it the jenkins-reader role configured in the last step.
When I hit Apply and Save, I try to login again and I get the ERROR
Access Denied
P000002 is missing the Overall/Read permission
Now Im not sure whether Ive missed something here or am taking a wrong approach to this. Ive been following this doc.

jenkins api authentication failure

I am using oauth authentication for jenkins. I can successfully make api calls if i use my_user_name:api_token when my user name is explicitly configure in global security. It fails when my user name does not exist but a group which contains the user name and has all permissions.
Any idea about this phenomenon ?
thanks in advance
The Jenkins api-token is obtained for a specific user http://<jenkins-server>/user/<username>/configure and can be used for that same user only.

LDAP user groups

How can I get users group list (as attribute) that user belongs too. I want to use LDAP server as SAML auth source and then I want to map LDAP attributes to SAML attributes and use them in spring-saml authentication for J2EE application group based role management. What I did at this moment it is LDAP->SAML->Spring-security (SAML module) authentication. But I can't get groups after login because LDAP didn't return them together with other information (cn, email, gidNumber and etc)
Unless you are using the OpenLDAP memberOf overlay you have to do a search for groups with the DN of the user as a value of the group membership attribute, which might be uniqueMember or roleOccupant, depending on how you have set up your LDAP server.
If you're using the memberOf overlay, just request the value of the memberOf attribute when you lookup the user.

Ruby - AD/LDAP auth - read user details

I am trying LDAP/Active directory authentication. This code is working perfectly, I can authenticate.
My question is - How do I retrieve user information from AD? I want to read firstname, lastname, fullname, email etc from AD for the authenticated user.
In LDAP, users do not authenticate, connections are authenticated. Once the authorization state
of the connection has been established (by a successful bind request), code that desires to
retrieve information from the directory must transmit a search request to the directory server
and then interpret the response.
Search requests must contain a minimum the following parameters:
the base object at which the search starts (no objects above the base objects are returned)
the scope of the search: base is the base object itself, one is the base object and
one level below thw base object, sub is the base object and all entries below the base object.
a filter which limits the entries returned to those entries which match the assertion in the
filter
A list of attributes can also be supplied, though many, but not all, LDAP APIs will request all
user attributes if none are supplied in the search request.
see also
LDAP: Mastering Search Filters
LDAP: Search best practices
LDAP: Programming practices

Resources