Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credentials: partial migration to SDK v3 #1766

Merged
merged 20 commits into from
Aug 12, 2021
Merged

Credentials: partial migration to SDK v3 #1766

merged 20 commits into from
Aug 12, 2021

Conversation

JadenSimon
Copy link
Contributor

@JadenSimon JadenSimon commented May 19, 2021

Problem

SDK v2 has some known issues in regards to credentials from source_profile. SDK v3 does not fix them out-right, however, it does expose some functionality that allows us to fix the bugs.

Solution

Migrate the credentials subsystem to use SDK v3, then add additional logic to handle source_profile resolution.
The new SDK credentials API allows us to 'pre-load' credentials when calling relevant APIs. We can use this functionality to load source profile credentials ourselves, letting the SDK treat them as static credentials. Any valid profile should now be usable as a base profile as well (e.g. processes, SSO, MFA, etc.)

TODO: re-add test for when SDK never resolves a credential provider. Current test broke since the API is a little bit different with v3
TODO: check if the STS region hack is still needed
TODO: add regression tests

Extra testing

Still thinking of more tests I can add.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@JadenSimon JadenSimon requested a review from a team as a code owner May 19, 2021 00:14
@JadenSimon
Copy link
Contributor Author

JadenSimon commented May 19, 2021

Ignore the huge package-lock diff for now, it's caused by a force-update due to peer dependencies unrelated to this PR.
I guess the package-lock really did need all those changes.

@JadenSimon
Copy link
Contributor Author

SDK has broken types I guess.

@JadenSimon JadenSimon marked this pull request as draft May 21, 2021 20:47
JadenSimon added 2 commits May 21, 2021 13:48
@JadenSimon
Copy link
Contributor Author

/runintegrationtests

@JadenSimon
Copy link
Contributor Author

Still need to test for C9 and some edge cases. Will be adding a few more unit tests too.

@JadenSimon JadenSimon marked this pull request as ready for review July 7, 2021 19:01
const ssoCredentialProvider = this.makeSsoProvider()
return await ssoCredentialProvider.refreshCredentials()
// Patches 'source_profile' credentials as static representations, which the SDK can handle in all cases
private async patchSourceCredentials(): Promise<ParsedIniData> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the PR fixes issues with the JS SDK's credential handling. The SDK is unable to resolve source_profile fields when the source profile uses SSO/MFA/credential_process. We can handle this resolution ourselves, giving the SDK the resolved credentials by 'pre-loading' them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this come up as a case customers are using? Do we have any idea if the ASK CLI supports this? Seems like a nice improvement on paper but we should also tread carefully when adding custom credentials logic on top of what the SDK provides. It will increase the surface area for bugs to creep in (and credentials always seem to have goofy edge cases) and is maintainability overhead. Another approach is contributing changes back to the JS SDK if we feel this is a gap.

Copy link
Contributor Author

@JadenSimon JadenSimon Jul 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See:
#1740
#1655
#1624

The reason for doing this patching is to implement functionality that SDK V2/V3 lack. The CLI supports this behavior, so we should support it too. You're right that we should be updating the SDK to support this functionality, but I was looking for a fast solution to solve user issues. I do want to fix-up the SDK, but they require quite a bit more changes on their end to make it work correctly. With this PR, we effectively only use the SDK to parse the credential files (and retrieve creds from the environment), then resolve the credentials ourselves.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks for the context. Agree this is the right solution for now since there's active customer pain on this issue.

await getMfaTokenFromUser(mfaSerial, this.profileName, callback),
})
private makeSharedIniFileCredentialsProvider(loadedCreds: ParsedIniData): AWS.CredentialProvider {
const assumeRole = async (credentials: AWS.Credentials, params: AssumeRoleParams) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V3 no longer performs role assumption for us; we must do it manually.

@@ -78,11 +77,6 @@ describe('Ec2CredentialsProvider', function () {
assert.strictEqual(credentialsProvider.getDefaultRegion(), undefined)
})

it('returns credentials', async function () {
const credentials = await credentialsProvider.getCredentials()
assert(credentials instanceof EC2MetadataCredentials)
Copy link
Contributor Author

@JadenSimon JadenSimon Jul 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V3 credentials are no longer instances of a class, they are just plain old data instead. So this test (and the corresponding environment var provider test) are unnecessary.

src/test/testUtil.ts Outdated Show resolved Hide resolved
@JadenSimon
Copy link
Contributor Author

/runintegrationtest

@JadenSimon
Copy link
Contributor Author

/retrybuild

Copy link
Contributor

@justinmk3 justinmk3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking ec2 instance credentials

2021-08-11 23:24:14 [VERBOSE]: credentials: EC2 metadata region: eu-central-1
2021-08-11 23:24:14 [VERBOSE]: credentials: EC2 metadata service call took 3ms
2021-08-11 23:24:14 [ERROR]: Error trying to connect to AWS with Credentials Provider ec2:instance. Toolkit will now disconnect from AWS. [Error [CredentialsProviderError]: Invalid response received from instance metadata service.
        at new i (/home/ec2-user/environment/.c9/extensions/aws-toolkit-vscode/dist/extension.js:1667:7169)
        at /home/ec2-user/environment/.c9/extensions/aws-toolkit-vscode/dist/extension.js:1680:11728
        at nt (/home/ec2-user/environment/.c9/extensions/aws-toolkit-vscode/dist/extension.js:1680:2892)
        at Object.next (/home/ec2-user/environment/.c9/extensions/aws-toolkit-vscode/dist/extension.js:1680:2170)
        at ke (/home/ec2-user/environment/.c9/extensions/aws-toolkit-vscode/dist/extension.js:1680:1726)
        at processTicksAndRejections (internal/process/task_queues.js:97:5)] {
  tryNextLink: true
}

edit: same behavior with 5a30d27 (current master)

@JadenSimon JadenSimon merged commit d1ce6de into master Aug 12, 2021
@JadenSimon JadenSimon deleted the sijaden/credv3 branch August 12, 2021 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants