A database often holds the most valuable data of an organisation. Database security protects that data from theft, misuse and accidental damage.

Security goals

  • Confidentiality: only authorised people can read data.
  • Integrity: only authorised people can change data, and correctly.
  • Availability: authorised users can use the data when needed.

Threats

Unauthorised access, stolen passwords, SQL injection, insider misuse, unpatched software, lost backups and malware.

Access control

Access control decides who may do what. Each user has an identity (authentication), and the DBMS checks permissions for each action (authorisation).

Discretionary access control (DAC)

The owner of an object decides who gets which privileges. SQL gives it through GRANT and REVOKE.

GRANT SELECT, INSERT ON student TO clerk1;
GRANT SELECT ON student TO teacher1 WITH GRANT OPTION;
REVOKE INSERT ON student FROM clerk1;

WITH GRANT OPTION lets the receiver pass the privilege on. Privileges can be given on tables, columns or views. A view that shows only some columns is a simple way to hide the rest.

DAC is flexible, but a user who is allowed to read data could copy it to someone else. Mandatory access control adds fixed levels (for example confidential, secret) set by the system, not by owners.

Other protections

  • Strong passwords and roles: group privileges into roles such as teacher and clerk.
  • Encryption: of stored data and of traffic on the network.
  • Auditing: logs of who did what and when.
  • SQL injection defence: use parameterised queries, never string-join user input.
  • Backups and patching.
-- unsafe: user input pasted into the query
"SELECT * FROM student WHERE name = '" + input + "'"
-- safe: parameter placeholder
"SELECT * FROM student WHERE name = ?"

Common mistakes

  • Giving every application the administrator account.
  • Storing passwords in plain text instead of hashing them.

Practice questions

  1. What are the goals of database security?
  2. What is discretionary access control? Which SQL commands support it?
  3. Write commands to give SELECT on student to teacher1 and then withdraw it.
  4. How does a view help security?
  5. What is SQL injection and how is it prevented?

Answers to the practice questions

  1. Confidentiality, integrity and availability.
  2. The owner decides who gets privileges; GRANT and REVOKE.
  3. GRANT SELECT ON student TO teacher1; and REVOKE SELECT ON student FROM teacher1;
  4. It shows only chosen rows or columns, hiding the rest from the user.
  5. An attack that inserts SQL through user input; prevented with parameterised queries.

Sources

  • Official BCA syllabus Database Management Systems, course code CC202, Unit IV
  • Raghu Ramakrishnan and Johannes Gehrke, Database Management Systems, 3rd edition, McGraw-Hill