Least privilege
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
Least privilege means giving every person and every program only the access its job needs, and nothing more. Follow one small online shop: Sam in support and a report bot both get one permission, written down in a seven-line Python rule. Watch one access check say yes once and no four times (a page Sam does not need, an unknown name, a stolen account and a buggy program), then see why access must be taken back when jobs change.
What least privilege means
Least privilege means giving each person and each program only the access its job needs, and nothing more. Our example is a small online shop: Sam, a report bot, and the orders, payroll and settings they could touch.
least privilege only the access the job needs
nothing more, for people and programs
NIST "the minimum system resources and
authorizations that the entity needs
to perform its function"
here Sam, a report bot
orders · payroll · settingsاقرأ الدرس خطوة بخطوة
What least privilege means
Least privilege means giving each person and each program only the access its job needs, and nothing more. Our example is a small online shop: Sam, a report bot, and the orders, payroll and settings they could touch.
least privilege only the access the job needs nothing more, for people and programs NIST "the minimum system resources and authorizations that the entity needs to perform its function" here Sam, a report bot orders · payroll · settingsStart from the job
Begin with what each job really needs. Sam works in customer support and reads orders to answer questions. The report bot, a small program, reads orders to count sales. Neither one needs payroll or the shop's settings.
job needs does not need Sam (support) read orders payroll, settings report bot read orders payroll, settings, changing orders a permission one action on one thing written thing:action e.g. orders:readWrite the rule down
In Python, a dictionary called GRANTS maps each name to a set of allowed actions. Sam gets exactly one permission, "orders:read", and so does the bot. Anything not written here is not allowed.
GRANTS = { "sam": {"orders:read"}, # one permission "bot": {"orders:read"}, # the same one } dictionary name → value (here: name → set) set a collection with no repeats; `in` asks "is this in it?"One check on every request
Every request passes one check: the function allowed(). It finds the name in GRANTS and asks if the action is in its set. Sam asks to read an order: True. The lamp shows 1 and the request goes through.
def allowed(who, act): mine = GRANTS.get(who, set()) return act in mine >>> allowed("sam", "orders:read") True # the request reaches the ordersA page Sam does not need
Now Sam clicks the payroll page. "payroll:read" is not in Sam's set, so allowed() returns False. The lamp shows 0 and the check stops the request. Sam can still do the whole job.
>>> allowed("sam", "payroll:read") False # not in {"orders:read"} stopped at the access check Sam's job still works: orders:read is enoughDeny by default
A request from the internet uses the name "guest", which is not in GRANTS. GRANTS.get(who, set()) then gives an empty set, so every answer is False. Deny by default: if nobody wrote a rule, the answer is no.
>>> GRANTS.get("guest", set()) set() # the default: an empty set >>> allowed("guest", "orders:read") False deny by default no rule → no access (OWASP: "Except for public resources, deny by default.")A stolen account stays small
Suppose Sam's password is stolen. The attacker signs in as Sam, so who is "sam" and they get only what Sam has: reading orders. Their try at the settings is refused. Least privilege keeps the harm small, the 'blast radius'.
stolen account the attacker acts as "sam" >>> allowed("sam", "settings:edit") False blast radius how much one stolen account or one mistake can reach Sam as admin orders, payroll, settings least privilege orders (read only)Programs get least privilege too
The rule is for programs too. The report bot only reads orders. When a bug makes it try to delete orders, the check says no, and nothing is lost. NIST applies least privilege to processes, not just people.
>>> allowed("bot", "orders:delete") False # the bot can only read a bug or a takeover of the bot still cannot change or delete orders NIST SP 800-53 AC-6 users, and processes acting for themTake access back
Access piles up unless someone removes it; this is called privilege creep. When Sam moves to another team, take "orders:read" away and grant only what the new job needs. Review everyone's access on a schedule.
privilege creep old access kept after a job changes Sam moves team remove "orders:read" grant only what the new job needs review check every account's access regularly (NIST AC-6(7)) temporary extra access for one task, then take it backLeast privilege in four habits
Four habits: start from the job, deny by default, check every request, and take access back when it is no longer needed. Mistakes and stolen accounts still happen; least privilege keeps the harm they can do small.
1 start from the job what does it really need? 2 deny by default no rule → no 3 check every request one allowed() for all 4 take access back review, remove, expire it does not stop mistakes; it limits the harm
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01Sam works in customer support and only needs to read orders. Which set of permissions follows least privilege?
Least privilege gives only what the job needs. Sam's job is reading orders, so one permission is enough; anything more only adds risk.
02With GRANTS = {"sam": {"orders:read"}}, what does allowed("kim", "orders:read") return?
GRANTS.get(who, set()) gives an empty set for a name that is not in the dictionary, so the action is not in it and the answer is False. That is deny by default.
03An attacker steals Sam's password and signs in as Sam. With least privilege in place, what can they do?
A stolen account carries exactly that account's access. Least privilege does not stop the theft (MFA helps there), but it keeps the harm small: the blast radius.
04Sam moves from support to the warehouse team. What should happen to Sam's "orders:read" permission?
Access left behind after a job changes piles up over time (privilege creep). Remove what is no longer needed and review everyone's access regularly.
05Why should an administrator use a separate admin account only for admin work?
A fake link opened from the everyday account can only reach what that account can. Keeping admin power in a separate account, used only when needed, follows least privilege (NIST SP 800-53 AC-6(2); CISA).
المسرد
- Least privilege
- Giving each person and each program only the access its job needs, and nothing more. NIST: the minimum resources and authorizations an entity needs to perform its function.
- Permission
- Being allowed to do one action on one thing, such as reading orders. In the lesson it is written as a short string like "orders:read".
- Access check
- The one place every request is checked against the rules before it reaches the data. In the lesson it is the Python function allowed(who, act).
- Deny by default
- If no rule says yes, the answer is no. A name or action nobody wrote down gets no access.
- Blast radius
- How much one stolen account, one mistake or one buggy program can reach. Least privilege keeps it small.
- Privilege creep
- Access that keeps piling up as people change jobs, because old permissions are never removed. Regular reviews fix it.
- Admin (privileged) account
- An account that can change settings or other people's access. Admins should use it only for admin work, and a normal account for everything else.
الملاحظات والمصادر
- Real systems keep permissions in a database or an identity service, and check far more than a name, but the idea is the same: one check, on every request, against a list that says what each account may do.
- Bigger organisations group permissions into roles (such as "support") and give people roles, not single permissions. That is role-based access control; least privilege still decides what goes in each role.
- Admins should have two accounts: a normal one for email and the web, and a separate admin account used only for admin work (NIST SP 800-53 AC-6(2); CISA Cross-Sector Performance Goals).
- Least privilege does not stop an account being stolen; MFA and phishing training help with that. It limits what a stolen account, or a mistake, can reach.
- This course is about defence. It explains how attacks work only at the level needed to stop them, and never how to attack a real system.
- NIST CSRC Glossary: least privilege
- NIST SP 800-53 Rev. 5: Security and Privacy Controls (AC-6 Least Privilege)
- Saltzer and Schroeder (1975): The Protection of Information in Computer Systems, Proc. IEEE 63(9)
- OWASP Top 10 2021: A01 Broken Access Control
- OWASP Authorization Cheat Sheet
- CISA: Cross-Sector Cybersecurity Performance Goals
- CISA and MS-ISAC: #StopRansomware Guide
- Python documentation: dict.get
- Python documentation: set types
اختبار يتاح بعد الخطوة الأخيرة.