Database access control

On this page 8

Database access control is the combination of authentication, authorization and policy enforcement that determines who may connect to a database, which objects they may see and which operations they may perform on them. It is a central discipline of database security: even a perfectly patched server leaks data if the wrong account can run SELECT on the wrong table.

In databases, access control works at several levels at once, from network connection rules to individual rows and columns. Its guiding rule is the principle of least privilege: every user, role and service account receives only the permissions its task requires, and nothing more.

How database access control decides each request

Database access control evaluates every request in a sequence of gates, and a request must pass all of them. First the server checks whether the client may connect at all, then it verifies identity, and finally it compares the requested operation with the privileges granted to that identity on the specific object.

  1. Connection filtering: host-based rules or a database firewall accept or reject the network source.
  2. Authentication: the server verifies the identity with a password, certificate, Kerberos ticket or external identity provider.
  3. Authorization: the engine checks object privileges such as SELECT, INSERT, UPDATE, DELETE or EXECUTE.
  4. Fine-grained policies: row-level and column-level rules filter or block specific data.
  5. Auditing: the decision and the statement are recorded for later review.

Each layer covers a different weakness. A strong password does not help if the account holds ALL PRIVILEGES, and tight grants do not help if a shared administrator account is used by everyone. Effective control therefore depends on all layers being configured together.

Access control models used in databases

Database engines implement several access control models, and most production systems combine them. SQL standard engines are built on discretionary access control (DAC), in which object owners grant privileges, extended by role-based access control (RBAC) for manageability.

ModelDecision basisTypical database feature
Discretionary (DAC)Owner grants rights to othersGRANT and REVOKE on tables and views
Role-based (RBAC)Permissions attached to roles, roles to usersDatabase roles such as reporting_reader
Attribute-based (ABAC)Attributes of user, data and contextPolicies using session context or labels
Mandatory (MAC)Central security labels and clearancesLabel security in high-assurance systems
Access control models and how databases apply them

RBAC is the practical default because it scales: an administrator manages a few dozen roles rather than thousands of individual grants. ABAC adds flexibility for multi-tenant applications, where the visible rows depend on a tenant identifier carried in the session.

Granularity levels of database permissions

Permissions can be granted at several levels of granularity, from the whole server down to single cells. Finer levels reduce exposure but add administrative complexity and sometimes query overhead.

LevelExample controlMain purpose
Server or instancePermission to create databases or manage loginsSeparate administrators from users
Database or schemaUSAGE on a schema, CONNECT on a databaseIsolate applications and teams
Table or viewSELECT on a reporting view onlyExpose curated data sets
ColumnColumn-level security on salary fieldsHide sensitive attributes
RowRow-level security filtered by tenantSeparate tenants or regions
ProcedureEXECUTE without direct table rightsAllow controlled operations only
Levels at which database access can be restricted

Views and stored procedures are classic tools for indirect access: users receive rights to the view or procedure, not to the underlying tables. Row-level security, available in PostgreSQL, SQL Server and Oracle, enforces filtering inside the engine so that application bugs cannot bypass it.

How access control relates to other security controls

Access control is one layer of database security and is often confused with neighboring controls. The distinction matters because each control fails differently and none replaces the others.

ControlQuestion it answersWhat it does not cover
Access controlWho may do what on which objectData stolen from disks or backups
Database authenticationIs this identity genuineWhat the identity may access
Database encryptionIs stored or transmitted data unreadable to outsidersMisuse by authorized accounts
Dynamic data maskingHow is sensitive output obscuredInference through crafted queries
Database auditWho did what and whenPrevention of the action itself
Access control compared with related database security controls

A typical failure illustrates the point: encryption at rest protects a stolen disk, but an over-privileged application account reads the same data in clear text. Only access control limits what legitimate connections can reach.

Designing access control in practice

A sound design starts from roles that mirror job functions and application components, not from individual people. Privileges are granted to roles, users join roles, and nobody works routinely with the owner or superuser account.

  • Separate accounts per application so that a compromised service exposes only its own data.
  • Remove default public privileges, such as the historical CREATE right on the public schema in older PostgreSQL versions.
  • Grant on views or procedures rather than base tables where business rules apply.
  • Use central identity through directory or single sign-on integration to revoke access promptly when staff leave.
  • Review grants periodically, for example quarterly, and remove privileges that are no longer used.

Applications should also use parameterized queries. SQL injection runs attacker statements with the application’s own privileges, so a narrowly scoped account limits the damage even when the code is vulnerable.

Common weaknesses and how to fix them

Most access control incidents result from configuration drift rather than missing features. Permissions accumulate over years, and nobody remembers why an account holds them.

ProblemRiskFix
Shared administrator loginNo accountability for changesPersonal accounts with role membership
Application runs as ownerInjection gains full controlDedicated least-privilege service role
Privilege creepFormer duties keep live accessScheduled access reviews
Wildcard grantsNew tables become exposed automaticallyExplicit grants and default privilege review
Frequent access control problems

The simple explanation

Think of a database as an office building full of filing cabinets. Access control is the combination of badges, locks and rules that decides who may enter, which rooms they may open and which drawers they may read.

A cleaner can enter the building but not open the payroll cabinet. An accountant can read payroll but not change the locks. Each person gets exactly the keys their job needs, which keeps mistakes and break-ins small.

How it is used in practice

A regional hospital runs its patient records in a relational database used by clinicians, billing staff and an analytics team. Previously, the clinical application connected with one powerful shared account, and analysts queried production tables directly.

The database team introduces separate roles for clinical, billing and analytics access. Clinicians reach full records only through the application role, and row-level security limits each ward to its own patients. Billing staff see diagnosis codes and invoices but not clinical notes, and analysts query a masked reporting schema with pseudonymized identifiers. Grants are reviewed every quarter against the staff directory.

Within the first review, the team revokes more than 40 stale accounts left by former contractors, and an external audit later confirms that every query against patient data can be traced to an individual role.