When more than 1 profile in ~/.aws/config is set up to use a gsts based credential_process the following issues are observed
If the gsts credentials file doesn't exist then this file is created and the credentials are saved to the file correctly
If the gsts credentials file does exist but the profile name being used is different than the initial profile through which the credentials file was created then a ProfileNotFoundError exception is thrown here.
gsts always tries to overwrite the gsts credentials file in saveCredentials instead of modifying the file if it already exists.
From my perspective the 2nd and 3rd bullets are bugs.
Proposed solution for the 2nd bullet is to gracefully handle the profile not found and retrieve credentials for this profile
index.js
if (!session) {
logger.info('Profile %s not found', argv.awsProfile);
} else if (session.isValid()) {
credentials-manager.js
if (!credentials[profile]) {
return null;
}
Proposed fix for 3rd bullet is to create the file with the profile if the file doesn't exist. If the file exists then just update it by adding/updating the profile
credentials-manager.js
/**
* Save AWS credentials to a profile section.
*/
async saveCredentials(profile, session) {
let contents;
try {
const credentials = ini.parse(await readFile(this.credentialsFile, 'utf-8'));
this.logger.info(`Loaded credentials from "${this.credentialsFile}" for profile "${profile}".`);
credentials[profile] = session.toIni(profile)[profile];
contents = ini.encode(credentials)
} catch (e) {
if (e.code === 'ENOENT') {
contents = ini.encode(session.toIni(profile));
} else {
throw e;
}
}
await mkdir(dirname(this.credentialsFile), { recursive: true });
await writeFile(this.credentialsFile, contents);
await chmod(this.credentialsFile, constants.S_IRUSR | constants.S_IWUSR);
this.logger.info('The credentials have been stored in "%s" under AWS profile "%s"', this.credentialsFile, profile);
this.logger.debug('Contents for credentials file "%s" is: \n %o', this.credentialsFile, contents);
}
Hi
When more than 1 profile in
~/.aws/config
is set up to use agsts
based credential_process the following issues are observedgsts
credentials file doesn't exist then this file is created and the credentials are saved to the file correctlygsts
credentials file does exist but the profile name being used is different than the initial profile through which the credentials file was created then aProfileNotFoundError
exception is thrown here.gsts
always tries to overwrite thegsts
credentials file in saveCredentials instead of modifying the file if it already exists.From my perspective the 2nd and 3rd bullets are bugs.
Proposed solution for the 2nd bullet is to gracefully handle the profile not found and retrieve credentials for this profile
index.js
credentials-manager.js
Proposed fix for 3rd bullet is to create the file with the profile if the file doesn't exist. If the file exists then just update it by adding/updating the profile
credentials-manager.js