Skip to content

postgresql_server: any entry in postgresql_server__privs__*_var aborts the run #379

Description

@NavidSassan

Bug description

postgresql_server__privs__host_var / __group_var cannot be used: as soon as it contains one entry, the run aborts while the role evaluates postgresql_server__privs__combined_var.

defaults/main.yml merges the privileges with combine_lod(unique_key="objs"), but objs is a list, as the role README documents it. combine_lod uses the value of the unique key as a dictionary key, and a list cannot be one:

TypeError: cannot use 'list' as a dict key (unhashable type: 'list')

Even with a hashable key, objs alone would not identify an entry: two grants on the same database to different roles would be merged into one.

Steps to reproduce

Run linuxfabrik.lfops.postgresql_server with the example from the role README:

postgresql_server__privs__host_var:
  - privs:
      - 'CONNECT'
    type: 'database'
    objs:
      - 'database1'
    roles:
      - 'user1'
    state: 'present'

The filter can also be called directly:

combine_lod([{'objs': ['database1'], 'roles': ['user1'], 'privs': ['CONNECT']}], unique_key='objs')

Expected behavior

The privileges are granted, and an entry can be overridden or revoked from the inventory like in the other combined variables.

Environment

LFOps main (c5ef30c), all platforms; the error is raised on the controller.

Additional context

Since no inventory can use the variable today, changing its format breaks nothing that works. Possible fixes:

  • Take objs and roles as comma-separated strings, as community.postgresql.postgresql_privs does, and merge on type, objs and roles. type then has to be mandatory, because combine_lod requires every key to be set.
  • Let combine_lod turn list values of a unique key into tuples, keep the documented list format and merge on type, objs and roles. This touches the plugin and its unit tests, and the order inside the lists becomes part of the identity.
  • Add a mandatory name subkey as the identity. Simplest, but the name means nothing to PostgreSQL.

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions