mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
postgresql_ping: add session_role and trust_input parameters (#312)
* postgresql_ping: add session_role and trust_input parameters * add changelog fragment
This commit is contained in:
parent
fce150fcf7
commit
31085fffb7
3 changed files with 42 additions and 0 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
minor_changes:
|
||||||
|
- postgresql_ping - add the ``trust_input`` parameter (https://github.com/ansible-collections/community.general/pull/312).
|
||||||
|
- postgresql_ping - add the ``session_role`` parameter (https://github.com/ansible-collections/community.general/pull/312).
|
|
@ -26,6 +26,19 @@ options:
|
||||||
type: str
|
type: str
|
||||||
aliases:
|
aliases:
|
||||||
- login_db
|
- login_db
|
||||||
|
session_role:
|
||||||
|
description:
|
||||||
|
- Switch to session_role after connecting. The specified session_role must
|
||||||
|
be a role that the current login_user is a member of.
|
||||||
|
- Permissions checking for SQL commands is carried out as though
|
||||||
|
the session_role were the one that had logged in originally.
|
||||||
|
type: str
|
||||||
|
trust_input:
|
||||||
|
description:
|
||||||
|
- If C(no), check whether a value of I(session_role) is potentially dangerous.
|
||||||
|
- It does make sense to use C(yes) only when SQL injections via I(session_role) are possible.
|
||||||
|
type: bool
|
||||||
|
default: yes
|
||||||
seealso:
|
seealso:
|
||||||
- module: postgresql_info
|
- module: postgresql_info
|
||||||
author:
|
author:
|
||||||
|
@ -72,6 +85,9 @@ except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible_collections.community.general.plugins.module_utils.database import (
|
||||||
|
check_input,
|
||||||
|
)
|
||||||
from ansible_collections.community.general.plugins.module_utils.postgres import (
|
from ansible_collections.community.general.plugins.module_utils.postgres import (
|
||||||
connect_to_db,
|
connect_to_db,
|
||||||
exec_sql,
|
exec_sql,
|
||||||
|
@ -117,12 +133,18 @@ def main():
|
||||||
argument_spec = postgres_common_argument_spec()
|
argument_spec = postgres_common_argument_spec()
|
||||||
argument_spec.update(
|
argument_spec.update(
|
||||||
db=dict(type='str', aliases=['login_db']),
|
db=dict(type='str', aliases=['login_db']),
|
||||||
|
session_role=dict(type='str'),
|
||||||
|
trust_input=dict(type='bool', default=True),
|
||||||
)
|
)
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not module.params['trust_input']:
|
||||||
|
# Check input for potentially dangerous elements:
|
||||||
|
check_input(module, module.params['session_role'])
|
||||||
|
|
||||||
# Set some default values:
|
# Set some default values:
|
||||||
cursor = False
|
cursor = False
|
||||||
db_connection = False
|
db_connection = False
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
login_port: 5432
|
login_port: 5432
|
||||||
ssl_mode: require
|
ssl_mode: require
|
||||||
ca_cert: '{{ ssl_rootcert }}'
|
ca_cert: '{{ ssl_rootcert }}'
|
||||||
|
trust_input: yes
|
||||||
register: result
|
register: result
|
||||||
when:
|
when:
|
||||||
- ansible_os_family == 'Debian'
|
- ansible_os_family == 'Debian'
|
||||||
|
@ -56,3 +57,19 @@
|
||||||
when:
|
when:
|
||||||
- ansible_os_family == 'Debian'
|
- ansible_os_family == 'Debian'
|
||||||
- postgres_version_resp.stdout is version('9.4', '>=')
|
- postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
|
- name: postgresql_ping - check trust_input
|
||||||
|
become_user: "{{ pg_user }}"
|
||||||
|
become: yes
|
||||||
|
postgresql_ping:
|
||||||
|
db: "{{ db_default }}"
|
||||||
|
login_user: "{{ pg_user }}"
|
||||||
|
trust_input: no
|
||||||
|
session_role: 'curious.anonymous"; SELECT * FROM information_schema.tables; --'
|
||||||
|
register: result
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- result is failed
|
||||||
|
- result.msg is search('is potentially dangerous')
|
||||||
|
|
Loading…
Reference in a new issue