Database security
21 questions in 7 subtopics.
Least-privilege accounts
A Spring Boot service connects to PostgreSQL as the database owner. Write the SQL to create a separate login role for the application that can only read and write the tables in schema app, and a migration role that owns the objects.An audit finds that 30 services share one MySQL account with ALL PRIVILEGES, and nobody knows which service needs what. How do you move to least privilege without an outage?Design a database access model for 200 services and 50 data analysts across PostgreSQL clusters, covering application accounts, human access, break-glass access and auditing.A breach report shows the attacker used an over-privileged database account from a compromised service to read data from unrelated systems. How would you change database access governance at company level?SQL injection beyond PreparedStatement
This Spring Data repository code uses parameters, yet a penetration test still finds SQL injection. Where is the hole and how do you fix it?String sql = "SELECT * FROM orders WHERE customer_id = ? ORDER BY " + sortColumn + " " + direction;
jdbcTemplate.query(sql, mapper, customerId);
PreparedStatement everywhere, and how you would find them in a review of a large Java service.SQL injection has been known for over 25 years and still appears in your company's audit findings. What would you change at organisation level so it stops recurring?Encryption at rest and in transit
What does encryption at rest protect against and what does it not protect against? How do you make a Spring Boot service connect to PostgreSQL over TLS and verify the server certificate?You must encrypt national ID numbers in a customer table so that DBAs cannot read them, while still allowing exact-match lookup by ID number. Design the scheme.Regulators require proof that all customer data is encrypted in transit and at rest across 80 databases, including backups and replicas. How do you deliver and prove it?Row-level security
Write PostgreSQL row-level security for a multi-tenant tableinvoices(tenant_id, ...) so each application session only sees its tenant's rows, and show how a Java service sets the tenant per transaction.After enabling row-level security on a large orders table, a common query became 20 times slower, and a reporting job that runs as the table owner still sees every tenant's data. Explain both.Compare tenant isolation approaches for a SaaS product on PostgreSQL: shared tables with row-level security, schema per tenant, and database per tenant. Which would you choose for 5,000 small tenants and 20 large regulated ones?Auditing
What options exist to audit who changed or read sensitive data in PostgreSQL and MySQL, and what is the difference between database audit logs and application audit trails?Design an audit trail for changes to customer bank details in a Spring Boot service that must show who changed what, when, from which value, and be tamper-evident.Your company's audit logs come from databases, applications and cloud providers in different formats, and an investigation last year took weeks to reconstruct who accessed customer data. What would you change?Rotating database credentials
How do you rotate the database password of a running Spring Boot service with HikariCP without downtime?Design short-lived database credentials for 100 services using a secret manager that creates a new database user per lease. What failure modes do you plan for?Data masking and PII
Developers need a copy of production data for testing. Write SQL that masks email addresses and phone numbers in a PostgreSQL customers table while keeping emails unique and formats valid.A support tool shows full customer records, and logs from a Java service include request bodies with card numbers and emails. What controls would you add in the database, the application and the logs?Your company must honour data deletion requests under privacy laws across 60 services and their backups, caches and analytics copies. How do you design and lead this?No question matches these choices.