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

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen authored and GitHub committed 2021-10-26 14:59:36 +03:00
1 parent 71f0502499
commit f1c2023533
2 files changed
+7 -3

No files matched your search

+1 -1
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> {
+6 -2
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") {
@@ -112,7 +116,7 @@ export class KubeAuthProxy {
});
await waitUntilUsed(this.port, 500, 10000);
this.ready = true;
}