4879769cc7
- Add standalone.enabled config flag to switch between LDAP+SSO and ORM-backed backends without changing the production code path - New ORM models: StandaloneUser (uid, passwordHash, sshPublicKeys, groups) and StandaloneHost (slug, displayName, kind, metadata) - user_file.js and hosts_file.js implement the same interfaces as the LDAP client and accessibleHosts() respectively - models/user_ldap.js and utils/access.js become conditional facades that delegate based on conf.standalone.enabled at require time - Zero changes to ssh_server.js core logic, bridge.js, key_inject.js, tui_picker.js, or any other consumer - Fix ssh_server.js: use ?? instead of || for listenPort (0 is falsy) - Fix ssh_server.js: register session listeners before awaiting audit.create() so client exec/shell requests aren't rejected - Patch StringField.toSequelize() and IntegerField.toSequelize() to pass through primaryKey (the ORM's UUIDField already does this) - 47 tests pass (24 existing + 15 new unit + 3 existing integration + 5 new standalone integration) - Defaults to SQLite; any Sequelize dialect works via conf.orm Co-Authored-By: Claude <noreply@anthropic.com>
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
// ORM model for standalone-mode users. Stored in the configured SQL database
|
|
// (default SQLite) when conf.standalone.enabled is true. The user_file.js
|
|
// wrapper translates between this model and the LDAP-client interface that
|
|
// ssh_server.js and key_inject.js expect.
|
|
|
|
const { Model, fields } = require('@simpleworkjs/orm');
|
|
|
|
// Patch: StringField.toSequelize() and IntegerField.toSequelize() don't pass
|
|
// through primaryKey / autoIncrement (unlike UUIDField which does). Fix them
|
|
// so string and int primary keys work.
|
|
const origStringToSeq = fields.StringField.prototype.toSequelize;
|
|
fields.StringField.prototype.toSequelize = function () {
|
|
const def = origStringToSeq.call(this);
|
|
if (this.primaryKey) def.primaryKey = true;
|
|
return def;
|
|
};
|
|
const origIntToSeq = fields.IntegerField.prototype.toSequelize;
|
|
fields.IntegerField.prototype.toSequelize = function () {
|
|
const def = origIntToSeq.call(this);
|
|
if (this.primaryKey) def.primaryKey = true;
|
|
if (this.autoIncrement) def.autoIncrement = true;
|
|
return def;
|
|
};
|
|
|
|
class StandaloneUser extends Model {
|
|
static fields = {
|
|
uid: { type: 'string', primaryKey: true },
|
|
passwordHash: { type: 'string', isPrivate: true },
|
|
sshPublicKeys: { type: 'json', default: [] },
|
|
groups: { type: 'json', default: [] },
|
|
};
|
|
}
|
|
|
|
module.exports = StandaloneUser;
|