mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add authentication header automatically to apiBase and apiKube
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
4662d1a36a
commit
f49676ebb0
@ -3,7 +3,9 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { lensAuthenticationHeaderValueInjectionToken } from "../auth/header-value";
|
||||
import { apiPrefix } from "../vars";
|
||||
import { lensAuthenticationHeader } from "../vars/auth-header";
|
||||
import isDebuggingInjectable from "../vars/is-debugging.injectable";
|
||||
import isDevelopmentInjectable from "../vars/is-development.injectable";
|
||||
import { apiBaseHostHeaderInjectionToken, apiBaseServerAddressInjectionToken } from "./api-base-configs";
|
||||
@ -17,6 +19,7 @@ const apiBaseInjectable = getInjectable({
|
||||
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||
const serverAddress = di.inject(apiBaseServerAddressInjectionToken);
|
||||
const hostHeaderValue = di.inject(apiBaseHostHeaderInjectionToken);
|
||||
const lensAuthenticationHeaderValue = di.inject(lensAuthenticationHeaderValueInjectionToken);
|
||||
|
||||
return createJsonApi({
|
||||
serverAddress,
|
||||
@ -25,6 +28,7 @@ const apiBaseInjectable = getInjectable({
|
||||
}, {
|
||||
headers: {
|
||||
"Host": hostHeaderValue,
|
||||
[lensAuthenticationHeader]: lensAuthenticationHeaderValue,
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
@ -82,7 +82,8 @@ export class LensProxy {
|
||||
const authHeader = req.headers[lensAuthenticationHeader.toLowerCase()];
|
||||
|
||||
if (authHeader !== this.dependencies.authHeaderValue) {
|
||||
socket.destroy(new Error("Missing authorization"));
|
||||
this.dependencies.logger.warn(`[LENS-PROXY]: Request from url=${req.url} missing authentication`);
|
||||
socket.destroy();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -11,6 +11,8 @@ import createKubeJsonApiInjectable from "../../common/k8s-api/create-kube-json-a
|
||||
import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
|
||||
import showErrorNotificationInjectable from "../components/notifications/show-error-notification.injectable";
|
||||
import windowLocationInjectable from "../../common/k8s-api/window-location.injectable";
|
||||
import { lensAuthenticationHeaderValueInjectionToken } from "../../common/auth/header-value";
|
||||
import { lensAuthenticationHeader } from "../../common/vars/auth-header";
|
||||
|
||||
const apiKubeInjectable = getInjectable({
|
||||
id: "api-kube",
|
||||
@ -20,6 +22,7 @@ const apiKubeInjectable = getInjectable({
|
||||
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||
const { port, host } = di.inject(windowLocationInjectable);
|
||||
const lensAuthenticationHeaderValue = di.inject(lensAuthenticationHeaderValueInjectionToken);
|
||||
|
||||
const apiKube = createKubeJsonApi({
|
||||
serverAddress: `http://127.0.0.1:${port}`,
|
||||
@ -28,6 +31,7 @@ const apiKubeInjectable = getInjectable({
|
||||
}, {
|
||||
headers: {
|
||||
"Host": host,
|
||||
[lensAuthenticationHeader]: lensAuthenticationHeaderValue,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user