feat: rebuild web UI on the shared theta42 app stack; OIDC + local admin auth

The web management UI was a bespoke minimal theme with LDAP-bind login.
Rebuild it to match the SSO Manager and Proxy — same stack, same look/feel,
same auth model. The SSH bridge, audit, metrics, and access logic are
unchanged; this is purely the web layer.

Frontend (mirrors proxy/sso):
- Express + EJS with the shared top.ejs/bottom.ejs shell, Bootstrap 5,
  jQuery, jq-repeat, FontAwesome, Socket.IO, and the shared app-base.js /
  val.js client framework (copied verbatim). Vendor libs served from
  node_modules via /static-modules; app assets via /static.
- Dashboard / Sessions / Audit pages render in the common look/feel,
  loading data through the authenticated /api/* endpoints.

Auth (mirrors proxy):
- OIDC against the SSO (utils/oidc.js + routes/auth.js + models/oidc_state)
  plus a local anti-lockout admin (models/user_redis.js, bootstrapped from
  auth.adminUsers[0] / auth.localAdminPass). AuthToken sessions carry the
  group snapshot; middleware gates the data API on adminGroups or the local
  admin. New config: oidc{} + auth.adminUsers/localAdminPass.
- /api/user/me drives the client login state; "Log in with SSO" hidden when
  oidc.enabled is false.

Verified end to end: local admin login -> token -> /api/user/me isAdmin,
metrics/sessions/audit 200 with token / 401 without / 401 bad password;
static + page shells serve; 26 tests green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-23 20:57:34 -04:00
parent eb8e5b409e
commit aa3b3ed515
38 changed files with 2550 additions and 374 deletions
+26 -21
View File
@@ -1,37 +1,42 @@
'use strict';
const path = require('path');
const express = require('express');
const conf = require('@simpleworkjs/conf');
const compression = require('compression');
const registry = require('./services/session_registry');
const { requireAdmin } = require('./middleware/auth');
const buildInfo = require('./models/build_info');
require('./models'); // wire model-redis + register models
const app = express();
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use('/public', express.static(path.join(__dirname, 'public')));
app.set('views', require('path').join(__dirname, 'views'));
// Open health check — no auth (used by Docker/compose + the proxy).
app.get('/health', (req, res) => {
res.json({ status: 'ok', activeSessions: registry.count(), version: buildInfo.version, commit: buildInfo.commit });
app.use(compression());
app.use(express.json());
app.use(express.urlencoded({extended: false}));
// Page shells + static assets + /health (mostly unauthenticated; the client
// gates itself on /api/user/me and redirects to /login).
app.use('/', require('./routes/render'));
// API — auth handled per-router inside (see routes/api.js).
app.use('/api', require('./routes/api'));
// 404
app.use((req, res, next) => {
const error = new Error('Not Found');
error.status = 404;
next(error);
});
// Login routes (no session required).
app.use('/', require('./routes/auth'));
// Everything else requires an admin session.
app.use(requireAdmin);
app.use('/api', require('./routes/api'));
app.use('/', require('./routes/index'));
// Error handler — JSON for API, redirect to login for pages on 401.
// eslint-disable-next-line no-unused-vars
app.use((err, req, res, next) => {
console.error(err);
if (req.path.startsWith('/api/')) return res.status(500).json({ error: err.message });
res.status(500).render('login', { error: 'Internal error.', name: conf.name });
const status = err.status || 500;
if(status >= 500) console.error(err);
if(req.path.startsWith('/api/')){
return res.status(status).json({name: err.name || 'Error', message: err.message || 'Error'});
}
res.status(status).send(err.message || 'Error');
});
module.exports = app;