<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Daniel Bass</title>
    <description>The latest articles on DEV Community by Daniel Bass (@imdburnot).</description>
    <link>https://dev.to/imdburnot</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F790123%2F6e768cb1-1013-43b3-8553-6d31ee2e9930.png</url>
      <title>DEV Community: Daniel Bass</title>
      <link>https://dev.to/imdburnot</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imdburnot"/>
    <language>en</language>
    <item>
      <title>Protecting Democracy Through Fine-Grained Authorization</title>
      <dc:creator>Daniel Bass</dc:creator>
      <pubDate>Thu, 22 Aug 2024 12:08:50 +0000</pubDate>
      <link>https://dev.to/permit_io/protecting-democracy-through-fine-grained-authorization-5dkh</link>
      <guid>https://dev.to/permit_io/protecting-democracy-through-fine-grained-authorization-5dkh</guid>
      <description>&lt;h1&gt;
  
  
  &lt;strong&gt;Protecting Democracy Through Fine-Grained Authorization&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;In recent years, the integrity of the election process has come under intense scrutiny, making it more important than ever to ensure that voting systems are secure, transparent, and reliable. Ensuring that only authorized personnel have access to sensitive voter data is critical in maintaining public trust. A breach could not only compromise the election but also erode confidence in the entire democratic process.&lt;/p&gt;

&lt;p&gt;From a software development perspective, this responsibility requires a refined approach to system access and permissions. Developers are on the front lines of this defense, tasked with creating and maintaining systems that must balance functionality with security.&lt;/p&gt;

&lt;p&gt;Maricopa County, one of the largest voting jurisdictions in the United States, encountered this challenge firsthand. Their solution, which manages vast amounts of voter data while maintaining strict security measures, offers a compelling case study on the importance of Fine-Grained Authorization (FGA).&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/AGpTLFGpzcY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Watch the full case study video here&lt;/p&gt;

&lt;h3&gt;
  
  
  The Challenge: Scaling Security for a Massive Voting Jurisdiction
&lt;/h3&gt;

&lt;p&gt;As the fourth-largest county in the U.S., Maricopa County’s Recorder's Office oversees a voting system that serves millions. Dealing with such a scale is no joke - especially given the delicate nature of the issue. This presented two key challenges:&lt;/p&gt;

&lt;p&gt;First, there is a need for precise control over who can access specific data and perform specific actions within the system. &lt;a href="https://www.permit.io/blog/an-introduction-to-role-based-access-control" rel="noopener noreferrer"&gt;Traditional role-based access control (RBAC)&lt;/a&gt; wasn’t sufficient for the level of granularity required, so they had to employ more precise control over who could access specific data and perform particular actions within their systems. &lt;/p&gt;

&lt;p&gt;Second, the challenge of managing permissions for a large and fluctuating workforce, especially during election periods. Temporary staff needed access to specific parts of the system without compromising sensitive voter information. Manually managing these permissions by writing policy code was a complex and time-consuming process that placed a significant burden on the IT department.&lt;/p&gt;

&lt;p&gt;As these challenges increased over time, the county’s voter registration system, known as Arrow, must handle an unprecedented level of complexity.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Solution: FGA and No-Code UIs
&lt;/h3&gt;

&lt;p&gt;To address the challenge of complex authorization policies, namely those that required considering a large number of attributes to enforce granular authorization decisions, Maricopa County turned to implementing &lt;a href="https://www.permit.io/blog/what-is-fine-grained-authorization-fga" rel="noopener noreferrer"&gt;Fine-Grained Authorization (FGA)&lt;/a&gt; as a solution.&lt;/p&gt;

&lt;p&gt;FGA goes beyond simple role-based access control by considering a broader set of factors when making authorization decisions. Instead of relying solely on user identity or role, FGA can make &lt;br&gt;
make nuanced authorization decisions based on multiple factors, such as attributes with &lt;a href="https://www.permit.io/blog/what-is-attribute-based-access-control" rel="noopener noreferrer"&gt;Attribute Based Access Control (ABAC)&lt;/a&gt; and relationships with &lt;a href="https://www.permit.io/blog/what-is-rebac" rel="noopener noreferrer"&gt;Relationship-Based Access Control (ReBAC)&lt;/a&gt;, allowing precise control over who can access what, down to the level of individual tasks and actions within a system.&lt;/p&gt;

&lt;p&gt;By implementing FGA, the county could ensure that each user, whether a full-time employee or a temporary staff member, had access only to the tools and information they needed for their role—nothing more, nothing less.&lt;/p&gt;

&lt;p&gt;To facilitate this implementation, Maricopa County utilized the capabilities of Permit.io. This allowed their developer team to integrate fine-grained authorization into their systems without completely refactoring their own solution and building a new one in-house. With Permit.io, permissions could also be set not just at a user level &lt;a href="https://docs.permit.io/overview/how-does-it-work" rel="noopener noreferrer"&gt;but at the API interaction level&lt;/a&gt;, allowing for even more detailed and secure control over who could access what within the system.&lt;/p&gt;

&lt;p&gt;Permit also allowed for automation in the permission management process. Instead of having IT staff manually assign permissions to each new user, they were able to create predefined permission sets through Permit’s no-code UI, which could be adjusted dynamically as an employee's tasks changed. Temporary workers brought in for election periods could, for example, be given access only to the specific functions they needed, and those permissions could be automatically revoked when their role ended.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Impact: Security and Efficiency
&lt;/h3&gt;

&lt;p&gt;The transition to Fine-Grained Authorization and the adoption of no-code UI for managing authorization had critical impacts on Maricopa County’s operations. First and foremost, it helped ensure no employee had more access than necessary, aligning with the principle of least privilege and preventing unauthorized access, whether intentional or accidental.&lt;/p&gt;

&lt;p&gt;Delegating permissions management to department managers, rather than centralizing it in IT, made the process faster and more responsive. Managers could directly control access, reducing bottlenecks and freeing IT resources for more critical tasks. IT, in turn, could focus on monitoring the processes happening within the system with automatically generated audit logs instead of manually writing policy codes and assigning roles and permissions. &lt;/p&gt;

&lt;p&gt;This shift allowed the voter registration department to take greater ownership of its security processes in its day-to-day operations. The ability to adjust permissions without the need for constant IT intervention meant that the office could remain agile and responsive, even during the intense periods leading up to elections.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Broader Lesson for Developers
&lt;/h3&gt;

&lt;p&gt;Maricopa County's experience is a great example for developers. Protecting data—whether it involves consumer information or the democratic process itself—is a technical responsibility.&lt;/p&gt;

&lt;p&gt;Fine-grained authorization is a tool that developers should consider, especially in high-stakes systems. FGA enhances security by ensuring that access is precisely controlled, while implementing it with a no-code authorization UI can help streamline operations by reducing the administrative burden on IT departments.&lt;/p&gt;

&lt;p&gt;In every system where integrity can have far-reaching consequences, developers' responsibility extends beyond just building functional software. They must anticipate vulnerabilities, implement efficient security measures, and adapt to emerging threats. Maricopa County’s experience shows how a strategic shift to FGA can meet these responsibilities.&lt;/p&gt;

&lt;p&gt;Maricopa County's challenges are not unique; they are indicative of the broader issues that arise in managing large, complex systems. By embracing Fine-Grained Authorization, the county not only solved its immediate access control challenges but also set a standard for how other development teams might approach similar issues.&lt;/p&gt;

&lt;p&gt;If you want to learn more about the best ways to implement FGA, make sure to join our &lt;a href="https://io.permit.io/permitslack" rel="noopener noreferrer"&gt;&lt;strong&gt;Slack community&lt;/strong&gt;&lt;/a&gt;, where there are hundreds of devs building and implementing authorization.&lt;/p&gt;

</description>
      <category>fga</category>
      <category>authorization</category>
      <category>programming</category>
      <category>security</category>
    </item>
    <item>
      <title>How Discord Built `Access!` - An Authorization Management Portal</title>
      <dc:creator>Daniel Bass</dc:creator>
      <pubDate>Tue, 18 Jun 2024 15:15:18 +0000</pubDate>
      <link>https://dev.to/permit_io/how-discord-built-access-an-authorization-management-portal-2n7f</link>
      <guid>https://dev.to/permit_io/how-discord-built-access-an-authorization-management-portal-2n7f</guid>
      <description>&lt;p&gt;Managing access permissions is a critical aspect of application security, especially for large platforms like Discord. In a great blog, “&lt;a href="https://discord.com/blog/access-a-new-portal-for-managing-internal-authorization"&gt;Access: A New Portal For Managing Internal Authorization&lt;/a&gt;,” Elisa Guerrant, Security Engineer at Discord, details how they built “Access!” - a secure, accessible internal authorization portal. &lt;/p&gt;

&lt;p&gt;This blog will discuss the importance of creating permission management systems that balance security and accessibility for all application users. It will also introduce "Permit: Elements," a set of prebuilt, embeddable UI components designed to further streamline and enhance permission delegation. Thus demonstrating how to improve the accessibility of your own authorization management system. Let’s dive in!&lt;/p&gt;

&lt;h2&gt;
  
  
  Authorization: Security First, Accessibility Second
&lt;/h2&gt;

&lt;p&gt;Building and managing a system that can handle access permissions is a must for basically any application these days, especially one as large as Discord. With applications growing ever more complex and the reality of microservice-based architectures, ensuring that the right users have appropriate access to the right resources at the right times is a bigger challenge than ever. &lt;/p&gt;

&lt;p&gt;When building authorization, especially considering it’s a feature &lt;a href="https://www.permit.io/blog/roll-your-own-rbac"&gt;mostly built in-house and requires a very large amount of effort to develop&lt;/a&gt;, developers tend to focus on building authorization that provides the required level of security and restrictions their app needs. This approach is great, but it comes with a catch—it often overlooks the importance of developer and user experience. &lt;/p&gt;

&lt;p&gt;To understand why experiences are important in authorization, let’s talk about who uses our app. &lt;/p&gt;

&lt;h3&gt;
  
  
  Who Uses Our Application?
&lt;/h3&gt;

&lt;p&gt;Every modern application consists of &lt;a href="https://www.permit.io/blog/best-practices-for-effective-user-permissions-and-access-delegation"&gt;several levels of users&lt;/a&gt;. It’s never as straightforward as end-users and developers. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;End-users&lt;/strong&gt; interact with our application in multiple areas, each of which must be considered when designing our authorization layer. This includes &lt;a href="https://www.permit.io/blog/generate-personalized-frontend-experiences-with-user-attributes-and-feature-flags"&gt;what users can see in the application&lt;/a&gt;, ****which actions they can perform, and what data they can access.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;App developers&lt;/strong&gt; need a level of user permissions management that allows them to create and handle new policies, requests, and processes. &lt;/p&gt;

&lt;p&gt;This obviously doesn't mean their access is unlimited, and it requires monitoring and management as well. Who decides what developers can access and what level of control they have over our application's authorization layer? More often than not, a specific person or group will be directly in charge (albeit reluctantly) of managing the application’s user and role management. &lt;/p&gt;

&lt;p&gt;Depending on our application, there are more possible levels here. &lt;strong&gt;Internal Users&lt;/strong&gt; who are members of our organization might need different levels of access, and some may need to manage and delegate access to end-users. &lt;strong&gt;Organizational Stakeholders&lt;/strong&gt;, such as DevOps, RevOps, and AppSec teams, require access to specific parts of the application, as well as the ability to manage user roles and delegate access management to internal users.&lt;/p&gt;

&lt;h3&gt;
  
  
  How Do We Handle All These Users?
&lt;/h3&gt;

&lt;p&gt;The prospect of creating all-powerful superusers is alluring to many developers. What can be more secure than directly calling all the shots yourself? And while that’s true to some extent, this approach backfires very quickly. If you, as a developer, are the person directly in charge of all user roles and permission management in your organization, you will very quickly realize the strain this will have on you and the entire R&amp;amp;D team as you turn into a bottleneck for the entire business operation.&lt;/p&gt;

&lt;p&gt;Only one person/group can manage authorization for every user of your application? Great - it’s their full-time job now.&lt;/p&gt;

&lt;p&gt;The opposite approach, delegating all power away from developers to other stakeholders, is often equally dangerous, as it can create a slow-moving, inefficient bureaucracy or an unstable, risk-filled environment. &lt;/p&gt;

&lt;p&gt;What this means is that our authorization layer needs not only to provide a solid, secure basis for determining who has access to what within your application, but it must also be approachable and easy to understand. This is emphasized even further in Elisa’s blog, where she mentions the fact that &lt;a href="https://www.verizon.com/business/resources/Tcdc/reports/2023-data-breach-investigations-report-dbir.pdf"&gt;74% of all breaches involve the human element, with privilege misuse and stolen user credentials being two of the primary threats&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;This is the direct result of developers’ tendency to focus on authorization being secure (which is great) while neglecting the need for it to be accessible (Which is bad). &lt;/p&gt;

&lt;p&gt;As Elisa mentioned in her article:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Policies designed to manage permissions tend to cause headaches for end-users and leave the decisions about “who can access what” in the hands of people who don’t have much information about the resources – often IT or Security”.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At Permit.io, we encounter this all the time. Many developers come to us because their homebrewed authorization solutions &lt;a href="https://www.permit.io/blog/devsecops-is-nothing-without-devex"&gt;lack both developer and user experience&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Let’s see what Discord did to help solve these issues: &lt;/p&gt;

&lt;h2&gt;
  
  
  What Did Discord Do?
&lt;/h2&gt;

&lt;p&gt;To address these concerns, the folks at Discord built an internal portal for staff to manage user permissions &lt;strong&gt;for their internal users, organizational stakeholders, and developers&lt;/strong&gt;. Focusing on &lt;strong&gt;workforce identity&lt;/strong&gt; (We’ll get to customer identity in a sec with Permit.io), they created it with the goals of being secure, transparent, and easy to use, and eventually &lt;a href="https://github.com/discord/access"&gt;made the tool publicly available and free to use&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What was their goal?
&lt;/h3&gt;

&lt;p&gt;Discord uses Okta as its authentication solution for SSO. As they grew, they wanted the ability to further customize access controls for their employees. These were the goals they set for themselves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This tool needed &lt;strong&gt;to be security-focused and enforce the principle of least privilege&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;It needed to have &lt;strong&gt;an intuitive user experience that didn’t require staff to have deep knowledge of the access control tool or the systems being managed&lt;/strong&gt;. This would help ensure the tool’s adoption within the company.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The tool needed to be “self-serve” and allow delegation within their internal policies&lt;/strong&gt;. As we mentioned previously, having IT or Security teams exclusively manage permissions would create a bottleneck in one particular organization and slow down the whole operation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Finally, they wanted a system that was transparent and discoverable. Users would&lt;/strong&gt; be able to see what access they or their teammates have, what resources are controlled by the system, and what permissions they had in the past but have since expired. They should also be able to request access to resources freely, empowering them to troubleshoot their own permissions and solve issues through access requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After what Elisa describes as “weeks of development time and dozens of cups of coffee”, the Discord team ended up building “Access” - an RBAC-based solution for managing their internal user access control. &lt;/p&gt;

&lt;h3&gt;
  
  
  What features does this tool provide?
&lt;/h3&gt;

&lt;p&gt;Let’s see what features Discord’s tool ended up providing and how these concur with the &lt;a href="https://www.permit.io/blog/best-practices-for-effective-user-permissions-and-access-delegation"&gt;Best Practices for Effective User Permissions and Access Delegation&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Delegated control:&lt;/strong&gt; Each group or app has a set of owners who control membership and access related to that resource, ensuring each group or app has designated owners responsible for managing membership and access. This follows the best practice of having a primary admin or owner who manages permissions, preventing conflicts such as two admins being able to remove each other and ensuring that those with the most context handle permissions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time-bounded access:&lt;/strong&gt; This feature mitigates the risk of accumulating unnecessary permissions over time by allowing access to be set for predetermined periods.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access requests:&lt;/strong&gt; Access requests enable users to discover and request necessary permissions, which are then reviewed by appropriate owners. This delegation supports a cascading model of permissions, ensuring that those with the best understanding of the needs grant permissions, balancing the load across different levels of the organization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Audit logs:&lt;/strong&gt; Every user, group, and role in Access has a page viewable by all employees that shows complete membership and ownership history. These comprehensive audit logs allow all users to see complete membership and ownership histories. This transparency supports the generation of audit logs, which are crucial for tracking changes and understanding permission alterations at every level of the system.
&lt;strong&gt;‍&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2z28skbcza4ysnpwt8j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2z28skbcza4ysnpwt8j.png" alt="Image description" width="800" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Using classic policy models for ‘high-level’ authorization policies&lt;/strong&gt; &lt;strong&gt;(e.g., &lt;a href="https://www.permit.io/blog/an-introduction-to-role-based-access-control"&gt;RBAC&lt;/a&gt;, &lt;a href="https://www.permit.io/blog/what-is-attribute-based-access-control"&gt;ABAC&lt;/a&gt;):&lt;/strong&gt; Access was built based on an RBAC model, which helped ensure consistency and ease of understanding across the system, lowering the cognitive load on system managers and users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Building an easy-to-use UI:&lt;/strong&gt; The intuitive and user-friendly interface built by the Discord team enables effective permission management. It makes permission management accessible and straightforward so that all users, regardless of technical expertise, can effectively manage and understand their permissions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Implementing Accessible Authorization Elements
&lt;/h2&gt;

&lt;p&gt;The tool built by Discord provides a masterful solution to the problem of effectively handling user permissions and access delegation. As mentioned before, we at &lt;a href="http://Permit.io"&gt;Permit.io&lt;/a&gt; encounter this problem with our users all the time, and it spans beyond internal users. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://Permit.io"&gt;Permit.io&lt;/a&gt; aims to provide a comprehensive solution for managing user permissions &lt;strong&gt;for all application users, from end-users to application developers,&lt;/strong&gt; in a single, unified interface. &lt;/p&gt;

&lt;p&gt;When we initially launched Permit, our goal was to provide developers with the building blocks needed (SDKs, gateway plugins, data updates) to integrate permissions into an application. This included a no-code UI for creating and managing permissions with RBAC, ABAC, and ReBAC support. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9oi8543y496uurpewc7n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9oi8543y496uurpewc7n.png" alt="Permit.io’s permission management UI with RBAC, ABAC, and ReBAC policies, all together in one interface." width="800" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Permit.io’s permission management UI with RBAC, ABAC, and ReBAC policies, all together in one interface.&lt;/p&gt;

&lt;p&gt;To further improve accessibility, we introduced “Permit Elements,” a set of prebuilt and embeddable UI components that provide fully functional access control. These components allow you to safely delegate permissions to your end users.&lt;/p&gt;

&lt;p&gt;Permit Elements enable crucial permission management functionalities (such as User Management, Audit Logs, Access Requests, and Process Approval) to propagate through your user stack—from developers to internal users and end users, ensuring efficient and secure access management without bottlenecks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feakecl99ooa4thy8dco3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feakecl99ooa4thy8dco3.png" alt="Image description" width="800" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By incorporating Permit Elements, you can enhance the accessibility and usability of your permission management system, ensuring that it is not only secure but also user-friendly and efficient.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Building an accessible permission management system is crucial for maintaining both security and efficiency in modern applications. Discord's innovative approach with its "Access" portal showcases how balancing security with user-friendly features can streamline operations and enhance overall security. By incorporating intuitive design and robust delegation capabilities, Discord has set a high standard for internal authorization management.&lt;/p&gt;

&lt;p&gt;To further enhance your permission management system, we covered "Permit: Elements” - a set of prebuilt, embeddable UI components that offer fully functional access control. These components enable you to delegate permissions safely and effectively to your end users. By adopting such solutions, you can ensure that your authorization processes are not only secure but also accessible and efficient for all users.&lt;/p&gt;

</description>
      <category>authorization</category>
      <category>iam</category>
      <category>discord</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Turning Secure Access Into Child’s Play with Permit Access Request APIs</title>
      <dc:creator>Daniel Bass</dc:creator>
      <pubDate>Mon, 22 Apr 2024 14:23:47 +0000</pubDate>
      <link>https://dev.to/permit_io/turning-secure-access-into-childs-play-with-permit-access-request-apis-235p</link>
      <guid>https://dev.to/permit_io/turning-secure-access-into-childs-play-with-permit-access-request-apis-235p</guid>
      <description>&lt;p&gt;When we build an application, some parts will be accessible to users, while others will be restricted. That’s a given. But building this kind of capability has its fair share of complexions - especially when these limitations aren’t static but change with the circumstances. As I’ll show you in this blog, enabling user access requests can be as simple as a children's story. &lt;/p&gt;

&lt;p&gt;Let’s get into it - &lt;/p&gt;

&lt;h2&gt;
  
  
  The Challenge
&lt;/h2&gt;

&lt;p&gt;Creating strict rules that allow certain users access to certain parts of the app isn’t a big issue - but that’s rarely enough for practically any modern application. In most cases, circumstances and user requirements constantly change over time. This gives us two options: &lt;/p&gt;

&lt;p&gt;Either &lt;strong&gt;manually&lt;/strong&gt; make changes to your authorization layer every time &lt;em&gt;or&lt;/em&gt; create an &lt;strong&gt;automated&lt;/strong&gt; system (An Access Request API) that allows users to request access and allows administrators to grant them access based on certain conditions. Let’s look at the manual option - &lt;/p&gt;

&lt;p&gt;Say a user wants access to a certain part of the application which can only be approved by a specific type of admin. This means that you will have to create a system which:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Associates the specific application segment to the relevant admin, and has their contact information.&lt;/li&gt;
&lt;li&gt;Allows the user to send an access request email/message requesting access. This will probably require the integration of some third-party tool. &lt;/li&gt;
&lt;li&gt;Once the request is sent, the user will need to wait for the administrator's approval, which might take time. While not directly your problem, this will create a UX issue that you’ll probably be expected to solve at some point. &lt;/li&gt;
&lt;li&gt;If the administrator approves the access request - there’s still the task of changing the actual authorization rule that enforces the access. This is, again, a problematic bottleneck that might require a different solution, especially as things scale. &lt;/li&gt;
&lt;li&gt;Once the appropriate changes to the authorization layer have been made, you’ll have to inform the administrator, who will need to inform the user. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This process will be required for any new access request. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkzgsj5cxb7avde1ldk2k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkzgsj5cxb7avde1ldk2k.png" alt="Access Control Comic" width="640" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can quite easily see, building this system and having you make manual changes to the code every time a user needs access to a new portion of the application (Say, if a user paid and should now have access to premium features) is obviously highly impractical. So let’s talk about creating an Access Request API that does this automatically. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is an Access Request API?
&lt;/h2&gt;

&lt;p&gt;An Access-Request API serves as a centralized mechanism for handling access requests within the application environment, streamlining the process by allowing users to directly request access to specific features or data sets from within the application, eliminating the need to do so manually. &lt;/p&gt;

&lt;h2&gt;
  
  
  The benefits of using an Access Request API
&lt;/h2&gt;

&lt;p&gt;Using an Access Request API provides the following benefits: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It allows users to request access directly within the application without you having to set up 3rd party channels like emails/DMs. This doesn’t only make the process more comfortable for the user, but, more importantly - it makes it &lt;strong&gt;manageable&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;With access requests all managed in one place, it becomes far easier to maintain a comprehensive history of requests, serving as documentation for access granted within the application.&lt;/li&gt;
&lt;li&gt;Additionally, it allows multiple individuals to approve or deny access according to the rules you define. This reduces both waiting times for access requests and enables efficient management of your admin team.&lt;/li&gt;
&lt;li&gt;Having multiple admins also allows you to follow which requests have been approved or denied and why.&lt;/li&gt;
&lt;li&gt;Sometimes you might need to grant someone access to a role within a specific time limit. having a well-organized access control API helps you manage who, and more importantly, for how long, a user has access to a resource within your app.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7t4b6fj8mv27y51ijt7a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7t4b6fj8mv27y51ijt7a.png" alt="Git Blame" width="800" height="1065"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How to implement an Access Control API?
&lt;/h3&gt;

&lt;p&gt;You can build an access control API yourself as long as you follow some important best practices for building authorization. Another option is to use the &lt;a href="http://Permit.io"&gt;Permit.io&lt;/a&gt; Access Control API, which generates access requests tailored to specific roles or resource instances and can be integrated into your app pretty quickly. It also allows you to assign suitable moderators who can evaluate and make decisions on user requests, helping make sure access is granted or denied in accordance with your specifications.&lt;/p&gt;

&lt;p&gt;We also plan to release an &lt;a href="https://docs.permit.io/embeddable-uis/overview"&gt;Access Request Element&lt;/a&gt;, one of a few UI components we provide that allows you to safely delegate access control to your end users.&lt;/p&gt;

&lt;h3&gt;
  
  
  What does an Access Control API implementation look like?
&lt;/h3&gt;

&lt;p&gt;To demonstrate how Access Control APIs work with Permit.io, let’s look at it through the simplest example possible - Goldilocks and the Three Bears. Imagine if the three bears had an application that used the Permit Access Request API - that story would look completely different:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fusr83zltwaidf9kl0svy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fusr83zltwaidf9kl0svy.png" alt="Story 1" width="800" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In the forest, hidden among the trees, stood the cozy cottage of the three bears. In it, three rooms, three beds, and three bears: Papa Bear, Mama Bear, and Little Baby Bear.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In his shrewdness, Papa Bear decided to implement Permit’s Access Control API  to track and manage access in their home.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw036c6mvkbybfu1ajhor.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw036c6mvkbybfu1ajhor.png" alt="Story 2" width="800" height="542"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;One day, the three bears were away, while a little girl with locks of gold, stumbled upon their home. Goldilocks was her name, and hungry she was. Lured by the scent of tasty porridge, and lack of authentication, she made her way in. Famished, Goldilocks spotted a sign on the wall. &lt;br&gt;
It read: “Access Restricted”. So she submitted an access request.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frj6vu0olk46kz91ix7ep.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frj6vu0olk46kz91ix7ep.png" alt="Story 3" width="800" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03l582cnspy023kpfzww.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03l582cnspy023kpfzww.png" alt="Story 4" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fulh3veamsglra41bb5su.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fulh3veamsglra41bb5su.png" alt="Story 5" width="800" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Papa Bear, deep in the forest, received a surprising access request. All the bears are here, yet some user named Goldilocks123 wants to eat their delicious porridge! Knowing Mama Bear’s hospitality well, he hastily approved the request and continued with his morning hike.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhy1zuf3tpmgv87uysd6a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhy1zuf3tpmgv87uysd6a.png" alt="Story 6" width="800" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi8i5cohjtl6px8shai9c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi8i5cohjtl6px8shai9c.png" alt="Story 7" width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F460w771f8xbly533hle6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F460w771f8xbly533hle6.png" alt="Story 8" width="800" height="542"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;After savoring the porridge, Goldilocks grew sleepy. Before settling into one of the beds for a nap, she requested permission for her impromptu rest. Recognizing her adventurous spirit, Papa bear granted her request and offered a playful warning: "This is the last time, young lady!"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjk8eev2e1gtek0spzad1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjk8eev2e1gtek0spzad1.png" alt="Story 9" width="800" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffu1kx42uoevt7ig2zg84.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffu1kx42uoevt7ig2zg84.png" alt="Story 10" width="800" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4pp5494oqiyqwre6per8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4pp5494oqiyqwre6per8.png" alt="Story 11" width="800" height="542"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;When the three bears returned to their home, they found Goldilocks there. She thanked the three bears, and swiftly left the cottage. As  Goldilocks departed, Papa Bear chuckled&lt;/em&gt;:&lt;br&gt;
&lt;strong&gt;“There’s nothing like properly implemented access control”.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The moral of the story
&lt;/h2&gt;

&lt;p&gt;So what did we learn? &lt;/p&gt;

&lt;p&gt;Most modern applications require an authorization system that allows not only static restrictions on user access but also the ability to adapt to reality. Allowing your users to request access to certain parts of your app is not something you want to do manually, and there are many benefits of having this capability embedded in your app in the form of an Access Request API. &lt;/p&gt;

&lt;p&gt;In this blog, we learned how to use Permit.io’s Access Request API to create a safer, more secure experience for both you and your users, handling access requests quickly and efficiently in both make-believe and real-life settings.&lt;/p&gt;

</description>
      <category>security</category>
      <category>api</category>
      <category>access</category>
      <category>iam</category>
    </item>
    <item>
      <title>How to build authorization like Netflix with Open Source?</title>
      <dc:creator>Daniel Bass</dc:creator>
      <pubDate>Sun, 19 Feb 2023 11:24:46 +0000</pubDate>
      <link>https://dev.to/permit_io/how-to-build-authorization-like-netflix-with-open-source-4dk8</link>
      <guid>https://dev.to/permit_io/how-to-build-authorization-like-netflix-with-open-source-4dk8</guid>
      <description>&lt;p&gt;This blog is based on the video "&lt;a href="https://www.youtube.com/watch?v=zsYdGrdDoDE" rel="noopener noreferrer"&gt;Build Authorization like Netflix with Open Source&lt;/a&gt;"&lt;/p&gt;

&lt;p&gt;Netflix has over 220 million active users and is worth over 100 billion dollars. With such an enormous user base, they are responsible for managing a vast amount of personal information. A big part of that is ensuring relevant people have the permissions required to access that information, while others do not. &lt;/p&gt;

&lt;p&gt;How does Netflix handle the challenge of &lt;strong&gt;managing its authorization&lt;/strong&gt;? Where does &lt;strong&gt;open-source&lt;/strong&gt; come in? How can you adopt this solution? (Or build something even better) Let’s find out. &lt;/p&gt;

&lt;h2&gt;
  
  
  With Great Power - 
&lt;/h2&gt;

&lt;p&gt;In 1997, Netflix was little more than an upstart DVD rental company. Fast forward two decades, and Netflix has become one of the biggest TV and movie studios in the world. &lt;/p&gt;

&lt;p&gt;As a company grows, the responsibility it has towards its customers grows as well, and security becomes increasingly important with every new user joining the platform. &lt;/p&gt;

&lt;p&gt;The first challenge is authenticating users when they log into the system - that’s &lt;strong&gt;authentication&lt;/strong&gt;. Once users are in the system, the second step is to decide what they have access to - that’s where &lt;strong&gt;authorization &lt;/strong&gt;comes in. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F069ngdsjfne5w9jeejpm.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F069ngdsjfne5w9jeejpm.gif" alt="With Great Power" width="498" height="266"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is authorization critical?
&lt;/h2&gt;

&lt;p&gt;Authorization (Not to be &lt;a href="https://www.permit.io/blog/authn-vs-authz" rel="noopener noreferrer"&gt;confused with authentication&lt;/a&gt;) is the process of managing access to &lt;strong&gt;resources **based on a user's &lt;/strong&gt;identity &lt;strong&gt;and the &lt;/strong&gt;permissions **assigned to that identity. This is typically done by comparing a user's credentials against a set of rules (policies) to determine what they are allowed to access.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorization is crucial for Netflix&lt;/strong&gt; - not only to make sure only paying customers have access to shows but also as &lt;strong&gt;a means of maximizing potential revenue&lt;/strong&gt;. How you may ask? By being able to tailor shows based on specific countries or user interests, by offering purchasing power parity - adjusting their prices in accordance with income levels per country, and more.&lt;br&gt;
 &lt;/p&gt;
&lt;h2&gt;
  
  
  Authorization is a complicated task
&lt;/h2&gt;

&lt;p&gt;Writing authorization policies is quite a complex task. To address this issue, Netflix chose &lt;a href="https://github.com/open-policy-agent/opa" rel="noopener noreferrer"&gt;Open Policy Agent&lt;/a&gt; (OPA) - an open-source general-purpose policy engine that unifies policy enforcement across the stack. &lt;/p&gt;

&lt;p&gt;OPA provides a high-level declarative language called &lt;strong&gt;Rego&lt;/strong&gt; that lets you write policy as code, along with a simple API to offload policy decision-making from your software (As pairing authorization logic with application logic &lt;a href="https://www.permit.io/blog/four-mistakes-you-make-when-building-permissions#2-mixing-up-app-logic-and-authorization" rel="noopener noreferrer"&gt;is a bad idea&lt;/a&gt;). OPA can be used to enforce policies in microservices, Kubernetes, CI/CD pipelines, API gateways, and more.&lt;/p&gt;

&lt;p&gt;The thing is - Rego is quite hard to master, thus limiting the ability to manage policies to a very small chunk of people. Netflix encountered a problem where &lt;strong&gt;very few people in the organization could actually write Rego policies&lt;/strong&gt;, yet they wanted to distribute the ability to create and manage policies across the organization.&lt;/p&gt;
&lt;h2&gt;
  
  
  How did Netflix solve its authorization problem? 
&lt;/h2&gt;

&lt;p&gt;Netflix built a UI on top of OPA, which allowed them to create Rego policies and simplify the process. That solved the issue, but then another problem emerged:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Once the policy was in place, did they actually capture its intent?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;They knew in plain English what they wanted to achieve with the policy, and they proceeded to define it in the UI, but they didn't know if it would actually perform. To solve this issue, Netflix ended up building &lt;strong&gt;unit-testing mechanisms&lt;/strong&gt; for the UI. &lt;/p&gt;

&lt;p&gt;You want a policy to be implemented in the system? Write it, write a test for it, and make sure that the test passes. Before you save and the policy change gets pushed, all the tests are run, and then if they all pass, the changes get applied to production. Voila. &lt;/p&gt;

&lt;p&gt;This allowed Netflix to create a solution on top of open-source components, saving them much of the effort it would take to build a homebrew authorization layer from scratch. Unfortunately - Netflix kept this solution to themselves, never exposing it to a wider audience.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A great video by the CNCF where Manish Mehta and Torin Sandall from Netflix tell the story of how Netflix solved authorization with OPA in much more technical depth:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/R6tUNpRpdnY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How can I implement this solution? 
&lt;/h2&gt;

&lt;p&gt;While Netflix never open-sourced their solution, the solution they built on top of OPA inspired another open-source project: &lt;a href="https://github.com/permitio/opal" rel="noopener noreferrer"&gt;OPAL&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OPAL (Open Policy Administration Layer) is an open-source administration layer for OPA that allows you to easily keep your authorization layer up-to-date in real time. As you push updates to your application's stores (e.g. Git, DBs, S3, SaaS services) OPAL will make sure your services are always in sync with the authorization data and policy they need.&lt;/p&gt;

&lt;p&gt;A similar high-level architecture to Netflix's is expressed within OPAL: &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Aggregator&lt;/strong&gt; is the OPAL server, the &lt;strong&gt;Distributor&lt;/strong&gt; is the split between a server and a client, and the &lt;strong&gt;Updater&lt;/strong&gt; is the OPAL client. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxavxnnjkpjk3u5ck07sd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxavxnnjkpjk3u5ck07sd.png" alt="OPAL Architecture" width="800" height="378"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.opal.ac/overview/architecture" rel="noopener noreferrer"&gt;&lt;em&gt;You can learn more about OPAL’s architecture here&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using this inspired approach allows OPAL to aggregate policy and data from different sources, and integrate them seamlessly into the authorization layer in real-time. The project is free and available to everyone as a public project and is already being used by companies like &lt;strong&gt;Tesla, Cisco, Palo Alto Networks&lt;/strong&gt;, and &lt;strong&gt;Walmart&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;If you want to go even further, &lt;a href="https://www.permit.io/" rel="noopener noreferrer"&gt;Permit.io&lt;/a&gt; provides a no-code UI that allows you to create, manage and enforce Rego policies and is based on a &lt;a href="https://www.permit.io/blog/opal-opa-vs-xacml" rel="noopener noreferrer"&gt;combination of OPA and OPAL&lt;/a&gt;. Allowing you to implement complex RBAC and ABAC policies into your application, and manage them with a simple UI anyone in your organization can use. &lt;/p&gt;

&lt;h2&gt;
  
  
  Help OPAL grow 
&lt;/h2&gt;

&lt;p&gt;OPAL is an ongoing open-source project which is already keeping hundreds of policy agents updated in real-time. You can &lt;a href="https://permit-io.slack.com/" rel="noopener noreferrer"&gt;join OPAL’s Slack community&lt;/a&gt; to chat with other devs who use OPAL for their projects, &lt;a href="https://github.com/permitio/opal" rel="noopener noreferrer"&gt;contribute to the open-source project&lt;/a&gt;, or &lt;a href="https://twitter.com/opal_ac" rel="noopener noreferrer"&gt;follow OPAL on Twitter&lt;/a&gt; for the latest news and updates.&lt;/p&gt;

</description>
      <category>iam</category>
      <category>opa</category>
      <category>opensource</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The four mistakes you make building permissions</title>
      <dc:creator>Daniel Bass</dc:creator>
      <pubDate>Sun, 21 Aug 2022 15:46:00 +0000</pubDate>
      <link>https://dev.to/permit_io/the-four-mistakes-you-make-building-permissions-4nhp</link>
      <guid>https://dev.to/permit_io/the-four-mistakes-you-make-building-permissions-4nhp</guid>
      <description>&lt;p&gt;Access control is a must in almost any application, yet most developers end up building and rebuilding it time and time again - forced to refactor with new customer, product, or security demands coming in. &lt;/p&gt;

&lt;p&gt;Why? Usually, &lt;strong&gt;they make one or more of four crucial mistakes&lt;/strong&gt; that prevent them from having a flexible access control layer that can be upgraded without having to rebuild it every time a new product demand comes in.&lt;/p&gt;

&lt;p&gt;Before we dive into these, we first need to acknowledge that &lt;strong&gt;Permissions are hard, and they're becoming harder&lt;/strong&gt; as the world moves into cloud-native ecosystems and microservices. Let’s try and understand why - &lt;/p&gt;

&lt;h2&gt;
  
  
  What makes permissions complex?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Moving from monoliths to distributed microservices
&lt;/h3&gt;

&lt;p&gt;Back when applications were structured as monoliths, the decision-making process of who connects to what within an application could be baked into one place, usually by using a specific framework such as Spring, Django, or Python.&lt;/p&gt;

&lt;p&gt;When working with &lt;strong&gt;distributed microservices&lt;/strong&gt;, especially in a polyglot structure, these solutions are no longer applicable, so you end up having to sprinkle a bit of access control into every little microservice and component you're building. This creates an issue where &lt;strong&gt;we struggle to upgrade, add capabilities and monitor the code overall as it is replicated between different microservices&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Connecting to 3rd party services
&lt;/h3&gt;

&lt;p&gt;It’s not just about the services you provide anymore: The ability to connect your application to 3rd party services (Like authentication, billing, analytics, machine learning agents, or databases) has become a crucial aspect of building any application - this requires us to manage access control for &lt;strong&gt;elements outside our own cloud&lt;/strong&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  New, complex permission models
&lt;/h3&gt;

&lt;p&gt;The policies, rules, and models we want to enforce permissions with are also becoming more complex. Applications often start with an Admin / Non-Admin model and quickly move to increasingly complex models such as &lt;strong&gt;RBAC&lt;/strong&gt;, &lt;strong&gt;ReBAC&lt;/strong&gt;, and &lt;strong&gt;ABAC&lt;/strong&gt;. Our expectations for applications and the different ways we can collaborate within them have never been higher, creating a need for ever-evolving complex policies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Security and Compliance
&lt;/h3&gt;

&lt;p&gt;If back in the day, doing SOC 2, ISO, or meeting GDPR or CCPA standards was out of the ordinary, today, these standards are common for basically any B2B (and often B2C) application. These standards, along with HIPPA and PCI, all have lots of requirements related to &lt;strong&gt;having checks and balances for your application's access control&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We can significantly reduce the amount of hardship we need to go through to meet compliance standards by implementing good access control. Having a feature like auditing, combined with visibility into your access control level, which you can share with your auditors, security, and compliance, is expected from almost any solution being built - maybe not on day one, but probably quickly down the road. &lt;/p&gt;

&lt;p&gt;If that's not enough, there's a lot of security friction and vulnerabilities surfacing from challenges in building access control. It's no surprise that &lt;strong&gt;&lt;a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/" rel="noopener noreferrer"&gt;broken access control is the top A1 item on OWASP’s list of vulnerability sources&lt;/a&gt;&lt;/strong&gt;, with the highest occurrence across all the surveys. &lt;/p&gt;

&lt;p&gt;Permissions are not only a problem in how we manage and build things, but it is also creating security issues in our production, which we may face as security incidents.&lt;/p&gt;

&lt;p&gt;Now that we understand the depth of the problem, let's jump into the common anti-patterns that people often end up implementing into the access control that they're building, creating security vulnerabilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Antipatterns
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Mixing ‘Auths’ - Authentication VS Authorization
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu1mkr8hrlx6qoud703zu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu1mkr8hrlx6qoud703zu.png" alt="The IAM Waterfall" width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mixing up &lt;strong&gt;authentication&lt;/strong&gt; and &lt;strong&gt;authorization&lt;/strong&gt; is probably the most common pitfall out there. Despite both belonging to the IAM space, the two are very different. In short - the IAM space consists of three parts: &lt;strong&gt;Identity Management&lt;/strong&gt; (IM), &lt;strong&gt;Authentication&lt;/strong&gt; (AuthN), and &lt;strong&gt;Authorization&lt;/strong&gt; (AuthZ). &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Identity management&lt;/strong&gt; solutions like OKTA and Azure Active Directory are used on the &lt;strong&gt;organization side&lt;/strong&gt;, defining different organizational identities and their relationships.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authentication&lt;/strong&gt; is done on the product side, where you &lt;strong&gt;verify identities before allowing them into the product&lt;/strong&gt; (Log in). &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authorization&lt;/strong&gt; is the layer that lets us &lt;strong&gt;enforce and check permissions within the product&lt;/strong&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These three steps trickle down into one another, but we must understand their differences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Role translation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One source of confusion between identity management, authentication, and authorization stems from their use of &lt;strong&gt;Roles&lt;/strong&gt;. The concept of Roles exists through the IAM space, &lt;strong&gt;but the meaning varies in each part&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Identity Management Roles indicate a role within an organization (Like “Head of Marketing” or “Member of Security Team”). These roles are drastically different from those used on the application level (Like “Admin,” “Reader,” or “Viewer”). Translating IM organizational roles into application-level Authorization roles is not always a straightforward process, but it is an issue that clearly needs to be addressed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffve56n68lohtpf12uxr3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffve56n68lohtpf12uxr3.png" alt="Role Translation" width="654" height="638"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The result of this translation (For example - Deciding that our Head of marketing, who is part of the marketing team, should have an editor role for the CMS) &lt;strong&gt;should be saved as part of the JSON web token (JWT) produced by the authentication layer&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;What else should JWTs be used for? Glad you asked.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using JWTs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Basically, &lt;strong&gt;the translation of the IM role into an authorization layer role&lt;/strong&gt; (Or - the translation from an organizational role into an application level role) &lt;strong&gt;should be the only thing included in the JWTs&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Developers often tend to overuse JWTs, sometimes going as far as storing all the routes that a user should access within them. That is a bad idea for several reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Mixing the authentication and authorization layers messes up our code. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Changing roles requires the user to log out and log in again, which can hinder the user experience and overall application performance. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As the JWT is sent for every request with a RESTful API, GraphQL, or any other HTTP-based solution, creating a bloated JWT would significantly slow down the application’s performance. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is a limit to how much data can be stored within a JWT. If we keep adding more rules, we will eventually run out of storage space. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8otkivfxoqo86nmgsi2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8otkivfxoqo86nmgsi2.jpg" alt="Using JWTs" width="517" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The best way to avoid this is to have the JWT &lt;strong&gt;only include the claims and scopes for the user's identity and their relationship within the organization&lt;/strong&gt; and keep all other authorization-related information in a separate layer within the application. &lt;/p&gt;

&lt;p&gt;Speaking of creating a separate layer for authorization, the next common mistake devs make is mixing up &lt;strong&gt;application logic&lt;/strong&gt; with &lt;strong&gt;authorization logic&lt;/strong&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  2. Mixing up App-logic and Authorization
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fllzh1nnz97s1sz26t31h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fllzh1nnz97s1sz26t31h.png" alt="Spaghetti" width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When building an application, we have the logic of &lt;strong&gt;what the application is supposed to do&lt;/strong&gt;, and we have the logic for &lt;strong&gt;who is allowed to perform which actions within it&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The combination of these two logic sets could easily result in us having spaghetti code composed of a mix of unrelated elements. If we will need to upgrade the application or the authorization layer (Which is rather likely to happen at some point), we'll end up having to cherry-pick different elements of code, trying to figure out which are application related and which are authorization related. &lt;/p&gt;

&lt;p&gt;When these two logic sets are combined, they inevitably grow organically and become increasingly cumbersome, &lt;strong&gt;turning any future effort of separating, editing, updating, or upgrading them into a nightmare&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;There’s also an issue of performance here - Let’s say our application checks a user's payment status to approve or deny access to certain features. Checking this every time as part of the application flow could significantly hinder the application’s performance.&lt;/p&gt;

&lt;p&gt;A much better way to approach this issue is to &lt;a href="https://www.permit.io/blog/5-best-practices-for-building-cloud-native-permissions#the-5-best-practices" rel="noopener noreferrer"&gt;decouple our policy from our code&lt;/a&gt;. This way, the authorization layer can run in the background and monitor the user’s payment status. Whenever we want to check that status, it will already be available in the authorization layer, eliminating the need to fetch it every time.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Mixing up your Access control layers
&lt;/h3&gt;

&lt;p&gt;Every application requires multiple layers of access control -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Physical access control&lt;/strong&gt;, like having locks on our doors and windows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Network level access control&lt;/strong&gt;, like firewalls, VPNs, and zero trust networks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Infrastructure level access control&lt;/strong&gt;, like limitations on which services can talk to each other.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And lastly, &lt;strong&gt;application level access control&lt;/strong&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each of these layers has &lt;strong&gt;different demands, requirements, policies, and models&lt;/strong&gt;. Ideally, we would have a unified interface/back-office where we can view, manage and audit all these different layers. The ability to manage them as code would be even better, as it allows us to manage and run tests on them as part of our source control. &lt;/p&gt;

&lt;p&gt;The main mistake we often see developers making in this aspect is combining their application-level access control with a tool that was built to manage infrastructure access control, like AWS IAM. &lt;/p&gt;

&lt;p&gt;Initially, this might look like a great idea - AWS IAM is a very powerful tool that can map many things into objects, which is why engineers use it to map their application-level access control. So why is this not a good idea? Let's look at a specific example. &lt;/p&gt;

&lt;p&gt;We often encounter engineers mapping their application-level access control using SS3 buckets in AWS. Because their data is stored in a bucket anyway, they feel they might as well use the access control for the bucket for the application itself. Although this may sound great on the surface, it's easy to see when things start to go wrong - &lt;/p&gt;

&lt;p&gt;The moment you’ll want to move to a different cloud or even a different storage layer within the same cloud, there’s a good chance you won't want to use the buckets anymore - you’ll want to use RDS, Redshift, or Snowflake. Just because the requirements for your application have changed, &lt;strong&gt;you will have to completely refactor your access control because it was coupled into that specific cloud component infrastructure&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It can also be a major problem to rely too much on how things are built for these specific components. A lot of people rely on the way you configure the API gateway to do enforcements for your application. Sadly, AWS encourages you to put routes inside the JWT - a practice devs end up adopting as something they can take into production in scale and end up regretting in the long run. &lt;/p&gt;

&lt;p&gt;Ultimately, it's important to remember that different access layers have different needs. If we ignore these needs, we might regret it later and end up having to refactor large parts of our applications. &lt;/p&gt;

&lt;h3&gt;
  
  
  4. Thinking that you can solve it once and for all
&lt;/h3&gt;

&lt;p&gt;The last major mistake developers tend to make when thinking about permission building is more of a conceptual one - Thinking they can solve it once and for all. &lt;/p&gt;

&lt;p&gt;Many young companies fall for this misconception and end up rebuilding their access control over and over again instead of developing crucial new features in the application itself. The worst thing about that is that &lt;strong&gt;every time they do it, they think this time will be the last&lt;/strong&gt;. In reality - if you follow even just some of the anti-patterns we described here, there's a good chance that every time a new requirement comes in from a customer, partner, security, or compliance, &lt;strong&gt;you just might have to throw out everything you've built and start from scratch&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The only way to avoid this scenario &lt;strong&gt;is to plan for it&lt;/strong&gt;. Building an ever-growing, ever-developing application, you have to assume that you will have to evolve your authorization layer to support more policies and complex roles. You have to assume you will move from RBAC to ABAC or other even more complicated models and provide interfaces on top of them. &lt;/p&gt;

&lt;p&gt;This doesn’t mean you should try and build a perfect, future-proof permission management system from day one - especially if you are working in a startup company. You’ll just never finish. Instead, focus on setting the right groundwork - &lt;strong&gt;if you plan ahead&lt;/strong&gt; and &lt;strong&gt;avoid the mistakes we discussed in this post&lt;/strong&gt;, you will be able to upgrade your permission layer with much more flexibility - instead of having to rebuild it from scratch every three to six months. &lt;/p&gt;

&lt;p&gt;Most companies go through the same steps - they initially build good schemas for their data layers and authorizations, but gradually, as they move forward, these schemas stop working, and they start facing performance issues. The only way to avoid this is to &lt;strong&gt;decouple your authorization layer from your application’s logic&lt;/strong&gt; and &lt;strong&gt;be ready to update it gradually as demands come in&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's sum everything up -
&lt;/h2&gt;

&lt;p&gt;Whether it's the &lt;strong&gt;move to distributed microservices from monoliths&lt;/strong&gt;, the requirement to &lt;strong&gt;integrate 3rd party services into your application&lt;/strong&gt;, the necessity of &lt;strong&gt;using complex permission models&lt;/strong&gt;, or the &lt;strong&gt;rise of security and compliance requirements&lt;/strong&gt;, permissions have become more complex than ever.&lt;/p&gt;

&lt;p&gt;All of these changes require us to &lt;strong&gt;&lt;a href="https://www.permit.io/blog/5-best-practices-for-building-cloud-native-permissions" rel="noopener noreferrer"&gt;adopt new best practices&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;avoid common mistakes&lt;/strong&gt; developers make when thinking about authorization: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mixing Authentication and Authorization&lt;/strong&gt;, especially when it comes to the somewhat confusing translation of organizational roles into application level ones and the correct usage of JWTs, &lt;strong&gt;mixing up application logic with authorization logic&lt;/strong&gt;, using tools designed for &lt;strong&gt;infrastructure access control&lt;/strong&gt; (like AWS IAM) &lt;strong&gt;to manage application level access control&lt;/strong&gt;, and thinking that we can solve our authorization problems once and for all on day one.&lt;/p&gt;

&lt;p&gt;Most importantly, it's important to understand that developing a good authorization layer in a constantly changing application requires planning ahead and building a flexible solution that can be upgraded without having to rebuild it every time a new product demand comes in.&lt;/p&gt;

&lt;p&gt;Building authorization? Got questions? Come talk to hundreds of developers working on solving their IAM challenges in our &lt;a href="http://www.bit.ly/permitcommunity" rel="noopener noreferrer"&gt;Slack community&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>iam</category>
      <category>permissions</category>
      <category>authorization</category>
      <category>authz</category>
    </item>
    <item>
      <title>How to Implement Multitenancy in Cloud Computing</title>
      <dc:creator>Daniel Bass</dc:creator>
      <pubDate>Thu, 04 Aug 2022 12:15:00 +0000</pubDate>
      <link>https://dev.to/permit_io/how-to-implement-multitenancy-in-cloud-computing-4pif</link>
      <guid>https://dev.to/permit_io/how-to-implement-multitenancy-in-cloud-computing-4pif</guid>
      <description>&lt;p&gt;Cloud-based SaaS solutions, as well as most other solutions, need multi-tenancy. Let’s quickly review what Multitenancy is, what we can gain from it, and how to easily implement it with two simple layers.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Multitenancy
&lt;/h2&gt;

&lt;p&gt;At its core, &lt;strong&gt;multi-tenancy allows every part of the service&lt;/strong&gt; (i.e., every microservice) to &lt;strong&gt;cater to multiple customers without deploying separate instances for each&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For a SaaS solution to scale affordably, meet customer demands, and be elastic in doing so (i.e., cost-effective in cloud resources), it has to support multi-tenancy.&lt;/p&gt;

&lt;p&gt;A multitenant architecture provides many great and often essential features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Allowing the application to serve multiple customers at once while sharing the underlying infrastructure and services&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Secure and compliant access separation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Load balancing and scaling&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The two layers of Multitenancy
&lt;/h2&gt;

&lt;p&gt;At the end of the day, multi-tenancy is easy once you understand it, and it basically requires only two things: &lt;strong&gt;Application level access control&lt;/strong&gt; and &lt;strong&gt;managing data schemas&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's break it down into two planes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The data plane&lt;/strong&gt; is all about how you &lt;strong&gt;transmit&lt;/strong&gt;, &lt;strong&gt;store **and &lt;/strong&gt;manage **the siloed data (i.e., How the underlying infra avoids mixing up the data of different tenants). Multi-tenancy for the data plane is often implemented as partitions on the data layers - e.g., separate partitions, tables, columns, identifiers, and/or labels on the data storage schema (how you save it in the database) and topics (e.g., Kafka topics), tags, domains, sockets, and/or ports, for the data at transit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F08565q1larbi8wp40cqf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F08565q1larbi8wp40cqf.png" alt="Application route enforcing multitenancy" width="800" height="286"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Example of DB tables with simple column-based tenant separation&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The application plane&lt;/strong&gt; is about how you silo context and access within the logical layer, i.e., have the same code work for different tenants. Authorization is the component within the application plane implementing multi-tenancy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frpf69g2s74zt228aod1u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frpf69g2s74zt228aod1u.png" alt="Application route enforcing multitenancy" width="568" height="254"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example application route enforcing multitenancy with Permit.io’s SDK&lt;/em&gt; (&lt;a href="https://github.com/permitio/permit-demo-todos-nodejs/blob/8fc58cf62e8c9afe43891ea65f666e71c0875ff7/src/api-with-permit/src/routes/api/boards.ts#L96" rel="noopener noreferrer"&gt;check it out on Github&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing multi-tenancy
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;An authorization layer&lt;/strong&gt; is the fastest and most reliable way to upgrade from a single-tenant application to a multi-tenant one safely. In addition, the authorization layer can implement separation without requiring changes to the services themselves by applying a policy across all relevant services.&lt;/p&gt;

&lt;p&gt;Choosing the right policy model can simplify this transition even further, with classic models like &lt;strong&gt;RBAC + Tenancy, ReBAC + Hierarchy&lt;/strong&gt; (tenants becoming root-level relationships), or plain vanilla *&lt;em&gt;ABAC *&lt;/em&gt;(with tenancy as an attribute).&lt;/p&gt;

&lt;p&gt;The great thing is we don’t need to implement multi-tenancy authorization on our own, and instead can enjoy ready-made open-source tools and services.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing multi-tenancy with OPA + OPAL (Open-Source)
&lt;/h2&gt;

