<?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: Cerbos</title>
    <description>The latest articles on DEV Community by Cerbos (cerbos).</description>
    <link>https://dev.to/cerbos</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.us-east-2.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F7005%2F1a1f2ae5-0b11-48cc-b982-3f9fdd62372e.png</url>
      <title>DEV Community: Cerbos</title>
      <link>https://dev.to/cerbos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cerbos"/>
    <language>en</language>
    <item>
      <title>What Is Runtime Authorization? A Guide to Dynamic Access Control and the Best Runtime Authorization Tools</title>
      <dc:creator>Anna</dc:creator>
      <pubDate>Fri, 13 Feb 2026 18:27:11 +0000</pubDate>
      <link>https://dev.to/cerbos/what-is-runtime-authorization-a-guide-to-dynamic-access-control-and-the-best-runtime-authorization-1849</link>
      <guid>https://dev.to/cerbos/what-is-runtime-authorization-a-guide-to-dynamic-access-control-and-the-best-runtime-authorization-1849</guid>
      <description>&lt;p&gt;In the complex landscape of modern software, ensuring that users, and automated actors, can only access the data and actions they are authorized to use is critical. As systems become more distributed and regulatory requirements tighten, static access control models are no longer sufficient. This is where runtime authorization becomes essential.&lt;/p&gt;

&lt;p&gt;This article explores what is runtime authorization, why it is replacing traditional static models, and what you should look for when evaluating the best runtime authorization tools for your stack.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Runtime Authorization?
&lt;/h2&gt;

&lt;p&gt;Runtime authorization (often called dynamic authorization) is the process of making access control decisions on the fly, at the moment of access, using real-time information and policies.&lt;br&gt;
Unlike traditional methods where permissions are assigned in advance and rarely change, runtime authorization evaluates the current context of a request to decide whether to permit or deny it. This decision typically considers:&lt;/p&gt;

&lt;p&gt;• Who the user is (identity and roles).&lt;br&gt;
• What they are trying to do (action).&lt;br&gt;
• Which resource they are targeting.&lt;br&gt;
• Contextual factors such as time of day, location, device security posture, or the current state of the resource.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Core Difference: Static vs. Dynamic
&lt;/h2&gt;

&lt;p&gt;To fully understand what is runtime authorization, it helps to contrast it with &lt;a href="https://www.cerbos.dev/blog/risks-of-static-authorization" rel="noopener noreferrer"&gt;admin-time (static)&lt;/a&gt; authorization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Admin-Time Authorization&lt;/strong&gt;: Permissions are configured in advance by an administrator. A user is assigned a role (e.g., "Manager"), and that role carries a static set of permissions. The system simply checks, "Does this user have the Manager role?" If yes, access is granted. This decision is based on configuration, not current context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Runtime Authorization&lt;/strong&gt;: Permissions are checked at execution time. The system asks, "Is this specific action allowed right now?" A policy might say, "Managers can approve invoices, but only if the amount is under $5,000 and the invoice belongs to their department." This logic requires real-time evaluation of the invoice amount and department attributes.&lt;/p&gt;

&lt;p&gt;While admin-time authorization is excellent for establishing baseline eligibility (who could do what), runtime authorization ensures that access is appropriate for the specific situation (who should do what now).&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Static Authorization Is No Longer Enough
&lt;/h2&gt;

&lt;p&gt;For years, Role-Based Access Control (RBAC) was the standard. However, relying solely on static assignments creates significant blind spots.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Risk Accumulates Silently&lt;br&gt;
When permissions are static, they tend to outlive their purpose. A user might be granted broad access for a specific project, but when the project ends, the access remains because no one manually revokes it. This accumulation of privileges creates a "blast radius" that attackers can exploit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Context Is Ignored&lt;br&gt;
Static roles cannot easily account for context. For example, a "Doctor" role might grant access to all patient records. However, a hospital may want to restrict access to only patients currently under that doctor's care. To enforce this statically, you would need to create unmanageable numbers of roles (e.g., "Doctor-Ward-A", "Doctor-Ward-B"). Runtime authorization handles this elegantly by checking the "department" attribute dynamically.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lack of Decision-Level Evidence&lt;br&gt;
In static systems, audits often only show intent (i.e., "User X was assigned Role Y"). They rarely show proof of what was actually enforced during a specific transaction. Runtime authorization generates decision-level evidence, allowing you to log exactly why a request was allowed or denied based on the specific policy version and inputs used.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Benefits of Runtime Authorization
&lt;/h2&gt;

&lt;p&gt;Implementing runtime authorization unlocks several critical capabilities for modern enterprises:&lt;/p&gt;

&lt;p&gt;• Zero Trust Architecture: It supports the principle of "never trust, always verify." Every request is evaluated against policy, regardless of whether the user is inside or outside the network.&lt;br&gt;
• Fine-Grained Control: You can enforce specific business rules, such as requiring Multi-Factor Authentication (MFA) for sensitive transactions or restricting access based on geolocation.&lt;br&gt;
• Instant Adaptability: If a user’s attributes change (e.g., they transfer departments), their access rights update immediately without administrative intervention.&lt;br&gt;
• Zero Standing Privileges: Instead of users holding powerful permissions 24/7, runtime authorization allows for ephemeral access. &lt;/p&gt;

&lt;p&gt;A developer can be granted access to production servers only when handling an active incident, with the permission automatically revoked afterward.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Runtime Authorization Tools: What to Look For
&lt;/h2&gt;

&lt;p&gt;As organizations shift toward dynamic access control, selecting the right tooling is paramount. The best runtime authorization tools share several key architectural characteristics that distinguish them from legacy IAM solutions.&lt;/p&gt;

&lt;p&gt;When evaluating solutions, look for these features:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Decoupled Policy Decision Points (PDP)
&lt;/h3&gt;

&lt;p&gt;The most effective tools separate the decision logic from the application code. This is often achieved using a Policy Decision Point (PDP).&lt;br&gt;
• How it works: Your application (the Policy Enforcement Point, or PEP) sends a query to the PDP: "Can User X perform Action Y on Resource Z?"&lt;br&gt;
• The Benefit: The PDP evaluates the policy and returns a simple "Allow" or "Deny." This keeps your application code clean and ensures that authorization logic is centralized, not scattered across IF/ELSE statements in your codebase.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Policy-as-Code
&lt;/h3&gt;

&lt;p&gt;Top-tier tools treat authorization policies as code. This means policies are defined in human-readable formats (like YAML or JSON), stored in version control systems (like Git), and subject to the same testing and review processes as software code. This approach enables "governance without new runtime risk," ensuring that every change is tracked and reversible.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Performance and Scalability
&lt;/h3&gt;

&lt;p&gt;Authorization is in the critical path of every request. The best runtime authorization tools must evaluate decisions in sub-millisecond timeframes. They should run close to the application—often as a sidecar or local service—to avoid network latency. If a policy engine introduces noticeable lag, teams will inevitably bypass it.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Auditability and Governance
&lt;/h3&gt;

&lt;p&gt;A robust tool provides more than just a yes/no answer; it provides a paper trail. Look for solutions that offer "decision-level evidence," recording exactly which policy version was used and what inputs led to the decision. This turns authorization from a theoretical control into a fully inspectable compliance asset.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Support for Non-Human Identities
&lt;/h3&gt;

&lt;p&gt;Modern architectures rely heavily on automated actors—service accounts, AI agents, and background jobs. The best tools treat these non-human identities with the same rigor as human users, applying context-aware policies to prevent automated systems from becoming security liabilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cerbos: A Leader in Runtime Authorization
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.cerbos.dev/blog/run-time-authorization" rel="noopener noreferrer"&gt;Cerbos&lt;/a&gt; exemplifies the modern approach to runtime authorization. It is an enterprise authorization solution for applications, APIs, workloads, and AI agents,&amp;nbsp;that integrates seamlessly into Zero Trust environments.&lt;/p&gt;

&lt;p&gt;• Contextual and Continuous: Cerbos enforces fine-grained policies across applications, APIs, and even AI agents. It evaluates policies based on identity, workload attributes, and execution context.&lt;br&gt;
• Developer-Centric: By using "policy-as-code," Cerbos allows developers to write policies in structured YAML, making it easy to map business requirements directly to authorization logic.&lt;br&gt;
• Centralized Governance: With Cerbos Hub, organizations can centrally manage, test, and distribute policies to distributed PDPs. This ensures consistent decision-making whether the policy is called from a monolith, a microservice, or a serverless function.&lt;/p&gt;

&lt;p&gt;Cerbos solves the "spaghetti code" problem by externalizing authorization. Instead of hard-coding complex logic (e.g., if user.role == manager &amp;amp;&amp;amp; invoice.amount &amp;lt; 5000), the application simply asks the Cerbos PDP for a decision. This makes systems simpler, more secure, and easier to audit.&lt;/p&gt;

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

&lt;p&gt;As applications evolve, what is runtime authorization is no longer just a theoretical question—it is a practical necessity. Static role-based models simply cannot keep pace with the dynamic nature of cloud-native infrastructure, AI agents, and evolving compliance demands.&lt;/p&gt;

&lt;p&gt;By adopting the best runtime authorization tools—those that offer decoupled PDPs, policy-as-code, and deep auditability—you can ensure your security posture is proactive rather than reactive. Tools like Cerbos allow you to enforce least privilege effectively, turning authorization into a continuously governed control that scales with your business.&lt;/p&gt;

&lt;p&gt;Ready to modernize your access control? Explore how Cerbos can help you implement externalized, dynamic authorization. &lt;a href="https://www.cerbos.dev/" rel="noopener noreferrer"&gt;Learn more about Cerbos&lt;/a&gt;, the enterprise authorization solution for applications, APIs, workloads, and AI agents.&amp;nbsp;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>cybersecurity</category>
      <category>security</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Importance of Role-Based Access Control (RBAC) in Web Security</title>
      <dc:creator>Anna</dc:creator>
      <pubDate>Thu, 17 Jul 2025 13:51:45 +0000</pubDate>
      <link>https://dev.to/cerbos/importance-of-role-based-access-control-rbac-in-web-security-1966</link>
      <guid>https://dev.to/cerbos/importance-of-role-based-access-control-rbac-in-web-security-1966</guid>
      <description>&lt;p&gt;&lt;a href="https://www.fortinet.com/resources/cyberglossary/what-is-web-security" rel="noopener noreferrer"&gt;Web security&lt;/a&gt; is a blanket term that refers to the practices that protect systems, resources, and data from malicious actors, threats, unauthorized access, and vulnerabilities as they interact on the web.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.cerbos.dev/features-benefits-and-use-cases/rbac" rel="noopener noreferrer"&gt;Role-based access Control&lt;/a&gt;, or RBAC, is an authorization approach that defines how users can interact with system resources based on predefined roles and permissions. This blog explores the role of RBAC in enhancing web security.&amp;nbsp;&amp;nbsp;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why web security is important
&lt;/h2&gt;

&lt;p&gt;Web security is essential to building resilient systems that inspire trust in users and are, by default, harder to breach.&lt;/p&gt;

&lt;p&gt;Implementing web security practices prevents unauthorized access to system resources, keeping user information safe from bad actors.&amp;nbsp;&lt;/p&gt;

&lt;p&gt;It also makes it easier for organizations to comply with legal requirements like &lt;a href="https://gdpr-info.eu/" rel="noopener noreferrer"&gt;GDPR&lt;/a&gt; and &lt;a href="https://www.hhs.gov/hipaa/for-professionals/privacy/laws-regulations/index.html" rel="noopener noreferrer"&gt;HIPAA&lt;/a&gt;, avoiding legal problems and further inspiring trust in their systems.&amp;nbsp;&lt;/p&gt;

&lt;h2&gt;
  
  
  What RBAC is and how it can enhance web security
&lt;/h2&gt;

&lt;p&gt;RBAC is an access control method that assigns permission to users' roles and defines what each role can access within the system. It simplifies access management by grouping users under roles rather than assigning direct individual permissions.&lt;/p&gt;

&lt;p&gt;It enhances web security by preventing unauthorized access by restricting user interaction to just the resources to which they have explicit access.&lt;/p&gt;

&lt;p&gt;Additionally, its design limits the negative impact of user-related errors by containing them to specific resources that the user can access, thus preventing unnecessary system-wide outages.&lt;/p&gt;

&lt;p&gt;As applications grow and logic becomes more complex, updating authorization logic to keep it in sync becomes more urgent. Maintaining RBAC will demand more attention, and at this point, external authorization providers like &lt;a href="https://www.cerbos.dev/" rel="noopener noreferrer"&gt;Cerbos&lt;/a&gt; will become involved.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Cerbos simplifies RBAC for enhanced web security
&lt;/h2&gt;

&lt;p&gt;Cerbos is an external authorization provider that enables organizations to separate or decouple their access control layer from the rest of their application logic. This allows organizations to centralize their RBAC policies, making them easier to manage, test, and scale.&lt;/p&gt;

&lt;p&gt;Cerbos evaluates whether a user with a specific role and attribute should be allowed access to a resource. It provides a simple ALLOW or DENY response, reducing code complexity and improving the security baseline by leaving authorization logic to the experts. This frees up developers to focus on application functionality instead of building an authorization engine and maintaining it in-house&lt;/p&gt;

&lt;p&gt;For example, if an organization is building a blog application where users have roles like Admin, Editor, and Author. Cerbos lets you define policies such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Admin: Full access to all resources.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Editor: Can view and manage Author blogs and schedules.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Author: Can only view and manage their blogs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementing RBAC in your application is streamlined Using Cerbos SDKs and policy decision points (PDPs). You can integrate Cerbos with your backend via its &lt;a href="https://docs.cerbos.dev/cerbos/latest/api/" rel="noopener noreferrer"&gt;SDKs or make a simple API request to the Cerbos service&lt;/a&gt;. This enables you to enforce authorization consistently without directly dealing with complex access rules in your system.&lt;/p&gt;

&lt;h2&gt;
  
  
  RBAC best practices
&lt;/h2&gt;

&lt;p&gt;We must consider and implement the following best practices to get the most security benefits from RBAC.&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  Do organizational research
&lt;/h3&gt;

&lt;p&gt;Gather information about the organizational hierarchy, data systems, roles, and needs. Verify the findings with major stakeholders and then create RBAC policy.&lt;/p&gt;

&lt;p&gt;The policy should cover all necessary use cases, constraints, and rules. It should be treated like documentation and be the single source of truth. It should also be made available to all relevant people in the organization.&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Principle of Least Privilege (PoLP)
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.upguard.com/blog/principle-of-least-privilege" rel="noopener noreferrer"&gt;The Principle of Least Privilege&lt;/a&gt; refers to assigning users the minimum permissions they need to perform their roles and nothing more. This is a central principle of access policies, and the following processes are used to implement it:&lt;/p&gt;

&lt;h4&gt;
  
  
  Granular Access Control
&lt;/h4&gt;

&lt;p&gt;This refers to breaking down the permissions a user might need into their smallest units. Instead of giving permissions to a section of a system, you give them to the specific part of the section that the user needs to access.&lt;/p&gt;

&lt;p&gt;For example, giving a marketing team access to traffic data in an analytics dashboard while blocking access to revenue information.&lt;/p&gt;

&lt;h4&gt;
  
  
  Just-in-Time Access
&lt;/h4&gt;

&lt;p&gt;If a user needs extra permissions, grant them elevated access for a given time instead of permanently upgrading their permissions. For example, a new developer might need access to sensitive production data only while fixing a particular bug, and the extra permission will auto-expire when it is done.&lt;/p&gt;

&lt;h4&gt;
  
  
  Create processes for elevated permissions
&lt;/h4&gt;

&lt;p&gt;Have vetted processes in place for when users need more permissions. This keeps things visible and creates a trail that makes auditing more straightforward.&lt;/p&gt;

&lt;p&gt;The benefits of carefully implementing this principle include containing any security breaches. Because the user has minimum permission, any damage caused by a compromised system is contained.&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Another benefit is that few permissions mean a smaller attack surface, increasing system resilience.&amp;nbsp;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Carrying out deep research before assigning roles and permissions makes this principle simpler to apply and ensures that your roles are appropriately designed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Review organizational structure periodically
&lt;/h3&gt;

&lt;p&gt;Organizational hierarchies change over time, and monitoring these changes keeps the roles and application logic in sync, preventing leaks and improving security.&lt;/p&gt;

&lt;p&gt;Regular reviews of your organization's structure help identify when new roles need to be created or existing ones modified. This includes reviewing department changes, business processes, and operational workflows that might affect access requirements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Log, audit, and test policies
&lt;/h3&gt;

&lt;p&gt;RBAC policies require regular testing and audits to ensure they work as expected and to be kept updated with organizational changes.&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Implementing logging in your RBAC systems makes the auditing part a lot simpler and makes it clear where policies are failing or need to be reviewed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Leverage automation
&lt;/h3&gt;

&lt;p&gt;Use automation to pick up when people move around the organization and roles no longer fit. Automating this enables you to stay on top of policies and &lt;a href="https://permify.co/post/role-explosion/" rel="noopener noreferrer"&gt;contain role explosion&lt;/a&gt;, which is when the roles grow a lot over time and become disorganized and hard to manage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Have a contingency plan
&lt;/h3&gt;

&lt;p&gt;Develop a way to securely access the system and data in the case of an emergency where the policies backfired or when the policies need to be bypassed.&lt;/p&gt;

&lt;p&gt;This should include proper documentation, transparent approval processes, and situation assessment afterward.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cultivate a security culture
&lt;/h3&gt;

&lt;p&gt;Actively train your team on best web security and RBAC practices. Have your team deeply understand and accept why all the processes and procedures are essential. This will encourage a shared security mindset, where your team proactively monitors and refines RBAC policies.&lt;/p&gt;

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

&lt;p&gt;RBAC is essential for securing web-based systems. It protects user data, ensures system integrity, and encourages user privacy. However, implementing RBAC at scale can be time-consuming and complex. Cerbos simplifies this process by centralizing and streamlining authorization, enabling organizations to focus on building secure, scalable applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Notes and resources
&lt;/h2&gt;

&lt;p&gt;Check out these links to learn more on RBAC, Cerbos, and web security best practices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.cerbos.dev/features-benefits-and-use-cases/rbac" rel="noopener noreferrer"&gt;About RBAC&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.fortinet.com/resources/cyberglossary/what-is-web-security" rel="noopener noreferrer"&gt;An Introduction to Web Security&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.cerbos.dev/blog/authorization-as-a-service" rel="noopener noreferrer"&gt;What is authorization as a service?&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.cerbos.dev/blog/how-to-use-cerbos-effectively" rel="noopener noreferrer"&gt;How to use Cerbos Effectively&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.cerbos.dev/blog/how-to-use-cerbos-in-docker-compose-pdp-hub" rel="noopener noreferrer"&gt;How to use Cerbos in Docker Compose (PDP + Hub)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>iam</category>
      <category>accesscontrol</category>
      <category>auhtorization</category>
      <category>rbac</category>
    </item>
    <item>
      <title>Cerbos PDP - Open source authorization for RBAC and ABAC. We have updates!</title>
      <dc:creator>Anna</dc:creator>
      <pubDate>Tue, 03 Dec 2024 16:56:20 +0000</pubDate>
      <link>https://dev.to/cerbos/cerbos-pdp-open-source-authorization-for-rbac-and-abac-we-have-updates-443</link>
      <guid>https://dev.to/cerbos/cerbos-pdp-open-source-authorization-for-rbac-and-abac-we-have-updates-443</guid>
      <description>&lt;p&gt;Our co-founders have seen firsthand how the implementation and management or roles and permissions can turn into a nightmare as your application grows. Tangled access control rules buried deep in your business logic, adding a new role feels like navigating a complex maze of if/else statements…&lt;/p&gt;

&lt;p&gt;Which is why 3 years ago, we released &lt;a href="https://www.cerbos.dev/product-cerbos-pdp" rel="noopener noreferrer"&gt;Cerbos PDP&lt;/a&gt; (and are continuing to work on it actively).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;PS. We’re happy to share that this week we surpassed &lt;a href="https://github.com/cerbos/cerbos" rel="noopener noreferrer"&gt;3333 stars on Github&lt;/a&gt;! 🌟 Feel free to support us by giving us a star 🙂&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Cerbos PDP?
&lt;/h2&gt;

&lt;p&gt;Cerbos PDP (Policy Decision Point) is an open source authorization layer designed to grow with your product. It allows developers to define powerful, context-aware access controls through simple, intuitive, and testable policies. &lt;a href="https://www.cerbos.dev/how-it-works" rel="noopener noreferrer"&gt;Here’s a video explaining how it works.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Latest updates we’ve introduced:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Improved error reporting&lt;/strong&gt; with better error descriptions and contextual information to help debug access policies issues faster.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support for policy versioning&lt;/strong&gt; and scoping within policy conditions, allowing for more fine-grained control over authorization logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Policy inspection&lt;/strong&gt; via the command line. The cerbosctl inspect command allows investigation of policies, showing what actions each policy covers​.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Artifact signing and SBOM generation&lt;/strong&gt;. All Cerbos release artifacts,binaries and containers, are now signed using Sigstore, making them verifiable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Development environment linked Playground&lt;/strong&gt; enables developers to author policies and in real time see their impact in the application they are developing. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.cerbos.dev/blog/updates-to-cerbos-pdp-open-source-authorization-solution" rel="noopener noreferrer"&gt;Click here for more details&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;PS. We’re happy to share that this week we surpassed &lt;a href="https://github.com/cerbos/cerbos" rel="noopener noreferrer"&gt;3333 stars on Github&lt;/a&gt;! 🌟 Feel free to support us by giving us a star 🙂&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is an Access Control System?</title>
      <dc:creator>Anna</dc:creator>
      <pubDate>Mon, 18 Nov 2024 16:35:14 +0000</pubDate>
      <link>https://dev.to/cerbos/what-is-an-access-control-system-2kkb</link>
      <guid>https://dev.to/cerbos/what-is-an-access-control-system-2kkb</guid>
      <description>&lt;p&gt;Access control systems play a crucial role in modern security, acting as the gatekeepers that determine who can go where and do what, both in the physical and digital realms. Whether it's restricting entry to a secure office space or limiting access to sensitive data on a network, access control systems are essential for protecting assets. You can think of them as high-tech bouncers—making sure only the right people get in.&lt;/p&gt;

&lt;p&gt;In this article, we'll explore what access control systems are, how they work, and why they are so important for both physical and network security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Access Control Systems
&lt;/h2&gt;

&lt;p&gt;An access control system is a security solution that manages and regulates access to resources, locations, or information. Its primary function is to ensure that only authorized users can gain access to specific areas or data. These systems are critical for safeguarding both physical spaces (like office buildings or data centers) and digital assets (like network resources or confidential files).&lt;/p&gt;

