封尘网

让学习成为一种习惯!

通过ldap认证里的邮箱地址登陆Jenkins

在上一次的文档中记录了jenkins 如何通过ldap认证登陆 https://www.58jb.com/html/jenkins-auth-with-ldap.html,文中是以用户名的方式登陆的,如果要使用邮件地址或者电话号码作为帐号登陆呢?如何实现?

由于最近网友的一个问题,能不能通过邮件地址的方式来登陆Jenkins,刚开始我觉得好像不行。后来研究了一下,发现其实很简单,因为在使用ldap认证时获取到整个用户的相应信息了。而至于使用该用户哪个字段, 用户、邮箱地址、或者电话号码等那是取决于我们过滤匹配字段。

 

其实在Jenkins里就已经有说明了。只是没太在意,以下是引用它的原文

 

User search filter右边问题的说明

One of the searches Jenkins does on LDAP is to locate the user record given the user name.
This field determines the query to be run to identify the user record. The query is almost always "uid={0}" as per defined in RFC 2798, so in most cases you should leave this field empty and let this default kick in.

If your LDAP server doesn't have uid or doesn't use a meaningful uid value, try "mail={0}", which lets people login by their e-mail address.

If you do specify a different query, specify an LDAP query string with marker token "{0}", which is to be replaced by the user name string entered by the user.

( LDAP Plugin)

 

通过说明就可以发现,如果要使用邮件地址登陆,就使用mail={0}来匹配User search filter

(&(mail={0})(memberof=cn=jenkins,ou=group,dc=sotemalltest,dc=com))

 

如果要通过手机号码认证登陆,就使用telephoneNumber={0} 来匹配User search filter

(&(telephoneNumber={0})(memberof=cn=jenkins,ou=group,dc=sotemalltest,dc=com))

 

注意:上面修改字段是在User search filter里使用的。为了清楚来一张完整的配置图。

 

 

 

 

配置说明

  • User search filter:用来匹配过滤,这里过滤用户信息时以邮件来匹配该目录下的用户。
  • Group membership :匹配组关系,这里使用默认memberOf ,当然也可以像上一篇文章的配置那样(&(mail={1})) ,这里使用1来获取,可以返回用户名。而使用0时在Test LDAP settings时返回一段Waring信息。
  • Display Name LDAP attribute :它作用是使用ldap里的用户登陆后,在Jenkins上面显示的用户名信息,如:telephoneNumber则显示ldap用户配置里的Telephone numbergivenName则显示ldap用户配置里的First name ; mail 则显示ldap用户配置里的Emaill address这里看个人喜欢配置。

 

特别说明

  • 虽然我们可以配置通过ldap上的用户名,邮箱地址,电话号码为帐号登陆jenkins,不管是哪一个登陆方式,在第一次登陆到jenkins时都会创建一个以登陆名为帐号的帐号;直接说就是,登陆名是邮件 ,就会创建一个邮件地址的帐号,登陆名是电话号码就会创建一个电话号码的帐号。当然密码还是一样的。
  • 不能同时使用邮件、用户名或者是电话号码登陆,因为配置过滤器里指定了过滤的方式User search filter
  • 当使用邮箱地址或者手机号登陆时就要注意了帐号唯一性的问题,不能相同的,不然无法正确识别。

 

提醒:本文最后更新于 1053 天前,文中所描述的信息可能已发生改变,请谨慎使用。