Security foundations Least privilege 2 min read

Least privilege: give only what’s needed

A job reads sales records for the monthly report. Its database role can also delete those records. What can you take away without breaking the report?

  1. The job only needs to read

    Start with the task: the report needs to read the sales data. Give the job a dedicated role that can read the table or view it uses. Writing or deleting sales records serves no purpose for this job.

    A report job gets a read-only role. Reading sales is allowed, while deleting sales is denied. Report jobRead-only roleRead salesAllowedDelete salesDenied

    In short Start with the task, then grant the access it needs.

  2. The narrower role contains a mistake

    If a bug makes the job send a delete request, the database checks the role and refuses it. The same job can still read the sales data and finish the report.

    In short The database enforces the difference between reading and deleting.

What the job can still do

A job with read access can still expose the data it can read. Limit the rows or fields too when the report only needs a subset.

Keep this

Grant what the job needs to finish.

Check that the expected request succeeds and an unnecessary request is denied.

Sources

Last reviewed 17 November 2026.

Next byte · Security foundations What is Zero Trust?