Check who may do what to which object
Picture
Authentication identifies a principal. Authorization asks whether that principal may perform this operation on this particular object.
Predict
Does a valid login automatically authorize reading any record ID?
Walk through the small example
No. Check authorization for the specific object and operation.
Mental model and runnable Python model
Threat-model actors, assets, entry points, and trust boundaries. Use established authentication and password-hashing libraries or managed identity rather than designing cryptography. Enforce object- and function-level authorization server-side, including search results, cached responses, uploads, and background jobs. Validate and bound inputs, use parameterized queries, protect state-changing browser requests as needed, and rate-limit abuse. Store secrets outside source code, rotate them, and apply least privilege. Plan encryption, retention, deletion, auditing, and incident response according to the data’s sensitivity.
What the function promises: read_note demonstrates only owner authorization after identity has already been verified by a trusted boundary. It is not a login system or a complete security implementation.
def read_note(notes, trusted_user_id, note_id):
note = notes.get(note_id)
if note is None or note["owner"] != trusted_user_id:
raise PermissionError("Note unavailable")
return {"id": note_id, "text": note["text"]}
notes = {"n1": {"owner": "Ana", "text": "private"}}
assert read_note(notes, "Ana", "n1")["text"] == "private"
try:
read_note(notes, "Bo", "n1")
except PermissionError:
pass
else:
raise AssertionError("Cross-user read allowed")
Work and storage: Expected O(1) lookup in the model; real authorization may involve policy or relationship queries that need careful caching.
When to recognize it: Use TLS, managed secrets, bounded inputs, safe queries, abuse controls, and minimal data exposure. Avoid inventing custom cryptography or logging credentials.
Check before applying it: Authentication, authorization, transport protection, and secret handling solve different security problems.
Change one rule
A background worker receives a note ID from a queue. Can it skip access checks because it is internal?
See what changes
No blanket exemption. Validate the event’s trusted provenance, intended tenant, and operation authority. Internal boundaries can still carry stale, forged, or cross-tenant data.
Connect
Make an API safe to call again: Every resource operation needs a trusted identity and permission check.
Design resumable file uploads: Private upload and download capabilities need scope, expiry, and ownership checks.