salt icon indicating copy to clipboard operation
salt copied to clipboard

State ssh_auth.absent does not work with source file

Open deyanx opened this issue 3 years ago • 4 comments

Description of Issue

State ssh_auth.absent does not work with source file

SLS file example

xxxxxxx:
  ssh_auth.absent:
    - user: xxxxxxx
    - source: salt://sudo/files/xxxxxxx.rsa.pub-remove

If I do ssh_auth.absent state for the same key with -name and -enc parameters, without -source file it works properly. Same source file was used to add this key before with ssh_auth.present function which confirms that file is in correct authorized_keys format.

Reported error

          ID: xxxxxxx
    Function: ssh_auth.absent
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3.6/site-packages/salt/state.py", line 2277, in call
                  *cdata["args"], **cdata["kwargs"]
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
                  return callable(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1276, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/states/ssh_auth.py", line 464, in absent
                  key = key.rstrip().split("\n")
              AttributeError: 'bool' object has no attribute 'rstrip'
     Started: 14:21:05.560949
    Duration: 17.931 ms
     Changes:

Versions Report

Salt Version:
          Salt: 3005.1

Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: 2.6.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.10.1
       libgit2: Not Installed
      M2Crypto: 0.35.2
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: Not Installed
        pygit2: Not Installed
        Python: 3.6.8 (default, Nov  9 2022, 09:57:34)
  python-gnupg: Not Installed
        PyYAML: 3.12
         PyZMQ: 20.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: almalinux 8.7 Stone Smilodon
        locale: UTF-8
       machine: x86_64
       release: 4.18.0-348.20.1.el8_5.x86_64
        system: Linux
       version: AlmaLinux 8.7 Stone Smilodon

deyanx avatar Jan 08 '23 14:01 deyanx

IMO the source argument should just be removed, as it makes no sense to provide it to absent. It looks like someone just copy-pasted the arguments from present.

OrangeDog avatar Jan 09 '23 09:01 OrangeDog

No, I believe it should also work with source file, as in my example, but it have a bug. It completely make sense to me. If key can be added from file we should be able to also remove it with same source file.

deyanx avatar Jan 09 '23 09:01 deyanx

I guess yes, if the target file has more keys, and the source file lists only the ones to remove.

OrangeDog avatar Jan 09 '23 10:01 OrangeDog

Fixed by #68405 (commit efa62a6892a), merged into 3006.x on 2025-11-22 and merged forward through 3007.x, 3008.x, and master. The absent path no longer calls cp.get_file_str; it uses cp.get_url for existence and delegates to ssh.rm_auth_key_from_file, so the 'bool' object has no attribute 'rstrip' traceback is no longer reachable. Closing.

dwoz avatar Jul 01 '26 23:07 dwoz