diff --git a/.changeset/four-buttons-design.md b/.changeset/four-buttons-design.md new file mode 100644 index 0000000000..172d011057 --- /dev/null +++ b/.changeset/four-buttons-design.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-kubernetes-backend': patch +--- + +Adds ability to send an ExternalId with the assume role request to AWS diff --git a/plugins/kubernetes-backend/api-report.md b/plugins/kubernetes-backend/api-report.md index 899f1fff00..f69977f5ad 100644 --- a/plugins/kubernetes-backend/api-report.md +++ b/plugins/kubernetes-backend/api-report.md @@ -16,6 +16,8 @@ import { Logger as Logger_2 } from 'winston'; export interface AWSClusterDetails extends ClusterDetails { // (undocumented) assumeRole?: string; + // (undocumented) + externalId?: string; } // Warning: (ae-missing-release-tag) "ClusterDetails" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) diff --git a/plugins/kubernetes-backend/src/kubernetes-auth-translator/AwsIamKubernetesAuthTranslator.ts b/plugins/kubernetes-backend/src/kubernetes-auth-translator/AwsIamKubernetesAuthTranslator.ts index 101bed32a3..111ed1cf56 100644 --- a/plugins/kubernetes-backend/src/kubernetes-auth-translator/AwsIamKubernetesAuthTranslator.ts +++ b/plugins/kubernetes-backend/src/kubernetes-auth-translator/AwsIamKubernetesAuthTranslator.ts @@ -55,7 +55,10 @@ export class AwsIamKubernetesAuthTranslator }); }; - async getCredentials(assumeRole: string | undefined): Promise { + async getCredentials( + assumeRole?: string, + externalId?: string, + ): Promise { return new Promise(async (resolve, reject) => { const awsCreds = await this.awsGetCredentials(); @@ -73,10 +76,12 @@ export class AwsIamKubernetesAuthTranslator if (!assumeRole) return resolve(creds); try { - const params = { + const params: AWS.STS.Types.AssumeRoleRequest = { RoleArn: assumeRole, RoleSessionName: 'backstage-login', }; + if (externalId) params.ExternalId = externalId; + const assumedRole = await new AWS.STS().assumeRole(params).promise(); if (!assumedRole.Credentials) { @@ -97,9 +102,10 @@ export class AwsIamKubernetesAuthTranslator } async getBearerToken( clusterName: string, - assumeRole: string | undefined, + assumeRole?: string, + externalId?: string, ): Promise { - const credentials = await this.getCredentials(assumeRole); + const credentials = await this.getCredentials(assumeRole, externalId); const request = { host: `sts.amazonaws.com`, @@ -132,6 +138,7 @@ export class AwsIamKubernetesAuthTranslator clusterDetailsWithAuthToken.serviceAccountToken = await this.getBearerToken( clusterDetails.name, clusterDetails.assumeRole, + clusterDetails.externalId, ); return clusterDetailsWithAuthToken; } diff --git a/plugins/kubernetes-backend/src/types/types.ts b/plugins/kubernetes-backend/src/types/types.ts index 6409229968..f4bb019108 100644 --- a/plugins/kubernetes-backend/src/types/types.ts +++ b/plugins/kubernetes-backend/src/types/types.ts @@ -86,4 +86,5 @@ export interface GKEClusterDetails extends ClusterDetails {} export interface ServiceAccountClusterDetails extends ClusterDetails {} export interface AWSClusterDetails extends ClusterDetails { assumeRole?: string; + externalId?: string; }