Authorization: deciding what they may do
Authentication got you a verified "who". Authorization answers "may they do this, to that" — and unlike authentication you cannot really buy it, because the answer depends entirely on your domain. It is also where the expensive breaches actually live. Far more data has been lost to a correctly authenticated user reading a record that was never theirs than to broken cryptography.
Three models, in order of what they can express
- Role-based. The user has roles, roles carry permissions.
adminmay delete. Simple and cacheable — and it collapses the moment the answer depends on which record, because "may delete their own posts" is not a role. - Attribute-based. A rule over attributes of the user, the resource and the context: same department, inside business hours, under this amount. Far more expressive, and quietly expensive, since every decision needs those attributes loaded.
- Relationship-based. Permission follows a graph — you may view the document because you are in a group that was granted access to a folder that contains it. This is what document and repository products genuinely need, and it turns every check into a reachability question.
Choose by the shape of the sentence you have to express. If your rules keep saying "their own" or "in the same", roles alone will not survive contact.
Where the decision runs
The tempting design is one central authorization service that everything calls. It gives you a single place to reason about policy — and puts that service in the path of every request, so its latency is your latency and its outage is a total outage.
The usual resolution separates policy from enforcement: one place owns and distributes the rules, many places evaluate them locally. Services get a fast local answer and the policy still has one owner. What you accept in exchange is propagation delay — a revoked permission takes effect everywhere in seconds rather than instantly. That is a tradeoff worth stating out loud rather than discovering during an incident.
The check almost everyone forgets
Most authorization bugs are not wrong rules. They are missing checks on the object:
GET /invoices/8842 <- authenticated as user 17
invoice 8842 belongs to user 41
...who checked that?
A gateway that verifies the token and a handler that fetches by id will serve that request happily. The rule is that authorization is per object, not per endpoint: the question is never "may this user call this route", it is "may this user do this to this row". Endpoint-level checks feel like security and enforce very little.
The structural fix is to make the unsafe version hard to write — have the data layer take the acting principal and refuse queries that do not constrain by it, so that "fetch by id" is not reachable without saying on whose behalf you are asking.
Enforcing authorization in the interface. The button is hidden, so nobody can do it — until someone calls the API directly, which takes about nine seconds to work out. The client is a convenience layer, never a boundary. Every rule the interface enforces has to exist again on the server, because the server is the only side an attacker cannot edit.
Deny by default, check on the object, and keep the rules somewhere you can read all at once. A policy nobody can enumerate is a policy nobody can audit.