CCyberwiki

Principle of least privilege

The principle of least privilege holds that every user, and every program acting for a user, receives only the permissions needed to complete its task and nothing more.1 Jerome Saltzer and Michael Schroeder stated it in 1975 in a paper on protecting information in computer systems: every program and every user "should operate using the least set of privileges necessary to complete the job".2 In software the permissions in question include database rights, API key scopes, operating system accounts and cloud roles.

Rationale

Saltzer and Schroeder gave two reasons for the principle. It limits the damage an accident or error can do, and it keeps the number of privileged programs small, so fewer of them need to be audited when a privilege is misused.2

Code that runs with more rights than it needs can create new weaknesses or make existing ones worse.3 The CWE entry for this failure cites CVE-2007-4217, an FTP client that ran with root rights through setuid and also had a buffer overflow. Other FTP clients had the same overflow, and in them it was no vulnerability, because they ran without the extra privileges. The wider fault of assigning or checking privileges wrongly has an entry of its own, Improper Privilege Management.4

Applied to Authorization, the rule is usually called "deny by default". Its violation, a capability meant for particular users or roles that is open to anyone, is listed among the common weaknesses of Broken Access Control in the OWASP Top 10:2025.5

Application

The usual mitigations start from the actions a program performs: it is allowed those and refused everything else. Each task gets its own account with limited rights, so that taking over one task does not reach the rest. The code that needs higher privileges stays small and apart from the rest, raises them as late as possible and drops them as soon as the operation is done. An application rarely needs to connect to its database as the administrator.3

On AWS, a team may start with broad permissions while it learns what a workload needs, then narrow them. AWS managed policies are written for all customers and may grant more than one application needs, and users, roles, keys and permissions that the records show as unused can be removed.6

Postgres and Supabase

A new Postgres object can be used only by its owner or a superuser until privileges are granted on it, and the special role PUBLIC stands for every role at once.7 Functions break that closed default: every role may run a new function. A function marked SECURITY DEFINER runs with its owner's rights instead of the caller's, so the public right is revoked and granted to chosen roles in the same transaction, with a fixed search_path:8

BEGIN;
CREATE FUNCTION check_password(uname TEXT, pass TEXT) RETURNS BOOLEAN
  LANGUAGE plpgsql SECURITY DEFINER
  SET search_path = admin, pg_temp
  AS $$ ... $$;
REVOKE ALL ON FUNCTION check_password(uname TEXT, pass TEXT) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION check_password(uname TEXT, pass TEXT) TO admins;
COMMIT;

Supabase maps its keys to Postgres roles. The publishable key, meant for browsers and mobile apps, reaches only what row level security allows. A secret key, and the older service_role key, uses the service_role role, which has the BYPASSRLS attribute and skips every row level security policy.9 With a separate secret key for each backend component, a leak from one component means rotating one key. A secret key in browser code is covered in Privileged key in client-side code.

GitHub Actions

Any action in a GitHub Actions job can read the job's GITHUB_TOKEN, even when the workflow does not pass the token to it. The permissions key limits the token, for the whole workflow or per job:10

jobs:
  open-issue:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      issues: write

Wider risks of tokens in workflows are described in Secret exposure in CI/CD workflows and Over-privileged access token.

Containers and servers

The Docker daemon runs as root unless rootless mode is chosen, and anyone who controls it can start a container with the host's root directory mounted and change any file on the host, so only trusted users should control it.11 Inside containers, Linux capabilities divide root's powers into separate rights: a web server that listens on a port below 1024 can hold net_bind_service instead of running as root. Containers start with an allowlist of the capabilities they need, and any capability a process does not use can be dropped from it. See Docker socket exposure.

In SecFlash

On the Security page, SF-SEC-804 reports a GitHub workflow whose token has more access than its steps need, SF-SEC-751 a privileged database function that visitors can run, and SF-SEC-755 a role given BYPASSRLS in the project's SQL files. On the Cloud page, SF-CLD-509 and SF-CLD-510 report privileged functions that visitors or every signed-in user can call. On the Server page, SF-SRV-303 reports accounts that can use sudo without a password, SF-SRV-304 accounts in the docker group, and SF-SRV-401, SF-SRV-402, SF-SRV-404 and SF-SRV-409 containers that run privileged, reach the Docker socket, hold powerful capabilities or run as root.

See also

References

  1. back "least privilege". Glossary. NIST Computer Security Resource Center.
  2. a b Saltzer, Jerome H.; Schroeder, Michael D. (1975). "The Protection of Information in Computer Systems". Web copy, University of Virginia, CS551.
  3. a b "CWE-250: Execution with Unnecessary Privileges". Common Weakness Enumeration. MITRE.
  4. back "CWE-269: Improper Privilege Management". Common Weakness Enumeration. MITRE.
  5. back "A01:2025 Broken Access Control". OWASP Top 10:2025. OWASP Foundation.
  6. back "Security best practices in IAM". AWS Identity and Access Management User Guide. Amazon Web Services.
  7. back "5.9. Privileges". PostgreSQL Documentation. PostgreSQL Global Development Group.
  8. back "CREATE FUNCTION". PostgreSQL Documentation. PostgreSQL Global Development Group.
  9. back "Understanding API keys". Supabase Docs. Supabase.
  10. back "Use GITHUB_TOKEN for authentication in workflows". GitHub Docs. GitHub.
  11. back "Docker Engine security". Docker Docs. Docker Inc.