Forked from blasterpal/add_read_only_pg_user.rb
Last active
September 2, 2017 03:27
-
-
Save YourFriendCaspian/89e6e0985f417143839827c9ca1ec3bc to your computer and use it in GitHub Desktop.
Add read only user to PG 9 on DB, cookbook snippet.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create a user with Login | |
| sql = [%(CREATE ROLE <username> WITH PASSWORD '<password>' LOGIN)] | |
| # # Allow to connect | |
| sql << %(GRANT CONNECT ON DATABASE reports TO <username>) | |
| # # Allow to use schema | |
| sql << %(GRANT USAGE ON SCHEMA public TO <username>) | |
| # # grant on current objects | |
| sql << %(GRANT SELECT ON ALL TABLES IN SCHEMA public TO <username>) | |
| # # grant on future objects | |
| sql << %(ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO <username>) | |
| %x(psql reports postgres -c "#{sql.join(';')}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment