Inducing how I should build permissions systems

2025-02-28

I have been warned that your permissions framework for your application is something that is part of the architecture, i.e., that you had better get it right early or you will suffer. I haven't built very many projects that require an incredibly detailed permissions framework, but I do feel the need to be ready when the time does come.

Now, while I haven't built projects that require permissions, I have certainly used projects that require permissions. I'm sure that there are a number of existing conceptual frameworks for permissions, but before I do the right thing and read up on those, I'll do the wrong thing and try to derive the principles from an existing implementation.

Components

I recently got certified with AWS. Permissions are managed in AWS using their "Identity and Access Management" service, or IAM. AWS IAM policies are hardly paragons of elegance, but their complexity comes directly from AWS needing to meet the needs of thousands of real enterprises.

If we start from AWS IAM's current state, we can identify the following components as core to a permissions system:

Presumably these policies are evaluated when some user, human or otherwise, tries to invoke an action through the action's HTTPS API endpoint. The trivial way to implement permissions would of course be to write the logic directly into the endpoint handler function, but this is clearly not a feasible approach for an application where users may control the permissions of other users. Users are not able to edit code. That is why in IAM, these components are all expressed in JSON, except for the user, which is expressed by attaching the policy to an IAM user/group/role.

Of course, if you are familiar with AWS yourself, you may notice that this is an oversimplification of IAM. I excluded things like permissions boundaries, identity-based versus resource-based policies, and service control policies from the example. I hear that these are all a series of band-aids that were implemented as the result of the gradual emergence of customer use cases. If I wanted to overanalyze, I could get into these too, but for now I will not.

Permissions design for web applications

I suppose the AWS management console itself is a "web application," but I want to see if we can take the distilled IAM principles and reconstruct them into a practical framework for implementing permissions in other web applications.

Now, given this, there will be a number of implementation details based on these concepts:

Remember that this is only necessary if some of your users, who may be superusers, must be able to affect the permissions of non-superusers. If only you, the programmer, must be able to affect permissions, you may find it workable to simply implement permissioning logic in your endpoint handlers.