&lt;p&gt;There are two main types of access control systems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Physical Access Control Systems:&lt;/strong&gt; These systems control access to physical locations, such as doors, gates, or secure areas within a building.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network Access Control (NAC) Systems:&lt;/strong&gt; These systems manage access to network resources, ensuring that only authorized users and devices can connect to a network.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An integral part of many access control systems is the &lt;strong&gt;&lt;a href="https://www.cerbos.dev/blog/3-most-common-authorization-designs-for-saas-products#:~:text=kind%20of%20authorization.-,Access%20Control%20List,-Perhaps%20the%20simplest" rel="noopener noreferrer"&gt;Access Control List (ACL)&lt;/a&gt;&lt;/strong&gt;, which specifies which users or system processes are granted access to objects, as well as what operations are allowed on given objects. ACLs are crucial for implementing fine-grained access control in both physical and digital environments. &lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Access Control Systems
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Physical Access Control Systems&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Physical access control systems restrict access to physical locations. This can include anything from a simple lock and key to more advanced systems like keycard readers, biometric scanners, and turnstiles. These systems are commonly used in office buildings, data centers, and other secure facilities to ensure that only authorized personnel can enter restricted areas.&lt;/p&gt;

&lt;p&gt;Physical access control systems typically involve an authentication mechanism, such as a keycard or fingerprint scanner, which grants or denies access based on the user's credentials. When a user presents their credentials at a reader, the system checks against its database to verify if the user has permission to access the area.&lt;/p&gt;

&lt;p&gt;Installing a physical access control system involves setting up hardware components like card readers, biometric scanners, and electronic locks. It also requires configuring the software that manages access rights and tracks user activity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Network Access Control (NAC) Systems&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Network access control systems are designed to secure digital environments by managing access to network resources. NAC systems ensure that only authorized users and devices can connect to a network, thereby preventing unauthorized access and potential security breaches.&lt;/p&gt;

&lt;p&gt;NAC systems operate by authenticating users and devices before granting network access. They may use various authentication methods, such as usernames and passwords, digital certificates, or device health checks, to verify that a user or device meets the network's security requirements. Once authenticated, the system enforces network policies that determine what resources the user or device can access.&lt;/p&gt;

&lt;p&gt;NAC systems are vital for protecting sensitive data and maintaining network integrity. They are especially important in environments where multiple devices and users need to connect to the network, such as corporate offices, educational institutions, and healthcare facilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Role-Based Access Control (RBAC) and Access Control Lists (ACLs)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.cerbos.dev/blog/rbac-vs-abac" rel="noopener noreferrer"&gt;&lt;strong&gt;RBAC&lt;/strong&gt;&lt;/a&gt; is a method of managing access to resources based on the roles assigned to users. Instead of granting permissions to individual users, permissions are associated with roles, and users are assigned to these roles. This approach simplifies permission management, especially in large organizations where users may have similar access needs. For example, an "Administrator" role may have full access to system settings, while a "User" role may have limited access to only certain areas.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ACLs&lt;/strong&gt; provide a more granular level of control by specifying exactly which users or system processes have access to specific objects and what actions they are allowed to perform. In network security, ACLs are often used to control access to routers, firewalls, and other network devices, specifying which IP addresses or networks are allowed or denied access to specific resources.&lt;/p&gt;

&lt;p&gt;RBAC and ACLs are used in various scenarios, such as controlling access to files and directories in an operating system, managing user permissions in applications, and securing network resources. For a deeper understanding of RBAC and ACLs, you can refer to this guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Access Control Systems Work
&lt;/h2&gt;

&lt;p&gt;Access control systems operate on the fundamental principles of authentication and authorization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authentication:&lt;/strong&gt; This is the process of verifying the identity of a user or device. In physical access control systems, authentication might involve a keycard swipe, a fingerprint scan, or facial recognition. In digital access control systems, it might involve entering a username and password, providing a digital certificate, or using multi-factor authentication (MFA).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorization:&lt;/strong&gt; Once a user's identity has been authenticated, the system then determines whether the user has the necessary permissions to access the requested resource. This decision is made based on the user's role, the access control list (ACL), or network access policies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Logging and Monitoring:&lt;/strong&gt; Most access control systems also include logging and monitoring features, which record access events and track user activity. This is crucial for auditing purposes and for detecting any unauthorized access attempts.&lt;/p&gt;

&lt;p&gt;For a more detailed look at how authentication and authorization work together in access control systems, you can &lt;a href="https://www.cerbos.dev/blog/authentication-vs-authorization" rel="noopener noreferrer"&gt;visit this comprehensive guide.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Implementing an Access Control System
&lt;/h2&gt;

&lt;p&gt;Implementing an access control system offers numerous benefits, such as:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enhanced Security:&lt;/strong&gt; Access control systems provide a robust layer of security for both physical and digital assets. By restricting access to only authorized users, they reduce the risk of unauthorized access, theft, or data breaches. This is particularly important for organizations that handle sensitive information or operate in regulated industries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Streamlined Access Management:&lt;/strong&gt; With an access control system in place, managing user access becomes more straightforward. Role-based access control (RBAC) and access control lists (ACLs) allow administrators to easily define and modify permissions based on user roles or specific needs, reducing the complexity of access management.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Improved Compliance:&lt;/strong&gt; Many industries are subject to regulatory requirements that mandate strict access controls to protect sensitive data. Implementing an access control system can help organizations comply with regulations like GDPR, HIPAA, and PCI-DSS by ensuring that only authorized users have access to sensitive information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Audit and Monitoring Capabilities:&lt;/strong&gt; Access control systems typically include logging and monitoring features, which provide detailed records of who accessed what and when. This information is invaluable for auditing purposes and for investigating any potential security incidents.&lt;/p&gt;

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

&lt;p&gt;Access control systems are essential tools for securing both physical and digital assets. Whether you're implementing a physical system to control entry to a building or a network access control (NAC) system to protect sensitive data, these systems play a crucial role in maintaining security and ensuring that only authorized users can access critical resources. By leveraging role-based access control (RBAC) and access control lists (ACLs), organizations can efficiently manage user permissions and enhance their overall security posture.&lt;/p&gt;

&lt;p&gt;If you're considering implementing or upgrading an access control system, it's worth evaluating your current security measures and exploring the latest technologies available.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Access Controls for Users and Roles in SQL</title>
      <dc:creator>Anna</dc:creator>
      <pubDate>Thu, 14 Nov 2024 13:32:54 +0000</pubDate>
      <link>https://dev.to/cerbos/access-controls-for-users-and-roles-in-sql-44b6</link>
      <guid>https://dev.to/cerbos/access-controls-for-users-and-roles-in-sql-44b6</guid>
      <description>&lt;p&gt;In the world of databases, having the right access controls in place is like having a security team for your most valuable assets. SQL access control allows you to manage who can do what with your data, ensuring that only authorized users have the necessary permissions to interact with your database. Think of it as having a bouncer for your tables, keeping the riff-raff out and letting the right folks in. In this article, we'll explore the different types of access controls available in SQL, how to implement them, and best practices to keep your database secure. If you're new to database security, &lt;a href="https://azure.microsoft.com/en-us/resources/cloud-computing-dictionary/what-is-database-security" rel="noopener noreferrer"&gt;start with this beginner’s guide to get an overview.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Access Control in SQL
&lt;/h2&gt;

&lt;p&gt;Access control in SQL refers to the process of managing permissions for users and roles within a database. This involves defining who can access specific data and what actions they can perform on that data. Access controls are crucial for database security, as they help protect sensitive information from unauthorized access or modification.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Users&lt;/strong&gt;: Individual accounts that interact with the database. Each user can have specific permissions that define what operations they can perform, such as querying data, modifying tables, or managing database settings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Roles&lt;/strong&gt;: A collection of permissions that can be assigned to users. Roles simplify access management by allowing you to group permissions together and assign them to multiple users at once.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Permissions&lt;/strong&gt;: Specific actions that a user or role is allowed to perform, such as SELECT, INSERT, UPDATE, or DELETE.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By implementing access controls, you can ensure that users have the appropriate level of access to the data they need while minimizing the risk of unauthorized actions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Access Controls in SQL
&lt;/h2&gt;

