Skip to content

[BUG] Salt relies on spwd module, deprecated in 3.11 and removed in 3.13 #67119

Closed

Description

@Vaelatern

This is very much like #67118

This time however linux_shadow and solaris_shadow are broken by the need for spwd. The official recommendation by Python is the third party python-pam.

I've not yet drafted an example patch.

Activity

  1. added
    bug
    on Dec 23, 2024
  2. Rudd-O commented on Feb 10, 2025

    @Rudd-O
    Contributor

    Even though I'm almost convinced this is a dead project and it was a huge mistake to port my Ansible stuff to Salt... since I have to maintain my systems and days only have 24 hours, I've had to make the fix myself.

    So here is the patch, and I formally disclaim any ownership or licensing interest on it, and no I will not sign your CLA:

    diff -up venv3007.1/lib/python3.12/site-packages/salt/modules/linux_shadow.py.old venv3007.1/lib/python3.12/site-packages/salt/modules/linux_shadow.py
    --- venv3007.1/lib/python3.12/site-packages/salt/modules/linux_shadow.py.old	2025-02-10 00:08:23.401850220 +0000
    +++ venv3007.1/lib/python3.12/site-packages/salt/modules/linux_shadow.py	2025-02-10 00:15:43.969807664 +0000
    @@ -8,6 +8,7 @@ Manage the shadow file on Linux systems
         <module-provider-override>`.
     """
     
    +import collections
     import datetime
     import functools
     import logging
    @@ -17,11 +18,6 @@ import salt.utils.data
     import salt.utils.files
     from salt.exceptions import CommandExecutionError
     
    -try:
    -    import spwd
    -except ImportError:
    -    pass
    -
     
     try:
         import salt.utils.pycrypto
    @@ -34,6 +30,21 @@ __virtualname__ = "shadow"
     
     log = logging.getLogger(__name__)
     
    +struct_spwd = collections.namedtuple(
    +    "struct_spwd",
    +    [
    +        "sp_namp",
    +        "sp_pwdp",
    +        "sp_lstchg",
    +        "sp_min",
    +        "sp_max",
    +        "sp_warn",
    +        "sp_inact",
    +        "sp_expire",
    +        "sp_flag",
    +    ]
    +)
    +
     
     def __virtual__():
         return __virtualname__ if __grains__.get("kernel", "") == "Linux" else False
    @@ -71,7 +82,7 @@ def info(name, root=None):
         if root is not None:
             getspnam = functools.partial(_getspnam, root=root)
         else:
    -        getspnam = functools.partial(spwd.getspnam)
    +        getspnam = functools.partial(_getspnam, root="/")
     
         try:
             data = getspnam(name)
    @@ -509,7 +520,7 @@ def list_users(root=None):
         if root is not None:
             getspall = functools.partial(_getspall, root=root)
         else:
    -        getspall = functools.partial(spwd.getspall)
    +        getspall = functools.partial(_getspall, root="/")
     
         return sorted(
             user.sp_namp if hasattr(user, "sp_namp") else user.sp_nam for user in getspall()
    @@ -529,7 +540,7 @@ def _getspnam(name, root=None):
                     # Generate a getspnam compatible output
                     for i in range(2, 9):
                         comps[i] = int(comps[i]) if comps[i] else -1
    -                return spwd.struct_spwd(comps)
    +                return struct_spwd(*comps)
         raise KeyError
     
     
    @@ -545,4 +556,4 @@ def _getspall(root=None):
                 # Generate a getspall compatible output
                 for i in range(2, 9):
                     comps[i] = int(comps[i]) if comps[i] else -1
    -            yield spwd.struct_spwd(comps)
    +            yield struct_spwd(*comps)
    

    Creating users on Linux systems will still fail in the absence of the python3-passlib package (or equivalent PyPI module). So I'll leave it to the brain trust to figure out how to fix that in the packaging.

    By the way, the whole "onedir" thing? It really screwed us salt-ssh users.

  3. Vaelatern commented on Feb 10, 2025

    @Vaelatern
    ContributorAuthor

    thank you for the patch! I will test it.

  4. Vaelatern commented on Feb 11, 2025

    @Vaelatern
    ContributorAuthor

    I've tested it and it works for me, so.

    I'm volunteering to make this an official PR.

  5. Rudd-O commented on Feb 12, 2025

    @Rudd-O
    Contributor

    Let's GOOOOOOOOOOOOOOOOOOOO!

  6. frebib commented on Mar 5, 2025

    @frebib
    Contributor

    Can you raise a PR for this?

  7. Vaelatern commented on Mar 6, 2025

    @Vaelatern
    ContributorAuthor
  8. linked a pull request that will close this issueRemove uses of spwd #68402on Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions