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

salt.modules.pdbedit doesn't work on samba older than 4.8 #55185

Closed
sjorge opened this issue Nov 1, 2019 · 13 comments
Closed

salt.modules.pdbedit doesn't work on samba older than 4.8 #55185

sjorge opened this issue Nov 1, 2019 · 13 comments
Labels
Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt P4 Priority 4 severity-low 4th level, cosemtic problems, work around exists ZRelease-Sodium retired label
Milestone

Comments

@sjorge
Copy link
Contributor

sjorge commented Nov 1, 2019

Description of Issue

Someone contacted me via email that pdbedit module/state wasn't working.
The person is using samba 4.3.11 and the required fields in the pdbedit output are missing.

I was using samba 4.8.x when writing this module, there should probably be a version check that doesn't load the module when the version is older.

Setup

N/a

Steps to Reproduce Issue

Try and use pdbedit module or state on samba older than 4.8.x

Versions Report

(from e-mail)

Salt Version:
           Salt: 2018.3.2
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.5.3
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: 0.3.8
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-116-generic
         system: Linux
        version: Ubuntu 16.04 xenial
@sjorge
Copy link
Contributor Author

sjorge commented Nov 1, 2019

[atlas :: sjorge][~]
[!]$ pdbedit -V
Version 4.9.8

Seems to print the version.

@Ch3LL
Copy link
Contributor

Ch3LL commented Nov 4, 2019

we will probably want to add this check to salt/modules/pdbedit.py in __virtual__. Did you want to take a stab at it or i can?

@Ch3LL Ch3LL added Bug broken, incorrect, or confusing behavior severity-low 4th level, cosemtic problems, work around exists P4 Priority 4 Core relates to code central or existential to Salt labels Nov 4, 2019
@Ch3LL Ch3LL added this to the Approved milestone Nov 4, 2019
@sjorge
Copy link
Contributor Author

sjorge commented Nov 4, 2019 via email

@stale
Copy link

stale bot commented Jan 7, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Jan 7, 2020
@sjorge
Copy link
Contributor Author

sjorge commented Jan 7, 2020

Nope, still an issue... might have some time to work on this later this month

@stale
Copy link

stale bot commented Jan 7, 2020

Thank you for updating this issue. It is no longer marked as stale.

@stale stale bot removed the stale label Jan 7, 2020
@sjorge
Copy link
Contributor Author

sjorge commented Jan 12, 2020

Very quick hack I made, it's not lint clean and no tests yet.

I ran out of time to get this turned into a PR with tests for now.

--- /opt/local/lib/python2.7/site-packages/salt/modules/pdbedit.py 2019-10-26 11:38:15.000000000 +0000
+++ pdbedit.py  2020-01-12 12:37:09.458602337 +0000
@@ -11,6 +11,7 @@
 from __future__ import absolute_import, print_function, unicode_literals

 # Import Python libs
+import re
 import logging
 import hashlib
 import binascii
@@ -39,14 +40,21 @@
     '''
     Provides pdbedit if available
     '''
-    if salt.utils.path.which('pdbedit'):
-        return __virtualname__
-    return (
-        False,
-        '{0} module can only be loaded when pdbedit is available'.format(
-            __virtualname__
-        )
-    )
+    # NOTE: check for pdbedit command
+    if not salt.utils.path.which('pdbedit'):
+        return (False, 'pdbedit command is not available')
+
+    # NOTE: check version is >= 4.8.x
+    ver = __salt__['cmd.run']('pdbedit -V')
+    ver_regex = re.compile(r'^Version\s(\d+)\.(\d+)\.(\d+)$')
+    ver_match = ver_regex.match(ver)
+    if not ver_match:
+        return (False, 'pdbedit -V returned an unknown version format')
+
+    if not (int(ver_match.group(1)) >= 4 and int(ver_match.group(2)) >= 8):
+        return (False, 'pdbedit is to old, 4.8.0 or newer is required')
+
+    return __virtualname__


 def generate_nt_hash(password):

dwoz added a commit that referenced this issue Mar 10, 2020
#55185 pdbedit module should check for version 4.8.x or newer
@xenadmin
Copy link

xenadmin commented May 7, 2020

Since I updated from Salt 2019.2 to 3000 the samba.users state I helped improve, doesn't work anymore. (https://github.com/saltstack-formulas/samba-formula/blob/master/samba/users)
I suspect it's because of this change. The minions are Debian 9.

pdbedit -V
Version 4.5.16-Debian

It worked before.