&lt;h3&gt;
  
  
  User-Based Access Control
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What It Is&lt;/strong&gt;: User-based access control involves assigning permissions directly to individual users. This method is useful when you need to grant specific access rights to certain users based on their unique requirements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How It Works&lt;/strong&gt;: In SQL, you can create new users and assign them permissions using commands like CREATE USER, GRANT, and REVOKE. For example, you can create a user and grant them permission to select data from a specific table:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;CREATE USER 'john_doe'@'localhost' IDENTIFIED BY 'password';&lt;br&gt;
GRANT SELECT ON database_name.table_name TO 'john_doe'@'localhost';&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;When to Use It&lt;/strong&gt;: User-based access control is ideal for scenarios where you need to assign unique permissions to individual users. However, it can become cumbersome to manage as the number of users increases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Further Reading&lt;/strong&gt;: For more on user-based access control in SQL, visit this guide.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Role-Based Access Control (RBAC) in SQL
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What It Is&lt;/strong&gt;: Role-based access control involves creating roles with specific permissions and then assigning these roles to users. This approach simplifies permission management by allowing you to group permissions together and assign them to multiple users at once.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How It Works&lt;/strong&gt;: You can create roles in SQL and grant permissions to these roles using the CREATE ROLE and GRANT commands. For example, you can create an editor role and grant it the ability to insert and update data:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;CREATE ROLE editor;&lt;br&gt;
GRANT INSERT, UPDATE ON database_name.table_name TO editor;&lt;br&gt;
GRANT editor TO 'john_doe'@'localhost';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this example, the editor role is created with INSERT and UPDATE permissions, and then assigned to the user john_doe.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Benefits of Using Roles&lt;/strong&gt;: RBAC makes it easier to manage permissions, especially in environments with many users. By defining roles for different job functions (e.g., admin, editor, viewer), you can quickly assign the appropriate permissions to users without having to specify individual permissions for each user.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Access Control Lists (ACLs) in SQL
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What They Are&lt;/strong&gt;: Access Control Lists (ACLs) provide fine-grained control over who can access specific database objects and what actions they can perform. ACLs are essentially lists that specify which users or roles have access to certain resources and what operations they are allowed to perform.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How They Work&lt;/strong&gt;: ACLs can be applied to various database objects, such as tables, views, and stored procedures. For example, you can use ACLs to grant a user permission to execute a stored procedure:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;GRANT EXECUTE ON PROCEDURE database_name.procedure_name TO 'john_doe'@'localhost';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command adds an entry to the ACL for the specified procedure, allowing the user john_doe to execute it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use Cases&lt;/strong&gt;: ACLs are useful for scenarios that require granular control over database access. They allow you to define precise permissions for different users or roles, enhancing the security and flexibility of your access control strategy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Implementing Access Controls in SQL
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Creating and Managing Users&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating Users&lt;/strong&gt;: In SQL, you can create new users using the CREATE USER command. Once a user is created, you can assign them specific permissions to interact with the database. Here's an example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE USER 'jane_doe'@'localhost' IDENTIFIED BY 'securePassword!';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Assigning Permissions&lt;/strong&gt;: After creating a user, you can grant them permissions using the GRANT command. For instance, to allow the user to select and insert data into a table:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GRANT SELECT, INSERT ON database_name.table_name TO 'jane_doe'@'localhost';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Modifying Permissions&lt;/strong&gt;: If you need to change a user's permissions, you can revoke existing permissions and grant new ones as necessary. For example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;REVOKE INSERT ON database_name.table_name FROM 'jane_doe'@'localhost';&lt;br&gt;
GRANT UPDATE ON database_name.table_name TO 'jane_doe'@'localhost';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Creating and Managing Roles&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating Roles&lt;/strong&gt;: Roles in SQL are created using the CREATE ROLE command. You can then grant specific permissions to these roles and assign them to users. For example, to create a report_viewer role:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE ROLE report_viewer;&lt;br&gt;
GRANT SELECT ON database_name.report_table TO report_viewer;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Assigning Roles to Users&lt;/strong&gt;: Once a role is created and has the necessary permissions, you can assign it to users:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GRANT report_viewer TO 'jane_doe'@'localhost';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, jane_doe inherits the permissions granted to the report_viewer role.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices&lt;/strong&gt;: When defining roles, group permissions based on job functions and responsibilities to simplify access management. This approach not only streamlines the assignment of permissions but also enhances security by ensuring that users have the appropriate level of access.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Granting and Revoking Permissions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Granting Permissions&lt;/strong&gt;: Permissions in SQL can be granted at various levels, such as on a database, table, or specific columns. Here’s how you can grant different types of permissions:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GRANT SELECT ON database_name.table_name TO 'jane_doe'@'localhost';&lt;br&gt;
GRANT INSERT, UPDATE ON database_name.table_name TO 'editor';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The first command grants the SELECT permission on a table to a user, while the second grants INSERT and UPDATE permissions to a role.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Revoking Permissions&lt;/strong&gt;: It's important to regularly review and update permissions. If a user or role no longer needs access to a resource, you should revoke the permissions:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;REVOKE SELECT ON database_name.table_name FROM 'jane_doe'@'localhost';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Importance of Revocation&lt;/strong&gt;: Revoking unnecessary permissions is a key part of maintaining database security. It ensures that users do not have access to data they no longer need, reducing the risk of unauthorized access or data breaches.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices for SQL Access Control
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Start with the Principle of Least Privilege&lt;/strong&gt;: Always grant the minimum permissions necessary for users and roles to perform their tasks. This reduces the risk of unauthorized access and potential security breaches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Regularly Audit Permissions&lt;/strong&gt;: Periodically review user and role permissions to ensure they are still appropriate. Remove any permissions that are no longer needed to maintain a secure environment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Roles to Simplify Management&lt;/strong&gt;: Define roles for different job functions and group permissions accordingly. Assign users to these roles instead of granting permissions directly to simplify access control and ensure consistency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitor and Log Access&lt;/strong&gt;: Implement logging and monitoring to track access to sensitive data. This helps detect any unauthorized access attempts and assists in audits and compliance reporting.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Implementing access controls for users and roles in SQL is essential for maintaining a secure and well-managed database environment. By understanding and using user-based access control, role-based access control &lt;a href="https://www.cerbos.dev/blog/rbac-vs-abac" rel="noopener noreferrer"&gt;(RBAC)&lt;/a&gt;, and access control lists (ACLs), you can effectively manage permissions and protect sensitive data. Remember, even your database tables need a bouncer to keep things in check. Regularly reviewing and updating access controls is key to ensuring that your database remains secure and that users have the appropriate level of access for their roles. If you're looking to dive deeper into SQL access control, there are plenty of resources and guides available to help you along the way.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>accesscontrol</category>
    </item>
    <item>
      <title>Keeping your AI on a tight leash</title>
      <dc:creator>Anna</dc:creator>
      <pubDate>Wed, 13 Nov 2024 12:39:34 +0000</pubDate>
      <link>https://dev.to/cerbos/keeping-your-ai-on-a-tight-leash-2pjh</link>
      <guid>https://dev.to/cerbos/keeping-your-ai-on-a-tight-leash-2pjh</guid>
      <description>&lt;p&gt;Picture this - your new AI system ends up spilling sensitive data. Nightmare scenario. As AI gets more complex, the risks of leaks and unauthorized access keep piling up.&lt;/p&gt;

&lt;p&gt;Fine-graind authorization can be a game-changer. It lets you enforce strict permissions tailored to your needs.&lt;/p&gt;

&lt;p&gt;In this piece, we'll look at how companies can protect their data in AI systems, especially when using retrieval-augmented generation (RAG) and large language models (LLMs).&lt;/p&gt;

&lt;h2&gt;
  
  
  Securing data in a centralized world
&lt;/h2&gt;

&lt;p&gt;A lot of companies are turning to RAG architectures for their AI apps. They let LLMs tap into internal data to improve outputs. But the tricky part is giving an LLM enough context without breaching privacy.&lt;/p&gt;

&lt;p&gt;The issue is making sure AI agents can't spill sensitive data. Most RAG setups centralize everything in a vector store, making it a pain to control what AI can access. The easy fix is loading all your data in one spot and using that with an LLM. But then you're giving anyone who touches that agent full access - recipe for privacy issues, compliance problems, and losing customer trust.&lt;/p&gt;

&lt;h2&gt;
  
  
  Access controls to the rescue
&lt;/h2&gt;

&lt;p&gt;To stay safe, organizations need a fine-grained permission model for their RAG architecture. This ensures AI systems provide the right context while keeping sensitive data locked down.&lt;/p&gt;

&lt;p&gt;But there are challenges. Building custom permissions for RAG is complicated. Without the right controls, you risk major data exposure. Plus, you need to set permissions before feeding data to models to stop leaks.&lt;/p&gt;

&lt;p&gt;That's where &lt;a href="https://www.cerbos.dev/" rel="noopener noreferrer"&gt;Cerbos&lt;/a&gt; comes in - the complete authorization solution. It makes sure AI only accesses authorized data, guarding your privacy and compliance. And it prevents leaks through real-time, permission-aware filtering. &lt;a href="https://docs.cerbos.dev/cerbos/latest/recipes/ai/rag-authorization/" rel="noopener noreferrer"&gt;Here's the documentation.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The path forward
&lt;/h2&gt;

&lt;p&gt;RAG and LLMs pack potential, but without watertight access controls, they can turn into a liability. Fine-grained authorization is the key to letting your AI systems deliver value without compromising security, privacy, or compliance.&lt;/p&gt;

&lt;p&gt;Cerbos provides a scalable solution. So if you’re looking for ways to install guardrails around your AI applications - &lt;a href="https://solutions.cerbos.dev/authorization-in-rag-based-ai-systems-with-cerbos" rel="noopener noreferrer"&gt;you can learn more here.&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Authorization needs to be dynamic, declarative, and decoupled</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Tue, 12 Nov 2024 10:00:00 +0000</pubDate>
      <link>https://dev.to/cerbos/authorization-needs-to-be-dynamic-declarative-and-decoupled-2omd</link>
      <guid>https://dev.to/cerbos/authorization-needs-to-be-dynamic-declarative-and-decoupled-2omd</guid>
      <description>&lt;p&gt;&lt;em&gt;Guest article written by Fatuma Abdullahi. Thanks! For more great community content and discussions, join our Slack today!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Authorization mechanisms have traditionally been closely tied to the main application logic, and while this works in traditional monolithic systems, maintaining this coupling becomes harder as application complexity grows.&lt;/p&gt;

&lt;p&gt;As authorization is a significant aspect of creating and maintaining secure systems, it is better to have it &lt;a href="https://www.cerbos.dev/features-benefits-and-use-cases/decoupled-authorization" rel="noopener noreferrer"&gt;decoupled&lt;/a&gt; (or "externalized"); that is, to reduce the dependence between authorization and core application logic. Decoupling simultaneously increases the reliability of the authorization functionality whilst decreasing the complexity of the core system itself.&lt;/p&gt;

&lt;p&gt;It is also advantageous to have authorization logic expressed in declarative terms to describe the rules and expected outcomes. This allows the system to make decisions rather than explicitly stating how decisions should be made, making the authorization system accessible to less technical members of an organization. This leads to a dynamic authorization system, or one that makes real-time decisions as requests come in.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjk6hfdxa1nfzr39a8is3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjk6hfdxa1nfzr39a8is3.png" alt="A flowchart that shows the process for user access to a resource. It starts with " width="800" height="1226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Decoupled, or externalized, authorization
&lt;/h2&gt;

&lt;p&gt;Using an authorization system that is external to your primary system offers some hard-to-beat advantages, including:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enhanced Security&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;External authorization providers are more secure because they are specialized, and are designed from the ground-up with domain-specific experience. They are more aware of the landscape and know what to look out for better than any team whose focus is pulled in many different directions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simpler Policy Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;External authorization providers offer a standard way of writing policies and rules, making policy management predictable and allowing the team to move faster.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Straightforward Scaling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;External authorization systems have the concept of scale built in. They can be adapted at any size, and when the application grows or its authorization needs change, the external system grows with it seamlessly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of externalizing authorization
&lt;/h2&gt;

&lt;p&gt;Decoupling authorization shares advantages with using an external system because both rely on the separation of authorization and business logic as a central pillar. However, additional advantages appear when using an internally-decoupled system. These include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Increased System Resilience&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Separating authorization logic and rules from your main application increases your systems' resilience as the interdependence between them reduces. This allows your system to withstand outages without affecting all your functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simplified Workflows&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Keeping authorization external to your primary system simplifies setting up authorization logic and rules. It keeps the teams' focus on how authorization should look independent of any core logic, reducing chances of blind spots and increasing clarity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Easier Maintenance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using separate authorization systems makes maintaining the authorization engine more straightforward because of the decoupling that occurs. This makes it simpler to debug and increases the team's developer experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  RBAC and decoupled authorization
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.cerbos.dev/features-benefits-and-use-cases/rbac" rel="noopener noreferrer"&gt;Role-based access Control (RBAC)&lt;/a&gt; is an authorization technique that uses a user's role in a system to determine what resources they can access. It is a common way to enforce authorization across systems by assigning permissions to roles rather than to individual users and then assigning roles to users. When enforcing decoupled authorization, RBAC is implemented by centralizing all roles and their related permissions across the system.&lt;/p&gt;

&lt;p&gt;There are some trade-offs when using RBAC to manage authorization, including:&lt;/p&gt;

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

&lt;p&gt;As a system grows, the number of roles and permissions might rapidly multiply leading to too many role definitions overall. This makes it harder to manage and reason about the authorization policies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Granular Permissions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sometimes, RBAC is used even in situations better served by more granular access controls. Scenarios requiring dynamic or context-specific permissions might be better served using other techniques like ABAC (Attribute-Based Access Control), which offer more control and flexibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reduced Flexibility&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Making changes to RBAC-based policies can be difficult in a growing system, and changes may cause system-wide repercussions. This can lead to a system being slower in adapting to changing authorization needs.&lt;/p&gt;

&lt;p&gt;It is important to consider these trade-offs when designing RBAC-based authorization policies and to consider whether other access control techniques might be a better fit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Authorization and microservices architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://solutions.cerbos.dev/monolith-to-microservices-migration-ebook" rel="noopener noreferrer"&gt;Microservice architecture&lt;/a&gt; refers to organizing application logic into services that typically carry out one thing and can be deployed independently while loosely coupled. For example, edge functions are microservices.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzzzkywpiqsbf32kv7cmk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzzzkywpiqsbf32kv7cmk.png" alt="A flowchart diagram showing a client communicating with an API Gateway, which routes requests to four services: Auth Service, User Service, Payment Service, and Notification Service. Each service connects to its respective database: Auth Database, User Database, Payment Database, and Notification Database." width="800" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a system where the backend isn’t distributed in this way (i.e. monolithic architecture), managing authorization queries is reasonably straightforward, as all the data is available in a central location. The challenge with authorization in a microservice architecture is that the services are separated by definition, and often may not talk to each other, making consistent access control and synchronization hard.&lt;/p&gt;

