Skip to content

Commit 5be0fd9

Browse files
authored
fix(codecatalyst): split session auth issues (#5199)
Fixes: - Adds 'source' to telemetry for logout prompt - If in dev env, fall back to MDE credentials if logged out (due to sharing connection with Q) - Bug where signing in to Amazon Q in dev env will add coca scopes (and otherwise share the underlying MDE credentials) - Amazon Q was also importing the MDE creds under the hood, so it was being detected as an existant connection. This means any login method will use that instead of creating a new connection.
1 parent 7d6d7fd commit 5be0fd9

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

packages/core/src/auth/auth.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ import {
5353
createBuilderIdProfile,
5454
createSsoProfile,
5555
hasScopes,
56-
isValidCodeCatalystConnection,
5756
loadIamProfilesIntoStore,
5857
loadLinkedProfilesIntoStore,
5958
scopesSsoAccountAccess,
6059
AwsConnection,
60+
scopesCodeWhispererCore,
6161
} from './connection'
6262
import { isSageMaker, isCloud9, isAmazonQ } from '../shared/extensionUtilities'
6363
import { telemetry } from '../shared/telemetry/telemetry'
@@ -528,8 +528,8 @@ export class Auth implements AuthService, ConnectionManager {
528528
})
529529
}
530530

531-
// XXX: never drop tokens in a dev environment
532-
if (getCodeCatalystDevEnvId() === undefined) {
531+
// XXX: never drop tokens in a dev environment, unless you are Amazon Q!
532+
if (getCodeCatalystDevEnvId() === undefined || isAmazonQ()) {
533533
await provider.invalidate()
534534
}
535535
} else if (profile.type === 'iam') {
@@ -882,9 +882,11 @@ export class Auth implements AuthService, ConnectionManager {
882882

883883
// When opening a Dev Environment, use the environment token if no other CodeCatalyst
884884
// credential is in use. This token only has CC permissions currently!
885-
if (getCodeCatalystDevEnvId() !== undefined) {
885+
if (!isAmazonQ() && getCodeCatalystDevEnvId() !== undefined) {
886886
const connections = await this.listConnections()
887-
const shouldInsertDevEnvCredential = !connections.some(isValidCodeCatalystConnection)
887+
const shouldInsertDevEnvCredential = !connections.some(
888+
c => c.type === 'sso' && hasScopes(c, scopesCodeCatalyst) && !hasScopes(c, scopesCodeWhispererCore)
889+
)
888890

889891
if (shouldInsertDevEnvCredential) {
890892
// Insert a profile based on the `~/.aws/config` sso-session:
@@ -1067,6 +1069,7 @@ export class SessionSeparationPrompt {
10671069
)
10681070
.then(async resp => {
10691071
await telemetry.toolkit_invokeAction.run(async () => {
1072+
telemetry.record({ source: 'sessionSeparationNotification' })
10701073
if (resp === 'Sign In') {
10711074
telemetry.record({ action: 'signIn' })
10721075
await vscode.commands.executeCommand(cmd)

packages/core/src/codewhisperer/activation.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import { securityScanLanguageContext } from './util/securityScanLanguageContext'
7070
import { registerWebviewErrorHandler } from '../webviews/server'
7171
import { logAndShowWebviewError } from '../shared/utilities/logAndShowUtils'
7272
import { openSettings } from '../shared/settings'
73+
import { getCodeCatalystDevEnvId } from '../shared/vscode/env'
7374

7475
let localize: nls.LocalizeFunc
7576

@@ -291,6 +292,16 @@ export async function activate(context: ExtContext): Promise<void> {
291292

292293
await auth.restore()
293294

295+
// Amazon Q may have code catalyst only credentials stored because it used to import the credentials stored on disk in the environment.
296+
if (getCodeCatalystDevEnvId() !== undefined) {
297+
for (const conn of await auth.auth.listConnections()) {
298+
if (conn.id !== auth.conn?.id) {
299+
getLogger().debug('forgetting extra amazon q connection in CoCa dev env: %O', conn)
300+
await auth.auth.forgetConnection(conn)
301+
}
302+
}
303+
}
304+
294305
if (auth.isConnectionExpired()) {
295306
auth.showReauthenticatePrompt().catch(e => {
296307
getLogger().error('showReauthenticatePrompt failed: %s', (e as Error).message)

0 commit comments

Comments
 (0)