[OpenBMC] LDAP 设定(一) - nss-pam-ldapd

3 篇文章 2 订阅

Note. OpenBMC的官方已经有文件对帐户管理有简单的介绍,可以先阅读

User Management - OpenBMC - Design documenticon-default.png?t=M0H8https://github.com/openbmc/docs/blob/master/architecture/user-management.mdOpenBMC ldap设定和验证,可分成几个部分,本篇会先介绍第一个部分nss-pam-ldapd

nss-pam-ldapd

OpenBMC - User Management - High Level architectural diagram

底下 OpenBMC 对nss-pam-ldapd 的描述

Bringing the LDAP authentication module support in openbmc stack requires to pull the nss-pam-ldapd which allows the LDAP server to provide the user, passwd, group info that we normally get from the /etc flat files.
openbmc auth stack 使用nss-pam-ldapd 来引入LDAP验证模组让我们能从/etc 平面文件中取得LDAP server 提供的 user, psswd, group 资讯。


nss-pam-ldapd provides libnss-ldap(Name Service Switch module) and pam_ldap(Pluggable Authentication Module) module which delegate the work to the nslcd(daemon) that queries the LDAP server.
nss-pam-ldapd 是透过 nslcd(daemon) 使用 libnss-ldap和 pam_ldap (thin NSS and PAM modules )来实现的

pam_ldap uses the openldap client API to interact with the LDAP server.
其中pam_ldap 是使用openldap client API来和LDAP server做沟通的

因此我们在OpenBMC 的进程中可以看到nslcd这个daemon

path of nss-pam-ldapd in Openbmc: meta-phosphor/recipes-support/nss-pam-ldapd at master · openbmc/meta-phosphor · GitHub

open source of nss-pam-ldapd:

GitHub - arthurdejong/nss-pam-ldapd: NSS and PAM modules for lookups using LDAP

nss-pam-ldapd 在接下来这边会分别介绍

  • nslcd的设定档(nslcd.conf)
  • pam module
  • nss module 

💣nslcd.conf

