Database Basics

A database management system (DBMS) stores and manages data. A relational database keeps data in tables of rows (records) and columns (fields); tables are linked by keys, and queries are written in SQL. Because a database holds an organisation's most valuable data in one place, it is a prime target.

Database Access Control

Access control decides who may do what to which data.

  • Authentication of users, then authorisation by privileges.
  • Discretionary access control (DAC): the owner grants rights with GRANT and removes them with REVOKE, for example GRANT SELECT ON emp TO clerk.
  • Role-based access control (RBAC): rights are given to roles (clerk, manager) and users get roles.
  • Mandatory access control (MAC): the system enforces labels such as Secret and Public, and users have clearances.
  • Views show only some columns or rows, so a user sees a safe part of a table.
  • Least privilege, auditing of access and separation of duties on administrators.

The Inference Problem

Inference is deducing sensitive data from non-sensitive results. Even when the user may not read individual salaries, answers to statistical queries (sum, count, average) can reveal them.

  • Direct attack: a query that is narrow enough to identify one person.
  • Indirect attack (tracker): combining aggregate queries, for example the sum of all salaries minus the sum of all salaries except one person's gives that person's salary.
  • Aggregation: combining individually harmless data gives a sensitive fact.

Defences: query-set-size restriction (refuse queries about fewer than k records), adding small random noise or rounding results (as in differential privacy), limiting the number of queries, partitioning data, and auditing queries.

Definition: Inference. Deducing sensitive information from data or query results that are individually allowed, for example by combining aggregate statistics about overlapping groups of records.

Table 2.4: Access control models

Model Who decides Example
DAC The data owner GRANT SELECT ON emp TO clerk
RBAC Roles set by administrators Role manager can update salary
MAC System labels and clearances Only Secret-cleared users read Secret rows
View-based Defined view limits columns Clerk sees name but not salary

Example 2.4: An inference attack using two sums

Problem: A user may query only totals (SUM) of salaries, not individual values. Salaries (in thousands) are Asha 80, Bina 95, Chand 120, Dev 115 and Ravi 90. The user asks for the total of all, and the total of everyone except Ravi. Find Ravi's salary. How would a query-set-size rule help?

Solution:

  1. Total of all = 80 + 95 + 120 + 115 + 90 = 500.
  2. Total except Ravi = 80 + 95 + 120 + 115 = 410.
  3. Ravi's salary = 500 − 410 = 90 thousand.
  4. A rule that rejects any query whose query set differs from another by a single record (or any set smaller than k) would stop the second query.

Result: The two allowed totals reveal Ravi's salary of 90 thousand; controls must consider combinations of queries and not only single queries.

import sqlite3
db = sqlite3.connect(":memory:")
db.execute("CREATE TABLE emp (name TEXT, salary INT)")
db.executemany("INSERT INTO emp VALUES (?, ?)",
               [("Asha", 80), ("Bina", 95), ("Chand", 120),
                ("Dev", 115), ("Ravi", 90)])
a = db.execute("SELECT SUM(salary) FROM emp").fetchone()[0]
q = "SELECT SUM(salary) FROM emp WHERE name <> 'Ravi'"
b = db.execute(q).fetchone()[0]
print("All:", a, "| Without Ravi:", b)
print("Ravi's salary:", a - b)

Output

All: 500 | Without Ravi: 410
Ravi's salary: 90

Common mistakes

  • Thinking that hiding individual rows is enough when aggregates are allowed.
  • Giving all users the same powerful account.
  • Granting rights directly to many users instead of to roles.
  • Not auditing who queried what.

Key takeaways

  • Access control: authentication, authorisation, DAC, RBAC, MAC, views.
  • GRANT gives and REVOKE removes privileges.
  • Inference: deducing secrets from allowed results (direct, tracker, aggregation).
  • Defences: set-size restriction, noise, query limits, auditing.

Practice questions

  1. What is inference in database security?
  2. Differentiate DAC and MAC.
  3. How does a view help security?

Answers to the practice questions

  1. Deducing sensitive data from results that are individually allowed.
  2. In DAC the owner grants access; in MAC the system enforces labels and clearances.
  3. It shows users only selected rows or columns of a table.

Sources

  • Official BCA syllabus Computer Security, course code 25BCA406DS02, Unit II