aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.12k stars 578 forks source link

Profile not found on profile names containing a "." #5521

Closed huyhua-nvg closed 11 months ago

huyhua-nvg commented 11 months ago

Checkboxes for prior research

Describe the bug

Previous issue: https://github.com/aws/aws-sdk-js-v3/issues/5449 It was closed but the bug is still there so I'm creating a new one.

Our company uses aws-sso-util to populate the aws sso profiles on config file A profile usually looks like this

[profile aws_re-someservice-dev.AdminPermissionSet]
sso_start_url = https://<company>.awsapps.com/start
sso_region = eu-central-1
sso_account_name = aws_re-someservice-dev
sso_account_id = ACCOUNTID
sso_role_name = AdminPermissionSet
region = AWS_REGION
credential_process = aws-sso-util credential-process --profile aws_re-someservice-dev.AdminPermissionSet
sso_auto_populated = true

I get an error saying that the profile cannot be found. I've debugged this and @smithy/shared-ini-file-loader doesn't like AWS CLI profile names which contain a . character. There is a regex called prefixKeyRegex which fails on such names and goes into the wrong code path.

In the aws docs there's no mention of forbidding a "." on the name, and the cli works fine for this kind of format

SDK version number

@smithy/shared-ini-file-loader@2.2.5

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v18.18.0

Reproduction Steps

import { S3 } from "@aws-sdk/client-s3";
import { fromIni } from "@aws-sdk/credential-providers";

const s3 = new S3({
region: "eu-central-1",
credentials: fromIni({ profile: "other.account" }),
});

async function main() {
const result = await s3.listBuckets({});
console.log(result);
}

main();

Observed Behavior

node_modules/@aws-sdk/credential-provider-ini/dist-cjs/resolveProfileData.js:30
throw new property_provider_1.CredentialsProviderError(Profile ${profileName} could not be found or parsed in shared credentials file.);
^
CredentialsProviderError: Profile other.account could not be found or parsed in shared credentials file.
at resolveProfileData (projects/assume/node_modules/@aws-sdk/credential-provider-ini/dist-cjs/resolveProfileData.js:30:11)
at projects/assume/node_modules/@aws-sdk/credential-provider-ini/dist-cjs/fromIni.js:9:56
at async coalesceProvider (projects/assume/node_modules/@smithy/property-provider/dist-cjs/memoize.js:14:24)
at async SignatureV4.credentialProvider (projects/assume/node_modules/@smithy/property-provider/dist-cjs/memoize.js:33:24)
at async SignatureV4.signRequest (projects/assume/node_modules/@smithy/signature-v4/dist-cjs/SignatureV4.js:106:29)
at async projects/assume/node_modules/@aws-sdk/middleware-signing/dist-cjs/awsAuthMiddleware.js:16:18
at async projects/assume/node_modules/@smithy/middleware-retry/dist-cjs/retryMiddleware.js:27:46
at async projects/assume/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/region-redirect-endpoint-middleware.js:14:24
at async projects/assume/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/region-redirect-middleware.js:9:20
at async projects/assume/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:7:26 {
tryNextLink: true,
'$metadata': { attempts: 1, totalRetryDelay: 0 }

Expected Behavior

A listing of buckets

Possible Solution

No response

Additional Information/Context

Similar issue that got reopened: https://github.com/smithy-lang/smithy-typescript/issues/1053

RanVaknin commented 11 months ago

Hi Can confirm that this is still an issue.

Thanks, Ran~

github-actions[bot] commented 10 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.