From 31dc20dbe715cf3bdee70213ede80549a5f39850 Mon Sep 17 00:00:00 2001 From: Jamie Klassen Date: Fri, 8 Sep 2023 11:53:41 -0400 Subject: [PATCH] replace noop with distinct strategies one for serviceaccount and one for anonymous (used by localKubectlProxy) Signed-off-by: Jamie Klassen --- plugins/kubernetes-backend/api-report.md | 24 ++++++++++----- .../src/auth/AnonymousStrategy.ts | 29 +++++++++++++++++++ ...pStrategy.ts => ServiceAccountStrategy.ts} | 2 +- plugins/kubernetes-backend/src/auth/index.ts | 3 +- .../src/service/KubernetesBuilder.ts | 7 +++-- .../src/service/KubernetesProxy.test.ts | 4 +-- 6 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 plugins/kubernetes-backend/src/auth/AnonymousStrategy.ts rename plugins/kubernetes-backend/src/auth/{NoopStrategy.ts => ServiceAccountStrategy.ts} (92%) diff --git a/plugins/kubernetes-backend/api-report.md b/plugins/kubernetes-backend/api-report.md index 1c5cb766dc..dad792843f 100644 --- a/plugins/kubernetes-backend/api-report.md +++ b/plugins/kubernetes-backend/api-report.md @@ -32,6 +32,14 @@ export class AksStrategy implements AuthenticationStrategy { validate(_: AuthMetadata): void; } +// @public (undocumented) +export class AnonymousStrategy implements AuthenticationStrategy { + // (undocumented) + getCredential(): Promise; + // (undocumented) + validate(): void; +} + // @public (undocumented) export interface AuthenticationStrategy { // (undocumented) @@ -383,14 +391,6 @@ export interface KubernetesServiceLocator { }>; } -// @public (undocumented) -export class NoopStrategy implements AuthenticationStrategy { - // (undocumented) - getCredential(): Promise; - // (undocumented) - validate(): void; -} - // @public (undocumented) export interface ObjectFetchParams { // (undocumented) @@ -451,6 +451,14 @@ export interface RouterOptions { permissions: PermissionEvaluator; } +// @public (undocumented) +export class ServiceAccountStrategy implements AuthenticationStrategy { + // (undocumented) + getCredential(clusterDetails: ClusterDetails): Promise; + // (undocumented) + validate(): void; +} + // @public (undocumented) export type ServiceLocatorMethod = 'multiTenant' | 'http'; diff --git a/plugins/kubernetes-backend/src/auth/AnonymousStrategy.ts b/plugins/kubernetes-backend/src/auth/AnonymousStrategy.ts new file mode 100644 index 0000000000..2b3215f118 --- /dev/null +++ b/plugins/kubernetes-backend/src/auth/AnonymousStrategy.ts @@ -0,0 +1,29 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AuthenticationStrategy, KubernetesCredential } from './types'; + +/** + * + * @public + */ +export class AnonymousStrategy implements AuthenticationStrategy { + public async getCredential(): Promise { + return undefined; + } + + public validate() {} +} diff --git a/plugins/kubernetes-backend/src/auth/NoopStrategy.ts b/plugins/kubernetes-backend/src/auth/ServiceAccountStrategy.ts similarity index 92% rename from plugins/kubernetes-backend/src/auth/NoopStrategy.ts rename to plugins/kubernetes-backend/src/auth/ServiceAccountStrategy.ts index 1af8f09cf8..29462dc5c7 100644 --- a/plugins/kubernetes-backend/src/auth/NoopStrategy.ts +++ b/plugins/kubernetes-backend/src/auth/ServiceAccountStrategy.ts @@ -21,7 +21,7 @@ import { ClusterDetails } from '../types/types'; * * @public */ -export class NoopStrategy implements AuthenticationStrategy { +export class ServiceAccountStrategy implements AuthenticationStrategy { public async getCredential( clusterDetails: ClusterDetails, ): Promise { diff --git a/plugins/kubernetes-backend/src/auth/index.ts b/plugins/kubernetes-backend/src/auth/index.ts index 2caefc3a12..bcdd620243 100644 --- a/plugins/kubernetes-backend/src/auth/index.ts +++ b/plugins/kubernetes-backend/src/auth/index.ts @@ -15,11 +15,12 @@ */ export * from './AksStrategy'; +export * from './AnonymousStrategy'; export * from './AwsIamStrategy'; export * from './AzureIdentityStrategy'; export * from './GoogleStrategy'; export * from './GoogleServiceAccountStrategy'; export * from './DispatchStrategy'; -export * from './NoopStrategy'; +export * from './ServiceAccountStrategy'; export * from './OidcStrategy'; export * from './types'; diff --git a/plugins/kubernetes-backend/src/service/KubernetesBuilder.ts b/plugins/kubernetes-backend/src/service/KubernetesBuilder.ts index 62cc53ed4a..f3e71e8dbc 100644 --- a/plugins/kubernetes-backend/src/service/KubernetesBuilder.ts +++ b/plugins/kubernetes-backend/src/service/KubernetesBuilder.ts @@ -30,9 +30,10 @@ import { Logger } from 'winston'; import { getCombinedClusterSupplier } from '../cluster-locator'; import { AuthenticationStrategy, + AnonymousStrategy, DispatchStrategy, GoogleStrategy, - NoopStrategy, + ServiceAccountStrategy, AwsIamStrategy, GoogleServiceAccountStrategy, AzureIdentityStrategy, @@ -369,9 +370,9 @@ export class KubernetesBuilder { azure: new AzureIdentityStrategy(this.env.logger), google: new GoogleStrategy(), googleServiceAccount: new GoogleServiceAccountStrategy(), - localKubectlProxy: new NoopStrategy(), + localKubectlProxy: new AnonymousStrategy(), oidc: new OidcStrategy(), - serviceAccount: new NoopStrategy(), + serviceAccount: new ServiceAccountStrategy(), }; return this.authStrategyMap; } diff --git a/plugins/kubernetes-backend/src/service/KubernetesProxy.test.ts b/plugins/kubernetes-backend/src/service/KubernetesProxy.test.ts index e1770d45b6..9c3e7e9187 100644 --- a/plugins/kubernetes-backend/src/service/KubernetesProxy.test.ts +++ b/plugins/kubernetes-backend/src/service/KubernetesProxy.test.ts @@ -33,7 +33,7 @@ import request from 'supertest'; import { AddressInfo, WebSocket, WebSocketServer } from 'ws'; import { LocalKubectlProxyClusterLocator } from '../cluster-locator/LocalKubectlProxyLocator'; -import { AuthenticationStrategy, NoopStrategy } from '../auth'; +import { AuthenticationStrategy, AnonymousStrategy } from '../auth'; import { ClusterDetails, KubernetesClustersSupplier } from '../types/types'; import { APPLICATION_JSON, @@ -495,7 +495,7 @@ describe('KubernetesProxy', () => { proxy = new KubernetesProxy({ logger: getVoidLogger(), clusterSupplier: new LocalKubectlProxyClusterLocator(), - authStrategy: new NoopStrategy(), + authStrategy: new AnonymousStrategy(), }); worker.use(