Skip to content

Feature/credential provider ini #25

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

Merged
merged 3 commits into from
Jun 27, 2017
Merged

Feature/credential provider ini #25

merged 3 commits into from
Jun 27, 2017

Conversation

jeskew
Copy link
Contributor

@jeskew jeskew commented Jun 13, 2017

Spun off from #5.

This PR adds support for loading credentials from the shared config and credentials ini files. It supports the full suite of recursive role assumption, MFA tokens, and configuration via environment variables.

@jeskew jeskew requested review from awood45 and chrisradek June 13, 2017 23:37
@jeskew jeskew mentioned this pull request Jun 13, 2017
5 tasks
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we still are targetting es5

* @param sourceCreds The credentials with which to assume a role.
* @param params
*/
roleAssumer?: (
Copy link
Contributor

Choose a reason for hiding this comment

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

I really like that roleAssumer is something that is passed in, rather than trying to have each credential provider rewrite logic to assume a role (and pull in all those dependencies)

}

async function resolveProfileData(
profile: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: does profileName make more sense? Only reason I say that is because you're also passing in profiles, and I'd expect profile to be a singular value from profiles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will update.

source_profile,
} = data;

const sourceCreds = fromIni({
Copy link
Contributor

Choose a reason for hiding this comment

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

If someone accidentally set their source_profile to be the same as their profile, would this cause a stack call exceeded error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would. I can detect a simple cycle here and throw, but detecting more complex cycles like the following would require this function to keep a breadcrumb trail of all profiles visited:

default:
    role_arn: foo
    source_profile: bar

bar:
    role_arn: baz
    source_profile: quux

quux:
    role_arn: fizz
    source_profile: default

Is it worth it in that case to throw a "cycle detected" error?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, since fromIni returns a CredentialProvider, and that resolves a promise, I think we'll never exceed the call stack limit since promises are put on the microtask queue, unless I'm missing something. That does however mean instead of getting a call stack error, the promise 'loop' will just keep going forever and never resolve.

If that's the case, it might be worth detecting a cycle so we can reject the promise instead.

Copy link
Contributor Author

@jeskew jeskew Jun 22, 2017

Choose a reason for hiding this comment

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

Err, yes, the particular error will be memory exhaustion or a failed malloc, but the user will still see a lag followed by a supremely unhelpful error message.

Cycle detection (and an appropriate test) added.

options: FromIniInit
): Promise<Credentials> {
const data = profiles[profile];
if (isStaticCredsProfile(data)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's an edge case, but I could see someone including source creds and role arn in the same profile.

Do you know what the CLI does in that situation? We might need to handle this if it turns out other SDKs support that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had assumed the CLI would prefer static credentials, but it looks like I had that backwards. I'd like to verify with someone on the boto team because the semantics of this seem a bit weird. (If I've specified a role ARN, access key, and secret key, should the profile use those credentials to call STS? What if I supply a role ARN, static credentials, and a source profile?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I spoke with Kyle, and the CLI will require any profile with a role_arn to also specify a source_profile, and any static credentials in that profile would be ignored. I'll update this PR to make the behavior matches the CLI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I switched the order of the checks and added a test to verify that we match the CLI.

});
}

function slurpFile(path: string): Promise<string> {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 on name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,9 @@
{
"compilerOptions": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're using async in this package, what about setting "importHelpers": true and depending on tslib? That should reduce the amount of code the TypeScript compiler generates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure; using tslib really helps our code coverage numbers, too.

Copy link
Contributor

@chrisradek chrisradek left a comment

Choose a reason for hiding this comment

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

:shipit:

@jeskew jeskew merged commit bcd9316 into aws:master Jun 27, 2017
@jeskew jeskew deleted the feature/credential-provider-ini branch June 27, 2017 19:27
trivikr referenced this pull request in trivikr/aws-sdk-js-v3 Dec 10, 2018
@lock
Copy link

lock bot commented Sep 26, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants