liveBook · Manning

Authorization

As explained in Grokking Relational Database Design

The restriction of data or system operations according to the permissions granted to users or processes.

Access control protects information by deciding who may view, modify, or delete it. In a database, it gives authorized people and processes only the authority they need, helping preserve confidentiality. section 7.4

Choose permissions using one of two main approaches:

  • Mandatory access control (MAC) applies centrally managed, rigid rules. Data receives classifications such as sensitive or confidential, and users need matching clearance; exceptions are not allowed. section 7.4
  • Role-based access control (RBAC) assigns permissions to roles rather than individual users. Users then receive roles such as standard user, analyst, or administrator. section 7.4

RBAC makes database permissions easier to manage. For a sample retail database, a standard user might read products and add purchases or reviews; an analyst might read several tables; an administrator might select, insert, update, and delete across them. The practical sequence is simple: create a role, grant table permissions to it, create a user, and assign the role. MySQL 8.0+ can also enable the assigned role by default. section 7.4

-- comment: works for MySQL and MariaDB
-- comment: consult ChatGPT on adaptations 
-- comment: for other RDBMS
-- step 1: create a role
CREATE ROLE standard_user;
-- step 2: grant permissions to a role
GRANT SELECT ON database_name.product TO standard_user;
GRANT INSERT ON database_name.purchase TO standard_user;
GRANT INSERT ON database_name.purchase_product 
  TO standard_user;
GRANT INSERT ON database_name.review TO standard_user;
-- step 3: assign the role to a new user
CREATE USER 'morpheus'@'%' IDENTIFIED BY 'password';
GRANT standard_user TO 'morpheus'@'%';

Follow the role-based setup as executable SQL: create a standard_user role, grant table-specific permissions, create a user, and assign the role. The listing targets MySQL and MariaDB and notes that other relational database systems may require adaptations. section 7.4

How Grokking Relational Database Design covers it

How deep it goes
Defines MAC and RBAC, then works through role creation, grants, user assignment, and default-role activation.
Examples
Uses a high school records database and a retail database with product, purchase, review, and related tables.
What you can do after
Apply RBAC through SQL by creating roles, granting table permissions, creating users, and assigning roles.
How it connects
Connects confidentiality with encryption, database tables, users, roles, permissions, and relational database systems.

Also explained in

Compare how 28 books explain authorization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Relational Database Design. The section links point to the parts of the book it draws on.