<?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: Long Nhãn</title>
    <description>The latest articles on DEV Community by Long Nhãn (@longmaba).</description>
    <link>https://dev.to/longmaba</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1637078%2F39957188-9b86-4a9e-b6d3-96051504d0b0.jpeg</url>
      <title>DEV Community: Long Nhãn</title>
      <link>https://dev.to/longmaba</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/longmaba"/>
    <language>en</language>
    <item>
      <title>EnvShare - A secured, Role-based Access way to share .env file</title>
      <dc:creator>Long Nhãn</dc:creator>
      <pubDate>Fri, 25 Apr 2025 14:10:41 +0000</pubDate>
      <link>https://dev.to/longmaba/envshare-a-secured-role-based-access-way-to-share-env-file-4mm9</link>
      <guid>https://dev.to/longmaba/envshare-a-secured-role-based-access-way-to-share-env-file-4mm9</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/permit_io"&gt;Permit.io Authorization Challenge&lt;/a&gt;: API-First Authorization Reimagined&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;I built an API-first, environment variable hosting service that demonstrates secure, role-based access to environment variables using Permit.io. The project solves the common problem of managing and sharing &lt;code&gt;.env&lt;/code&gt; files in teams—preventing accidental leaks, insecure sharing, and misconfiguration—by centralizing environment variables behind a secure API. Access to each environment (dev, staging, prod) is strictly controlled by Permit.io roles and permissions, ensuring only authorized users can fetch the secrets they need.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Screenshots:&lt;/strong&gt;&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%2F5tkshzx4tf6qanw1nrwu.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%2F5tkshzx4tf6qanw1nrwu.png" alt="Resources Setup" width="800" height="243"&gt;&lt;/a&gt;&lt;br&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%2F1lnj174za0ejmwx9b7b2.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%2F1lnj174za0ejmwx9b7b2.png" alt="Role Setup" width="783" height="817"&gt;&lt;/a&gt;&lt;br&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%2F1822cwit3m8fgjfygzt1.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%2F1822cwit3m8fgjfygzt1.png" alt="User Setup" width="800" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Video: &lt;a href="https://youtu.be/rKPC_3-ui7A" rel="noopener noreferrer"&gt;https://youtu.be/rKPC_3-ui7A&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample API Usage:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Fetch dev environment variables as a Developer&lt;/span&gt;
curl &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"X-API-Key: dev1"&lt;/span&gt; http://localhost:3000/getEnv/dev

&lt;span class="c"&gt;# Fetch staging environment variables as a Manager&lt;/span&gt;
curl &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"X-API-Key: manager1"&lt;/span&gt; http://localhost:3000/getEnv/staging

&lt;span class="c"&gt;# Fetch prod environment variables as a Director&lt;/span&gt;
curl &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"X-API-Key: director1"&lt;/span&gt; http://localhost:3000/getEnv/prod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See more in &lt;a href="//./demo-commands.md"&gt;demo-commands.md&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Repo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/longmaba/permit-challenge" rel="noopener noreferrer"&gt;GitHub Repo: permit-challenge&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Includes a thorough &lt;a href="//./README.md"&gt;README.md&lt;/a&gt; with setup, usage, and Permit.io integration instructions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  My Journey
&lt;/h2&gt;

&lt;p&gt;I started by defining the problem: &lt;code&gt;.env&lt;/code&gt; file sprawl and the risks of manual sharing. My goal was to create a backend service that would serve environment variables securely, using Permit.io for fine-grained, role-based access control.&lt;/p&gt;

&lt;p&gt;Later on, this could expand to multiple projects as well, which would be super handy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenges:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mapping API keys to Permit.io users and roles required careful dashboard configuration.&lt;/li&gt;
&lt;li&gt;Ensuring error messages and status codes were consistent for a clean API experience.&lt;/li&gt;
&lt;li&gt;Debugging Permit.io PDP connectivity and resource naming conventions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What I learned:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Permit.io makes it easy to add RBAC to any API, but planning your resource and role model up front is key.&lt;/li&gt;
&lt;li&gt;API-first authorization can be both secure and developer-friendly with the right tools and patterns.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  API-First Authorization
&lt;/h2&gt;

&lt;p&gt;Permit.io powers all access control in this project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each environment (&lt;code&gt;env:dev&lt;/code&gt;, &lt;code&gt;env:staging&lt;/code&gt;, &lt;code&gt;env:prod&lt;/code&gt;) is a Permit.io resource.&lt;/li&gt;
&lt;li&gt;Roles (&lt;code&gt;Developer&lt;/code&gt;, &lt;code&gt;Manager&lt;/code&gt;, &lt;code&gt;Director&lt;/code&gt;) are mapped to users in the Permit.io dashboard and granted &lt;code&gt;read&lt;/code&gt; permissions on the corresponding resources.&lt;/li&gt;
&lt;li&gt;The Express API checks authorization on every request using &lt;code&gt;permit.check(user_key, 'read', resource)&lt;/code&gt;, where &lt;code&gt;user_key&lt;/code&gt; is the API key provided in the request header.&lt;/li&gt;
&lt;li&gt;All access decisions, including denials, are handled by Permit.io—making the API stateless and secure by design.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Permit.io Setup Steps:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define resources for each environment in the dashboard.&lt;/li&gt;
&lt;li&gt;Create roles and assign &lt;code&gt;read&lt;/code&gt; permissions.&lt;/li&gt;
&lt;li&gt;Add users with their API keys and assign roles.&lt;/li&gt;
&lt;li&gt;The API enforces these rules with a single call to Permit.io on each request.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Team Submissions: &lt;a class="mentioned-user" href="https://dev.to/longmaba"&gt;@longmaba&lt;/a&gt; , &lt;a class="mentioned-user" href="https://dev.to/tubakhuym"&gt;@tubakhuym&lt;/a&gt; &lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>permitchallenge</category>
      <category>webdev</category>
      <category>security</category>
    </item>
  </channel>
</rss>
