mask portal connetions - FE needs no passwords

This commit is contained in:
Jan Prochazka
2022-03-20 11:33:44 +01:00
parent 2bec053809
commit 5df0204450
6 changed files with 28 additions and 12 deletions

View File

@@ -5,13 +5,14 @@ const fs = require('fs-extra');
const { datadir, filesdir } = require('../utility/directories'); const { datadir, filesdir } = require('../utility/directories');
const socket = require('../utility/socket'); const socket = require('../utility/socket');
const { encryptConnection } = require('../utility/crypting'); const { encryptConnection, maskConnection } = require('../utility/crypting');
const { handleProcessCommunication } = require('../utility/processComm'); const { handleProcessCommunication } = require('../utility/processComm');
const { pickSafeConnectionInfo } = require('../utility/crypting'); const { pickSafeConnectionInfo } = require('../utility/crypting');
const JsonLinesDatabase = require('../utility/JsonLinesDatabase'); const JsonLinesDatabase = require('../utility/JsonLinesDatabase');
const processArgs = require('../utility/processArgs'); const processArgs = require('../utility/processArgs');
const { safeJsonParse } = require('dbgate-tools'); const { safeJsonParse } = require('dbgate-tools');
const platformInfo = require('../utility/platformInfo');
function getNamedArgs() { function getNamedArgs() {
const res = {}; const res = {};
@@ -165,7 +166,9 @@ module.exports = {
list_meta: true, list_meta: true,
async list() { async list() {
return portalConnections || this.datastore.find(); return portalConnections && !platformInfo.allowShellConnection
? portalConnections.map(maskConnection)
: this.datastore.find();
}, },
test_meta: true, test_meta: true,
@@ -244,14 +247,21 @@ module.exports = {
return res; return res;
}, },
get_meta: true, async getCore({ conid, mask = false }) {
async get({ conid }) {
if (!conid) return null; if (!conid) return null;
if (portalConnections) return portalConnections.find(x => x._id == conid) || null; if (portalConnections) {
const res = portalConnections.find(x => x._id == conid) || null;
return mask && !platformInfo.allowShellConnection ? maskConnection(res) : res;
}
const res = await this.datastore.get(conid); const res = await this.datastore.get(conid);
return res || null; return res || null;
}, },
get_meta: true,
async get({ conid }) {
return this.getCore({ conid, mask: true });
},
newSqliteDatabase_meta: true, newSqliteDatabase_meta: true,
async newSqliteDatabase({ file }) { async newSqliteDatabase({ file }) {
const sqliteDir = path.join(filesdir(), 'sqlite'); const sqliteDir = path.join(filesdir(), 'sqlite');

View File

@@ -79,7 +79,7 @@ module.exports = {
async ensureOpened(conid, database) { async ensureOpened(conid, database) {
const existing = this.opened.find(x => x.conid == conid && x.database == database); const existing = this.opened.find(x => x.conid == conid && x.database == database);
if (existing) return existing; if (existing) return existing;
const connection = await connections.get({ conid }); const connection = await connections.getCore({ conid });
const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [ const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [
'--is-forked-api', '--is-forked-api',
'--start-process', '--start-process',
@@ -392,8 +392,8 @@ module.exports = {
const targetDb = generateDbPairingId( const targetDb = generateDbPairingId(
extendDatabaseInfo(await this.structure({ conid: targetConid, database: targetDatabase })) extendDatabaseInfo(await this.structure({ conid: targetConid, database: targetDatabase }))
); );
// const sourceConnection = await connections.get({conid:sourceConid}) // const sourceConnection = await connections.getCore({conid:sourceConid})
const connection = await connections.get({ conid: targetConid }); const connection = await connections.getCore({ conid: targetConid });
const driver = requireEngineDriver(connection); const driver = requireEngineDriver(connection);
const targetDbPaired = matchPairedObjects(sourceDb, targetDb, dbDiffOptions); const targetDbPaired = matchPairedObjects(sourceDb, targetDb, dbDiffOptions);
const diffRows = computeDbDiffRows(sourceDb, targetDbPaired, dbDiffOptions, driver); const diffRows = computeDbDiffRows(sourceDb, targetDbPaired, dbDiffOptions, driver);

View File

@@ -37,7 +37,7 @@ module.exports = {
const res = await lock.acquire(conid, async () => { const res = await lock.acquire(conid, async () => {
const existing = this.opened.find(x => x.conid == conid); const existing = this.opened.find(x => x.conid == conid);
if (existing) return existing; if (existing) return existing;
const connection = await connections.get({ conid }); const connection = await connections.getCore({ conid });
const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [ const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [
'--is-forked-api', '--is-forked-api',
'--start-process', '--start-process',

View File

@@ -78,7 +78,7 @@ module.exports = {
create_meta: true, create_meta: true,
async create({ conid, database }) { async create({ conid, database }) {
const sesid = uuidv1(); const sesid = uuidv1();
const connection = await connections.get({ conid }); const connection = await connections.getCore({ conid });
const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [ const subprocess = fork(global['API_PACKAGE'] || process.argv[1], [
'--is-forked-api', '--is-forked-api',
'--start-process', '--start-process',

View File

@@ -20,7 +20,7 @@ async function loadConnection(driver, storedConnection, connectionMode) {
} }
await connections._init(); await connections._init();
const loaded = await connections.get({ conid: storedConnection._id }); const loaded = await connections.getCore({ conid: storedConnection._id });
const loadedWithDb = { const loadedWithDb = {
...loaded, ...loaded,
database: storedConnection.database, database: storedConnection.database,

View File

@@ -55,7 +55,7 @@ function encryptPasswordField(connection, field) {
[field]: 'crypt:' + getEncryptor().encrypt(connection[field]), [field]: 'crypt:' + getEncryptor().encrypt(connection[field]),
}; };
} }
return connection; return connection;
} }
function decryptPasswordField(connection, field) { function decryptPasswordField(connection, field) {
@@ -75,6 +75,11 @@ function encryptConnection(connection) {
return connection; return connection;
} }
function maskConnection(connection) {
if (!connection) return connection;
return _.omit(connection, ['password', 'sshPassword', 'sshKeyfilePassword']);
}
function decryptConnection(connection) { function decryptConnection(connection) {
connection = decryptPasswordField(connection, 'password'); connection = decryptPasswordField(connection, 'password');
connection = decryptPasswordField(connection, 'sshPassword'); connection = decryptPasswordField(connection, 'sshPassword');
@@ -95,5 +100,6 @@ module.exports = {
loadEncryptionKey, loadEncryptionKey,
encryptConnection, encryptConnection,
decryptConnection, decryptConnection,
maskConnection,
pickSafeConnectionInfo, pickSafeConnectionInfo,
}; };