&lt;p&gt;Open source is a great option to start implementing your authorization layer for multi-tenancy. While there are multiple options, Open Policy Agent (OPA) is among the most promising.&lt;br&gt;
OPA acts as an authorization microservice that we can add to our application and use to enforce access with rules written in its proprietary &lt;a href="https://www.permit.io/blog/implement-rbac-using-opa" rel="noopener noreferrer"&gt;Rego language&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Combining &lt;a href="//opal.ac"&gt;OPA with OPAL&lt;/a&gt; (Open Policy Administration Layer) enables us to manage our authorization layer in scale, using Pub/Sub topics to keep our agents up to date with policy (Rego code) and data (JSON documents). The topics, for example, can be our tenant names or IDs, allowing us to sync our agents with changes per tenant. &lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing multi-tenancy with Permit.io (Service)
&lt;/h2&gt;

&lt;p&gt;App authorization solutions (Such as &lt;a href="//permit.io"&gt;Permit.io&lt;/a&gt; 😇 ) solve the application aspect out of the box and layer easily on-top of the data plane by providing (or correlating according to) unique identifiers that can be used to partition the data plane.&lt;br&gt;
⁠&lt;br&gt;
Permit builds on top of &lt;a href="//opal.ac"&gt;OPA and OPAL&lt;/a&gt;, adding management interfaces, including a tenants list,  tenant resource management, and per tenant user management.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5j35p69c1evy72114054.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5j35p69c1evy72114054.png" alt="Permit.io multitenancy dashboard" width="800" height="314"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Switching between tenants in Permit.io’s dashboard&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  To sum things up - 
&lt;/h2&gt;

&lt;p&gt;Multi-tenancy allows our application to &lt;strong&gt;cater to multiple customers without deploying separate instances for each&lt;/strong&gt;. Multi-tenancy enforcement in gist consists of two planes: data and application. One of the best ways to achieve Multi-tenancy is by creating an &lt;strong&gt;authorization layer&lt;/strong&gt; that can implement separation without requiring changes to the services themselves. Although you can build your own authorization layer, there are also &lt;strong&gt;open-source&lt;/strong&gt; options (Such as OPA + OPAL) and *&lt;em&gt;Services *&lt;/em&gt;(Such as Permit.io) that allow you to implement one in your application - making the critical shift into multi-tenancy more accessible.&lt;/p&gt;

&lt;p&gt;Considering multitenancy for your app? Got questions? &lt;a href="//bit.ly/permitcommunity"&gt;Join our Slack community&lt;/a&gt; and chat with fellow developers building authorization!&lt;/p&gt;

</description>
      <category>multitenancy</category>
      <category>permissions</category>
      <category>authorization</category>
      <category>cloud</category>
    </item>
    <item>
      <title>OPAL + OPA VS XACML</title>
      <dc:creator>Daniel Bass</dc:creator>
      <pubDate>Thu, 19 May 2022 12:57:19 +0000</pubDate>
      <link>https://dev.to/permit_io/opal-opa-vs-xacml-5946</link>
      <guid>https://dev.to/permit_io/opal-opa-vs-xacml-5946</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Way back in 2013, various devs were either &lt;a href="https://www.forrester.com/blogs/13-05-07-xacml_is_dead/" rel="noopener noreferrer"&gt;announcing&lt;/a&gt; or &lt;a href="https://www.kuppingercole.com/blog/kuppinger/another-dead-body-in-it-or-is-xacml-still-alive" rel="noopener noreferrer"&gt;debating&lt;/a&gt; the death of XACML - yet XACML’s goal to promote a common terminology and interoperability between authorization implementations remains valid, and it still serves as a solid base to describe the structure of authorization architectures.&lt;/p&gt;

&lt;p&gt;The IAM landscape, authorization included, has &lt;a href="https://www.permit.io/blog/authorization-is-changing" rel="noopener noreferrer"&gt;evolved drastically in the past couple of years&lt;/a&gt; and allowed for new XACML alternatives to be created. This significant shift was a result of the rising demand for increasingly advanced authorization, which was generated by the growing complexity of applications and their migration to microservices and cloud-native structures. With advancements in technology, the emergence of shift-left and low/no-code developers, and the need for event-driven dynamic authorization - a replacement for XACML had to evolve. &lt;/p&gt;

&lt;p&gt;One such XACML alternative is OPA + OPAL. &lt;a href="https://www.openpolicyagent.org/" rel="noopener noreferrer"&gt;Open Policy Agent&lt;/a&gt; (OPA) is an open-source project created as a general-purpose policy engine to serve any policy enforcement requirements that unifies policy enforcement across the stack without being dependent on implementation details. It can be used with any language and network protocol, supports any data type, and evaluates and returns answers quickly. OPA’s policy rules are written in Rego - a high-level declarative (Datalog-like) language. You can find a more detailed introduction to OPA &lt;a href="https://www.permit.io/blog/introduction-to-opa" rel="noopener noreferrer"&gt;here&lt;/a&gt;. It’s important to note that OPA itself only provides an alternative to XACML’s PDP (More on that further). OPA is enhanced by &lt;a href="http://opal.ac/" rel="noopener noreferrer"&gt;OPAL &lt;/a&gt;(Open Policy Administration Layer) - another open-source solution that allows you to easily keep your authorization layer up-to-date in real-time. More information about the project is available &lt;a href="https://www.permit.io/blog/introduction-to-opal" rel="noopener noreferrer"&gt;here&lt;/a&gt;. The combination of OPA and OPAL provides a solid alternative for XACML. &lt;/p&gt;

&lt;p&gt;To better understand this alternative, we’ll compare the traditional XACML architecture authorization flow with the one provided by OPA + OPAL and then discuss the differences. It's important to note that while being a primarily Attribute-Based Access Control (ABAC) system XACML can also be used to describe Role-Based Access Control (RBAC) and other models.&lt;/p&gt;

&lt;h2&gt;
  
  
  A few basic terms to understand the flow:
&lt;/h2&gt;

