diff --git a/swh/core/db/db_utils.py b/swh/core/db/db_utils.py --- a/swh/core/db/db_utils.py +++ b/swh/core/db/db_utils.py @@ -662,3 +662,12 @@ "Asked for flavor %s, but module does not support database flavors", flavor, ) + + # Grant read-access to guest user on all tables of the schema + with connect_to_conninfo(db_or_conninfo) as db: + if not db: + return None + + with db.cursor() as c: + query = "grant select on all tables in schema public to guest" + c.execute(query) diff --git a/swh/core/db/pytest_plugin.py b/swh/core/db/pytest_plugin.py --- a/swh/core/db/pytest_plugin.py +++ b/swh/core/db/pytest_plugin.py @@ -144,6 +144,13 @@ else: logger.debug("Create %s from scratch", self.dbname) cur.execute(f'CREATE DATABASE "{self.dbname}";') + + try: + cur.execute("CREATE ROLE guest LOGIN PASSWORD 'guest'") + except psycopg2.errors.DuplicateObject: + # We want that role to exist idempotently, if already there fine + pass + if self.dump_files: logger.warning( "Using dump_files on the postgresql_fact fixture " diff --git a/swh/core/db/tests/test_cli.py b/swh/core/db/tests/test_cli.py --- a/swh/core/db/tests/test_cli.py +++ b/swh/core/db/tests/test_cli.py @@ -13,6 +13,7 @@ from swh.core.cli.db import db as swhdb from swh.core.db import BaseDb from swh.core.db.db_utils import import_swhmodule, swh_db_module, swh_db_version +from swh.core.db.pytest_plugin import postgresql_fact from swh.core.tests.test_cli import assert_section_contains @@ -43,6 +44,8 @@ ), ) +postgresql = postgresql_fact("postgresql_proc") + def test_cli_swh_db_help(swhmain, cli_runner): swhmain.add_command(swhdb)