How do you ensure the security of data in a database?
Instruction: Discuss methods and best practices for securing data stored in a database.
Updated
Official answer
Start with the data's sensitivity and threat model. Restrict network exposure, patch supported software, protect credentials, and grant each application/operator only the database privileges needed. Separate ordinary application roles from schema or policy administration.
Use parameterized queries for values and allowlisted, safely quoted identifiers where dynamic structure is unavoidable. Enforce object/tenant authorization at every relevant path, including exports and background jobs. Test with actual low-privilege roles, not only an administrator account.
Use authenticated encrypted connections and encryption for stored data/backups with a controlled key lifecycle. Encryption at rest does not prevent a compromised authorized application from reading decrypted rows, and masking is not necessarily anonymization. Protect backup keys and prove that recovery still works.
Audit meaningful access and privilege changes without placing secrets or unnecessary personal data in logs. Monitor failures, review access, rotate exposed credentials, and rehearse containment and restoration. Validate cross-tenant denial and least-privilege behavior after schema changes. Security is a set of maintained controls; no single encryption or monitoring feature guarantees it.