Scrivio Interview library

Database security

21 questions in 7 subtopics.

Least-privilege accounts

CodingFoundations8 min read
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.
ScenarioIntermediate7 min read
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?
DesignAdvanced7 min read
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.
LeadershipPrincipal6 min read
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

DebuggingFoundations7 min read
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);
ScenarioIntermediate6 min read
List places where SQL injection appears even in a codebase that uses JPA and PreparedStatement everywhere, and how you would find them in a review of a large Java service.
LeadershipPrincipal6 min read
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

ConceptFoundations6 min read
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?
DesignIntermediate7 min read
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.
LeadershipAdvanced6 min read
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

CodingFoundations7 min read
Write PostgreSQL row-level security for a multi-tenant table invoices(tenant_id, ...) so each application session only sees its tenant's rows, and show how a Java service sets the tenant per transaction.
DebuggingIntermediate7 min read
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.
DesignAdvanced6 min read
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

ConceptFoundations6 min read
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?
DesignIntermediate7 min read
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.
LeadershipPrincipal6 min read
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

ScenarioFoundations7 min read
How do you rotate the database password of a running Spring Boot service with HikariCP without downtime?
DesignIntermediate6 min read
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

CodingFoundations6 min read
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.
ScenarioIntermediate7 min read
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?
LeadershipAdvanced7 min read
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?