Managing Authorization in Microservices

Part 4 of 4 Β· My Software Journey

Authorization in Microservices#

When developing a monolithic application, managing authorization and permissions is a bit easier since you have a single point of control for all authorization and permissions. However, with the rise of microservices, this task becomes more complex.

In a microservices architecture, each service typically has its own database and logic for handling permissions. This can lead to duplication and inconsistency in how permissions are managed across services. Additionally, sharing permissions between services can become problematic.

One way to solve this issue is by using Authorization-as-a-Service πŸ”. This approach involves creating a separate service dedicated to managing all authorization for the various services within your architecture. This centralizes control, ensuring consistency and simplifying the management of permissions across your microservices. 🌐

Proof of Concept (POC) πŸš€#

Today, I’ll do a quick proof of concept (POC) to explore authorization management. I’ll use an open-source solution that provides this functionality.

There are plenty of options available.

Some Open-Source Solutions πŸ› οΈ#

  • permify
  • openfga
  • casbin
  • topaz

Cloud Solutions ☁️#

  • There are good cloud solutions like Permit.io

For today’s POC, I’ll be using Permify. βœ…

permify


  1. Run the Permify service on Docker and expose HTTP and gRPC ports.

Terminal running the Permify container with HTTP and gRPC ports exposed


  1. Created a new tenant in Permify to store our policies.

HTTP request creating the Permify tenant t1


  1. Created our schema, using the traditional RBAC model for simplicity πŸ”§. However, in real-world complex applications, there are many models designed to handle complex use cases.

In fact, Permify is considered a fine-grained access control service, inspired by Google’s Zanzibar. 🌐 This allows for more detailed and flexible permission management, making it suitable for more complex scenarios.

Permify has a great article about their solution Here

Permify schema with user and workspace entities, admin, member, and supervisor relations, and file and report permissions


HTTP request writing the schema to the t1 tenant


  1. Attached roles to our users.

HTTP requests giving user 1 the admin role and user 2 the member role in workspace 1


  1. Created simple Node.js services to check user permissions using gRPC via the Permify SDK.

Service 1 Express route checking file permissions for both users


Service 2 Express route checking report permissions for both users


  1. Created a wrapper to check user permissions.

Wrapper function that checks a permission through the Permify gRPC client


  1. Final Test

Terminal output from both services showing which permission checks pass and fail