&lt;p&gt;There are several ways to handle authorization in a microservices architecture, including implementing a gateway API (Application Programming Interface) service. Cerbos can be integrated into a microservices architecture as a mechanism deployed alongside microservices (e.g. a sidecar in Kubernetes), such that every service has consistent access to the authorization endpoint.&lt;/p&gt;

&lt;p&gt;This flexible approach ensures that policies stay consistent across the entire system, regardless of the many services involved. This further simplifies policy management while enhancing security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Authorization best practices
&lt;/h2&gt;

&lt;p&gt;There are several principles to keep in mind to help make your authorization system robust and to follow best practices, including:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Principle of Least Privilege&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This principle emphasizes that users should only ever have the minimum access to perform the required role and no more. This reduces the risk of unauthorized access and the chances of a breach.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Continuous Monitoring and Logging&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Logging authorization requests is good practice. This makes it easier to monitor and detect any anti-patterns. Implementing this makes your authorization system more robust and secure, and it also simplifies compliance and audit procedures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Separation of Concerns&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Keeping authorization logic and policies decoupled increases your system's resilience, as any issues in parts of the application will not bring down the entire system. Additionally, decoupling authorization increases flexibility, extensibility, and maintainability at a system level.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn more!
&lt;/h2&gt;

&lt;p&gt;You can learn more about decoupled / externalized authorization using the resources below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.cerbos.dev/blog/authentication-vs-authorization" rel="noopener noreferrer"&gt;AuthN vs AuthZ&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cerbos.dev/blog/why-organizations-are-turning-to-decoupled-authorization-solutions" rel="noopener noreferrer"&gt;On decoupled authorization&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>authorization</category>
      <category>authz</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Best Practices for Managing Users, Roles, and Permissions</title>
      <dc:creator>Anna</dc:creator>
      <pubDate>Wed, 06 Nov 2024 16:02:20 +0000</pubDate>
      <link>https://dev.to/cerbos/best-practices-for-managing-users-roles-and-permissions-5140</link>
      <guid>https://dev.to/cerbos/best-practices-for-managing-users-roles-and-permissions-5140</guid>
      <description>&lt;p&gt;Managing users, roles, and permissions is like being the gatekeeper of a medieval castle. You have to decide who gets in, who stays out, and which keys each person carries. A well-thought-out system for managing user roles and permissions is crucial for keeping your organization's data secure and ensuring that teams have the right access to perform their jobs efficiently. But as much as we trust our colleagues, we wouldn't want "Bob from Accounting" wandering into the server room, right?&lt;/p&gt;

&lt;p&gt;Striking the right balance between security and functionality is key. In this article, we’ll explore best practices for managing users, roles, and permissions, so you can keep things running smoothly without compromising on security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Users, Roles, and Permissions
&lt;/h2&gt;

&lt;p&gt;Managing access control within an organization starts with understanding the basics: users, roles, and permissions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Users: These are the individuals who need access to your system. Each user should have a unique account to ensure that their actions can be tracked. This uniqueness is crucial for accountability and helps in auditing user activity.&lt;/li&gt;
&lt;li&gt;Roles: A role is essentially a group of permissions bundled together to match a specific job function. For instance, an "Administrator" role might include permissions to manage users, configure settings, and access all data, while a "Viewer" role might only include permissions to view certain data without making changes. Roles simplify the management of permissions by allowing administrators to assign a predefined set of permissions to users based on their role in the organization.&lt;/li&gt;
&lt;li&gt;Permissions: These are specific access rights granted to users or roles. Permissions define what actions a user can perform, such as reading data, modifying records, or deleting files. In a more granular system, permissions can be defined at different levels, such as database level, table level, or even column level.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A roles and permissions matrix is a tool that helps you visualize and define the relationships between these elements. It provides a clear overview of what each role is allowed to do, making it easier to manage and audit access controls. For more on creating a roles and permissions matrix, &lt;a href="https://clickup.com/templates/roles-and-permission-matrix-t-200633907" rel="noopener noreferrer"&gt;visit this detailed guide.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices for Managing Users, Roles, and Permissions
&lt;/h2&gt;

&lt;p&gt;1.Define Clear User Roles&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start with a Plan: Begin by identifying the various job functions within your organization and outline the responsibilities of each role. This planning phase is crucial for ensuring that each role has the appropriate level of access. It's helpful to involve stakeholders from different departments to make sure all functions are adequately covered.&lt;/li&gt;
&lt;li&gt;Use a Roles and Permissions Matrix: A roles and permissions matrix is an essential tool in this process. It allows you to map out each role and the permissions associated with it. This not only streamlines the process of assigning permissions but also provides a clear documentation trail. You can find a useful template for creating your matrix at &lt;a href="https://clickup.com/templates/roles-and-permission-matrix-t-200633907" rel="noopener noreferrer"&gt;this source.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2.Implement the Principle of Least Privilege&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Minimize Access: The principle of least privilege (PoLP) dictates that users should be given the minimum level of access necessary to perform their duties. By applying PoLP, you reduce the risk of unauthorized access and potential data breaches. For instance, a marketing analyst might only need read access to customer data, while an IT administrator might need write access to system configurations.&lt;/li&gt;
&lt;li&gt;Apply to All Roles: This principle should be applied across the board. Even users with elevated roles, like administrators, should only have access to systems and data that are essential for their responsibilities. A well-defined roles and permissions matrix can help enforce this principle by clearly outlining the permissions associated with each role. For more on PoLP, you can &lt;a href="https://www.techtarget.com/searchsecurity/definition/principle-of-least-privilege-POLP" rel="noopener noreferrer"&gt;read this article.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3.Regularly Review and Update Permissions&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Conduct Periodic Audits: Permissions need to be reviewed regularly to ensure that they remain appropriate. Over time, users' roles within an organization can change, and permissions that were once necessary may no longer be needed. Conducting regular audits helps identify these discrepancies and mitigate security risks. During an audit, compare the current permissions against the roles and permissions matrix to identify and resolve any inconsistencies.&lt;/li&gt;
&lt;li&gt;Adapt to Organizational Changes: Organizations are dynamic, and so are user roles. As teams evolve or take on new projects, their access needs may change. It's important to adjust permissions accordingly to avoid "permission creep," where users accumulate more access than necessary over time. The matrix you created can be a helpful reference point during these updates.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;4.Automate Where Possible&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Leverage Automation Tools: Managing user roles and permissions manually can be time-consuming and prone to errors. Automated tools can streamline this process by assigning, modifying, and revoking access based on predefined rules. Tools like IAM (Identity and Access Management) systems can automatically assign roles to new users based on their job titles or departments. This not only speeds up the onboarding process but also ensures consistency in permission assignments. To explore popular IAM tools, visit this list of &lt;a href="https://www.cerbos.dev/blog/identity-and-access-management-tools" rel="noopener noreferrer"&gt;IAM software.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Monitor Access Automatically: Automation tools can also monitor user activities, generating alerts for any unusual access patterns or potential security threats. This real-time monitoring is crucial for quickly identifying and responding to potential security incidents.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;5.Establish a Robust Onboarding and Offboarding Process&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set Up Roles During Onboarding: Onboarding is the perfect time to set up user roles and permissions. During this process, assign roles based on the new team member's responsibilities and ensure they receive only the necessary access. Automation tools can assist by assigning roles automatically based on job titles or departments. A well-defined onboarding checklist can help streamline this process and ensure nothing is overlooked.&lt;/li&gt;
&lt;li&gt;Prompt Offboarding: When a team member leaves the organization or changes roles, it's essential to revoke or adjust their permissions immediately. This practice helps prevent unauthorized access from former employees and maintains system security. Automating the offboarding process can ensure that no permissions are left unchecked. You can find more on secure &lt;a href="https://www.forbes.com/advisor/business/offboarding/" rel="noopener noreferrer"&gt;offboarding processes here.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;6.Document and Communicate Roles and Permissions&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create Clear Documentation: Proper documentation is vital for maintaining an organized and secure system. Your documentation should include detailed descriptions of each role, the permissions associated with each role, and the rationale behind these assignments. This level of detail is not only helpful for current administrators but also essential for audits and training new administrators.&lt;/li&gt;
&lt;li&gt;Communicate Policies to the Team: It’s important that all users understand the roles and permissions policies in place. Clear communication can help set expectations and foster a culture of security awareness. Regular training sessions can be beneficial in educating users about the importance of following these policies. For tips on effective communication of security policies, check out &lt;a href="https://www.linkedin.com/advice/3/how-can-you-ensure-your-data-security-policies-osfkf" rel="noopener noreferrer"&gt;this article.&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Effective management of users, roles, and permissions is essential for maintaining a secure and efficient system within any organization. By defining clear roles, adhering to the principle of least privilege, and regularly reviewing and updating permissions, you can safeguard your data while enabling your team to work effectively. Remember, it's not just about keeping unauthorized users out—it's about making sure that everyone has the right level of access to do their job well.&lt;/p&gt;

&lt;p&gt;And, of course, let’s keep the server room safe from Bob and his snacks! By adopting these best practices, you’ll be well on your way to a more secure and organized access management system.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>New tools for effortless policy creation and testing in Cerbos Hub</title>
      <dc:creator>Anna</dc:creator>
      <pubDate>Wed, 09 Oct 2024 09:10:06 +0000</pubDate>
      <link>https://dev.to/cerbos/new-tools-for-effortless-policy-creation-and-testing-in-cerbos-hub-4eh7</link>
      <guid>https://dev.to/cerbos/new-tools-for-effortless-policy-creation-and-testing-in-cerbos-hub-4eh7</guid>
      <description>&lt;p&gt;We are introducing new features in the &lt;a href="https://www.cerbos.dev/news/new-tools-for-effortless-policy-creation-and-testing-in-cerbos-hub" rel="noopener noreferrer"&gt;Cerbos Hub Playground&lt;/a&gt; that aim to simplify how developers write, test, and iterate on authorization policies. &lt;/p&gt;

&lt;p&gt;This release includes three additions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The RBAC Policy Generator&lt;/li&gt;
&lt;li&gt;The API Request Simulator&lt;/li&gt;
&lt;li&gt;Connect a local PDP&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These new features were introduced to reduce the time and effort involved in writing and testing policies, addressing common frustrations developers face in their workflow. The goal is to streamline the entire process, allowing for more efficient and realistic policy testing without the need for repetitive manual tasks.&lt;/p&gt;

&lt;p&gt;With these enhancements, developers can spend less time on setup and more time on meaningful experimentation and testing, leading to a more productive workflow.&lt;/p&gt;

&lt;p&gt;Let’s explore each new feature individually.&lt;/p&gt;

&lt;h2&gt;
  
  
  RBAC Policy Generator
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;RBAC Policy Generator&lt;/strong&gt;, (or the RPG if you enjoy playing with acronyms) which was released to the public playground last year, is now part of Cerbos Hub. This feature allows users to create role-based access control (RBAC) policies using a simple, no-code wizard. Once you’re done defining your roles and permissions in the RPG it will populate your playground with the YAML code corresponding to your defined RBAC policies, and a test dataset you can use for troubleshooting and further experimentation.&lt;/p&gt;

