Skip to content

Commit

Permalink
fix(mis): 不使用sudo作为普通用户来刷新VNC密码
Browse files Browse the repository at this point in the history
  • Loading branch information
ddadaal committed Jan 3, 2023
1 parent 789b791 commit ec0e636
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/portal-server/src/clusterops/slurm/app.ts
Expand Up @@ -328,7 +328,7 @@ export const slurmAppOps = (cluster: string): AppOps => {
// connect as user so that
// the service node doesn't need to be able to connect to compute nodes with public key
return await sshConnect(host, userId, logger, async (computeNodeSsh) => {
const password = await refreshPassword(computeNodeSsh, userId, logger, displayId!);
const password = await refreshPassword(computeNodeSsh, null, logger, displayId!);
return {
code: "OK",
appId: sessionMetadata.appId,
Expand Down
20 changes: 16 additions & 4 deletions apps/portal-server/src/utils/turbovnc.ts
Expand Up @@ -10,7 +10,7 @@
* See the Mulan PSL v2 for more details.
*/

import { executeAsUser } from "@scow/lib-ssh";
import { executeAsUser, loggedExec } from "@scow/lib-ssh";
import { NodeSSH } from "node-ssh";
import { join } from "path";
import { portalConfig } from "src/config/portal";
Expand Down Expand Up @@ -62,9 +62,21 @@ export function parseDisplayId(stdout: string): number {

const vncPasswdPath = join(portalConfig.turboVNCPath, "bin", "vncpasswd");

export const refreshPassword = async (ssh: NodeSSH, userId: string, logger: Logger, displayId: number) => {
const resp = await executeAsUser(ssh, userId, logger, true,
vncPasswdPath, ["-o", "-display", ":" + displayId]);
/**
* Refresh VNC session's OTP
* @param ssh SSH connection
* @param runAsUserId the user id to run as. If null, run as SSH connection user
* @param logger logger
* @param displayId displayId
* @returns new OTP
*/
export const refreshPassword = async (ssh: NodeSSH, runAsUserId: string | null, logger: Logger, displayId: number) => {

const params = ["-o", "-display", ":" + displayId];

const resp = runAsUserId
? await executeAsUser(ssh, runAsUserId, logger, true, vncPasswdPath, params)
: await loggedExec(ssh, logger, true, vncPasswdPath, params);

return parseOtp(resp.stderr);
};
Expand Down

0 comments on commit ec0e636

Please sign in to comment.