Skip to content

Commit d9831c2

Browse files
committed
fix(amplify-provider-awscloudformation): mfa role assumption fails with cached credentials (aws-amplify#14626)
Fixes three related bugs in credential caching for MFA-based role assumption introduced in commit 04f7bcf (PR aws-amplify#14315). Bug 1 - MFA prompt never appears: getCachedRoleCredentials() always returned { credentials: {} } even with no valid cache, so the STS AssumeRole call was never executed. Fix: return undefined when no valid cached credentials exist. Bug 2 - Cache validation always fails: credentials were cached in nested format { credentials: { accessKeyId, ... } } but validateCachedCredentials() expected flat format. Fix: cache the flat credentials object (roleCredentials.credentials). Bug 3 - expiration.getTime error: cached Date is deserialized as a string, but the AWS SDK calls expiration.getTime(). The fix in PR aws-amplify#14315 only addressed this in getConfiguredAWSClientConfig(), not in getProfiledAwsConfig(). Fix: convert expiration to Date when returning cached credentials.
1 parent bea564a commit d9831c2

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

packages/amplify-provider-awscloudformation/src/system-config-manager.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ const getRoleCredentials = async (context: $TSContext, profileName: string, prof
186186
log(ex);
187187
}
188188
if (profileConfig.role_arn && roleSessionName && roleCredentials) {
189-
cacheRoleCredentials(profileConfig.role_arn, roleSessionName, roleCredentials);
189+
cacheRoleCredentials(profileConfig.role_arn, roleSessionName, roleCredentials.credentials);
190190
}
191191
}
192192

@@ -245,9 +245,14 @@ const getCachedRoleCredentials = (roleArn: string, sessionName: string): $TSAny
245245
return undefined;
246246
}
247247
}
248+
if (!roleCredentials) {
249+
return undefined;
250+
}
248251
return {
249252
credentials: {
250253
...roleCredentials,
254+
// Ensure expiration is a Date object (JSON serialization converts it to string)
255+
expiration: roleCredentials.expiration ? new Date(roleCredentials.expiration) : undefined,
251256
},
252257
};
253258
};

0 commit comments

Comments
 (0)