Глава 19. Настройка прав

В этом руководстве права предоставляются по иерархии: от главного администратора локальным администраторам групп пользователей и аналитикам (обратитесь к диаграмме ниже).

Где:

  • У суперпользователя есть все права.

  • axe_admin — это администратор Postgres Pro AXE.

  • Администраторы A и B — это локальные администраторы групп пользователей, у которых есть доступ к объектам каталога метаданных, связанным с этими группами.

    Права администраторам A и B предоставляет администратор Postgres Pro AXE, и эти администраторы могут предоставлять права аналитикам в каждой группе.

  • Аналитики A, B, C и D — пользователи, которые работают с данными.

Чтобы настроить права:

  1. Создайте роли от имени суперпользователя.

    Например:

      postgres=# SELECT current_user;
      current_user
      --------------
      root
      postgres=# CREATE USER axe_admin;
      postgres=# CREATE USER admin_a;
      postgres=# CREATE USER admin_b;
      postgres=# CREATE USER analyst_a;
      postgres=# CREATE USER analyst_b;
      postgres=# CREATE USER analyst_c;
      postgres=# CREATE USER analyst_d;
  2. Создайте схемы для групп пользователей.

    Например:

      postgres=# SELECT current_user;
      current_user
      --------------
      root
      postgres=# CREATE SCHEMA schema_a;
      postgres=# CREATE SCHEMA schema_b;

    Шаги ниже основаны на группе A со схемой schema_a. Для группы B (со схемой schema_b) выполняются такие же шаги.

  3. Предоставьте ролям axe_admin и admin_a права на схему schema_a.

    Например:

      postgres=# SELECT current_user;
      current_user
      --------------
      root
      postgres=# GRANT ALL ON SCHEMA schema_a TO axe_admin;
      postgres=# GRANT ALL ON SCHEMA schema_a TO admin_a WITH GRANT OPTION;
  4. Предоставьте роли axe_admin права на схему axe и назначьте её администратором Postgres Pro AXE.

    Например:

      postgres=# SELECT current_user;
      current_user
      --------------
      root
      postgres=# GRANT ALL ON SCHEMA axe TO axe_admin;
      postgres=# ALTER SYSTEM SET axe.postgres_role TO 'axe_admin';
  5. Перезапустите сервер.

Теперь администратор Postgres Pro AXE может создать секрет каталога метаданных.

Например:

  postgres=> SELECT current_user;
  current_user
  -----------------
  axe_admin
  postgres=> ALTER SYSTEM SET axe.data_storage_location TO 's3://axe-bucket/';
  postgres=> SELECT axe.create_catalog_secret('localhost', '5433', 'postgres', '', '');

Если в схеме группы A есть таблица-куча и данные из этой таблицы необходимо использовать для аналитических запросов в Postgres Pro AXE:

  1. Администратор Postgres Pro AXE создаёт хранилище и аналитическую таблицу.

    Например:

      postgres=> SELECT current_user;
      current_user
      -----------------
      axe_admin
      postgres=> SELECT axe.create_storage('axe_storage', 'file:///tmp/axe_storage/');
      postgres=> CREATE TABLE schema_a.axe_table USING axe WITH (storage = 'axe_storage')
      AS SELECT * FROM schema_a.pg_table WITH NO DATA;
  2. Администратор Postgres Pro AXE предоставляет право SELECT WITH GRANT OPTION на аналитическую таблицу роли admin_a. Роль admin_a теперь может копировать данные из таблицы-кучи в аналитическую таблицу и предоставлять право другим ролям.

    Например:

      postgres=> SELECT current_user;
      current_user
      -----------------
      axe_admin
      postgres=> GRANT SELECT ON schema_a.axe_table TO admin_a WITH GRANT OPTION;
  3. Теперь роль admin_a предоставляет право роли analyst_a.

    Например:

      postgres=> SELECT current_user;
      current_user
      --------------
      admin_a
      (1 row)
    
      postgres=> GRANT USAGE ON SCHEMA schema_a TO analyst_a;
      postgres=> GRANT SELECT ON schema_a.axe_table TO analyst_a;
  4. В итоге роль analyst_a может выполнять запрос SELECT на аналитическую таблицу.

    Например:

      postgres=> SELECT current_user;
      current_user
      --------------
      analyst_a
      (1 row)
    
      postgres=> SELECT COUNT(*) FROM schema_a.axe_table;
      count
      -------
      50
      (1 row)

Chapter 19. Configuring Privileges

In this guide, privileges are granted based on a hierarchy from the main administrator to local administrators of user groups and analysts (refer to the diagram below).

Where:

  • Superuser has all privileges.

  • axe_admin is the Postgres Pro AXE administrator.

  • Administrators A and B are local administrators of user groups that can access metadata catalog objects associated with these groups.

    Privileges are granted to administrators A and B by the Postgres Pro AXE administrator, and these administrators can grant privileges to analysts within each group.

  • Analysts A, B, C, and D are users that work with the data.

To configure privileges:

  1. Create roles on behalf of the superuser.

    For example:

      postgres=# SELECT current_user;
      current_user
      --------------
      root
      postgres=# CREATE USER axe_admin;
      postgres=# CREATE USER admin_a;
      postgres=# CREATE USER admin_b;
      postgres=# CREATE USER analyst_a;
      postgres=# CREATE USER analyst_b;
      postgres=# CREATE USER analyst_c;
      postgres=# CREATE USER analyst_d;
    
  2. Create schemas for user groups.

    For example:

      postgres=# SELECT current_user;
      current_user
      --------------
      root
      postgres=# CREATE SCHEMA schema_a;
      postgres=# CREATE SCHEMA schema_b;
    

    The steps below are based on group A, whose schema is schema_a. For group B (the schema_b schema), the steps are similar.

  3. Grant privileges on the schema_a schema to axe_admin and admin_a roles.

    For example:

      postgres=# SELECT current_user;
      current_user
      --------------
      root
      postgres=# GRANT ALL ON SCHEMA schema_a TO axe_admin;
      postgres=# GRANT ALL ON SCHEMA schema_a TO admin_a WITH GRANT OPTION;
    
  4. Grant privileges on the axe schema to the axe_admin role and designate this role as the Postgres Pro AXE administrator.

    For example:

      postgres=# SELECT current_user;
      current_user
      --------------
      root
      postgres=# GRANT ALL ON SCHEMA axe TO axe_admin;
      postgres=# ALTER SYSTEM SET axe.postgres_role TO 'axe_admin';
    
  5. Restart the server.

The Postgres Pro AXE administrator can now create a metadata catalog secret.

For example:

  postgres=> SELECT current_user;
  current_user
  -----------------
  axe_admin
  postgres=> ALTER SYSTEM SET axe.data_storage_location TO 's3://axe-bucket/';
  postgres=> SELECT axe.create_catalog_secret('localhost', '5433', 'postgres', '', '');

If group A has a heap table in its schema, and the data from this table must be used in Postgres Pro AXE for analytical queries:

  1. The Postgres Pro AXE administrator creates a storage and analytical table.

    For example:

      postgres=> SELECT current_user;
      current_user
      -----------------
      axe_admin
      postgres=> SELECT axe.create_storage('axe_storage', 'file:///tmp/axe_storage/');
      postgres=> CREATE TABLE schema_a.axe_table USING axe WITH (storage = 'axe_storage')
      AS SELECT * FROM schema_a.pg_table WITH NO DATA;
    
  2. The Postgres Pro AXE administrator grants the SELECT privilege WITH GRANT OPTION on the analytical table to the admin_a role. The admin_a role can now copy the data from the heap table to the analytical table and grant the privilege to other roles.

    For example:

      postgres=> SELECT current_user;
      current_user
      -----------------
      axe_admin
      postgres=> GRANT SELECT ON schema_a.axe_table TO admin_a WITH GRANT OPTION;
    
  3. Now the admin_a role grants the privilege to the analyst_a role.

    For example:

      postgres=> SELECT current_user;
      current_user
      --------------
      admin_a
      (1 row)
    
      postgres=> GRANT USAGE ON SCHEMA schema_a TO analyst_a;
      postgres=> GRANT SELECT ON schema_a.axe_table TO analyst_a;
    
  4. Finally, the analyst_a role can execute the SELECT command on the analytical table.

    For example:

      postgres=> SELECT current_user;
      current_user
      --------------
      analyst_a
      (1 row)
    
      postgres=> SELECT COUNT(*) FROM schema_a.axe_table;
      count
      -------
      50
      (1 row)
    
FAQ