Hierarchical access control

Creating PostgreSQL Databases

Darryl Reeves

Industry Assistant Professor, New York University

Access control with schemas

  • Schema - named container for db objects
  • Schemas can be used for access control
Creating PostgreSQL Databases

Example: schema use in finances database

  • Spouse access to finances database
  • public schema used by default
  • Two new schemas: me and spouse
CREATE SCHEMA me;
CREATE SCHEMA spouse;
CREATE TABLE me.account (...);
CREATE TABLE spouse.account (...);
Creating PostgreSQL Databases

Granting schema privileges

CREATE USER better_half WITH PASSWORD 'changeme';
GRANT USAGE ON SCHEMA spouse TO better_half;
GRANT USAGE ON SCHEMA public TO better_half;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA spouse;

TO better_half;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public

TO better_half;

Schema-based access control implemented

Creating PostgreSQL Databases

Using groups

  • Group - a type of role that identifies one or more users
  • Access control can be applied at group level
CREATE GROUP family;
GRANT USAGE ON SCHEMA public TO family;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA

public TO family;
ALTER GROUP family ADD USER fin
ALTER GROUP family ADD USER better_half;
Creating PostgreSQL Databases

Shared and individual data access

  • Shared schema access enabled to public schema
  • Individual schemas control data access
Creating PostgreSQL Databases

Let's practice!

Creating PostgreSQL Databases

Preparing Video For Download...