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

Make granting on ALL TABLES IN SCHEMA idempotent #564

Merged
merged 1 commit into from
Mar 12, 2015

Conversation

antaflos
Copy link
Contributor

Define a proper SELECT statement to feed into Postgresql_psql's
unless parameter that checks if there are any tables in the specified
schema for which the specified role does not have the specified
privilege. Only then allow the GRANT statement to be executed. For
details see comments.

Note that this, too, suffers from the problem that there is no feasible
way to check if a role has ALL PRIVILEGES on a table in plain SQL. By
terrible convention the INSERT privilege represents ALL PRIVILEGES here.

@antaflos
Copy link
Contributor Author

Since I am obviously no DBA that can perform powerful magic with SQL the SELECT statement I devised may not be optimal. But it certainly is better than having the GRANT statement executed on every single Puppet run, which is the current situation.

@antaflos
Copy link
Contributor Author

The failed Travis checks say things like:

Undefined variable "::is_pe"; Undefined variable "is_pe" at

I don't think this has anything to do with my changes here.

default => "SELECT 1 WHERE ${unless_function}('${role}',
false => undef,
'custom' => $custom_unless,
default => "SELECT 1 WHERE ${unless_function}('${role}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this end up being

select 1 where select 1 from ( select

is that correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The is_pe bit is caused by recent changes in puppetlabs-concat. The fix is at puppetlabs/puppetlabs-concat#270

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igalic, $custom_unless contains the SQL query that is passed to Postgresql_psql (via $_unless). It will be executed as is by Postgresql_psql, just like the SQL query constructed in the default case here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack ack ack, didn't see $custom_privilege variable name, and thought it was assigned to $_unless as $unless_function

@antaflos
Copy link
Contributor Author

FWIW, we have this change deployed in our production environments and it works fine.

@antaflos
Copy link
Contributor Author

antaflos commented Mar 3, 2015

@cmurphy I am being forward and pinging you so that this PR possibly gets some attention :)

Define a proper SELECT statement to feed into Postgresql_psql's
`unless` parameter that checks if there are any tables in the specified
schema for which the specified role *does not* have the specified
privilege. Only then allow the GRANT statement to be executed. For
details see comments.

Note that this, too, suffers from the problem that there is no feasible
way to check if a role has ALL PRIVILEGES on a table in plain SQL. By
terrible convention the INSERT privilege represents ALL PRIVILEGES here.
@antaflos antaflos force-pushed the idempotency_for_grant_all_tables branch from 4c9eed8 to dbbb7aa Compare March 5, 2015 16:19
@igalic
Copy link
Contributor

igalic commented Mar 11, 2015

@tphoney pinging you also!

hunner added a commit that referenced this pull request Mar 12, 2015
Make granting on ALL TABLES IN SCHEMA idempotent
@hunner hunner merged commit 9e9aa9d into puppetlabs:master Mar 12, 2015
@raphink
Copy link
Contributor

raphink commented Mar 12, 2015

Great, thanks!
On 12 Mar 2015 18:28, "Hunter Haugen" notifications@github.com wrote:

Merged #564 #564
.


Reply to this email directly or view it on GitHub
#564 (comment)
.

cegeka-jenkins pushed a commit to cegeka/puppet-postgresql that referenced this pull request Oct 23, 2017
…_all_tables

Make granting on ALL TABLES IN SCHEMA idempotent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants