Skip to content

Commit 8ff6754

Browse files
committed
Add role ARN field to IAM credentials form
1 parent 6b5689a commit 8ff6754

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

packages/core/src/auth/auth2.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export class LanguageClientAuth {
155155
sso_session: profileName,
156156
aws_access_key_id: '',
157157
aws_secret_access_key: '',
158+
role_arn: '',
158159
},
159160
},
160161
ssoSession: {
@@ -168,9 +169,9 @@ export class LanguageClientAuth {
168169
} satisfies UpdateProfileParams)
169170
}
170171

171-
updateIamProfile(profileName: string, accessKey: string, secretKey: string, sessionToken?: string): Promise<UpdateProfileResult> {
172-
// Use unknown profile type if invalidating all IAM fields
173-
const kind = !accessKey && !secretKey && !sessionToken ? ProfileKind.EmptyProfile : ProfileKind.IamCredentialProfile
172+
updateIamProfile(profileName: string, accessKey: string, secretKey: string, sessionToken?: string, roleArn?: string): Promise<UpdateProfileResult> {
173+
// Use empty profile type if invalidating all IAM fields
174+
const kind = !accessKey && !secretKey ? ProfileKind.EmptyProfile : ProfileKind.IamCredentialProfile
174175
// Add credentials and delete SSO settings from profile
175176
return this.client.sendRequest(updateProfileRequestType.method, {
176177
profile: {
@@ -182,6 +183,7 @@ export class LanguageClientAuth {
182183
aws_access_key_id: accessKey,
183184
aws_secret_access_key: secretKey,
184185
aws_session_token: sessionToken,
186+
role_arn: roleArn,
185187
},
186188
},
187189
ssoSession: {
@@ -488,7 +490,7 @@ export class IamLogin extends BaseLogin {
488490
// )
489491
}
490492

491-
async login(opts: { accessKey: string; secretKey: string, sessionToken?: string }) {
493+
async login(opts: { accessKey: string; secretKey: string, sessionToken?: string, roleArn?: string }) {
492494
await this.updateProfile(opts)
493495
return this._getIamCredential(true)
494496
}
@@ -504,18 +506,18 @@ export class IamLogin extends BaseLogin {
504506
if (this.iamCredentialId) {
505507
await this.lspAuth.invalidateStsCredential(this.iamCredentialId)
506508
}
507-
await this.lspAuth.updateIamProfile(this.profileName, '', '', '')
509+
await this.lspAuth.updateIamProfile(this.profileName, '', '', '', '')
508510
this.updateConnectionState('notConnected')
509511
this._data = undefined
510512
// TODO: DeleteProfile api in Identity Service (this doesn't exist yet)
511513
}
512514

513-
async updateProfile(opts: { accessKey: string; secretKey: string, sessionToken?: string }) {
514-
await this.lspAuth.updateIamProfile(this.profileName, opts.accessKey, opts.secretKey, opts.sessionToken)
515+
async updateProfile(opts: { accessKey: string; secretKey: string, sessionToken?: string, roleArn?: string }) {
516+
await this.lspAuth.updateIamProfile(this.profileName, opts.accessKey, opts.secretKey, opts.sessionToken, opts.roleArn)
515517
this._data = {
516518
accessKey: opts.accessKey,
517519
secretKey: opts.secretKey,
518-
sessionToken: opts.sessionToken
520+
sessionToken: opts.sessionToken,
519521
}
520522
}
521523

@@ -585,7 +587,9 @@ export class IamLogin extends BaseLogin {
585587
this.cancellationToken = undefined
586588
}
587589

588-
this.iamCredentialId = response.id
590+
if (response.credentials.sessionToken) {
591+
this.iamCredentialId = response.id
592+
}
589593
this.updateConnectionState('connected')
590594
return response
591595
}

packages/core/src/codewhisperer/util/authUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ export class AuthUtil implements IAuthProvider {
174174
}
175175

176176
// Log in using IAM or STS credentials
177-
async login_iam(accessKey: string, secretKey: string, sessionToken?: string): Promise<GetIamCredentialResult | undefined> {
177+
async login_iam(accessKey: string, secretKey: string, sessionToken?: string, roleArn?: string): Promise<GetIamCredentialResult | undefined> {
178178
let response: GetIamCredentialResult | undefined
179179
// Create IAM login session
180180
if (!this.isIamSession()) {
181181
this.session = new IamLogin(this.profileName, this.lspAuth, this.eventEmitter)
182182
}
183-
response = await (this.session as IamLogin).login({ accessKey: accessKey, secretKey: secretKey, sessionToken: sessionToken })
183+
response = await (this.session as IamLogin).login({ accessKey: accessKey, secretKey: secretKey, sessionToken: sessionToken, roleArn: roleArn })
184184
await showAmazonQWalkthroughOnce()
185185
return response
186186
}

packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ export class AmazonQLoginWebview extends CommonAuthWebview {
197197
profileName: string,
198198
accessKey: string,
199199
secretKey: string,
200-
sessionToken?: string
200+
sessionToken?: string,
201+
roleArn?: string
201202
): Promise<AuthError | undefined> {
202203
getLogger().debug(`called startIamCredentialSetup()`)
203204
// Defining separate auth function to emit telemetry before returning from this method
@@ -206,7 +207,7 @@ export class AmazonQLoginWebview extends CommonAuthWebview {
206207
})
207208
const runAuth = async (): Promise<AuthError | undefined> => {
208209
try {
209-
await AuthUtil.instance.login_iam(accessKey, secretKey, sessionToken)
210+
await AuthUtil.instance.login_iam(accessKey, secretKey, sessionToken, roleArn)
210211
} catch (e) {
211212
getLogger().error('Failed submitting credentials %O', e)
212213
return { id: this.id, text: e as string }

packages/core/src/login/webview/vue/backend.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export abstract class CommonAuthWebview extends VueWebview {
176176
accessKey: string,
177177
secretKey: string,
178178
sessionToken?: string,
179+
role_arn?: string,
179180
): Promise<AuthError | undefined>
180181

181182
async showResourceExplorer(): Promise<void> {

packages/core/src/login/webview/vue/login.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@
289289
v-model="sessionToken"
290290
@keydown.enter="handleContinueClick()"
291291
/>
292+
<div class="title">Role ARN (Optional)</div>
293+
<input
294+
class="iamInput bottomMargin"
295+
type="text"
296+
id="roleArn"
297+
name="roleArn"
298+
v-model="roleArn"
299+
@keydown.enter="handleContinueClick()"
300+
/>
292301
</div>
293302
<button class="continue-button" :disabled="shouldDisableIamContinue()" v-on:click="handleContinueClick()">
294303
Continue
@@ -379,6 +388,7 @@ export default defineComponent({
379388
accessKey: '',
380389
secretKey: '',
381390
sessionToken: '',
391+
roleArn: '',
382392
}
383393
},
384394
async created() {
@@ -517,7 +527,7 @@ export default defineComponent({
517527
return
518528
}
519529
this.stage = 'AUTHENTICATING'
520-
const error = await client.startIamCredentialSetup(this.profileName, this.accessKey, this.secretKey, this.sessionToken)
530+
const error = await client.startIamCredentialSetup(this.profileName, this.accessKey, this.secretKey, this.sessionToken, this.roleArn)
521531
if (error) {
522532
this.stage = 'START'
523533
void client.errorNotification(error)

0 commit comments

Comments
 (0)