salt icon indicating copy to clipboard operation
salt copied to clipboard

[BUG] salt.modules.postgres fails to modify privileges with PostgreSQL 17

Open jdelic opened this issue 1 year ago • 0 comments

Description PostgreSQL 17 adds the MAINTAIN privilege which breaks states that modify database privileges.

For example, this state

mailforwarder-read-privileges-emailalias:
    postgres_privileges.present:
        - name: {{pillar['mailforwarder']['dbuser']}}
        - object_name: mailauth_emailalias
        - object_type: table
        - privileges:
            - SELECT
        - user: postgres
        - maintenance_db: {{pillar['authserver']['dbname']}}

Leads to the following error when executed with PostgreSQL 17:

          ID: mailforwarder-read-privileges-emailalias
    Function: postgres_privileges.present
        Name: mailforwarder
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/state.py", line 2428, in call
                  ret = self.states[cdata["full"]](
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 160, in __call__
                  ret = self.loader.run(run_func, *args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1269, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1284, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1317, in wrapper
                  return f(*args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/postgres_privileges.py", line 184,
in present
                  if not __salt__["postgres.has_privileges"](
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 160, in __call__
                  ret = self.loader.run(run_func, *args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1269, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1284, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/postgres.py", line 3260, in has_pr
ivileges
                  _validate_privileges(object_type, _privs, privileges)
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/postgres.py", line 3023, in _valid
ate_privileges
                  _perms = [_PRIVILEGES_MAP[perm] for perm in _PRIVILEGE_TYPE_MAP[object_type]]
                File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/postgres.py", line 3023, in <listc
omp>
                  _perms = [_PRIVILEGES_MAP[perm] for perm in _PRIVILEGE_TYPE_MAP[object_type]]
              KeyError: 'm'
     Started: 20:19:22.278137
    Duration: 2.41 ms
     Changes:

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
          Salt: 3007.1
 
Python Version:
        Python: 3.10.14 (main, Apr  3 2024, 21:30:09) [GCC 11.2.0]
 
Dependency Versions:
          cffi: 1.16.0
      cherrypy: unknown
      dateutil: 2.8.2
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.4
       libgit2: Not Installed
  looseversion: 1.3.0
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.7
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 23.1
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: Not Installed
  python-gnupg: 0.5.2
        PyYAML: 6.0.1
         PyZMQ: 25.1.2
        relenv: 0.16.0
         smmap: Not Installed
       timelib: 0.3.0
       Tornado: 6.3.3
           ZMQ: 4.3.4
 
Salt Package Information:
  Package Type: onedir
 
System Versions:
          dist: debian 12.7 bookworm
        locale: utf-8
       machine: x86_64
       release: 6.1.0-26-amd64
        system: Linux
       version: Debian GNU/Linux 12.7 bookworm

jdelic avatar Oct 11 '24 20:10 jdelic