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:
parent
71f0502499
commit
f1c2023533
@ -114,7 +114,7 @@ export class ContextHandler {
|
|||||||
await this.ensureServer();
|
await this.ensureServer();
|
||||||
const path = this.clusterUrl.path !== "/" ? this.clusterUrl.path : "";
|
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> {
|
async getApiTarget(isLongRunningRequest = false): Promise<httpProxy.ServerOptions> {
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
import { ChildProcess, spawn } from "child_process";
|
import { ChildProcess, spawn } from "child_process";
|
||||||
import { waitUntilUsed } from "tcp-port-used";
|
import { waitUntilUsed } from "tcp-port-used";
|
||||||
|
import { randomBytes } from "crypto";
|
||||||
import { broadcastMessage } from "../common/ipc";
|
import { broadcastMessage } from "../common/ipc";
|
||||||
import type { Cluster } from "./cluster";
|
import type { Cluster } from "./cluster";
|
||||||
import { Kubectl } from "./kubectl";
|
import { Kubectl } from "./kubectl";
|
||||||
@ -38,6 +39,7 @@ const startingServeRegex = /^starting to serve on (?<address>.+)/i;
|
|||||||
|
|
||||||
export class KubeAuthProxy {
|
export class KubeAuthProxy {
|
||||||
public lastError: string;
|
public lastError: string;
|
||||||
|
public readonly apiPrefix: string;
|
||||||
|
|
||||||
public get port(): number {
|
public get port(): number {
|
||||||
return this._port;
|
return this._port;
|
||||||
@ -56,6 +58,7 @@ export class KubeAuthProxy {
|
|||||||
this.env = env;
|
this.env = env;
|
||||||
this.cluster = cluster;
|
this.cluster = cluster;
|
||||||
this.kubectl = Kubectl.bundled();
|
this.kubectl = Kubectl.bundled();
|
||||||
|
this.apiPrefix = `/${randomBytes(8).toString("hex")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
get acceptHosts() {
|
get acceptHosts() {
|
||||||
@ -78,7 +81,8 @@ export class KubeAuthProxy {
|
|||||||
"--kubeconfig", `${this.cluster.kubeConfigPath}`,
|
"--kubeconfig", `${this.cluster.kubeConfigPath}`,
|
||||||
"--context", `${this.cluster.contextName}`,
|
"--context", `${this.cluster.contextName}`,
|
||||||
"--accept-hosts", this.acceptHosts,
|
"--accept-hosts", this.acceptHosts,
|
||||||
"--reject-paths", "^[^/]"
|
"--reject-paths", "^[^/]",
|
||||||
|
"--api-prefix", this.apiPrefix
|
||||||
];
|
];
|
||||||
|
|
||||||
if (process.env.DEBUG_PROXY === "true") {
|
if (process.env.DEBUG_PROXY === "true") {
|
||||||
@ -112,7 +116,7 @@ export class KubeAuthProxy {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await waitUntilUsed(this.port, 500, 10000);
|
await waitUntilUsed(this.port, 500, 10000);
|
||||||
|
|
||||||
this.ready = true;
|
this.ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user