Skip to content

Properly quote role name in default_privileges type#1666

Open
antaflos wants to merge 1 commit intopuppetlabs:mainfrom
antaflos:fix_default_privileges_quoting
Open

Properly quote role name in default_privileges type#1666
antaflos wants to merge 1 commit intopuppetlabs:mainfrom
antaflos:fix_default_privileges_quoting

Conversation

@antaflos
Copy link
Copy Markdown
Contributor

Summary

Like in many other places in this module we need to ensure that user-supplied identifiers, such as role names, database names, etc. are quoted in SQL queries, because they may contain characters such as the hyphen that the SQL standard considers illegal unless the identifier is surrounded by double quotes.

The unless clause in the default_privileges defined type constructs an SQL query to check if the ALTER DEFAULT PRIVILEGES grant is already applied, but this SQL query does not quote the role name. This leads to server-side errors when trying to run the query if the role name contains a character like the hyphen. In this example the role name is monitoring-user:

Could not evaluate: Error evaluating 'unless' clause, returned pid 891642 exit 1: 'ERROR:  unrecognized key word: "monitoring"
LINE 1: ...amespace AS n ON da.defaclnamespace = n.oid WHERE 'monitori...
                                                             ^
HINT:  ACL key word must be "group" or "user".
'

This change fixes the SQL query for the unless clause and contains updated spec tests.

Fixes #1665

Additional Context

  • Root cause and the steps to reproduce. (If applicable)
  • Thought process behind the implementation.

Related Issues (if any)

#1665

Checklist

  • 🟢 Spec tests.
  • 🟢 Acceptance tests.
  • Manually verified. (For example puppet apply)

Like in many other places in this module we need to ensure that
user-supplied identifiers, such as role names, database names, etc. are
quoted in SQL queries, because they may contain characters such as the
hyphen that the SQL standard considers illegal unless the identifier is
surrounded by double quotes.

The `unless` clause in the default_privileges defined type constructs an
SQL query to check if the ALTER DEFAULT PRIVILEGES grant is already
applied, but this SQL query does not quote the role name. This leads to
server-side errors when trying to run the query if the role name
contains a character like the hyphen. In this example the role name is
`monitoring-user`:

    Could not evaluate: Error evaluating 'unless' clause, returned pid 891642 exit 1: 'ERROR:  unrecognized key word: "monitoring"
    LINE 1: ...amespace AS n ON da.defaclnamespace = n.oid WHERE 'monitori...
                                                                 ^
    HINT:  ACL key word must be "group" or "user".
    '

This change fixes the SQL query for the `unless` clause and contains
updated spec tests.

Fixes puppetlabs#1665
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

postgresql::server::default_privileges does not quote role name correctly, leading to faulty SQL query in the "unless" clause

1 participant