: asapien/signet

commit ad9e63e74265c4e8a0038eb53c373f0eadec5788
parent 4f04109a37e2950558fdd5f70702e82b5bab88dd
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 19 Sep 2026 05:53:48 +0530

PIM: Remove dev mode, require Authelia authentication

Update PIM portal to work with Authelia only (no localStorage fallback).

Changes:
- Remove devHeaders() function
- Call /pim-api/me instead of /api/me (PIM API endpoint)
- Remove localStorage dev identity fallback
- Show clear error messages about Authelia setup requirement

Auth flow:
1. User must be authenticated via Authelia (upstream proxy)
2. Authelia sets Remote-User and Remote-Groups headers
3. PIM API checks headers and verifies pim_admin role
4. Frontend displays appropriate auth/permission messages

Requires:
1. Authelia container running on port 9091
2. lighttpd proxy enabled to forward requests to Authelia
3. User logged in with pim_admin role

This ensures PIM can only be accessed by properly authenticated
administrators, not via dev mode shortcuts.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 file changed, 12 insertions(+), 17 deletions(-)
M
pim/www/pim.js
|
29
++++++++++++-----------------
diff --git a/pim/www/pim.js b/pim/www/pim.js
@@ -7,36 +7,33 @@ let attrs = {};
 
 async function boot() {
   try {
-    const res = await fetch('/api/me', { headers: devHeaders() });
-    if (!res.ok) throw new Error('Not authenticated');
+    const res = await fetch('/pim-api/me');
+    if (res.status === 401) {
+      document.getElementById('auth').innerHTML = '<h1>Not Authenticated</h1><p>PIM requires Authelia authentication. Start Authelia and enable the proxy in lighttpd.</p><p><code>docker run -d --name authelia -p 9091:9091 -v $(pwd)/etc/authelia.yml:/etc/authelia/authelia.yml -v $(pwd)/etc/authelia-users.yml:/etc/authelia/users.yml authelia/authelia:latest</code></p><p>Then uncomment the proxy line in test/lighttpd-dev.conf and restart the test container.</p>';
+      return;
+    }
+    if (!res.ok) throw new Error('HTTP ' + res.status);
     me = await res.json();
-    
+
     if (!me.roles.pim_admin) {
-      document.getElementById('auth').innerHTML = '<h1>Access Denied</h1><p>Only users with <code>pim_admin</code> role can manage attributes.</p>';
+      document.getElementById('auth').innerHTML = '<h1>Access Denied</h1><p>You are logged in as <strong>' + me.user + '</strong>. Only users with <code>pim_admin</code> role can access PIM.</p><p>Login with a user that has pim_admin role (e.g., admin/admin).</p>';
       return;
     }
-    
+
     document.getElementById('auth').style.display = 'none';
     document.getElementById('attrs').style.display = 'block';
     document.getElementById('whoami').textContent = me.user + ' ยท pim_admin';
-    
+
     await loadOrgs();
   } catch (e) {
     document.getElementById('auth').innerHTML = '<h1>Error</h1><p>' + e.message + '</p>';
   }
 }
 
-function devHeaders() {
-  try {
-    const dev = JSON.parse(localStorage.getItem('signetDevIdentity') || 'null');
-    return dev ? { 'Remote-User': dev.user, 'Remote-Groups': dev.groups } : {};
-  } catch { return {}; }
-}
-
 async function loadOrgs() {
   try {
-    const res = await fetch(API + '/attrs', { headers: devHeaders() });
-    if (!res.ok) throw new Error('Failed to load attributes');
+    const res = await fetch(API + '/attrs');
+    if (!res.ok) throw new Error('Failed to load attributes: ' + res.status);
     const data = await res.json();
     
     attrs = {};

@@ -107,7 +104,6 @@ async function addAttr() {
   try {
     const res = await fetch(API + '/attrs', {
       method: 'POST',
-      headers: devHeaders(),
       body: params
     });
     if (!res.ok) throw new Error(await res.text());

@@ -130,7 +126,6 @@ async function delAttr(org, key) {
   try {
     const res = await fetch(API + '/attrs', {
       method: 'POST',
-      headers: devHeaders(),
       body: params
     });
     if (!res.ok) throw new Error(await res.text());