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

Support "ALL TABLES" in postgresql_user_privileges #341

Open
JeanDaniel-Fischer opened this issue Apr 16, 2018 · 8 comments
Open

Support "ALL TABLES" in postgresql_user_privileges #341

JeanDaniel-Fischer opened this issue Apr 16, 2018 · 8 comments
Labels

Comments

@JeanDaniel-Fischer
Copy link

Hi,

I am trying to create an account with only CONNECT grant on a specific database and SELECT grand on all tables.

PostgreSQL documentation says "ALL TABLES" can be used (https://www.postgresql.org/docs/9.1/static/sql-grant.html) but I can't manage to use it. The following failed with:

relation "ALL TABLES" does not exist

    postgresql_user_privileges:
      - name: myaccount_ro
        db: mydb
        priv: "CONNECT/ALL TABLES:SELECT"
@aoyawale
Copy link
Contributor

what version of ansible are you using?

@gclough
Copy link
Collaborator

gclough commented Apr 17, 2018

This appears to be a limitation of the core postgresql_user Ansible module:

https://docs.ansible.com/ansible/latest/modules/postgresql_user_module.html

We literally pass the list of privileges in postgresql_user_privileges into postgresql_user:

- name: PostgreSQL | Update the user privileges
  postgresql_user:
    name: "{{item.name}}"
    db: "{{item.db | default(omit)}}"
    port: "{{postgresql_port}}"
    priv: "{{item.priv | default(omit)}}"
    state: present
    login_host: "{{item.host | default(omit)}}"
    login_user: "{{postgresql_admin_user}}"
    role_attr_flags: "{{item.role_attr_flags | default(omit)}}"
  become: yes
  become_user: "{{postgresql_admin_user}}"
  with_items: "{{postgresql_user_privileges}}"
  when: postgresql_users|length > 0

I'd agree that the documentation for the Ansible module is quite thin, but I think this is a generic problem. I'll have to dig in the ansible code a bit to be sure...

@JeanDaniel-Fischer
Copy link
Author

I am using ansible 2.3.1.0.

Should I submit the issue directly to the core module ?

@aoyawale
Copy link
Contributor

first try with ansible 2.4 since that is the minimum with this role then if not then I suggest you get on IRC and ask.

@alexanderkgonzalez
Copy link

Hey @JeanDaniel-Fischer , did you make any progress with this? Having a similar issue.

@n1ngu
Copy link

n1ngu commented Feb 24, 2020

Indeed, this https://docs.ansible.com/ansible/latest/modules/postgresql_privs_module.html is the module that implements this feature

@n1ngu
Copy link

n1ngu commented Feb 26, 2020

FWIW, we extended the anxs.postgresql role with an aditional task that implements this:

- name: PostgreSQL | Update privileges
  postgresql_privs:
    db: "{{item.db}}"
    objs: "{{item.objs | default(omit)}}"
    privs: "{{item.privs | default(omit)}}"
    roles: "{{item.roles}}"
    schema: "{{item.schema | default(omit)}}"  # defaults to 'public
    state: present
    type: "{{item.type | default(omit)}}"  # defaults to 'table'
    login_host: "{{item.host | default(omit)}}"
    login_port: "{{postgresql_port}}"
    login_user: "{{postgresql_admin_user}}"
  become: yes
  become_user: "{{postgresql_admin_user}}"
  with_items: "{{postgresql_privileges}}"
  when: postgresql_privileges|length > 0

Then make the postgresql_privileges variable available to your inventory

postgresql_privileges:
  - {roles: 'readonly', db: 'mydatabase', privs: 'SELECT', objs: 'ALL_IN_SCHEMA'}

I believe a final solution would look like this, I hope it helps both the maintainers and users missing this feature

Copy link

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

@github-actions github-actions bot added the stale label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants