Bug 2176337

Summary: systemd upgrade should not forcibly add 'systemd' in passwd nsswitch.conf
Product: Red Hat Enterprise Linux 9 Reporter: Ding-Yi Chen <dchen>
Component: systemdAssignee: Jacek Migacz <jmigacz>
Status: VERIFIED --- QA Contact: Frantisek Sumsal <fsumsal>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 9.1CC: msekleta, pbrezina, systemd-maint-list
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: systemd-252-16.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 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:

Description Ding-Yi Chen 2023-03-08 01:38:54 UTC
Description of problem:

post script of systemd forcily append of `systemd` in following databases

- passwd
- group

While the behavior make sense for initial installation, but not necessary for upgrade. Some customers need to use their own nsswitch.conf, and would not want it to be modified by systemd upgrade script.


Quote Pavel Březina from https://bugzilla.redhat.com/show_bug.cgi?id=1577250#c7

> Do you actually need to run it during upgrade?
> Wouldn't it be sufficient to run it only during first installation?


Version-Release number of selected component (if applicable):

systemd-250-12.el9_1.1.x86_64

How reproducible:

always


Steps to Reproduce:
1. Edit /etc/nsswitch.conf, and make the passwd line become: 
 
   passwd: sss files
2. Upgrade systemd
3. grep passwd /etc/nsswitch.conf

Actual results:

systemd is forcibly appended 

passwd: sss files systemd

Expected results:

the passwd line is untouched

passwd: sss files

Additional info:

Work around:

Instead of removing systemd keywords, comment them out like

 
passwd:     files sss # systemd
group:      files sss # systemd


================ systemd post script
# rpm -q --scripts systemd-libs
postinstall scriptlet (using /bin/sh):


function mod_nss() {
    if [ -f "$1" ] ; then
        # Add nss-systemd to passwd and group
        grep -E -q '^(passwd|group):.* systemd' "$1" ||
        sed -i.bak -r -e '
                s/^(passwd|group):(.*)/\1:\2 systemd/
                ' "$1" &>/dev/null || :
    fi
}

FILE="$(readlink /etc/nsswitch.conf || echo /etc/nsswitch.conf)"
if [ "$FILE" = "/etc/authselect/nsswitch.conf" ] && authselect check &>/dev/null; then
        mod_nss "/etc/authselect/user-nsswitch.conf"
        authselect apply-changes &> /dev/null || :
else
        mod_nss "$FILE"
        # also apply the same changes to user-nsswitch.conf to affect
        # possible future authselect configuration
        mod_nss "/etc/authselect/user-nsswitch.conf"
fi
...

Comment 1 Pavel Březina 2023-03-29 08:42:25 UTC
Does systemd still touch the nsswitch.conf on its own? AFAIK I removed the scriptlets in Fedora 37... This can be left on authselect, so it shouldn't be necessary to run any scriptlet on systemd side.

See: https://fedoraproject.org/wiki/Changes/Make_Authselect_Mandatory

Comment 2 Pavel Březina 2023-03-29 08:46:48 UTC
Ah, this is RHEL, the authselect change is not yet there. In that case, probably touching nsswitch.conf only on first install should be sufficient to avoid overriding user changes.