Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1071010

Summary: SELinux user map is not applied to Active Directory users coming through IPA trust
Product: Red Hat Enterprise Linux 7 Reporter: Alexander Bokovoy <abokovoy>
Component: pamAssignee: Tomas Mraz <tmraz>
Status: CLOSED CURRENTRELEASE QA Contact: Patrik Kis <pkis>
Severity: high Docs Contact:
Priority: high    
Version: 7.0CC: abokovoy, dpal, dwalsh, grajaiya, jgalipea, ksrot, ldv, lslebodn, mkosek, pbrezina, preichl, sbose, tmraz
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: pam-1.1.8-7.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1083981 (view as bug list) Environment:
Last Closed: 2014-06-13 09:22:25 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1083981    

Description Alexander Bokovoy 2014-02-27 22:33:06 UTC
SSSD cannot apply SELinux user map for Active Directory users due to SELinux rules being placed under AD domain's cn in sssd's cache but searched under IPA
domain's cn:

dn: cn=selinux,cn=ad.test,cn=sysdb
createTimestamp: 1393538073
lastUpdate: 1393538073
objectClass: selinux
order: guest_u:s0$xguest_u:s0$user_u:s0$staff_u:s0-s0:c0.c1023$unconfined_u:s0-s0:c0.c1023
user: unconfined_u:s0-s0:c0.c1023
distinguishedName: cn=selinux,cn=ad.test,cn=sysdb

dn: name=mymap,cn=selinux,cn=ad.test,cn=sysdb
createTimestamp: 1393538073
enabled: TRUE
lastUpdate: 1393538073
name: mymap
objectClass: selinuxusermap
originalDN: ipaUniqueID=81460176-9ec9-11e3-81c4-001a4ab8f505,cn=usermap,cn=selinux,dc=ipa7,dc=test
originalMemberUser: cn=adusers_u,cn=groups,cn=accounts,dc=ipa7,dc=test
selinuxUser: user_u:s0
uniqueID: 81460176-9ec9-11e3-81c4-001a4ab8f505
distinguishedName: name=mymap,cn=selinux,cn=ad.test,cn=sysdb

but

(Thu Feb 27 23:54:36 2014) [sssd[be[ipa7.test]]] [sysdb_search_groups] (0x2000): Search groups with filter: (&(objectclass=group)(originalDN=ipauniqueid=81460176-9ec9-11e3-81c4-001a4ab8f505,cn=usermap,cn=selinux,dc=ipa7,dc=test))
(Thu Feb 27 23:54:36 2014) [sssd[be[ipa7.test]]] [sysdb_search_groups] (0x2000): No such  entry
(Thu Feb 27 23:54:36 2014) [sssd[be[ipa7.test]]] [add_ad_user_to_cached_groups] (0x4000): Group
  [ipauniqueid=81460176-9ec9-11e3-81c4-001a4ab8f505,cn=usermap,cn=selinux,dc=ipa7,dc=test] not in the cache.
  (Thu Feb 27 23:54:36 2014) [sssd[be[ipa7.test]]] [ipa_add_ad_memberships_get_next] (0x0020): There are unresolved external group memberships even after all groups have been looked up on the LDAP server.

Note that it looks up objectclass=group while it should lookup
objectclass=selinuxusermap and take originalMemberUser from there.

This is for the following configuration:

[root@rh7-01 ~]# ipa group-show adusers
   Group name: adusers
   Description: AD users
   Member of groups: adusers_u
   External member: domain admins
[root@rh7-01 ~]# ipa group-show adusers_u
   Group name: adusers_u
   Description: POSIX group for AD users
   GID: 487000006
   Member groups: adusers
[root@rh7-01 ~]# ipa selinuxusermap-show mymap
   Rule name: mymap
   SELinux User: user_u:s0
   Enabled: TRUE
   User Groups: adusers_u

Here is what I see when log in as AD user:

[ab@rh7-01 ~]$ klist
Ticket cache: KEYRING:persistent:1000:1000
Default principal: Administrator

Valid starting       Expires              Service principal
02/27/2014 23:52:37  02/28/2014 09:52:09  host/rh7-01.ipa7.test
	renew until 02/28/2014 23:52:06
02/27/2014 23:52:33  02/28/2014 09:52:09  krbtgt/IPA7.TEST
	renew until 02/28/2014 23:52:06
02/27/2014 23:52:09  02/28/2014 09:52:09  krbtgt/AD.TEST
	renew until 02/28/2014 23:52:06
[ab@rh7-01 ~]$ ssh -k -l Administrator `hostname`
Last login: Fri Feb 28 00:32:12 2014 from rh7-01.ipa7.test
-sh-4.2$ id -Z
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
-sh-4.2$ id
uid=1115000500(administrator) gid=1115000500(administrator) groups=1115000500(administrator),487000006(adusers_u),1115000512(domain admins),1115000513(domain users),1115000518(schema admins),1115000519(enterprise admins),1115000520(group policy creator owners) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
-sh-4.2$

Comment 2 Jakub Hrozek 2014-03-04 15:57:50 UTC
Upstream ticket:
https://fedorahosted.org/sssd/ticket/2266

Comment 3 Jakub Hrozek 2014-03-05 09:53:23 UTC
Dan, we've debugged the problem with Alexander yesterday. The problem is that pam_selinux.so expects the file with the context (/etc/selinux/targeted/$name) in the exact same case as format as the one used for login.

However, for AD users, there are many login formats that can be used, typically one would use user@domain or domain\user, but the login format is ultimately configurable in sssd. Moreover, AD is case-insensitive so the user can use any combination of case (the forms administrator@domain, Administrator@domain and even AdMiNiStRaToR@domain all represent the same user). The sssd internally parses and normalizes the login and uses a unified representation internally.

Instead of writing out a file based on what login representation the user chose for this particular login and ending up with different files for different users (and with potentially different content over time) would it be possible for pam_selinux to call out to sssd that would return the normalized format for this particular user?

Comment 4 Alexander Bokovoy 2014-03-05 10:20:52 UTC
What if we do avoid relying on a file system properties here and instead add optional way for pam_selinux to retrieve the context out of a kernel keyring?

SSSD PAM module may write information about both normalized user name and its centrally-provided SELinux context there under predefined keys that pam_selinux could retrieve. If they do not exist or unparsable, fallback to the original behavior of fetching the context from /etc/selinux/targeted/$name.

For example, _sss_normalized_username and _sss_selinux_context could be used.

Comment 5 Simo Sorce 2014-03-05 18:36:11 UTC
Just 2c, to "call out to SSSD" all pam_selinux really need to to do is to run a getpwnam() with the login form and then use the resulting pwd->pw_name as the canoinical form.

This is the appropriate way to go about it in the general case and will work with other identity backends like Winbindd or other proprietary solutions that provide access to Active Directory backed identities.

Comment 6 Daniel Walsh 2014-03-05 18:42:42 UTC
Sounds good to me.  pam_selinux is in the pam package.

Comment 7 Tomas Mraz 2014-03-06 10:55:55 UTC
Actually should the canonicalization of the user name be done in pam_selinux or libselinux?

See the discussion here for another example where canonicalization was not right thing to do: https://fedorahosted.org/linux-pam/ticket/22#comment:6

Comment 8 Sumit Bose 2014-03-06 12:21:20 UTC
As Stephen said in the comment, this is not possible with SSSD.

Additionally I would say that it is the definition of a canonical name that

getpwnam(CANONICAL_NAME)->pw_name is CANONICAL_NAME;

If think the given example is artificial, it might be possible to configure such behavior, but I would expect all kinds of other issues with this setup.

Comment 9 Dmitry V. Levin 2014-03-07 00:40:49 UTC
From pam_selinux point of view, such canonicalization seems to be SSSD specific.
Also, report https://fedorahosted.org/linux-pam/ticket/22 shows that other pam modules might need this canonicalization in some SSSD configurations.

From Linux-PAM point of view, I'd prefer a more universal approach.

Comment 10 Sumit Bose 2014-03-07 11:43:43 UTC
I think canonicalization in general is not SSSD specific because PAM and NSS are separate interfaces. E.g. with pam_ldap and nss_ldap you can configure pam_ldap to use an attribute containing the email address of a user as pam_login_attribute so that the user can log in with his email address but let nss_ldap still use an attribute with the short name.

Another use case would be an environment where you want to allow people to authenticate with there Google/Facebook/whatever account. Here the name used at the login prompt might be different from the system user name.

I'm all for a universal approach. Are you thinking of a new item type like e.g. PAM_CANON_USER? If yes, please note that this should not be needed for pam_authenticate() and the framework should only add it for later steps. The reason is that there are use cases where getting the user data after authentication is much easier (or only possible) after authentication.

Comment 19 Ludek Smid 2014-06-13 09:22:25 UTC
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.