&lt;p&gt;This feature makes setting up and testing RBAC policies faster and more straightforward and frees developers from the curse of the blank page.&lt;/p&gt;

&lt;p&gt;To use the R(BAC)PG, click &lt;strong&gt;New Playground&lt;/strong&gt; in the Hub Playground’s main page and then click the RBAC Policy Generator option when prompted to choose a set up method.&lt;/p&gt;

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

&lt;p&gt;You’ll then be prompted to define your users, resource types, and actions, which will populate a checkbox grid you can use to assign permissions to roles.&lt;/p&gt;

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

&lt;p&gt;Then click Generate Policy and you’ll see that the Playground automatically populates with policies written in YAML that reflect your selections in the wizard. It also comes ready with test data. You can then continue to manipulate and test your policies in the playground using the normal interface.&lt;/p&gt;

&lt;h2&gt;
  
  
  API Request Simulator
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;API Request Simulator&lt;/strong&gt;, (APIRS? ARSim? This one’s not as fun, unfortunately) also previously released in the public playground, is now integrated into Cerbos Hub. This feature allows users to simulate API requests without running a local policy decision point (PDP) and view the output of the Check Resources and Query Plan Resources APIs for any combination of user and resource.&lt;/p&gt;

&lt;p&gt;This feature bridges the gap between written documentation and practical use by showing actual responses from the PDP, helping developers understand and verify how their policies behave in different scenarios. You can see the details of how the PDP evaluates policies, including the structure and data in the response. It’s useful for both understanding how Cerbos works and debugging policies based on real API outputs.&lt;/p&gt;

&lt;p&gt;To use the API simulator, find the *&lt;em&gt;Implement *&lt;/em&gt; tab in the Hub Playground's right sidebar. Select from test fixtures already defined in your playground, (principal, resource, actions, etc.). You’ll be able to see exactly how the request and response are structured and observe the expected allow/deny response based on your policies.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Connect a PDP to your Playground
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Playground PDP&lt;/strong&gt; (PG PDP?) feature allows developers to establish a live connection between their development environment and the Hub Playground, eliminating the need to download files and reconfigure a Policy Decision Point (PDP) for each change. This setup lets developers test authorization policies in real-time, significantly reducing the manual steps previously required for policy testing and iteration.&lt;/p&gt;

&lt;p&gt;Any changes you make in the playground are immediately reflected in your local PDP, providing a real-time feedback loop for integration testing.&lt;/p&gt;

&lt;p&gt;To &lt;strong&gt;connect a PDP&lt;/strong&gt; to your playground, go to the Implement tab in your right hand sidebar, and click Connect a PDP. You will be guided with detailed instructions within the UI. And you can view our demo to see how it’s done.&lt;/p&gt;

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

&lt;p&gt;&lt;em&gt;Important note:&lt;br&gt;
The live-connected PDP is intended for development and testing purposes only. For production environments, you should use Cerbos Hub's managed CI/CD pipeline by setting up a workspace connected to your policy repository. In production, you can also leverage Cerbos Hub's audit logs feature to store and analyze all authorization decisions made by your PDPs, offering greater visibility and control over policy enforcement.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We invite you to explore these new features and share your feedback with us on &lt;a href="https://community.cerbos.dev/" rel="noopener noreferrer"&gt;Slack!&lt;/a&gt;&lt;/p&gt;

</description>
      <category>authorization</category>
      <category>security</category>
      <category>softwareengineering</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Authentication and authorization in Node.js applications</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Tue, 08 Oct 2024 13:00:00 +0000</pubDate>
      <link>https://dev.to/cerbos/authentication-and-authorization-in-nodejs-applications-12fk</link>
      <guid>https://dev.to/cerbos/authentication-and-authorization-in-nodejs-applications-12fk</guid>
      <description>&lt;p&gt;&lt;em&gt;Thanks to our friendly Cerbos community member—who wishes to remain anonymous—for this tutorial. For more great community content and discussions, &lt;a href="https://go.cerbos.io/slack" rel="noopener noreferrer"&gt;join our Slack&lt;/a&gt; today!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this article, we will discuss authentication and authorization, and how to implement both JWT authentication and Cerbos authorization in a Node.js application.&lt;/p&gt;

&lt;h1&gt;
  
  
  Understanding authentication
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.cerbos.dev/blog/authentication-vs-authorization" rel="noopener noreferrer"&gt;Authentication&lt;/a&gt; is the process of verifying the identity of a user. In a Node.js application, we typically authenticate a user based on a set of credentials, such as a username and password, to gain access to the application.&lt;/p&gt;

&lt;p&gt;Some common authentication methods are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Username and password&lt;/li&gt;
&lt;li&gt;Token-based authentication&lt;/li&gt;
&lt;li&gt;Single Sign-On (SSO)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The authentication process works like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The user provides their credentials.&lt;/li&gt;
&lt;li&gt;The server verifies the provided credentials.&lt;/li&gt;
&lt;li&gt;If the credentials are valid, the server generates an authentication token or session ID for the user.&lt;/li&gt;
&lt;li&gt;The newly generated token/session ID is sent back to the client and stored for future use.&lt;/li&gt;
&lt;li&gt;To prove their authenticity, the user includes the token/session ID in each request.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Understanding authorization
&lt;/h1&gt;

&lt;p&gt;Authorization is the process of giving access to users to do specific work/actions. It decides what an authenticated user is allowed to do within the application. After authentication, authorization makes sure that the user only does what they're allowed to do, following specific rules and permissions.&lt;/p&gt;

&lt;p&gt;Some common authentication models are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.cerbos.dev/features-benefits-and-use-cases/rbac" rel="noopener noreferrer"&gt;Role-based access control (RBAC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cerbos.dev/features-benefits-and-use-cases/abac" rel="noopener noreferrer"&gt;Attribute-based access control (ABAC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cerbos.dev/features-benefits-and-use-cases/pbac" rel="noopener noreferrer"&gt;Policy-based access control (PBAC)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How does authorization work?
&lt;/h2&gt;

&lt;p&gt;The authorization process works like this: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The authenticated user makes a request to the server.&lt;/li&gt;
&lt;li&gt;The server verifies the user and gets their assigned roles and permissions.&lt;/li&gt;
&lt;li&gt;The server evaluates if the user has permission for the requested actions.&lt;/li&gt;
&lt;li&gt;If the user is authorized, the server allows the user to perform the requested actions.&lt;/li&gt;
&lt;li&gt;Otherwise, it denies access and returns an appropriate error response.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Role Based Access Control, or RBAC, is an access control method that gives permissions to the user based on their assigned roles within our applications. In simple words, it controls what users can do within the application.&lt;/p&gt;

&lt;p&gt;Instead of assigning permissions to individual users, RBAC groups users into roles, and then assigns permissions to those roles. This makes it easier to manage access control, as we only need to update permissions for a role, rather than for each individual user. &lt;/p&gt;

&lt;p&gt;Key components of RBAC are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Role: Defines a set of responsibilities, tasks, or functions within the application.&lt;/li&gt;
&lt;li&gt;Permissions: Represents specific actions that users can perform.&lt;/li&gt;
&lt;li&gt;Role Assignments: Users are assigned to one or more roles, and each role is associated with a set of permissions.&lt;/li&gt;
&lt;li&gt;Access control policies: Dictate which roles can access particular resources and what actions they can take.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foeijuj5c5d5ub200d9bw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foeijuj5c5d5ub200d9bw.png" alt="{User} -- is assigned to --&gt; {Role} -- has --&gt; {Permission} -- grants access to --&gt; {Resource}" width="632" height="624"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;RBAC is powerful, but implementing and managing it yourself is not easy. The open-source Cerbos PDP (or Policy Decision Point), acts as a &lt;a href="https://www.cerbos.dev/blog/authorization-as-a-service" rel="noopener noreferrer"&gt;stand-alone service&lt;/a&gt;, streamlining access control by centralizing both policy decisions and audit log collection, and decoupling authorization logic from your application. &lt;/p&gt;

&lt;p&gt;Cerbos can function effectively within diverse software environments, from monoliths to fully decentralized architectures. It’s stateless and can be deployed via a Kubernetes sidecar, in a Docker container, or even as a single binary on a virtual machine. Cerbos exposes a rich HTTP API, which makes it language-agnostic, and allows it to interact and scale seamlessly with other services.&lt;/p&gt;

&lt;h1&gt;
  
  
  Implementing authentication and authorization in Node.js
&lt;/h1&gt;

&lt;p&gt;Now that we have an understanding of authentication and authorization, let’s explore how to implement them in our Node.js application. In this section, we’ll build a simple Node.js app and integrate authentication and authorization functionalities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before starting the project, make sure you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node.js and npm installed on your system.&lt;/li&gt;
&lt;li&gt;Docker installed on your machine (for running the Cerbos container).&lt;/li&gt;
&lt;li&gt;Postman or a similar tool for testing API endpoints.&lt;/li&gt;
&lt;/ul&gt;

&lt;center&gt;

  &lt;a href="https://cta-service-cms2.hubspot.com/web-interactives/public/v1/track/redirect?encryptedPayload=AVxigLJA2octU4MHpvkByVY8c8GGX54s4sv%2FREy0FQ%2BENY%2BVh7GayBJpPBkDBHlFn%2BKRuPaVeZltIDeDoMZ69iqehJYl0A4MPFRzo00stUk2S%2Bttd%2FH6pEZn4tU%2FfISJxM5G0vTcoT514DqmX7ZIbcifP4z4zly5UN2NRmyOeKg%3D&amp;amp;webInteractiveContentId=168994186087&amp;amp;portalId=20289770" rel="noopener noreferrer"&gt;
    &lt;img alt="BlogCTA - PDP" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fno-cache.hubspot.com%2Fcta%2Fdefault%2F20289770%2Finteractive-168994186087.png" width="538" height="277"&gt;
  &lt;/a&gt;

&lt;/center&gt;

&lt;h2&gt;
  
  
  Set up a Node.js project
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create the project
&lt;/h3&gt;

&lt;p&gt;To start with, we need to set up a Node.js project. Run the following command in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will initialize a new Node.js project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install the dependencies
&lt;/h3&gt;

&lt;p&gt;Next, install the required dependencies for our project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;express jsonwebtoken dotenv bcryptjs nodemon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install the following packages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;express&lt;/code&gt;: A popular web framework for Node.js.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;jsonwebtoken&lt;/code&gt;: For generating and verifying JSON Web Tokens (JWT) for authentication.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dotenv&lt;/code&gt;: loads environment variables from a &lt;code&gt;.env&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bcryptjs&lt;/code&gt;: to hash the password.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;nodemon&lt;/code&gt;: nodemon helps Node.js-based application restarts automatically when there is a change in the code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Environment variables
&lt;/h3&gt;

&lt;p&gt;Next, create a &lt;code&gt;.env&lt;/code&gt; file to securely store our sensitive information, such as API credentials.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="py"&gt;JWT_SECRET&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Your_Secret_Key_Here"&lt;/span&gt;
&lt;span class="py"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;3000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create the Express server
&lt;/h3&gt;

&lt;p&gt;Now, we'll create an &lt;code&gt;index.js&lt;/code&gt; file in the base directory and set up a simple Express server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dotenv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;//middleware provided by Express to parse incoming JSON requests.&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; 

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Server is running on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the top of the project, we're loading environment variables using &lt;code&gt;dotenv.config()&lt;/code&gt; to make them accessible throughout the file. This way, we can use the &lt;code&gt;dotenv&lt;/code&gt; package to access the &lt;code&gt;PORT&lt;/code&gt; number from the &lt;code&gt;.env&lt;/code&gt; file, instead of hardcoding it directly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Run the project
&lt;/h3&gt;

&lt;p&gt;In this step, we'll add a start script to the package.json file to easily run our project.&lt;/p&gt;

&lt;p&gt;By default we'd have to restart our server each time we make changes to a file. To avoid this, we can use &lt;code&gt;nodemon&lt;/code&gt;, which will scan for changes and restart automatically.&lt;/p&gt;

&lt;p&gt;Add the following item to &lt;code&gt;package.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nodemon index.js"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now, we test!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff3r2g8u6ilmxsu7v1im1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff3r2g8u6ilmxsu7v1im1.png" alt="Screenshot of npm run start, running successfully" width="800" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, open &lt;code&gt;http://localhost:3000/&lt;/code&gt; in a browser, and if everything went to plan, you'll see the default "Hello World" page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing authentication with JWT
&lt;/h2&gt;

&lt;p&gt;Our basic project setup is done! Next, we’ll implement authentication using JWT tokens.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create routes for authentication
&lt;/h3&gt;

&lt;p&gt;The authentication route will allow users to sign up and log in. Commonly, routes go in &lt;code&gt;routes/&lt;/code&gt;, and since this is an authentication mechanism, we'll name it &lt;code&gt;authentication.js&lt;/code&gt;. I've split this into multiple sections to make it easier to read, but it's the same file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jsonwebtoken&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bcrypt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bcryptjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// in-memory database to keep things basic for this tutorial&lt;/span&gt;

&lt;span class="c1"&gt;// Register route&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/signup, (req, res) = &amp;gt;{

  const { username, password, role } = req.body;

  if (!Array.isArray(role)) {
    return res.status(400).json({ message: "Role must be an array" });
  }

  const userExists = users.find(user = &amp;gt;user.username === username);
  if (userExists) {
    return res.status(400).json({
      message: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="nx"&gt;already&lt;/span&gt; &lt;span class="nx"&gt;exists&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;
    });
  }

  const hashedPassword = bcrypt.hashSync(password, 8);

  users.push({
    username,
    password: hashedPassword,
    role
  });

  res.status(201).json({
    message: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="nx"&gt;registered&lt;/span&gt; &lt;span class="nx"&gt;successfully&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;
  });
});
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Login route &lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/login&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;password&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;User not found&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isPasswordValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compareSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isPasswordValid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid credentials&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;JWT_SECRET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;expiresIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1h&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="nx"&gt;token&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The signup route allows users to register by providing a username and password. Upon receiving the data, it creates a new user instance and saves it to the in-memory database.&lt;/p&gt;

