1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

use random api prefix on kubectl-proxy (#4137)

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-10-26 14:59:36 +03:00 committed by GitHub
parent 71f0502499
commit f1c2023533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -114,7 +114,7 @@ export class ContextHandler {
await this.ensureServer();
const path = this.clusterUrl.path !== "/" ? this.clusterUrl.path : "";
return `http://127.0.0.1:${this.kubeAuthProxy.port}${path}`;
return `http://127.0.0.1:${this.kubeAuthProxy.port}${this.kubeAuthProxy.apiPrefix}${path}`;
}
async getApiTarget(isLongRunningRequest = false): Promise<httpProxy.ServerOptions> {

View File

@ -21,6 +21,7 @@
import { ChildProcess, spawn } from "child_process";
import { waitUntilUsed } from "tcp-port-used";
import { randomBytes } from "crypto";
import { broadcastMessage } from "../common/ipc";
import type { Cluster } from "./cluster";
import { Kubectl } from "./kubectl";
@ -38,6 +39,7 @@ const startingServeRegex = /^starting to serve on (?<address>.+)/i;
export class KubeAuthProxy {
public lastError: string;
public readonly apiPrefix: string;
public get port(): number {
return this._port;
@ -56,6 +58,7 @@ export class KubeAuthProxy {
this.env = env;
this.cluster = cluster;
this.kubectl = Kubectl.bundled();
this.apiPrefix = `/${randomBytes(8).toString("hex")}`;
}
get acceptHosts() {
@ -78,7 +81,8 @@ export class KubeAuthProxy {
"--kubeconfig", `${this.cluster.kubeConfigPath}`,
"--context", `${this.cluster.contextName}`,
"--accept-hosts", this.acceptHosts,
"--reject-paths", "^[^/]"
"--reject-paths", "^[^/]",
"--api-prefix", this.apiPrefix
];
if (process.env.DEBUG_PROXY === "true") {