📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Why is running EF Core migrations with Database.Migrate() at application start-up a least-privilege problem, and how do you run them instead?

Mid-Level Theory Intermediate

🎯 Key points

  • Start-up migration forces DDL rights on the runtime identity
  • Concurrency and availability: several instances migrating, long migrations blocking start-up; EF Core 9+ uses a migration lock but doesn't fix the coupling
  • Run idempotent scripts or migration bundles once, in the pipeline
  • Separate migration identity with db_ddladmin; runtime identity keeps DML only
  • Backup and approval gate before production migrations; transactions where the provider supports them
  • Expand-and-contract migrations keep old and new versions working during rollout

⏱ 30-second answer

Database.Migrate() at start-up means the runtime identity must hold DDL rights, so any SQL injection or RCE can alter or drop schema. It also couples deployment to start-up: several scaled-out instances can try to migrate at once (EF Core 9+ takes a database lock to serialise this, but a long migration still blocks start-up and health checks), and a failed migration takes the app down with it. Instead I generate an idempotent script or a migration bundle (dotnet ef migrations bundle) in CI and run it once in the release stage under a separate migration identity with db_ddladmin, after a backup and an approval gate for production. Migrations are written to be backward compatible (expand, then contract) so the old and new app versions both work during rollout, and the runtime identity keeps only DML.

🔍 What the interviewer is checking

Checks the candidate connects deployment design to database permissions.

↩ Usually asked after

More in Senior Security Topics

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me