&lt;p&gt;And, the login route verifies the user's credentials against the in-memory database. If the username and password match, it generates a JWT token and returns it to the client.&lt;/p&gt;

&lt;h3&gt;
  
  
  Middleware for JWT verification
&lt;/h3&gt;

&lt;p&gt;Now, we’ll add one middleware function called &lt;code&gt;verifyJWT&lt;/code&gt; that verifies the JWT token sent by the client, and which authenticates the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jsonwebtoken&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;authenticateToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;allowedRoles&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;authHeader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;authorization&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;authHeader&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;authHeader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;No&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="nx"&gt;provided&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;
      });
    }

    jwt.verify(token, process.env.JWT_SECRET, (err, user) = &amp;gt;{
      if (err) {
        return res.status(403).json({
          message: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="nx"&gt;Invalid&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;
        });
      }

      if (!allowedRoles.includes(user.role)) {
        return res.status(403).json({
          message: ‘You do not have the correct role&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;authenticateToken&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Protected route
&lt;/h3&gt;

&lt;p&gt;Finally, we'll integrate these authentication routes with our express application in the &lt;code&gt;index.js&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/protected&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;authenticateToken&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Welcome Admin &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have created a &lt;code&gt;/protected&lt;/code&gt; route that uses &lt;code&gt;authenticateToken&lt;/code&gt; to check if the user is authenticated.&lt;/p&gt;

&lt;p&gt;If the user is authenticated, the server sends back a response saying "This is a Protected Route. Welcome [username]".&lt;/p&gt;

&lt;p&gt;Here, &lt;code&gt;[username]&lt;/code&gt; is replaced with the username of the authenticated user.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test the endpoints
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Sign-up
&lt;/h4&gt;

&lt;p&gt;To validate the sign-up endpoint, we'll make a POST request to this route:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;http://localhost:3000/auth/signup&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this header:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Content-Type : application/json&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the following JSON body:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Arindam Majumder"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"password"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"071227"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"roles"&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="s2"&gt;"admin"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzclu41leah8wi4b6hbci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzclu41leah8wi4b6hbci.png" alt="Screenshot of a postman interaction" width="800" height="501"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We got the token back as a response. We will copy the token as we'll need it in the next section.&lt;/p&gt;

&lt;h4&gt;
  
  
  Protected route
&lt;/h4&gt;

&lt;p&gt;Now that we have obtained a JWT token from the login endpoint, we will test the protected route by including this token in the request headers.&lt;/p&gt;

&lt;p&gt;For that, we'll make a GET request to the protected route URL &lt;code&gt;http://localhost:3000/protected&lt;/code&gt;. In the request headers, we'll include the JWT token obtained from the login endpoint:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwgyx6244kp4a64eq21x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwgyx6244kp4a64eq21x.png" alt="Screenshot of a postman interaction" width="800" height="471"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With this, we have successfully implemented JWT authentication in Node.js!&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing authorization with Cerbos
&lt;/h2&gt;

&lt;p&gt;Now that we have added authentication to our project, we can now proceed authorization using the Cerbos PDP.&lt;/p&gt;

&lt;h3&gt;
  
  
  Launch the Cerbos container
&lt;/h3&gt;

&lt;p&gt;We will begin by launching the Cerbos container via Docker.&lt;/p&gt;

&lt;p&gt;In the base directory, use the following command to run the Docker container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; cerbos &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;/cerbos/policies:/policies &lt;span class="nt"&gt;-p&lt;/span&gt; 3592:3592 &lt;span class="nt"&gt;-p&lt;/span&gt; 3593:3593 ghcr.io/cerbos/cerbos:0.34.0 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And a quick &lt;code&gt;docker ps&lt;/code&gt; to verify that the container persists.&lt;/p&gt;

&lt;p&gt;For more information about the Cerbos container, see the &lt;a href="https://docs.cerbos.dev/cerbos/latest/installation/container.html" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Initialize the Cerbos client
&lt;/h3&gt;

&lt;p&gt;Next, we set up the Cerbos client using the &lt;code&gt;@cerbos/grpc&lt;/code&gt; library, which we first need to install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @cerbos/grpc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we initialize the client with a few lines of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;GRPC&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@cerbos/grpc&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cerbos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GRPC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;localhost:3593&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;tls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Define a CRUD policy
&lt;/h3&gt;

&lt;p&gt;After initializing the Cerbos client, we’ll define a simple CRUD policy in place for our application. Add this basic policy into the policies folder at &lt;code&gt;cerbos/policies/contact.yaml&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;api.cerbos.dev/v1&lt;/span&gt;
&lt;span class="na"&gt;resourcePolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;default&lt;/span&gt;
  &lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;contact&lt;/span&gt;
  &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;actions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;read"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;roles&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;admin&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;user&lt;/span&gt;
    &lt;span class="na"&gt;effect&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;EFFECT_ALLOW&lt;/span&gt;

  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;actions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;create"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;roles&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;admin&lt;/span&gt;
    &lt;span class="na"&gt;effect&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;EFFECT_ALLOW&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Access control middleware
&lt;/h3&gt;

&lt;p&gt;Next, we'll create some middleware to check access for requests. In &lt;code&gt;middleware/access.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;GRPC&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@cerbos/grpc&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cerbos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GRPC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;localhost:3593&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;tls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jwtToPrincipal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;iat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;roles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;rest&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;readAccess&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;cerbos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;checkResource&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;principal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;jwtToPrincipal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;contact&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;read&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;decision&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isAllowed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;read&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Unauthorized&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;writeAccess&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;cerbos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;checkResource&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;principal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;jwtToPrincipal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;contact&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;create&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;decision&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isAllowed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;create&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Unauthorized&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;readAccess&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;writeAccess&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the &lt;code&gt;jwtToPrincipal&lt;/code&gt; function is a utility function that converts a JSON Web Token (JWT) payload into a Cerbos principal object. It extracts the &lt;code&gt;sub&lt;/code&gt; (subject), &lt;code&gt;iat&lt;/code&gt; (issued at), and &lt;code&gt;roles&lt;/code&gt; properties from the JWT payload and assigns them to the corresponding properties of the principal object&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;readAccess&lt;/code&gt; function is an asynchronous middleware function that checks if the current user has permission to read a contact resource. It uses the &lt;code&gt;cerbos.checkResource&lt;/code&gt; method to make an authorization decision. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;writeAccess&lt;/code&gt; function is similar to the &lt;code&gt;readAccess&lt;/code&gt; function, but it checks for permission to write to the contact resource instead of reading. It uses the "write" action in the &lt;code&gt;cerbos.checkResource&lt;/code&gt; method.&lt;/p&gt;

&lt;h3&gt;
  
  
  Implement authorized routes
&lt;/h3&gt;

&lt;p&gt;Finally, let's implement routes to check user access using Cerbos.&lt;/p&gt;

&lt;p&gt;Import the required middleware functions for read and write access checks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;readAccess&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;writeAccess&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./middleware/access&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update &lt;code&gt;index.js&lt;/code&gt; file to include the following routes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/read&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;userMiddleware&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;readAccess&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Read Access Granted&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/write&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;userMiddleware&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;writeAccess&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Write Access Granted&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that’s it! By following these steps, we have successfully implemented authorization and RBAC in our Node.js application using Cerbos.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the authorized route
&lt;/h2&gt;

&lt;p&gt;Now, we’ll test to see if the user has permission to do specific tasks. &lt;/p&gt;

&lt;p&gt;To check if the user has write access, we'll make a POST request to &lt;code&gt;http://localhost:3000/write&lt;/code&gt; with the following headers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Content-Type: application/json&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Authorization: JWT_TOKEN&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsvt5629hfx909l9g014j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsvt5629hfx909l9g014j.png" alt="Screenshot of a postman interaction" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The user with the admin role has access to this route.&lt;/p&gt;

&lt;p&gt;Next, to check if the user has read access, we'll make a GET request to &lt;code&gt;http://localhost:3000/read&lt;/code&gt; with the following headers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Content-Type: application/json&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Authorization: JWT_TOKEN&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If successful, that will return as &lt;code&gt;Read Access Granted&lt;/code&gt; as well.&lt;/p&gt;

&lt;p&gt;Finally, let's check a user with the &lt;em&gt;user&lt;/em&gt; role to see if it has write access or not. Make a POST request to &lt;a href="http://localhost:3000/write" rel="noopener noreferrer"&gt;http://localhost:3000/write&lt;/a&gt; with the following headers &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Content-Type: application/json&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;`Authorization: JWT_TOKEN&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As expected, we got an &lt;em&gt;unauthorized&lt;/em&gt; response. That means the user doesn’t have access to that route. &lt;/p&gt;

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

&lt;p&gt;In this article, we covered the basics of authentication and authorization, and how to integrate JWT authentication and Cerbos authorization into a Node.js application.&lt;/p&gt;

&lt;center&gt;

  &lt;a href="https://cta-service-cms2.hubspot.com/web-interactives/public/v1/track/redirect?encryptedPayload=AVxigLJcZiZ24z6ZSah4IpOn8dABnds9mrKKh6e4PJqvKxet7ffhWKXW0MdjhgVQy4mpPiz%2BmP6afTEqsC16yImlV%2FKtxCF9SLhJub2UaJVdW9FJFbjqw2pDljc4t3o7wysyDZUCo3QHGt4JiG3yBqSqDFxK%2FhbxRSgua197Oqt7wTaa07SsSxBmDYqFpmLr&amp;amp;webInteractiveContentId=168996984756&amp;amp;portalId=20289770" rel="noopener noreferrer"&gt;
    &lt;img alt="BlogCTA - Hub" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fno-cache.hubspot.com%2Fcta%2Fdefault%2F20289770%2Finteractive-168996984756.png" width="538" height="277"&gt;
  &lt;/a&gt;

&lt;/center&gt;

</description>
      <category>authorization</category>
      <category>node</category>
      <category>tutorial</category>
      <category>express</category>
    </item>
    <item>
      <title>How to implement authorization in a React application</title>
      <dc:creator>Anna</dc:creator>
      <pubDate>Fri, 06 Sep 2024 12:24:20 +0000</pubDate>
      <link>https://dev.to/cerbos/how-to-implement-authorization-in-a-react-application-48fb</link>
      <guid>https://dev.to/cerbos/how-to-implement-authorization-in-a-react-application-48fb</guid>
      <description>&lt;p&gt;React is a JavaScript-based framework and UI development library as opposed to a programming language. React offers a variety of extensions that make it useful beyond its best-known role as a UI development tool that handles CSS file prefixes. Implementing authorization in a React application using Cerbos produces a slew of benefits we'll get into shortly. But first, here is a simplified step-by-step guide covering &lt;a href="https://www.cerbos.dev/blog/how-to-implement-authorization-in-react-js" rel="noopener noreferrer"&gt;how to implement Cerbos authorization into your React app.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implement Cerbos authorization in a React application
&lt;/h2&gt;

&lt;p&gt;Step 1: Install the Cerbos client library in your React project.&lt;br&gt;
Step 2: Create a Cerbos client instance in a central location within the React app. Typically where you would initialize the application.&lt;br&gt;
Step 3: Be certain that you replace '&lt;a href="http://your-cerbos-server-endpoint" rel="noopener noreferrer"&gt;http://your-cerbos-server-endpoint&lt;/a&gt;' with the endpoint of your Cerbos server.&lt;br&gt;
Step 4: Use Cerbos to check permissions prior to rendering various components or enabling certain actions.&lt;br&gt;
Step 5: Handle unauthorized access by creating custom responses to users who do not demonstrate the necessary permissions.&lt;br&gt;
Step 6: Integrate Cerbos with your React router to control access to specific routes using the Cerbos hook in concert with the useHistory hook from the React router. (Note this step is optional since your React app may not use the React router for navigation.)&lt;br&gt;
Step 7: Don’t forget to adjust the relevant code snippets in accordance with your specific needs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.cerbos.dev/blog/how-to-implement-authorization-in-react-js" rel="noopener noreferrer"&gt;For more details covering implementation of Cerbos in React applications, please refer here.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of implementing Cerbos authorization in a React application
&lt;/h2&gt;

&lt;p&gt;Implementing Cerbos into your React app will provide a variety of benefits including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fine-grained access control: Cerbos enables you to enforce precise control based on attributes like user roles, actions, resource types and more.&lt;/li&gt;
&lt;li&gt;Centralized policy management: Cerbos centralizes and simplifies policy management making it easy to define, manage and update all your access control policies on the fly.&lt;/li&gt;
&lt;li&gt;More effective audit and compliance capabilities: Cerbos allows you to monitor all access control decisions thereby enhancing your ability to enforce compliance.&lt;/li&gt;
&lt;li&gt;Policy as code: With Cerbos, authorization policies are defined using declarative language making it easy to understand and audit access control policies.&lt;/li&gt;
&lt;li&gt;React component level authorization: The Cerbos React library enables you to implement React component level authorization which can produce a more responsive and personalized experience for the user.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;In summary, when you integrate Cerbos into your React app you improve application security, flexibility and overall manageability.&lt;/p&gt;

&lt;p&gt;Relevant links&lt;br&gt;
Are you looking to improve your application's authorization logic and security? Look no further than Cerbos! Discover how Cerbos works and explore its powerful features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.cerbos.dev/blog/how-to-implement-authorization-in-react-js" rel="noopener noreferrer"&gt;Detailed React + Cerbos guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.cerbos.dev/features-benefits-and-use-cases/cerbos-playground" rel="noopener noreferrer"&gt;Cerbos playground&lt;/a&gt;, where you can easily build and test policies in an online editor&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.cerbos.dev/features-benefits-and-use-cases/ecosystem" rel="noopener noreferrer"&gt;Cerbos ecosystem&lt;/a&gt; and its seamless integrations with various SDKs, modern frameworks, and authentication providers&lt;/li&gt;
&lt;li&gt;Learn more about &lt;a href="https://www.cerbos.dev/product-cerbos-hub" rel="noopener noreferrer"&gt;Cerbos Hub here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Get started building your first policies with ease and join the &lt;a href="https://www.cerbos.dev/customers" rel="noopener noreferrer"&gt;companies that trust Cerbos in production&lt;/a&gt; for their authorization needs.&lt;/p&gt;

</description>
      <category>react</category>
      <category>authorization</category>
      <category>cerbos</category>
    </item>
    <item>
      <title>PBAC vs. Zanzibar For User Authorization</title>
      <dc:creator>Anna</dc:creator>
      <pubDate>Wed, 04 Sep 2024 12:26:10 +0000</pubDate>
      <link>https://dev.to/cerbos/pbac-vs-zanzibar-for-user-authorization-5h0d</link>
      <guid>https://dev.to/cerbos/pbac-vs-zanzibar-for-user-authorization-5h0d</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;a href="https://www.cerbos.dev/blog/pbac-vs-zanzibar-finding-the-right-fit-for-your-application" rel="noopener noreferrer"&gt;Originally published on the Cerbos blog.&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When selecting an authorization solution, it’s important to consider your application’s needs. Both Policy-Based Access Control (PBAC) and Zanzibar-based authorization offer unique advantages. &lt;/p&gt;

&lt;p&gt;Remember, authorization is not a one-time setup – it's an ongoing process that requires continuous attention and refinement. So choose wisely, but also be prepared to adapt as your application evolves.&lt;/p&gt;

&lt;p&gt;Here's a breakdown of approaches.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Makes PBAC Effective?
&lt;/h2&gt;

&lt;p&gt;PBAC makes access control decisions based on defined policies, providing flexibility and adaptability. &lt;/p&gt;

&lt;p&gt;PBAC supports multiple access control models such as ABAC, RBAC, and ReBAC. &lt;/p&gt;

&lt;p&gt;With PBAC, policies are evaluated in real time, which is crucial for applications that need to respond quickly to changes in user roles or data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of PBAC&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-Time Decision Making: Ensures access decisions are based on up-to-date data, reducing the risk of unauthorized access.&lt;/li&gt;
&lt;li&gt;Flexibility: Adapts to various access control models and can handle complex scenarios.&lt;/li&gt;
&lt;li&gt;Ease of Management: Policies are written in a straightforward, human-readable format, making them easy to create, test, and modify.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why Cerbos’s stateless approach enhances PBAC&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scalability and Performance: Cerbos’s stateless architecture allows for horizontal scaling without the overhead of maintaining state. This enables handling a large number of authorization requests quickly and efficiently.&lt;/li&gt;
&lt;li&gt;Simplicity in Deployment: Stateless systems are easier to deploy and manage because they don’t require complex state synchronization across different servers. This makes your authorization infrastructure more resilient and easier to maintain.&lt;/li&gt;
&lt;li&gt;Reduced Latency: Without the need to manage state, Cerbos reduces latency in processing authorization requests, making it ideal for applications that demand high performance and low response times.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To learn more about how PBAC and Cerbos’s stateless architecture can optimize your authorization processes, &lt;a href="https://www.cerbos.dev/features-benefits-and-use-cases/pbac?utm_campaign=topic_authorization&amp;amp;utm_source=dev.to&amp;amp;utm_medium=social&amp;amp;utm_content=&amp;amp;utm_term="&gt;check out how Cerbos implements PBAC.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Where Zanzibar-Based Authorization Fits Best
&lt;/h2&gt;

&lt;p&gt;Zanzibar-based authorization uses a centralized system to manage access control lists (ACLs) for each resource, providing fine-grained control over who can access what. It is well-suited for applications with very large numbers of individual resources requiring individual permissions. Zanzibar offers consistency with a centralized access control logic system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of Zanzibar-based Authorization&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fine-grained control: Ideal for managing access to a large number of distinct resources with specific, individualized permissions.&lt;/li&gt;
&lt;li&gt;Centralized Management: Provides a single point of control, which can simplify auditing and policy enforcement for large-scale applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, Zanzibar’s centralized nature requires constant synchronization between your application and the authorization system, which can introduce complexity and latency. This approach might be less suitable for applications that need to adapt quickly to changing data and user roles.&lt;/p&gt;

&lt;h2&gt;
  
  
  PBAC vs. Zanzibar: Choosing the Right Approach
&lt;/h2&gt;

&lt;p&gt;Choosing between PBAC and Zanzibar depends on your application’s specific needs and constraints. Here’s a balanced look at what each approach offers:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data synchronization:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PBAC with Cerbos: Operates without the need for external state synchronization, eliminating delays and reducing complexity.&lt;/li&gt;
&lt;li&gt;Zanzibar: Relies on syncing data with a centralized system, which can add overhead and latency, especially in rapidly changing environments.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Flexibility and adaptability:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PBAC with Cerbos: Supports multiple access control models and can easily adapt to changing requirements, making it suitable for most applications.&lt;/li&gt;
&lt;li&gt;Zanzibar: Offers fine-grained control but may not provide the same level of flexibility for applications with dynamic or complex access rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Simplicity and ease of use:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PBAC with Cerbos: Easy to implement and manage, with a stateless design that simplifies deployment and enhances scalability.&lt;/li&gt;
&lt;li&gt;Zanzibar: Centralized management can be beneficial for consistency and auditing but requires more setup and ongoing maintenance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your application deals with dynamic data, frequently changing access requirements, or simply needs a flexible, easy-to-manage solution, PBAC with Cerbos is likely your best bet. It offers adaptability, real-time responsiveness, and the added benefits of Cerbos’s stateless architecture, making it ideal for most modern applications without synchronizing the application state or replicating database records to your authorization layer.&lt;/p&gt;

&lt;p&gt;However, if your application manages a static collection of resources with highly specific access controls, Zanzibar could be a strong candidate. Its centralized approach ensures consistent and precise control, which can be advantageous in certain contexts.&lt;/p&gt;

&lt;p&gt;Still not sure which approach is right for you? Learn more about how Cerbos can help you implement the best authorization strategy by &lt;a href="https://www.cerbos.dev/workshop?utm_campaign=topic_authorization&amp;amp;utm_source=dev.to&amp;amp;utm_medium=social&amp;amp;utm_content=&amp;amp;utm_term="&gt;booking some time to chat with an engineer.&lt;/a&gt;&lt;/p&gt;

</description>
      <category>authorization</category>
      <category>zanzibar</category>
      <category>learning</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
