@@ -9,6 +9,7 @@ import { builderIdStartUrl, SsoToken } from './sso/model'
9
9
import { SsoClient } from './sso/clients'
10
10
import { CredentialsProviderManager } from './providers/credentialsProviderManager'
11
11
import { fromString } from './providers/credentials'
12
+ import { getLogger } from '../shared/logger/logger'
12
13
13
14
export const ssoScope = 'sso:account:access'
14
15
export const codecatalystScopes = [ 'codecatalyst:read_write' ]
@@ -247,18 +248,27 @@ export async function loadIamProfilesIntoStore(store: ProfileStore, manager: Cre
247
248
}
248
249
}
249
250
251
+ /**
252
+ * Fetches profiles from the given SSO ("IAM Identity Center", "IdC") connection.
253
+ */
250
254
export async function * loadLinkedProfilesIntoStore (
251
255
store : ProfileStore ,
252
256
source : SsoConnection [ 'id' ] ,
253
- client : SsoClient
257
+ client : SsoClient ,
258
+ profileLabel : string
254
259
) {
260
+ const accounts = new Set < string > ( )
261
+ const found = new Set < Connection [ 'id' ] > ( )
262
+
255
263
const stream = client
256
264
. listAccounts ( )
257
265
. flatten ( )
258
- . map ( resp => client . listAccountRoles ( { accountId : resp . accountId } ) . flatten ( ) )
266
+ . map ( resp => {
267
+ accounts . add ( resp . accountId )
268
+ return client . listAccountRoles ( { accountId : resp . accountId } ) . flatten ( )
269
+ } )
259
270
. flatten ( )
260
271
261
- const found = new Set < Connection [ 'id' ] > ( )
262
272
for await ( const info of stream ) {
263
273
const name = `${ info . roleName } -${ info . accountId } `
264
274
const id = `sso:${ source } #${ name } `
@@ -280,6 +290,20 @@ export async function* loadLinkedProfilesIntoStore(
280
290
yield [ id , profile ] as const
281
291
}
282
292
293
+ if ( accounts . size === 0 ) {
294
+ // Possible causes:
295
+ // - SSO org has no "Permission sets"
296
+ // - user is not an "Assigned user" in any account in the SSO org
297
+ // - user is an "Assigned user" but no "Permission sets"
298
+ getLogger ( ) . warn ( 'auth: SSO org (%s) returned no accounts' , profileLabel )
299
+ } else if ( found . size === 0 ) {
300
+ getLogger ( ) . warn (
301
+ 'auth: SSO org (%s) returned no IAM credentials for account: %s' ,
302
+ profileLabel ,
303
+ Array . from ( accounts ) . join ( )
304
+ )
305
+ }
306
+
283
307
// Clean-up stale references in case the user no longer has access
284
308
for ( const [ id , profile ] of store . listProfiles ( ) ) {
285
309
if ( profile . type === 'iam' && profile . subtype === 'linked' && profile . ssoSession === source && ! found . has ( id ) ) {
0 commit comments