mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix check for user exec command (#3664)
This commit is contained in:
1 parent
068c78d48d
commit
056b818ceb
6 files changed
+62
-23
No files matched your search
@@ -25,11 +25,11 @@ import path from "path";
|
||||
import os from "os";
|
||||
import yaml from "js-yaml";
|
||||
import logger from "../main/logger";
|
||||
import commandExists from "command-exists";
|
||||
import { ExecValidationNotFoundError } from "./custom-errors";
|
||||
import { Cluster, Context, newClusters, newContexts, newUsers, User } from "@kubernetes/client-node/dist/config_types";
|
||||
import { resolvePath } from "./utils";
|
||||
import Joi from "joi";
|
||||
import which from "which";
|
||||
|
||||
export type KubeConfigValidationOpts = {
|
||||
validateCluster?: boolean;
|
||||
@@ -295,13 +295,17 @@ export function validateKubeConfig(config: KubeConfig, contextName: string, vali
|
||||
|
||||
// Validate exec command if present
|
||||
if (validateExec && user?.exec) {
|
||||
const execCommand = user.exec["command"];
|
||||
// check if the command is absolute or not
|
||||
const isAbsolute = path.isAbsolute(execCommand);
|
||||
try {
|
||||
which.sync(user.exec.command);
|
||||
|
||||
// validate the exec struct in the user object, start with the command field
|
||||
if (!commandExists.sync(execCommand)) {
|
||||
return new ExecValidationNotFoundError(execCommand, isAbsolute);
|
||||
// If this doesn't throw an error it also means that it has found the executable.
|
||||
} catch (error) {
|
||||
switch (error?.code) {
|
||||
case "ENOENT":
|
||||
return new ExecValidationNotFoundError(user.exec.command);
|
||||
default:
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user