16. Access control: RBAC, ABAC, row and column security, masking
Access control decides who may do what with which data. Roles group permissions (RBAC); attributes of the person, the data and the situation decide case by case (ABAC). Row and column security and masking apply the decision inside a table, and least privilege and separation of duties keep any one person from holding too much.
The clip sends one query, every customer with name, email and birth date, to the database as four different people. The claims handler sees every column for the customers of the region she works in. The analyst sees the rows of the country set for her session, with the name as an initial and the birth date as a year. The auditor sees counts but no personal columns. The platform engineer runs the database and sees no customer rows at all. Then the clip shows why: roles carry permissions, attributes of the session and the row decide which rows, column grants decide which columns, and a masked view decides which form a value takes.
The intuition: the same question, four answers
At Harbour Mutual, four people type the same query: show me the customers, with their names, emails and birth dates. A claims handler in the Dutch team needs all of it, for her own customers, to call them about their claims. An analyst studying claims by age needs the age, not the name. An internal auditor needs to know how many customers there are, not who they are. The engineer who runs the database needs to keep it running, and nothing in it.
A single yes or no on the table cannot serve all four. The answer has to depend on who is asking, which rows they ask for, which columns, and in what form. That is what access control is: a decision, made for every request, about who may do what with which data, and the means to enforce it inside the data platform.
The theory: models, granularity and principles
Every access decision has a subject (who asks: a person or a service), an action (read, write, delete, share), a resource (a table, a row, a column) and a context (time, place, purpose). A policy says which combinations are allowed. The models differ in how they write the policy.
In role-based access control (RBAC), standardised by NIST, permissions are granted to roles (claims handler, analyst) and people are made members of roles. Changing a job means changing a membership, not a list of grants. The NIST model adds role hierarchies (a senior handler inherits the handler's permissions) and constraints such as mutually exclusive roles. Its weakness: every new combination of conditions ("handlers, but only for their region") tempts a new role, and roles multiply.
In attribute-based access control (ABAC), described in NIST SP 800-162, a policy is a rule over attributes: of the subject (department, country, clearance), of the resource (classification, owning domain, region), of the action, and of the environment (time, device). "A handler may read a claim if the claim's region is the handler's region" is one rule, not one role per region. ABAC is more expressive and harder to audit: to know who can see a row, you must evaluate the rules.
Granularity goes below the table. Row-level security filters the rows a subject sees by a predicate (the region, the country, the owning broker). Column-level security grants or withholds columns. Masking shows a value in a reduced form: an initial instead of a name, a year instead of a birth date, the last four digits of an account. Static masking writes a masked copy; dynamic masking masks at query time, by role. Masking reduces what a value reveals; it is not encryption, and a masked column can still be re-identified when combined with others.
CREATE ROLE theory_analyst NOLOGIN;
GRANT SELECT (customer_id, region_id, customer_since) ON customers TO theory_analyst;
GRANT SELECT ON regions TO theory_analyst;
ALTER TABLE customers ENABLE ROW LEVEL SECURITY;
CREATE POLICY customers_by_country ON customers FOR SELECT TO theory_analyst
USING (region_id IN (SELECT region_id FROM regions WHERE country = current_setting('app.country')));
CREATE VIEW customers_masked AS
SELECT c.customer_id, LEFT(c.name, 1) || '.' AS name, EXTRACT(YEAR FROM c.birth_date)::int AS birth_year
FROM customers c
JOIN regions r ON r.region_id = c.region_id
WHERE r.country = current_setting('app.country');
GRANT SELECT ON customers_masked TO theory_analyst;
SET ROLE theory_analyst;
SET app.country = 'NL';
SELECT COUNT(*) FROM customers; -- only the rows of the country set for the session
SELECT email FROM customers; -- refused: no grant on the column
SELECT * FROM customers_masked ORDER BY customer_id LIMIT 3; -- an initial and a year
RESET ROLE;Run as the analyst with the session's country set to NL, the query sees 11 of the 40 customers; asking for the email is refused, because the role has no grant on that column; and the masked view shows an initial and a year of birth. The policy is written once and enforced by the database for every tool that connects.
Access decisions should be enforced where the data is (the database, the lakehouse's catalogue, the search index of page 33), not only in the application in front of it, because data is reached by many tools. And every grant needs a reason, an owner who approved it (page 15) and a review date; access that nobody reviews only grows.
Why it matters
After the merger, Kestrel's staff will join Harbour Mutual's platform. Role by role and attribute by attribute, the access design decides whether a Kestrel claims handler can see Kestrel's customers on day one, and nothing more. Chapter 42 builds exactly that, and chapter 44 extends it to an AI assistant's search index.
A clear model also makes the reviews possible: listing who can see special-category data is a query over roles and policies, not a month of interviews.
Where it goes wrong
- Role explosion. One role per region, per product, per team, until nobody knows what a role means; move the conditions to attributes.
- Security in the application only. A report tool or a notebook connecting directly bypasses it.
- Masking mistaken for anonymisation. An initial, a birth year and a postcode together can name a person.
- Access that only grows. People change jobs and keep their grants; without reviews, least privilege decays.
- Shared accounts. When five people use one login, nobody can say who read what.
Check yourself
Choose an answer to each question, then press Check.
Sources
The works this page draws on, summarised in its own words rather than quoted. Read them for the full argument.
- D. F. Ferraiolo, R. Sandhu, S. Gavrila, D. R. Kuhn and R. Chandramouli, "Proposed NIST Standard for Role-Based Access Control", ACM Transactions on Information and System Security 4(3), 2001Core RBAC, role hierarchies and constraints such as separation of duties.
- V. C. Hu et al., NIST Special Publication 800-162, Guide to Attribute Based Access Control (ABAC) Definition and Considerations (2014)Subject, resource, action and environment attributes, and policies as rules over them.
- J. H. Saltzer and M. D. Schroeder, "The Protection of Information in Computer Systems", Proceedings of the IEEE 63(9), 1975Least privilege, separation of privilege and the other design principles of protection.
- PostgreSQL 18 documentation: Privileges, and Row Security PoliciesColumn privileges, CREATE POLICY and how row security applies to roles.
Practise it
The chapters that put this theory to work on Harbour Mutual and Kestrel:
- Chapter 22: Classification, privacy and security controls
- Chapter 42: Stage 5: Who owns what
- Chapter 44: Stage 7: AI pilot under pressure
The tools to try it in:
- Retrieval workbench · Chunk and index Harbour Mutual's documents with their access rights, and ask questions as different roles.
Terms taught here: MaskingRow-level securityRole-based access controlAttribute-based access controlLeast privilege