fix(striker-ui-api): check bad keys regardless of peer conn success

main^2
Tsu-ba-me 7 months ago
parent ce0c36af33
commit 7b1ea9c56c
  1. 73
      striker-ui-api/src/lib/request_handlers/command/getHostSSH.ts
  2. 2
      striker-ui-api/src/middlewares/proxyServerVnc.ts
  3. 2
      striker-ui-api/src/types/ApiCommand.d.ts
  4. 2
      striker-ui-api/src/types/ApiSshKey.d.ts
  5. 5
      striker-ui-api/src/types/ErrorResponse.d.ts

@ -7,13 +7,13 @@ import {
REP_PEACEFUL_STRING, REP_PEACEFUL_STRING,
} from '../../consts'; } from '../../consts';
import { getLocalHostUUID, getPeerData, query } from '../../accessModule'; import { getPeerData, query } from '../../accessModule';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
import { perr } from '../../shell'; import { perr } from '../../shell';
export const getHostSSH: RequestHandler< export const getHostSSH: RequestHandler<
unknown, unknown,
GetHostSshResponseBody, GetHostSshResponseBody | ErrorResponseBody,
GetHostSshRequestBody GetHostSshRequestBody
> = async (request, response) => { > = async (request, response) => {
const { const {
@ -45,35 +45,60 @@ export const getHostSSH: RequestHandler<
return response.status(400).send(); return response.status(400).send();
} }
const localHostUUID = getLocalHostUUID();
let rsbody: GetHostSshResponseBody; let rsbody: GetHostSshResponseBody;
try { try {
rsbody = await getPeerData(target, { password, port }); rsbody = await getPeerData(target, { password, port });
} catch (subError) { } catch (error) {
perr(`Failed to get peer data; CAUSE: ${subError}`); const emsg = `Failed to get peer data; CAUSE: ${error}`;
perr(emsg);
const rserror: ErrorResponseBody = {
code: 'fe14fb1',
message: emsg,
name: 'AccessError',
};
return response.status(500).send(rserror);
}
let states: [string, string][];
return response.status(500).send(); try {
states = await query<[stateUuid: string, hostUuid: string][]>(`
SELECT a.state_uuid, a.state_host_uuid
FROM states AS a
WHERE a.state_name = '${HOST_KEY_CHANGED_PREFIX}${target}';`);
} catch (error) {
const emsg = `Failed to list SSH key conflicts; CAUSE: ${error}`;
perr(emsg);
const rserror: ErrorResponseBody = {
code: 'd5a2acf',
message: emsg,
name: 'AccessError',
};
return response.status(500).send(rserror);
} }
if (!rsbody.isConnected) { if (states.length > 0) {
const rows: [stateNote: string, stateUUID: string][] = await query(` rsbody.badSshKeys = states.reduce<DeleteSshKeyConflictRequestBody>(
SELECT sta.state_note, sta.state_uuid (previous, state) => {
FROM states AS sta const [stateUuid, hostUuid] = state;
WHERE sta.state_host_uuid = '${localHostUUID}'
AND sta.state_name = '${HOST_KEY_CHANGED_PREFIX}${target}';`); const { [hostUuid]: list = [] } = previous;
if (rows.length > 0) { list.push(stateUuid);
rsbody.badSSHKeys = rows.reduce<DeleteSshKeyConflictRequestBody>(
(previous, [, stateUUID]) => { previous[hostUuid] = list;
previous[localHostUUID].push(stateUUID);
return previous;
return previous; },
}, {},
{ [localHostUUID]: [] }, );
);
}
} }
response.status(200).send(rsbody); response.status(200).send(rsbody);

@ -49,7 +49,7 @@ export const proxyServerVnc = createProxyMiddleware({
const serverUuid = getServerUuid(request.url); const serverUuid = getServerUuid(request.url);
const errapiName = cname(`vncerror.${serverUuid}`); const errapiName = cname(`vncerror.${serverUuid}`);
const errapiObj = { const errapiObj: ErrorResponseBody = {
code: '72c969b', code: '72c969b',
message: error.message, message: error.message,
name: error.name, name: error.name,

@ -5,7 +5,7 @@ type GetHostSshRequestBody = {
}; };
type GetHostSshResponseBody = { type GetHostSshResponseBody = {
badSSHKeys?: DeleteSshKeyConflictRequestBody; badSshKeys?: DeleteSshKeyConflictRequestBody;
hostName: string; hostName: string;
hostOS: string; hostOS: string;
hostUUID: string; hostUUID: string;

@ -9,4 +9,4 @@ type SshKeyConflict = {
}; };
}; };
type DeleteSshKeyConflictRequestBody = { [hostUUID: string]: string[] }; type DeleteSshKeyConflictRequestBody = Record<string, string[]>;

@ -0,0 +1,5 @@
type ErrorResponseBody = {
code: string;
message: string;
name: string;
};
Loading…
Cancel
Save