Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Vaelatern opened this issue Dec 23, 2024 · 6 comments
Open
Labels
Bug broken, incorrect, or confusing behavior needs-triage

Comments

@Vaelatern
Copy link
Contributor

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.

@Vaelatern Vaelatern added Bug broken, incorrect, or confusing behavior needs-triage labels Dec 23, 2024
@Rudd-O
Copy link

Rudd-O commented Feb 10, 2025

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.

@Vaelatern
Copy link
Contributor Author

thank you for the patch! I will test it.

@Vaelatern
Copy link
Contributor Author

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

I'm volunteering to make this an official PR.

@Rudd-O
Copy link

Rudd-O commented Feb 12, 2025

Let's GOOOOOOOOOOOOOOOOOOOO!

@frebib
Copy link
Contributor

frebib commented Mar 5, 2025

Can you raise a PR for this?

@Vaelatern
Copy link
Contributor Author

@frebib #67788

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior needs-triage
Projects
None yet
Development

No branches or pull requests

3 participants