#1148069 dh-nss: fix adding non-default nsswitch config fields on package upgrades

Package:
dh-nss
Source:
dh-nss
Submitter:
Mike Gabriel
Date:
2026-10-05 01:43:04 UTC
Severity:
normal
Tags:
#1148069#5
Date:
2026-09-16 16:24:41 UTC
From:
To:
Dear Gioele,

I am currently on a mission to get sssd back into Debian testing,
currently blocked by:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1129522

The proposed fix for the above issue involves sudo becoming the
"owner" of the sudoers: entry in nsswitch.conf:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1147179

The proposed fix in above bug report (adding debian/sudo.nss with
below content) does fail when upgrading sudo from a version of the
sudo package that did not have debian/sudo.nss, yet:

```
sudoers database-add

sudoers first files
```

When installing sudo a-fresh, with above sudo.nss file, "sudoers:
files" appears at the end of nsswitch.conf (GOOD). However, when
upgrading from an earlier version of the sudo package, we get
"sudoers:" in nsswitch.conf (BOOM). So, we end up in a broken state.

The fix for this needs to be applied to dh-nss, I guess:

```
diff -Nru dh-nss-1.7.1/autoscripts/preinst-nss
dh-nss-1.7.1+nmu1/autoscripts/preinst-nss
--- dh-nss-1.7.1/autoscripts/preinst-nss	2026-08-20 01:17:24.000000000 +0200
+++ dh-nss-1.7.1+nmu1/autoscripts/preinst-nss	2026-09-16
16:05:08.000000000 +0200
@@ -1,4 +1,4 @@
-if [ "$1" = install ]; then
+if [ "$1" = install ] || ( [ "$1" = upgrade ] && ! grep -q -E
#SERVICE_PATTERNS# "${DPKG_ROOT}/etc/nsswitch.conf" ); then
   	# Signal to postinst that the NSS services should be installed,
even if the package has been removed but not purged.
   	touch
"${DPKG_ROOT}/etc/nsswitch.conf.nss.${DPKG_MAINTSCRIPT_PACKAGE}-will-install"
   fi
diff -Nru dh-nss-1.7.1/debian/changelog dh-nss-1.7.1+nmu1/debian/changelog
--- dh-nss-1.7.1/debian/changelog	2026-08-20 01:17:24.000000000 +0200
+++ dh-nss-1.7.1+nmu1/debian/changelog	2026-09-16 16:05:25.000000000 +0200
@@ -1,3 +1,16 @@
+dh-nss (1.7.1+nmu1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * {autoscripts/preinst-nss,dh_installnss}: Apply .nss configs on package
+    upgrade, too. (Closes: -1).
+    - Also signal nsswitch.conf.nss.${DPKG_MAINTSCRIPT_PACKAGE}-will-install
+      from preinst to postinst on package upgrades if SERVICE_PATTERN has not
+      been applied, yet.
+    - Assure SERVICE_PATTERN macro gets populated properly during preinst
+      autoscript generation.
+
+ -- Mike Gabriel <sunweaver@debian.org>  Wed, 16 Sep 2026 16:05:25 +0200
+
   dh-nss (1.7.1) unstable; urgency=medium

     * t/dh_installnss: Fix typo
diff -Nru dh-nss-1.7.1/dh_installnss dh-nss-1.7.1+nmu1/dh_installnss
--- dh-nss-1.7.1/dh_installnss	2026-08-20 01:17:24.000000000 +0200
+++ dh-nss-1.7.1+nmu1/dh_installnss	2026-09-16 16:05:25.000000000 +0200
@@ -405,7 +405,9 @@
   	my $service_patterns_expr = service_patterns_expr(\%db_services);

   	# Add a snippet in preinst to detect installation of non-purged packages.
-	autoscript($package, "preinst", "preinst-nss");
+	autoscript($package, "preinst", "preinst-nss", {
+		"SERVICE_PATTERNS" => $service_patterns_expr,
+		});

   	# Generate one snippet for each extra NSS databases to be added.
   	foreach my $db_extra (@dbs_extra_add) {
```

Same .debdiff is attached. Please let us know if you see this as a
possible fix and if you can provide this change anytime soon.

Thanks,
Mike (and Marc, maintainer of sudo)

#1148069#10
Date:
2026-09-26 13:02:27 UTC
From:
To:
Hi Gioele, hi all,

ping via BTS @ dh-nss maintainer, cross-posting to the other related
bugs affected by this, to keep other people in the loop.

People start asking about when sssd is fixed (because autofs is also
impacted by sssd not being in testing).

For the background story and how this all is related:

   * autofs is not in testing, because sssd is not in testing
   * sssd is not in testing because of #1129522
   * to get sssd fixed (#1129522) it needs sudo bug #1147179 getting fixed
   * to get the approach suggested in #1147179 fully functional dh-nss needs
     love (#1148069)
   * this also impact the Debian Edu 14 development, but this is not so
     pressing at the moment, because we are still busy with fine-polishing
     the Debian Edu 13 release

@Gioele (dh-nss maintainer): let me know if there is anything we can
do to speed up the upcoming dh-nss release. Thanks.

Cheers,
Mike

#1148069#17
Date:
2026-10-02 13:06:44 UTC
From:
To:
Control: tags 1148069 - patch
simple fix like the one proposed here does not properly cover all the
possible upgrade paths (for arbitrary changes to .nss files). Upgrades
are hard.

I'll try now a different strategy: making the maintscript snippets go
back to a clean state before each upgrade. On paper it works, but I'm
afraid it may cause intermittent issues because there will be a window
of time in which the service will not be enabled in /etc/nsswitch.conf.
In case of a failed upgrade that window may be arbitrarily long and if
that service is something needed to log in, the admin may end up locked
out of their accounts.

Another option, more in line with what sssd and autofs need at the
moment, would be to state something along the lines of ".nss files can
only be added to or removed from a package; changing the content of .nss
files between package versions is not allowed without additional ad-hoc
code in maintscripts".

Both options are unsatisfactory. Option 2 is perhaps the best to unblock
the current sssd situation.

I'll do some other testing and play with these two options during the
weekend, then release a version that will at least unblock sssd.

Ideas and comments are welcome!

#1148069#22
Date:
2026-10-02 15:58:00 UTC
From:
To:
Hi Gioele,

Thanks for the info update and for providing a fix to unblock sssd.

Mike

#1148069#27
Date:
2026-10-03 23:47:42 UTC
From:
To:
Hi Mike,

On Fri, 02 Oct 2026 15:58:00 +0000 Mike Gabriel <sunweaver@debian.org> wrote:
matches the reality, can you please confirm my reading of the solution
you agreed upon in the other bugs?

 From <https://bugs.debian.org/1147179#30>:

## sudo

sudoers database-add
sudoers first  files

## libsss-sudo

Pre-Depends: sudo (>= $some-version)

sudoers database-require
sudoers after=files  sss

Regards,

#1148069#32
Date:
2026-10-04 06:48:53 UTC
From:
To:
Hi Gioele,

Confirming! That's the proposed solution, indeed.

Mike

#1148069#37
Date:
2026-10-05 01:41:46 UTC
From:
To:
Hi, I have uploaded dh-nss v1.8~exp2 to experimental. The new code
should fix the issue that affect sssd and sudo (although many other
problems are still lurking.)

Please test. I'll wait for your feedback before uploading v1.8 to unstable.

Regards,