&lt;p&gt;The architecture of XACML consists of a few different modules that make up the process of making authorization decisions. Let’s take a look at those different parts: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PEP - “Policy Enforcement Point”: &lt;/strong&gt;&lt;br&gt;
The PEP intercepts a user’s access to a resource, and either grants or denies access to the resource requested by the user. PEPs don't make the decisions; they enforce them.&lt;br&gt;
PEPs can potentially also adjust requests or their results before passing them through (aka data-filtering). Examples of PEPs are in-code control flow (i.e. “if”), middleware, reverse proxies, and API gateways.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PDP - “Policy Decision Point”:&lt;/strong&gt;&lt;br&gt;
The PDP evaluates authorization requests against relevant policies and a data snapshot aggregated from the distributed data layer and makes an authorization decision. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PAP - “Policy Administration Point”:&lt;/strong&gt;&lt;br&gt;
⁠The PAP is in charge of managing all relevant policies to be used by the PDP.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PIP - “Policy Information Point”:&lt;/strong&gt;&lt;br&gt;
The PIP is any data source (Internal or external) that contains attributes that are relevant for making policy decisions. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PRP - “Policy Retrieval Point”:&lt;/strong&gt;&lt;br&gt;
⁠The PAP is the main source of policies - it stores all relevant policies to be used by the PDP, and is managed by the PAP (In OPA it's a bundle-server, and in OPAL this is often a Git repository or an HTTP bundle server). &lt;/p&gt;

&lt;h2&gt;
  
  
  Traditional XACML Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb7fu94fb2bhvanadl3q8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb7fu94fb2bhvanadl3q8.png" alt="XACML" width="655" height="630"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s start by reviewing the architecture of traditional XACML and its authorization flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Everything starts with a user (or automated entity) interacting with an application.&lt;/strong&gt; The user sends a &lt;strong&gt;request&lt;/strong&gt; to access and perform an action on any sort of resource within the application. Before being submitted to the application logic, the request passes through the PEP. The PEP is in charge of either granting or denying a user’s request for access to the resource.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The PEP translates the user's request into an XACML authorization request. It is important to note that one user request can trigger multiple authorization queries (as it interacts with multiple resources).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To know whether the request should be approved or rejected, the PEP sends the authorization request to the PDP.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The PDP makes make authorization decisions based on pre-configured XACML formatted policies.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The policies are stored in the PRP and are managed by the PAP.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If needed - the PDP queries relevant PIPs &lt;strong&gt;per query&lt;/strong&gt; for any additional relevant information. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The PDP reaches a decision (Permit / Deny / etc.) and returns it to the PEP.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The user is either granted or denied access to the resource by the PEP, based on the PDP’s decision.&lt;br&gt;
⁠ &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  OPA + OPAL Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6aowm27l8a9ftxz1uo1r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6aowm27l8a9ftxz1uo1r.png" alt="OPA_OPAL" width="656" height="630"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While based on similar principles, OPA and OPAL provide a slightly different authorization model with significant benefits:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The first step is identical to XACML - the user / automated entity sends a request and it passes through the PEP.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The PEP converts the user's request into queries for the PDP (In this case - OPA).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The queries are submitted by the PEP to the PDP (OPA) to know whether the request should be approved or rejected. So far so good - here is where things are a bit different. First of all, OPA stores all relevant policies within its cache. Second - the policies are represented as code (In Rego), unlike XACML where they are represented as configuration (as XML schema).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The PAP (In this case - the OPAL Server) serves a dual function. It both functions as a Policy Administration Point and a Policy Information Administration Point. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;4.1 &lt;strong&gt;As a Policy Administration Point&lt;/strong&gt; - The OPAL server is in charge of managing all relevant policies and supplying them to OPA, within the PDP.&lt;/p&gt;

&lt;p&gt;Policies are stored as code in a GIT repository (default option, though others exist), which acts as the PRP. The OPAL Server receives policy updates from the PRP and instructs the OPAL clients to update OPAs’ caches accordingly. Every time a change in a policy happens in GIT, it is pulled by the OPAL Server and pushed into OPA’s cache via the OPAL clients which listen to the server (based on topics) and are located next to the OPA instances. By leveraging GIT and policy as code, OPAL allows us to use Gitops best practices (e.g. tests, code-review, benchmarking) &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In this manner, OPA always stays up to date with the latest policy changes in real-time without the need for redeployment.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;4.2 &lt;strong&gt;As a Policy Information Administration Point&lt;/strong&gt; - the OPAL server informs the OPAL Client within the PDP on changes to data within the PIPs according to selected topics. With the updates to the client, the server sends instructions on how to query the PIPs, and the OPAL Client fetches the data directly from the PIPs (according to the instructions) and updates OPA with the most recent information. As this process is continuous, &lt;strong&gt;the information stored in the PDP cache is always up to date with the latest data needed to make access decisions in the most accurate way possible&lt;/strong&gt;. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The PDP (OPA) reaches a decision (Permit / Deny / etc.) and returns it to the PEP.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Based on the decision made by the PDP (OPA), the PEP either grants or denies the user’s access to the resource. &lt;br&gt;
⁠&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The differences
&lt;/h2&gt;

&lt;p&gt;From the differences in the authorization flow between the traditional XACML and OPA+OPAL, we can note three significant benefits which the latter provides:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;XACML&lt;/th&gt;
&lt;th&gt;OPA+OPAL&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Policy&lt;/td&gt;
&lt;td&gt;XAXML Configuration&lt;/td&gt;
&lt;td&gt;Rego code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PDP&lt;/td&gt;
&lt;td&gt;-------------------&lt;/td&gt;
&lt;td&gt;OPA (+OPAL Client)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PAP&lt;/td&gt;
&lt;td&gt;-------------------&lt;/td&gt;
&lt;td&gt;OPAL server&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PRP&lt;/td&gt;
&lt;td&gt;-------------------&lt;/td&gt;
&lt;td&gt;GIT (Or any other policy source)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Policy loading&lt;/td&gt;
&lt;td&gt;As part of the deployment&lt;/td&gt;
&lt;td&gt;Real-time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Paragraph&lt;/td&gt;
&lt;td&gt;As part of a query&lt;/td&gt;
&lt;td&gt;Real-time&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The OPAL server’s ability to receive updates from GIT (Or any other policy source) keeps OPA up to date with the most recent policies - &lt;strong&gt;allowing us to make policy changes on the fly and have them utilized by the PDP with minimal latency&lt;/strong&gt;. Leveraging policy as code within a GIT repository enables the adoption of configuration as code and Gitops in general.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The OPAL server not only manages the policies themselves, but also the PIPs from which additional data is often required to make a policy decision. The OPAL Client constantly listens to changes in relevant PIPs (Internal or external databases) and uses data fetchers to keep OPA’s cache constantly up to date with the latest information needed to reach an authorization decision. Because this is an ongoing process and not done per query, &lt;strong&gt;OPA can have all the relevant information in its cache to make policy decisions even if the PIP is not available&lt;/strong&gt; - preventing the PDP from making the authorization decision. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;While not evident from the authorization flow which we described, it is important to note that policy in Rego is much more accessible and easier to read/maintain than in XACML. Check out this example: (For a more detailed explanation of this example &lt;a href="https://www.permit.io/blog/implement-rbac-using-opa" rel="noopener noreferrer"&gt;check out this guide&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyet815zkona43n1ichqe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyet815zkona43n1ichqe.png" alt="XACML_VS_REGO" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Same policy side to side - Rego and XACML&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The differences between Traditional XACML and OPA+OPAL highlight the drastic changes in the authorization space that occurred in recent years. OPAL’s ability to receive both data and policy updates in real-time allows for the creation of event-driven dynamic authorization. At the same time, OPA provides the ability to define more complex authorization structures fit for microservices and cloud-native structures, and its policy language Rego is easier to read/maintain and provides accessibility to low/no-code developers. &lt;/p&gt;

&lt;p&gt;OPAL is a mature open-source project which is already keeping hundreds of policy agents updated in real-time. You can join &lt;a href="https://permit-io.slack.com/" rel="noopener noreferrer"&gt;OPAL’s Slack community&lt;/a&gt; to chat with other devs who use OPAL for their projects, &lt;a href="https://github.com/permitio/opal" rel="noopener noreferrer"&gt;contribute to the open-source project&lt;/a&gt;, or &lt;a href="https://twitter.com/opal_ac" rel="noopener noreferrer"&gt;follow OPAL on Twitter&lt;/a&gt; for the latest news and updates.&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>xacml</category>
      <category>opa</category>
      <category>authorization</category>
    </item>
    <item>
      <title>Real-time dynamic authorization - an introduction to OPAL</title>
      <dc:creator>Daniel Bass</dc:creator>
      <pubDate>Thu, 28 Apr 2022 09:33:55 +0000</pubDate>
      <link>https://dev.to/permit_io/real-time-dynamic-authorization-an-introduction-to-opal-4064</link>
      <guid>https://dev.to/permit_io/real-time-dynamic-authorization-an-introduction-to-opal-4064</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;OPAL is an &lt;a href="https://github.com/permitio/opal" rel="noopener noreferrer"&gt;open-source&lt;/a&gt; administration layer for &lt;a href="https://www.openpolicyagent.org/" rel="noopener noreferrer"&gt;Open Policy Agent&lt;/a&gt; (OPA) that allows you to easily keep your authorization layer up-to-date in real-time. OPAL detects changes to both policy and policy data and pushes live updates to your agents - bringing open policy up to the speed needed by live applications.&lt;/p&gt;

&lt;p&gt;As your application state changes (whether it's via your APIs, DBs, git, S3, or 3rd-party SaaS services), OPAL will make sure your services are always in sync with the authorization data and policy they need.&lt;/p&gt;

&lt;h2&gt;
  
  
  The challenge of building authorization
&lt;/h2&gt;

&lt;p&gt;Cloud-native / microservice-based products can be quite complicated, and so is building access control and managing permissions for them. Distributed applications and microservices require a lot of authorization points by design and the ever-changing requirements and regulations from various departments constantly challenge every authorization solution. Moreover, even the simplest miscalculation in the authorization layer can lead to devastating consequences for your application in the form of security vulnerabilities and privacy/compliance issues. &lt;/p&gt;

&lt;p&gt;There are &lt;a href="https://www.permit.io/blog/5-best-practices-for-building-cloud-native-permissions" rel="noopener noreferrer"&gt;several best practices&lt;/a&gt; for building an authorization layer correctly (and avoiding the need to constantly rebuild it) - the first of which is decoupling policy and code. In short - Having the code of the authorization layer mixed in with the code of your application can result in trouble upgrading, adding capabilities, and monitoring the code as it is replicated between different microservices. Each change would require us to refactor large areas of code that constantly continue to drift further from one another as these microservices develop. &lt;/p&gt;

&lt;p&gt;To avoid this, we recommend creating a separate microservice for authorization that will be used by the other services in order to fulfill their authorization needs. Open Policy Agent (OPA), which is the default policy engine for OPAL, allows you to do just that. You can read more about OPA &lt;a href="https://dev.to/permit_io/an-introduction-to-opa-3ggk"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Another best practice, which OPA alone does not fulfill, is making your authorization layer event-driven.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv4jhbmeftvagli1cpumm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv4jhbmeftvagli1cpumm.png" alt="XACML" width="800" height="615"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why event-driven?
&lt;/h2&gt;

&lt;p&gt;Almost all modern applications rely on abilities such as user invites, role assignment, or the usage of 3rd party data sources. All of these abilities have one thing in common: &lt;strong&gt;They have to be managed in a real-time fashion&lt;/strong&gt;. Every time an event that affects authorization happens, we need it to be pushed into our authorization layer ASAP so it can stay in sync with the application, any relevant 3rd party data service, or changes in policy. &lt;/p&gt;

&lt;p&gt;Here’s an example - Say you want to control who has access to a specific feature in your application based on a user’s payment status. If the user paid for the feature - they have access. This scenario creates three main challenges:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The data about the payment status of users (As well as various other types of data relevant to making authorization decisions) often resides in a database external to your organization, or a 3rd party service like Stripe or PayPal. You need your authorization layer to be aware of any relevant changes in these databases and make decisions based on the most up-to-date information available. To achieve this, we’d need something that listens to changes in the data sources relevant to us, and pulls them into our authorization layer so it can make the most accurate, relevant, and up-to-date decisions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Delays in updates to the authorization snapshot can create consistency problems. Consider this example - a request is being handled by two microservices in the same chain. The first microservice can consider the request in one state (e.g. This user is not a paying user), while the following microservice considers the request in another state. This can cause the overall request to fall into an undefined state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Different microservices need different subsets of policy and data, just keeping track of the needs of each one can be challenging without an event stream to guide us.  &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Being a common problem, large organizations such as Netflix and Pinterest who rely on OPA as their policy engine were required to create their own solutions, building multiple administration layers on top of OPA. Manish Mehta, a senior security officer from Netflix, shared &lt;a href="https://youtu.be/R6tUNpRpdnY?t=915" rel="noopener noreferrer"&gt;Netflix’s permissions design in a talk at KubeCon&lt;/a&gt;. Unfortunately, these giants haven’t open-sourced their solutions; but their work did inspire the creation of OPAL.&lt;br&gt;
⁠&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj9wpo73s1708dltwbyeu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj9wpo73s1708dltwbyeu.png" alt="Netflix at KubeCon 2017" width="800" height="484"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;How Netflix uses OPA in permissions enforcement talk at KubeCon, 2017.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How OPAL helps solve these challenges: 
&lt;/h2&gt;

&lt;p&gt;OPAL is an open-source solution that helps us solve these two challenges by providing two significant features: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The ability to track a &lt;strong&gt;designated policy repository&lt;/strong&gt; (Such as GitHub, GitLab, Bitbucket) for changes (by either setting a webhook or web polling every X seconds), thus serving as a PAP (Policy Administration Point) and propagating these changes into OPA (The PDP - Policy Decision Point in this case) thus always keeping it up to date.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The ability to track &lt;strong&gt;any relevant data source&lt;/strong&gt; (API, Database, external service) for updates via REST API, and fetch up-to-date data back into OPA. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These two features make sure that OPA is always up to date with both the latest policy information and the latest data - allowing it to always make the most accurate and relevant authorization decisions.&lt;br&gt;
  &lt;br&gt;
OPAL’s ability to solve these challenges led to its adoption by a number of leading organizations such as Tesla, Zapier, and Accenture.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does it work? A little deep dive into OPAL’s architecture:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjo9ki5s8y5zjp9t7esoc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjo9ki5s8y5zjp9t7esoc.png" alt="OPAL Architecture" width="800" height="378"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OPAL consists of two main components: the &lt;strong&gt;OPAL Server&lt;/strong&gt; and the &lt;strong&gt;OPAL Client&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The OPAL Server&lt;/strong&gt; is responsible for two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It tracks a designated policy repository for changes via webhook or polling for policy updates and pushes these changes to the OPAL Client. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It tracks all relevant data sources for changes via webhook, signals the OPAL Client about any changes via WebSocket, and provides it with information on where the data is located. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In both of these cases, the OPAL server creates a pub/sub channel that the OPAL client(s) can subscribe to with topics they need to track. As soon as there’s a change, the OPAL server notifies the subscribed clients. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The OPAL client&lt;/strong&gt; is deployed alongside OPA and provides real-time updates of all relevant data and policy from the OPAL Server to OPA, so it also has a dual function:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Policy changes&lt;/strong&gt;: Whenever there is a relevant policy update in the policy repository, it is pulled by the client from the server, and propagated into OPA. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data updates&lt;/strong&gt;: Whenever there’s a relevant data update in a topic that the OPAL client is registered to, the OPAL server will push an update to the OPAL client with information on where to pull the newly updated data from. The client will then reach out to fetch the latest relevant data with the help of &lt;strong&gt;OPAL Data Fetchers&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;OPAL Data Fetchers are configured to grab updates from a specific data source. A data fetcher has two main methods: &lt;code&gt;fetch()&lt;/code&gt;, which is in charge of querying the data source, and &lt;code&gt;process()&lt;/code&gt; to filter the data and convert it to JSON format, OPA’s format. The OPAL Data fetchers retrieve any relevant data from their designated data source and propagate it to OPA. &lt;/p&gt;

&lt;p&gt;Another important feature of the OPAL client is its ability to only subscribe to the specific data that it needs. If your application requires large amounts of data to support authorization logic, the OPAL client can subscribe only to the specific parts needed for that specific agent - this provides benefits both in terms of security (By keeping access to data on a “need-to-know” basis) and manageability. &lt;/p&gt;

&lt;p&gt;This way, OPA is able to make policy decisions based on the most recent policies and data. A deeper dive into OPAL’s architecture and communication flows is available in &lt;a href="https://github.com/permitio/opal/blob/master/docs/architecture.md" rel="noopener noreferrer"&gt;OPAL’s documentation&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keeping OPA up to date in real-time is crucial&lt;/strong&gt;, especially when dealing with authorization at the application level. By using OPAL we enhance OPA’s authorization capabilities with two major abilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Updating our policies in real-time&lt;/strong&gt;, and having our authorization decisions made on the most up-to-date policies available. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pulling relevant data from any source&lt;/strong&gt;, thus being able to make authorization decisions based on data from any Database or service. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Help us grow - 
&lt;/h2&gt;

&lt;p&gt;OPAL is an ongoing open-source project which is already keeping hundreds of policy agents updated in real-time. You can join &lt;a href="https://permit-io.slack.com/" rel="noopener noreferrer"&gt;OPAL’s Slack community&lt;/a&gt; to chat with other devs who use OPAL for their projects, &lt;a href="https://github.com/permitio/opal" rel="noopener noreferrer"&gt;contribute to the open-source project&lt;/a&gt;, or &lt;a href="https://twitter.com/opal_ac" rel="noopener noreferrer"&gt;follow OPAL on Twitter&lt;/a&gt; for the latest news and updates.&lt;/p&gt;

</description>
      <category>authorization</category>
      <category>permissions</category>
      <category>iam</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Authorization is changing - how we can harness the benefits?</title>
      <dc:creator>Daniel Bass</dc:creator>
      <pubDate>Sun, 13 Feb 2022 10:46:38 +0000</pubDate>
      <link>https://dev.to/permit_io/achieving-modern-authorization-4pi5</link>
      <guid>https://dev.to/permit_io/achieving-modern-authorization-4pi5</guid>
      <description>&lt;p&gt;The landscape of authorization has changed drastically in the last few years - Today’s applications require complex authorization systems and call for well-designed, adaptive solutions. In this post we will try to answer what changed, both in terms of the challenges and the solutions, and how we can adapt to these changes.&lt;/p&gt;

&lt;p&gt;But first, before we dive into this - let’s establish the space that we're going to be discussing:&lt;/p&gt;

&lt;h1&gt;
  
  
  The IAM landscape
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;IAM (Identity Access Management)&lt;/strong&gt; is composed of three separate parts: &lt;strong&gt;Identity management&lt;/strong&gt;, &lt;strong&gt;Authentication&lt;/strong&gt; (AuthN), and &lt;strong&gt;Authorization&lt;/strong&gt; (AuthZ). &lt;/p&gt;

&lt;h2&gt;
  
  
  Identity management
&lt;/h2&gt;

&lt;p&gt;⁠⁠Identity management is about being able to tell who's part of your organization, what attributes they have, and which departments they belong to. This allows you to &lt;strong&gt;create identities&lt;/strong&gt; that can be aggregated and managed in a unified interface.&lt;/p&gt;

&lt;h2&gt;
  
  
  Authentication
&lt;/h2&gt;

&lt;p&gt;⁠⁠Authentication is all about &lt;strong&gt;verifying the identity&lt;/strong&gt; of the person connecting to your product. These are designated to monitor who has access to the product itself. &lt;/p&gt;

&lt;h2&gt;
  
  
  Authorization
&lt;/h2&gt;

&lt;p&gt;⁠⁠Once a user has logged in to the product, authorization handles deciding &lt;strong&gt;who&lt;/strong&gt; can do &lt;strong&gt;what&lt;/strong&gt; and in &lt;strong&gt;what context&lt;/strong&gt; within the product.&lt;/p&gt;

&lt;p&gt;As you can see, each stage relies on information gathered from the previous one. ⁠A more detailed introduction to the IAM waterfall can be found &lt;a href="https://www.permit.io/blog/what-is-authorization" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;/p&gt;



&lt;h1&gt;
  
  
  Building (and re-building) authorization
&lt;/h1&gt;

&lt;p&gt;Up until recently, developers have mostly been building authorization by themselves from scratch. As a developer, you might think - &lt;/p&gt;

&lt;p&gt;“Ok, so I’ll start off with two types of users: Admin, and non-admin, and make decisions based on this distinction”.&lt;/p&gt;

&lt;p&gt;Then, a user comes in and asks you to create an editor role.&lt;br&gt;
⁠So you rebuild your authorization system to allow an editor role. &lt;/p&gt;

&lt;p&gt;Later, stakeholders from your company ask you for access to audit logs, and the ability to monitor them on their side.&lt;br&gt;
So you rebuild your authorization system to allow that as well. &lt;/p&gt;

&lt;p&gt;Then sales approach you and ask you to create an impersonation tool that allows them to see the system from a different perspective. &lt;br&gt;
And you rebuild again.&lt;/p&gt;

&lt;p&gt;Another stakeholder asks you for their own back-office that will allow them to manage new users they onboard into the system.&lt;br&gt;
 &lt;br&gt;
You see where we’re going with this. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9pmaz4w987rf5hjy7zl4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9pmaz4w987rf5hjy7zl4.png" alt="Rebuilding Authorization" width="800" height="794"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As your product evolves, building authorization yourself requires you to keep rebuilding it time after time in order to adapt it. From the very beginning, you have to ask yourself - Who can access my application, work with it at the infrastructure level, manage it as the developer or work with it as a user?  The answer to this question will help you determine how complex the authorization building process will be.&lt;/p&gt;



&lt;h1&gt;
  
  
  How microservices changed AuthZ
&lt;/h1&gt;

&lt;p&gt;If you look at this issue in the context of the emergence of microservices, it becomes even more complicated. When you built a monolith application, you had the ability to bake in the decision-making process of who connects to what within the application into just one place - usually by using a  specific framework such as Spring, Django, or Python. As you start breaking an application into multiple services, you end up having to replicate the authorization code across each and every microservice. And each time you want to restructure, change something, or add another feature, you have to do it in each microservice separately.&lt;br&gt;
 &lt;br&gt;
The rising demand for increasingly advanced authorization, the rising complexity of the applications themselves, and their migration to microservices and cloud-native structures magnified the pain of building authorization into the application itself. &lt;/p&gt;

&lt;p&gt;The good news is that the field of authorization is adapting, and new solutions to resolve these issues are beginning to develop. These become available now thanks to the overall evolution of the cloud space, both in technology and mindset. &lt;/p&gt;



&lt;h1&gt;
  
  
  Rethinking services, new technology, and a shift-left midset.
&lt;/h1&gt;

&lt;p&gt;There have been a couple of major developments that allow us to view authorization differently: &lt;strong&gt;An advancement in technology&lt;/strong&gt;, a &lt;strong&gt;change of approach towards microservices&lt;/strong&gt;, and the emergence of &lt;strong&gt;shift-left and low/no-code developers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In terms of &lt;strong&gt;technology&lt;/strong&gt;, to create significant changes in authorization we needed the previous layers - identity management and authentication to be working well. Until we had SAML and SSO connect between identity management and authentication, that entire area wasn't stable enough to build upon. The maturity of those standards enabled the entire Authentication space to blossom almost a decade ago, and now again with Passwordless. Before we had standards like the JSON Web Token in the authentication layer, it was basically impossible to connect to it in a standardized way. JSON Web Tokens (JWT), which only became mature in recent years, are a great way to communicate from the authentication layer into the application, and specifically into the authorization layer. &lt;/p&gt;

&lt;p&gt;The authentication process ends when the JWT is handed to the application - specifically, to the authorization layer within it. While the authentication layer provides claims that affect the access policy, it's still up to the authorization layer to translate and enforce those claims based on the JWT and, often, additional context data. &lt;/p&gt;

&lt;p&gt;In terms of thinking about &lt;strong&gt;services&lt;/strong&gt;, if you go back five years, people were still thinking things like billing, authentication, or databases, being core and critical, require developers to implement them themselves. Thanks to companies like Stripe, Auth0, and MongoDB, developers have realized how complex these issues are, and how problematic it is to try and build them yourself. Thus, a mindset of adopting critical services as part of an application you're building became legitimate. Moreover - it became a consensus that you &lt;strong&gt;have to&lt;/strong&gt; adapt these kinds of solutions since the risk of making mistakes when trying to build them yourself just isn’t worth it.&lt;br&gt;
 &lt;br&gt;
The overall trend of &lt;strong&gt;shift-left&lt;/strong&gt;, which has been discussed in the security sphere ad nauseam, and the increasing number of people who are becoming &lt;strong&gt;low/no-code&lt;/strong&gt; developers (eg. product, security, compliance) makes it critical for us to enable them to work on such fundamental experiences as access control. &lt;/p&gt;

&lt;p&gt;So what can be done about this?&lt;/p&gt;



&lt;h1&gt;
  
  
  Modern authorization, finally.
&lt;/h1&gt;

&lt;p&gt;This new reality has created an understanding that new solutions to resolve these issues should be built. Thankfully, the developer community has started creating these solutions with open source projects (e.g. &lt;a href="https://www.openpolicyagent.org/" rel="noopener noreferrer"&gt;OPA&lt;/a&gt;, &lt;a href="//opal.ac"&gt;OPAL&lt;/a&gt;). This way, you can adopt them as building blocks into your application without paying anything, and more importantly, they allow you to implement practices that prevent you from repeating the mistakes of the past. &lt;/p&gt;

&lt;p&gt;The most important matter here is that while building applications, we &lt;strong&gt;understand the complexities&lt;/strong&gt; that come with creating a functional authorization layer, and &lt;a href="https://www.permit.io/blog/5-best-practices-for-building-cloud-native-permissions" rel="noopener noreferrer"&gt;the best practices&lt;/a&gt; that should be implemented while building it in order to avoid constantly having to rebuild them.&lt;/p&gt;

&lt;p&gt;There are already &lt;strong&gt;good ready-made solutions&lt;/strong&gt; (e.g. &lt;a href="http://permit.io" rel="noopener noreferrer"&gt;Permit.io&lt;/a&gt;)  out there - as open-source or as services that you can build upon while avoiding common mistakes. You can also approach this by building it yourself,  but if you choose to do so, you have to do it right.&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary 
&lt;/h1&gt;

&lt;p&gt;The drastic changes in the landscape of authorization over the last few years make it necessary for us to change our mindset and adopt new best practices in order to avoid constantly rebuilding authorization. The advancement in technology, a change of approach towards microservices, and the emergence of shift-left and low/no-code developers created an environment in which we can adopt existing solutions and use them as building blocks for our applications.&lt;/p&gt;

</description>
      <category>iam</category>
      <category>authorization</category>
      <category>microservices</category>
      <category>auth</category>
    </item>
    <item>
      <title>How to Implement Attribute Based Access Control (ABAC) using Open Policy Agent (OPA)</title>
      <dc:creator>Daniel Bass</dc:creator>
      <pubDate>Mon, 17 Jan 2022 12:13:40 +0000</pubDate>
      <link>https://dev.to/permit_io/how-to-implement-attribute-based-access-control-abac-using-open-policy-agent-opa-3ek4</link>
      <guid>https://dev.to/permit_io/how-to-implement-attribute-based-access-control-abac-using-open-policy-agent-opa-3ek4</guid>
      <description>&lt;p&gt;Building authorization can be a complicated endeavor. There are different models for building authorization and different ways of implementing them. At the end of the day, only one thing matters - we want the &lt;strong&gt;right person&lt;/strong&gt; to have the &lt;strong&gt;right access&lt;/strong&gt; to the &lt;strong&gt;right asset&lt;/strong&gt;.&lt;br&gt;
 &lt;br&gt;
For this purpose, we want to review a couple of &lt;strong&gt;authorization models&lt;/strong&gt; (ABAC and RBAC), and then explain how (and why) should you implement them using Open Policy Agent - which allows you to create a separate microservice for authorization, decoupling our policy from our code.&lt;br&gt;
⁠&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  So why ABAC and RBAC?
&lt;/h2&gt;

&lt;p&gt;ABAC and RBAC are the two most basic and commonly used authorization models, and they provide the baseline for most other complex and specific ones. Let’s start by getting to know them a little better:&lt;br&gt;
⁠&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  What is RBAC?
&lt;/h2&gt;

&lt;p&gt;Role-based access control (RBAC), is an authorization model used to determine access control based on predefined roles. Permissions are assigned onto roles (Like “Admin or “User”), and roles are assigned to users by the administrator. This structure allows you to easily understand who has access to what.&lt;br&gt;
 &lt;br&gt;
The combination of three elements - &lt;strong&gt;who &lt;/strong&gt;(What role are they assigned?) can do &lt;strong&gt;what &lt;/strong&gt;(What actions are they allowed to perform) with a &lt;strong&gt;resource &lt;/strong&gt;(Which resources) is called a &lt;strong&gt;policy&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.permit.io/blog/implement-rbac-using-opa" rel="noopener noreferrer"&gt;⁠You can also check out our tutorial on implementing RBAC in OPA&lt;/a&gt;&lt;br&gt;
⁠&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  What is ABAC?
&lt;/h2&gt;

&lt;p&gt;ABAC (Attribute-based access control), determines access based on a set of characteristics called &lt;strong&gt;“attributes”&lt;/strong&gt;, rather than roles. Attributes include parameters such as a user’s role, security clearance, time of access, current time, location of the data, current organizational threat levels, resource creation date or ownership, data sensitivity, etc.&lt;/p&gt;

&lt;p&gt;It's important to note that the attributes examined in ABAC are not just the user's - but of the accessed resource, the overall system, and anything else that is relevant in this context.&lt;/p&gt;

&lt;p&gt;ABAC based policies are based on a combination of four elements: &lt;strong&gt;Who &lt;/strong&gt;(The identity of the user) can do &lt;strong&gt;what &lt;/strong&gt;(What actions are they allowed to perform) with a &lt;strong&gt;resource &lt;/strong&gt;(Which resources) in what *&lt;em&gt;context *&lt;/em&gt;(What are the circumstances required for the action to be performed).&lt;br&gt;
⁠&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  RBAC VS ABAC
&lt;/h2&gt;

&lt;p&gt;The choice between RBAC and ABAC depends on the needs of your organization -&lt;/p&gt;

&lt;p&gt;RBAC provides a rather simple solution for determining authorization. Having evolved from RBAC, ABAC provides a more in-depth approach for authorization needed in order to prevent unauthorized access. While requiring more processing power and time, ABAC provides a more complex and detailed authorization method factoring a much greater number of variables.&lt;/p&gt;

&lt;p&gt;In many cases, RBAC and ABAC can be used together hierarchically, with broad access enforced by RBAC protocols and more complex access managed by ABAC. That being said, it is important to choose relevant authorization methods tailored to your organization’s needs - so the authorization process is &lt;strong&gt;neither too simplistic nor too complex&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For the purpose of this post, we’ll assume you decided you want to set up your policies with ABAC. &lt;br&gt;
⁠&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  The challenge of setting up policies with ABAC 
&lt;/h2&gt;

&lt;p&gt;In case you decided to set up your policies using ABAC, it is important to note the challenges you’ll have to face along the way:&lt;br&gt;
 &lt;/p&gt;

&lt;p&gt;The set of policies for each individual service has to be manually set up inside the service itself. This can be kind of a pain to do - as the amount of policies, users, and services grows, updating them in each relevant service becomes super tedious and time-consuming. Not only that, but considering the fact that policies change all the time - they have to be at least somewhat fluid.&lt;br&gt;
 &lt;br&gt;
Another issue can come from having the code of the authorization layer mixed in with the code of the application itself. This creates a situation where we struggle to upgrade, add capabilities and monitor the code as it is replicated between different microservices. Each change would require us to refactor large areas of code that only drift further from one another as these microservices develop. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So how can we solve these challenges? &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F78n4tnnk9mvu18dt19dq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F78n4tnnk9mvu18dt19dq.gif" alt="Plankton Safe" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By creating &lt;strong&gt;a separate microservice for authorization&lt;/strong&gt;, thus &lt;strong&gt;decoupling our policy from our code&lt;/strong&gt;. Controlling access management centrally through a separate authorization service allows you to offer it as a service to every system that needs to check whether a user can or cannot access its resources. This can be done by using &lt;a href="https://www.openpolicyagent.org/" rel="noopener noreferrer"&gt;Open Policy Agent&lt;/a&gt; (OPA). &lt;/p&gt;

&lt;p&gt;⁠&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  What OPA gives us?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;OPA unifies all policies across each individual service in one server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Takes on the role of policy decision-making and enforcement from the service: The service queries OPA, OPA makes a decision and sends an output to the service, The service acts according to OPA’s reply. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It allows you to have a policy as code, that can be easily reviewed, edited, and rolled back.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While we have a centralized authorization solution, the enforcement itself is still distributed - &lt;br&gt;
&lt;br&gt;
We have an OPA agent next to every microservice, providing decisions and enforcement with near-zero network latency. The OPA agents are distributed and can grow as the services scales. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvb9abkffzifew1fbpa2k.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvb9abkffzifew1fbpa2k.gif" alt="Spongebob Door" width="480" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;⁠&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How to implement ABAC in OPA?
&lt;/h2&gt;

&lt;p&gt;With attribute-based access control, you make policy decisions using the attributes of users, objects, and actions involved in the request. For this we need three types of information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Attributes for users&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Attributes for objects&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Logic dictating which attribute combinations are authorized&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, let’s take the following attributes for our users:&lt;br&gt;
&lt;code&gt;Squid&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Joined the company 10 years ago&lt;/li&gt;
&lt;li&gt;Is a cashier&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Pat&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Joined the company 6 months ago&lt;/li&gt;
&lt;li&gt;Is a cashier &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We would also have attributes for the objects, in this case, menu items:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Burger&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is sold on the menu&lt;/li&gt;
&lt;li&gt;Costs 3$&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Shake&lt;/code&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is sold on the menu&lt;/li&gt;
&lt;li&gt;Costs 1$&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we try and write up an example ABAC policy in English, it will look like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cashiers may process orders of up to 1$ total. &lt;/li&gt;
&lt;li&gt;Cashiers with more than 1 year of experience may process orders of up to 10$ total. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9xyd3xrqjmcllu1ti4kl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9xyd3xrqjmcllu1ti4kl.jpg" alt="Patrick" width="800" height="525"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;⁠&lt;strong&gt;OPA supports ABAC policies as shown below:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package abac

# User attributes
user_attributes := {
    "Squid": {"tenure": 10, "title": "cashier"},
    "Pat": {"tenure": 0.000114155, "title": "cashier"}
}

# Menu attributes
menu_attributes := {
    "Burger": {"items": "Menu", "price": 3},
    "Shake": {"items": "Menu", "price": 1}
}

default allow = false

# All cashiers may process orders of up to 1$ total
allow {
    # Lookup the user's attributes
    user := user_attributes[input.user]
    # Check that the user is a cashier
    user.title == "cashier"
    # Check that the item being sold is on the menu
    menu_attributes[input.ticker].items == "Menu"
    # Check that the processed amount is under 1$
    input.amount &amp;lt;= 1

}

# Cashiers with 1=&amp;gt; year of experience may ⁠process orders of up to 10$ total.
allow {
    # Lookup the user's attributes
    user := user_attributes[input.user]
    # Check that the user is a cashier
    user.title == "cashier"

    # Check that the item being sold is on the menu
    menu_attributes[input.ticker].items == "Menu"
    # Check that the user has at least 1 year of experience
    user.tenure &amp;gt; 1
    # Check that the processed amount is under is under $10
    input.amount &amp;lt;= 10
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⁠Now let’s review the following input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "user": "Squid",
  "menu": "Burger",
  "action": "sell",
  "amount": 2
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⁠Querying the allow rule with the input above returns the following answer: &lt;code&gt;True&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8a7x0zpey0deethmmm8q.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8a7x0zpey0deethmmm8q.gif" alt="Patrick Plank" width="540" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Congrats! You have successfully implemented ABAC in OPA! &lt;/strong&gt;&lt;br&gt;
⁠&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  To sum things up:
&lt;/h2&gt;

&lt;p&gt;Let’s do a quick review of what we learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;RBAC&lt;/strong&gt; is an authorization model based on &lt;strong&gt;predefined roles&lt;/strong&gt;, while &lt;strong&gt;ABAC&lt;/strong&gt; determines access based on a set of characteristics called &lt;strong&gt;“attributes”&lt;/strong&gt;. &lt;br&gt;
&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;While RBAC provides a rather simple solution for determining authorization that fits most organizations, ABAC is a more complex and detailed authorization method factoring in a much greater number of variables.&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is important to choose an authorization model that fits your organization's needs, so it’s &lt;strong&gt;neither too simple nor too complex&lt;/strong&gt;.&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The main challenges of setting up policies with RBAC are the requirement to manually set up the set of policies for each individual service, and having the code of the authorization layer mixed in with the code of the application itself. &lt;strong&gt;Both can be solved by using OPA&lt;/strong&gt;.&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;OPA solves these issues by &lt;strong&gt;unifying all policies&lt;/strong&gt; in one server, &lt;strong&gt;taking on the role of policy decision-making and enforcement&lt;/strong&gt; from the service, and allowing you to manage &lt;strong&gt;policy as code&lt;/strong&gt;. &lt;br&gt;
&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We saw an example of how to &lt;strong&gt;successfully implement ABAC in OPA&lt;/strong&gt; :)&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;⁠Want to learn more? check out the rest of our &lt;a href="https://www.permit.io/blog" rel="noopener noreferrer"&gt;Blog&lt;/a&gt; for more useful tutorials, or join our ⁠&lt;a href="https://opal-access.slack.com/join/shared_invite/zt-nz6yjgnp-RlP9rtOPwO0n0aH_vLbmBQ#/shared-invite/email" rel="noopener noreferrer"&gt;Slack channel&lt;/a&gt; to ask questions and talk about authorization.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>authorization</category>
      <category>openpolicyagent</category>
      <category>abac</category>
    </item>
    <item>
      <title>How to Implement Role Based Access Control (RBAC) using Open Policy Agent (OPA)</title>
      <dc:creator>Daniel Bass</dc:creator>
      <pubDate>Tue, 11 Jan 2022 10:08:17 +0000</pubDate>
      <link>https://dev.to/permit_io/how-to-implement-role-based-access-control-rbac-using-open-policy-agent-opa-1el3</link>
      <guid>https://dev.to/permit_io/how-to-implement-role-based-access-control-rbac-using-open-policy-agent-opa-1el3</guid>
      <description>&lt;p&gt;Building authorization can be a complicated endeavor. There are different models for building authorization and different ways of implementing them. At the end of the day, only one thing matters - we want the &lt;strong&gt;right person&lt;/strong&gt; to have the &lt;strong&gt;right access&lt;/strong&gt; to the &lt;strong&gt;right asset&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;For this purpose, we want to review a couple of &lt;strong&gt;authorization models&lt;/strong&gt; (RBAC and ABAC), and then explain how (and why) you should implement them using Open Policy Agent - which allows you to create a separate microservice for authorization, decoupling our policy from our code.&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  So why RBAC and ABAC?
&lt;/h2&gt;

&lt;p&gt;RBAC and ABAC are the two most basic and commonly used authorization models, and they provide the baseline for most other complex and specific ones. Let’s start by getting to know them a little better:&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  What is RBAC?
&lt;/h2&gt;

&lt;p&gt;Role-based access control (RBAC), is an authorization model used to determine access control based on &lt;strong&gt;predefined roles&lt;/strong&gt;. Permissions are assigned onto roles (Like “Admin or “User”), and roles are assigned to users by the administrator. This structure allows you to easily understand who has access to what. &lt;/p&gt;

&lt;p&gt;The combination of &lt;strong&gt;who&lt;/strong&gt; (What role are they assigned?) can do &lt;strong&gt;what&lt;/strong&gt; (What actions are they allowed to perform) with a &lt;strong&gt;resource&lt;/strong&gt; (On which resources) is called a &lt;strong&gt;policy&lt;/strong&gt;.&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  What is ABAC?
&lt;/h2&gt;

&lt;p&gt;ABAC (Attribute-based access control), determines access based on a set of characteristics called “&lt;strong&gt;attributes&lt;/strong&gt;”. Attributes include parameters such as a user’s role, security clearance, time of access, location of the data, current organizational threat levels, resource creation date or ownership, data sensitivity, etc.&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  RBAC VS ABAC
&lt;/h2&gt;

&lt;p&gt;The choice between RBAC and ABAC depends on the needs of your organization -&lt;/p&gt;

&lt;p&gt;RBAC provides a rather simple solution for determining authorization and is usually sufficient for most organizations. In some cases, a more in-depth approach for authorization is needed in order to prevent unauthorized access - This is where ABAC comes in. While requiring more processing power and time, ABAC provides a more complex and detailed authorization method factoring a much greater number of variables.&lt;/p&gt;

&lt;p&gt;In many cases, RBAC and ABAC can be used together hierarchically, with broad access enforced by RBAC protocols and more complex access managed by ABAC. That being said, it is important to choose relevant authorization methods tailored to your organization’s needs - so the authorization process is &lt;strong&gt;neither too simplistic nor too complex&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For the purpose of this post, we’ll assume you decided you want to set up your policies with RBAC.&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  The challenge of setting up policies with RBAC
&lt;/h2&gt;

&lt;p&gt;After you decided to set up your policies using RBAC, it is important to note the challenges you’ll have to face along the way: &lt;/p&gt;

&lt;p&gt;The set of policies for each individual service has to be manually set up inside the service itself. This can be kind of a pain to do - as the amount of policies, users, and services grows, updating them in each relevant service becomes super tedious and time-consuming. Not only that, but considering the fact that policies change all the time - they have to be at least somewhat fluid. &lt;/p&gt;

&lt;p&gt;Another issue can come from having the code of the authorization layer mixed in with the code of the application itself. This creates a situation where we struggle to upgrade, add capabilities and monitor the code as it is replicated between different microservices. Each change would require us to refactor large areas of code that only drift further from one another as these microservices develop. &lt;/p&gt;

&lt;p&gt;But how can we solve these challenges? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzx3pqajchzthhw0ayv8x.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzx3pqajchzthhw0ayv8x.gif" alt="Plankton.gif" width="498" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By creating a &lt;strong&gt;separate microservice for authorization&lt;/strong&gt;, thus &lt;strong&gt;decoupling our policy from our code&lt;/strong&gt;. Controlling access management centrally through a separate authorization service allows you to offer it as a service to every system that needs to check whether a user can or cannot access its resources. This can be done by using &lt;a href="https://www.openpolicyagent.org/" rel="noopener noreferrer"&gt;Open Policy Agent&lt;/a&gt; (OPA). &lt;br&gt;
&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  What OPA gives us?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;OPA unifies all policies across each individual service in one server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Takes on the role of policy decision-making and enforcement from the service: The service queries OPA, OPA makes a decision and sends an output to the service, The service acts according to OPA’s reply. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It allows you to have a policy as code, that can be easily reviewed, edited, and rolled back.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While we have a centralized authorization solution, the enforcement itself is still distributed - &lt;br&gt;
&lt;br&gt;
We have an OPA agent next to every microservice, providing decisions and enforcement with near-zero network latency. The OPA agents are distributed and can grow as the services scales. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftcb8kwd7zx4v9sue1l1y.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftcb8kwd7zx4v9sue1l1y.gif" alt="Total Control" width="320" height="240"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How to implement RBAC in OPA?
&lt;/h2&gt;

&lt;p&gt;In order to use RBAC, we need two types of information: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which &lt;strong&gt;users&lt;/strong&gt; have which &lt;strong&gt;roles&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Which &lt;strong&gt;roles&lt;/strong&gt; have which &lt;strong&gt;permissions&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once we provide RBAC with this information, we decide how to make an authorization decision; A user is assigned to a role and is authorized to do what the role permits. &lt;/p&gt;

&lt;p&gt;For example, let us look at the following role assignments:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;
&lt;p&gt;User&lt;/p&gt;
&lt;p&gt;(Who is performing the action)&lt;/p&gt;
&lt;/th&gt;
&lt;th&gt;
&lt;p&gt;Role&lt;/p&gt;
&lt;p&gt;(What is the user’s assigned role)&lt;/p&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Crab&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Admin&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Bob&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Cook&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Plankton&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Villain&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;And this role/permission assignment: &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;th&gt;
&lt;p&gt;Operation&lt;/p&gt;
&lt;p&gt;(What are they doing)&lt;/p&gt;
&lt;/th&gt;
&lt;th&gt;
&lt;p&gt;Resource &lt;/p&gt;
&lt;p&gt;(What are they performing the action on)&lt;/p&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Admin&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Write&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Secret formula&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Admin&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Read&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Secret formula&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Cook&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Read&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Secret formula&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Villain&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Want&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Secret formula&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In this example, RBAC will make the following authorization decisions:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;
&lt;p&gt;User&lt;/p&gt;

&lt;/th&gt;
&lt;th&gt;
&lt;p&gt;Operation&lt;/p&gt;

&lt;/th&gt;
&lt;th&gt;
&lt;p&gt;Resource&lt;/p&gt;

&lt;/th&gt;
&lt;th&gt;
&lt;p&gt;Decision&lt;/p&gt;
&lt;p&gt;(Should the action be allowed, and why?)&lt;/p&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Crab&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Write&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Secret formula&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Allow&lt;/code&gt; because &lt;code&gt;Crab&lt;/code&gt; is in &lt;code&gt;Admin&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Bob&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Read&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Secret formula&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Allow&lt;/code&gt; because &lt;code&gt;Bob&lt;/code&gt; is in &lt;code&gt;Cook&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Villain&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Read&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Secret formula&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Deny&lt;/code&gt; because &lt;code&gt;Plankton&lt;/code&gt; is in &lt;code&gt;Villain&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Villain&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Want&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Secret formula&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Allow&lt;/code&gt; because &lt;code&gt;Plankton&lt;/code&gt; is in &lt;code&gt;Villain&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmduvqq52vpgendysm0s.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmduvqq52vpgendysm0s.gif" alt="Cheer" width="500" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With OPA, you can write the following snippets to implement the example RBAC policy shown above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package rbac.authz

# Assigning user roles 

user_roles := {

    "crab": ["admin"],

    "bob": ["cook"],

    “plankton”:[“villain”]

}

# Role permission assignments
role_permissions := {
    "cook":    [{"action": "read",  "object": "secret_formula"}],
    "admin":   [{"action": "read",  "object": "secret_formula"},
                {"action": "write", "object": "secret_formula"}],
    "villain": [{"action": "want",  "object": "secret_formula"}]
}

# Logic that implements RBAC.
default allow = false
allow {
    # Lookup the list of roles for the user
    roles := user_roles[input.user]
    # For each role in that list
    r := roles[_]
    # Lookup the permissions list for role r
    permissions := role_permissions[r]
    # For each permission
    p := permissions[_]
    # Check if the permission granted to r matches the user's request
    p == {"action": input.action, "object": input.object}
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Querying the allow rule with the following input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "user": "plankton",
  "action": "read",
  "object": "secret_formula"
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Results in the response you’d expect: &lt;code&gt;False&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff1zyszjyh6ya3cygcsty.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff1zyszjyh6ya3cygcsty.gif" alt="Slow_Clap" width="498" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;⁠&lt;strong&gt;Congrats! You have successfully implemented ABAC in OPA! &lt;/strong&gt;&lt;br&gt;
⁠&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  To sum things up:
&lt;/h2&gt;

&lt;p&gt;Let’s do a quick review of what we learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;RBAC&lt;/strong&gt; is an authorization model based on &lt;strong&gt;predefined roles&lt;/strong&gt;, while &lt;strong&gt;ABAC&lt;/strong&gt; determines access based on a set of characteristics called “&lt;strong&gt;attributes&lt;/strong&gt;”. &lt;/li&gt;
&lt;li&gt;While RBAC provides a rather simple solution for determining authorization that fits most organizations, ABAC is a more complex and detailed authorization method factoring in a much greater number of variables.&lt;/li&gt;
&lt;li&gt;It is important to choose an authorization model that fits your organization's needs, so it’s &lt;strong&gt;neither too simple nor too complex&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The main challenges of setting up policies with RBAC are the requirement to manually set up the set of policies for each individual service, and having the code of the authorization layer mixed in with the code of the application itself. &lt;strong&gt;Both can be solved by using OPA&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;OPA solves these issues by &lt;strong&gt;unifying all policies&lt;/strong&gt; in one server, &lt;strong&gt;taking on the role of policy decision-making and enforcement&lt;/strong&gt; from the service, and allowing you to manage &lt;strong&gt;policy as code&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;We saw an example of how to &lt;strong&gt;successfully implement RBAC in OPA&lt;/strong&gt; :)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Want to learn more? check out the rest of our &lt;a href="https://www.permit.io/blog" rel="noopener noreferrer"&gt;Blog&lt;/a&gt; for more useful tutorials, or join our ⁠&lt;a href="https://opal-access.slack.com/join/shared_invite/zt-nz6yjgnp-RlP9rtOPwO0n0aH_vLbmBQ#/shared-invite/email" rel="noopener noreferrer"&gt;Slack&lt;/a&gt;&lt;a href="https://opal-access.slack.com/join/shared_invite/zt-nz6yjgnp-RlP9rtOPwO0n0aH_vLbmBQ#/shared-invite/email" rel="noopener noreferrer"&gt; &lt;/a&gt;&lt;a href="https://opal-access.slack.com/join/shared_invite/zt-nz6yjgnp-RlP9rtOPwO0n0aH_vLbmBQ#/shared-invite/email" rel="noopener noreferrer"&gt;channel&lt;/a&gt; to ask questions and talk about authorization. &lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>authorization</category>
      <category>openpolicyagent</category>
      <category>rbac</category>
    </item>
  </channel>
</rss>