nslcd.conf 是存放LDAP server的配置的文件,包含了base dc, binddn, bindpw 等资讯,在官方网站(https://arthurdejong.org/nss-pam-ldapd/setup)中有说明最低配置应该包含如以下: 

在BMC中,当我们设定完ldap的连线后,会由 phosphor-ldap-conf  这个daemon来更新nslcd.conf的内容,举的例子,我们先透过redfish 来设定LDAP service ([PATCH] redfish/v1/AccountService)

redfish 会将资料透过Dbus 由phosphor-ldap-conf  来更新nslcd.conf

💣PAM(Pluggable Authentication Modules)

在Linux中,我们常常需要用不同的机制来判断帐号密码,例如本地帐号密码,LDAP,指纹读取机等,越来越多元的帐号认证方式,就出现了PAM,可插拔身分验证模块,他可以透过使用配置文件而不是更改应用程序代码来切换安全应用程序的身份验证方法。例如密码输入错误几次就要锁几分钟,几个月要换一次密码,能不能透过LDAP登入,这些设定都记录在pam.d/* 或 pam.conf中,并且透过不同的shared library(.so)来实现

pam shared library(.so) 在obmc的位置是存放在/lib/security/*

pam config file位在/etc/pam.d/*

如果我们要同时使用LDAP和local user 都能登入的话,就需要在/etc/pam.d 下编辑相关文件。在任何有呼叫pam_unix的地方,也需要呼叫pam_ldap。

以webserver 为例

这边include common-auth,从common-auth中可以看到验证帐号的步骤分别呼叫了 pam_tally2.so, pam_unix.so and pam_ldap.so,(unix后也呼叫了ldap)

user-management.md中有分别说明三个模块的目的为何

而有了以上设定,webserver就能同时使用local user 或 ldap user 登入了,流程如下图,LDAP server的相关资料会存放在nslcd.conf中


💣nsswitch(Name Service Switch)

最后,我们需要在nsswitch.conf中新增ldap 的配置供client 端验证查询使用,在pam 验证模块中,会去分别对有效帐户,密码核对,所属群组去做验证,通常在本地端会将帐户讯息存在 /etc/passwd, 密码放在 /etc/shadow (for uid),群组讯息放在/etc/group (for gid) ,但LDAP的讯息并不会存放在本地端档案中,因此我们就需要透过nss来找到相对应的database source

因此 nss 被视为任何在client端呼叫getXbyY()的介面,例如: 

getpwnam()    (&(objectClass=posixAccount)(uid=%s))
getpwuid()    (&(objectClass=posixAccount)(uidNumber=%d))
getpwent()    (objectClass=posixAccount)


透过nssswitch.conf 列出database(资料库, 如group, passwd等)相对应的来源,格式如下:

Name Service Switch Types: Sources#1 Sources#2


例如 passwd: files ldap --> 搜寻passwd database 会依序lookup /etc/passwd 再 ldap 

目前支援的Name Service Switch Type有16种: aliases, bootparams, ethers, group, hosts, ipnodes, netgroup, netmasks, networks, passwd (includes shadow information), protocols, publickey, rpc, services, automount, sendmailvars

如果要启用ldap 服务的话,至少要将ldap 加到passwd, group and shadow 的映射中,在local lookup后面加上ldap。如以下


nsswitch.conf

也可以通过更改nslcd.conf配置来修改 NSS lookup(查找)和LDAP database之间的mapping。
在Redfish AccountService的schema中,可以看到LDAP有两个property: GroupNameAttribute
和 GroupsAttribute如下:

"GroupNameAttribute": {
    "description": "The attribute name that contains the LDAP group name entry.",
    "longDescription": "This property shall contain the attribute name that contains the LDAP group name.",
    "readonly": false,
    "type": [
        "string",
        "null"
    ],
    "versionAdded": "v1_3_0"
},
"GroupsAttribute": {
    "description": "The attribute name that contains the groups for a user on the LDAP user entry.",
    "longDescription": "This property shall contain the attribute name that contains the groups for an LDAP user entry.",
    "readonly": false,
    "type": [
        "string",
        "null"
    ],
    "versionAdded": "v1_3_0"
}


这什么意思呢? 因为在pam中识别user都是透过uid (user id), group 是透过 gid(group id),那我们也能设定不同的识别方式,就是透过MAP

如以下当在比对 uid (&(objectClass=posixAccount)(uidNumber=%d))的时候,uid就会自动map成sAccountName,那这两个property是可以为null的,所以没设定的时候这两个值是默认uid 和 gid

map passwd uid              sAccountName
map passwd gidNumber        primaryGroupID

nss_pam_ldap lookup 流程如下


总结大概是是"NSS可以枚举有关服务/用户的信息(属于哪个组,主目录在哪里等)。PAM决定如何处理该信息"

最后附上obmc的nsswitch.conf 

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SSSD、PAM(Pluggable Authentication Modules)和NSS(Name Service Switch)是在Linux系统中用于身份验证和名称解析的关键组件,它们的作用和功能略有不同。 SSSD(System Security Services Daemon)是一个守护进程,用于集成和管理身份验证和授权服务。它提供了一个统一的框架,使得Linux系统能够与不同的身份源(如LDAP、Active Directory等)进行集成,并提供一致的身份验证和访问控制机制。SSSD负责与身份源通信,并提供用户信息缓存、组信息管理等功能。 PAM(Pluggable Authentication Modules)是一个可插拔的身份验证模块框架。它允许系统管理员通过配置不同的PAM模块来实现灵活的身份验证策略。PAM通过一系列的认证模块来处理用户身份验证,例如密码验证、指纹识别、智能卡等。PAM的作用是在用户登录或执行特权操作时,验证用户提供的凭证,并根据配置的PAM模块来确定是否允许访问。 NSS(Name Service Switch)是用于处理Linux系统中的名称解析的组件。它允许系统管理员通过配置不同的NSS模块来解析不同类型的名称,如用户、组、主机等。NSS模块通常与其他服务(如SSSD、LDAP、NIS等)集成,从不同的身份源获取用户、组等信息,并将其提供给系统使用。 总结来说,SSSD负责集成和管理身份验证和授权服务,提供统一的身份验证和访问控制机制;PAM用于处理用户身份验证,通过配置不同的认证模块来确定是否允许访问;NSS用于名称解析,通过配置不同的模块来解析不同类型的名称。它们在Linux系统中各自扮演着不同的角色,但也可以相互配合使用以提供更全面的身份验证和名称解析功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值