root@salt:/srv/formulas# salt 'minion' state.apply samba.users
minion:
  Name: smbclient - Function: pkg.installed - Result: Clean Started: - 16:11:29.341049 Duration: 24.363 ms
  Name: agent - Function: user.present - Result: Clean Started: - 16:11:29.367723 Duration: 2.51 ms
----------
          ID: agent
    Function: pdbedit.managed
      Result: False
     Comment: State 'pdbedit.managed' was not found in SLS 'samba.users'
              Reason: 'pdbedit' __virtual__ returned False: pdbedit state module can only be loaded when the pdbedit module is available
     Changes:   

Summary for minion
------------
Succeeded: 2
Failed:    1
------------
Total states run:     3
Total run time:  26.873 ms
ERROR: Minions returned with non-zero exit code

Issue #56553 looks very similar, but I get a different error message.
Must I migrate my minions to Debian 10 or will Debian 9 still be supported?

@sjorge
Copy link
Contributor Author

sjorge commented May 7, 2020

4.5 is definitelyprobably to old for having the output format we can parse, however the error is probably because debian seems to tag the version with -Debian at the end. The regex should be updated to account for that at least.

Edit: Was it working on 4.5.x for you before? If so, we could probably lower the version requirement. I wrote pdbedit against 4.8 and I had reports of it being broken on 4.3.x and 4.4.x.

@sjorge
Copy link
Contributor Author

sjorge commented May 7, 2020

I can probably look at fixing the regex and updating the tests to ignore the -Debian tomorrow or saturday.

@sjorge
Copy link
Contributor Author

sjorge commented May 7, 2020

Created a PR to ignore -Debian and accept 4.5.0 as minimal version #57141

@xenadmin
Copy link

xenadmin commented May 7, 2020

I will test that on my master, and update this post later with my findings.

Later:

I changed the following file on a salt-minion 3000.2:
/usr/lib/python3/dist-packages/salt/modules/pdbedit.py
in regards to your PR #57141

root@salt:/srv# salt 'MINION' pdbedit.generate_nt_hash my_passwd
MINION:
    582A7D8A2EA026919589828D03F91F8F
root@salt:/srv# salt 'MINION' state.apply samba.users
MINION:
  Name: smbclient - Function: pkg.installed - Result: Clean Started: - 00:13:37.821146 Duration: 23.863 ms
  Name: agent - Function: user.present - Result: Clean Started: - 00:13:37.846517 Duration: 1.2 ms
  Name: agent - Function: pdbedit.managed - Result: Clean Started: - 00:13:37.848272 Duration: 90.093 ms

Summary for MINION
------------
Succeeded: 3
Failed:    0
------------
Total states run:     3
Total run time: 115.156 ms

So first test looks very promising.

Do you have a suggestion how I get my environment back running? Easiest would be a salt state file.managed that runs before samba.users, which corrects the file, wouldn't it?
I guess it will take some time until this gets part of a salt-minion release.

@sjorge

Was it working on 4.5.x for you before? If so, we could probably lower the version requirement. I wrote pdbedit against 4.8 and I had reports of it being broken on 4.3.x and 4.4.x.

Yes! I'm using Debian 9 with salt-minion 2018/2018 with samba.users since Q3/2019. You can see exactly when I started using it in this PR: saltstack-formulas/samba-formula@c3ca137
This PR was created with salt-minion 2019 and Debian 9 and pdbedit 4.5.

Update:
I created a custom Salt state for my own environment, to deal with that problem in the meantime. Everything applies again a 100% green now. This is just an example, if someone else might encounter that problem.
/srv/salt/salt/MHN_salt_pdbedit.sls

/usr/lib/python3/dist-packages/salt/modules/pdbedit.py:
  file.managed:
    - source: salt://salt/files/pdbedit.py
    - user: root
    - group: root
    - mode: 644
    - require_in:
      - sls: samba.users

dwoz pushed a commit that referenced this issue May 8, 2020
Debian seems to prepend `-Debian` behind the version, we should test those too.
Also lower the requirement to 4.5.0 as apparently that version is new enough according to
#55185 (comment)
@sagetherage sagetherage added the ZRelease-Sodium retired label label May 18, 2020
@sagetherage
Copy link
Contributor

closing as fixed will be released in Sodium

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 Core relates to code central or existential to Salt P4 Priority 4 severity-low 4th level, cosemtic problems, work around exists ZRelease-Sodium retired label
Projects
None yet
Development

No branches or pull requests

4 participants