Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
postgresql: Cleaning up Read Only User docs
Browse files Browse the repository at this point in the history
Per the comments on the PR, I am fixing these docs to be more
presentable.
  • Loading branch information
richard-joerger-aiven committed Nov 8, 2023
1 parent 6fdc98d commit f2962d3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/products/postgresql/howto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Aiven for PostgreSQL® how-tos
- :doc:`Prevent PostgreSQL® full disk issues </docs/products/postgresql/howto/prevent-full-disk>`
- :doc:`Enable and use pgvector on Aiven for PostgreSQL® </docs/products/postgresql/howto/use-pgvector>`
- :doc:`Check size of a database, a table or an index </docs/products/postgresql/howto/pg-object-size>`
- :doc:`Add Read Only User </docs/products/postgresql/howto/readonly-user>`
- :doc:`Restrict access to databases or tables in Aiven for PostgreSQL®". </docs/products/postgresql/howto/readonly-user>`

.. dropdown:: Migration

Expand Down
6 changes: 5 additions & 1 deletion docs/products/postgresql/howto/list-dba-tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Database administration tasks
:shadow: md
:margin: 2 2 0 0

.. grid-item-card:: :doc:`Use the PostgreSQL® pg_repack extension </docs/products/postgresql/howto/use-pg-repack-extension>`
.. grid-item-card:: :doc:`Use the PostgreSQL® pg_repack extension </docs/productspostgresql/howto/use-pg-repack-extension>`
:shadow: md
:margin: 2 2 0 0

Expand Down Expand Up @@ -72,5 +72,9 @@ Database administration tasks
:margin: 2 2 0 0

.. grid-item-card:: :doc:`Check size of a database, a table or an index </docs/products/postgresql/howto/pg-object-size>`
:shadow: md
:margin: 2 2 0 0

.. grid-item-card:: :doc:`Restrict access to databases or tables in Aiven for PostgreSQL®". </docs/products/postgresql/howto/readonly-user>`
:shadow: md
:margin: 2 2 0 0
28 changes: 19 additions & 9 deletions docs/products/postgresql/howto/readonly-user.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
Read Only User for PostgreSQL
=============================
In the interest of having users with the least permissions to complete their tasks, one may need a user with read only access to the whole database or a handful of tables. In some cases, we may want this to happen automatically, below are two approaches to complete this task.
Restrict access to databases or tables in Aiven for PostgreSQL®
===============================================================
This article shows how you can restrict access to Aiven for PostgreSQL® databases and tables by setting up read-only permissions for specific user's roles.

All new objects shall have a role with read-only permissions
------------------------------------------------------------
1. Alter the default permissions for the role for the given schema: ``ALTER DEFAULT PRIVILEGES FOR ROLE <target role> IN SCHEMA <schema name> abbreviated_grant_or_revoke``
Set read-only access in a schema
--------------------------------
1. Modify default permissions for a user's role in a particular schema.

2. To update any existing database objects, run the following: ``GRANT SELECT ON ALL TABLES IN SCHEMA <schema name> to <myreadonlyrole>;``
.. code-block:: bash
ALTER DEFAULT PRIVILEGES FOR ROLE NAME_OF_ROLE IN SCHEMA NAME_OF_SCHEMA abbreviated_grant_or_revoke
2. Apply the new read-only access setting to your existing database objects that uses the affected schema.

.. code-block:: bash
GRANT SELECT ON ALL TABLES IN SCHEMA NAME_OF_SCHEMA to NAME_OF_READ_ONLY_ROLE
Set read-only access in a database
----------------------------------
You can set up the read-only access for a specific user's role in a particular database.

Only certain databases should be read-only for users in a particular role:
==========================================================================
1. Create a new database which will be used as a template ``CREATE DATABASE ro_<name>_template...``
2. Update the standardizable information of the database

Check failure on line 24 in docs/products/postgresql/howto/readonly-user.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/products/postgresql/howto/readonly-user.rst#L24

[Aiven.aiven_spelling] 'standardizable' does not seem to be a recognised word
Raw output
{"message": "[Aiven.aiven_spelling] 'standardizable' does not seem to be a recognised word", "location": {"path": "docs/products/postgresql/howto/readonly-user.rst", "range": {"start": {"line": 24, "column": 15}}}, "severity": "ERROR"}
3. When creating a new database, use ``CREATE DATABASE <name> WITH TEMPLATE = 'ro_<name>_template'``

0 comments on commit f2962d3

Please sign in to comment.