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

postgresql_set: add trust_input parameter #302

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- postgresql_set - add the ``trust_input`` parameter (https://github.com/ansible-collections/community.general/pull/302).
22 changes: 19 additions & 3 deletions plugins/modules/database/postgresql/postgresql_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
type: str
aliases:
- login_db
trust_input:
description:
- If C(no), check whether values of parameters are potentially dangerous.
- It does make sense to use C(yes) only when SQL injections are possible.
type: bool
default: yes
notes:
- Supported version of PostgreSQL is 9.4 and later.
- Pay attention, change setting with 'postmaster' context can return changed is true
Expand Down Expand Up @@ -166,6 +172,9 @@
from copy import deepcopy

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 (
connect_to_db,
get_conn_params,
Expand Down Expand Up @@ -287,15 +296,22 @@ def main():
value=dict(type='str'),
reset=dict(type='bool'),
session_role=dict(type='str'),
trust_input=dict(type='bool', default=True),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)

name = module.params["name"]
value = module.params["value"]
reset = module.params["reset"]
name = module.params['name']
value = module.params['value']
reset = module.params['reset']
session_role = module.params['session_role']
trust_input = module.params['trust_input']

if not trust_input:
# Check input for potentially dangerous elements:
check_input(module, name, value, session_role)

# Allow to pass values like 1mb instead of 1MB, etc:
if value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
<<: *task_parameters
postgresql_set:
<<: *pg_parameters
trust_input: yes
name: archive_command
value: 'test ! -f /mnt/postgres/mb/%f && cp %p /mnt/postgres/mb/%f'

Expand All @@ -302,3 +303,21 @@
- assert:
that:
- result.query_result.0.reset_val == "test ! -f /mnt/postgres/mb/%f && cp %p /mnt/postgres/mb/%f"

#############################
# Check trust_input parameter
- name: postgresql_set - check trust_input
<<: *task_parameters
postgresql_set:
<<: *pg_parameters
name: shared_buffers
value: 111MB
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')