-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Allow overwriting STS config in ChainableTemporaryCredentials #2803
Allow overwriting STS config in ChainableTemporaryCredentials #2803
Conversation
STS uses the global endpoint per default which does not work for "opt-in" regions. The `ChainableTemporaryCredentials` wrapper for fetching credentials via `AssumeRole` or `GetSessionToken` does not allow overriding the endpoint or set a different region. This change will introduce another optional constructor parameter for specifying the STS client configuration and forwarding it to the client constructor. In addition I remove the incorrect typing for the second `masterCredentials` constructor parameter. The parameter needs to be passed as a nested value in `options`. issue: aws#2673
@@ -3,7 +3,7 @@ import {AWSError} from '../error'; | |||
import STS = require('../../clients/sts'); | |||
|
|||
export class ChainableTemporaryCredentials extends Credentials { | |||
constructor(options: ChainableTemporaryCredentials.ChainableTemporaryCredentialsOptions, masterCredentials?: Credentials); | |||
constructor(options: ChainableTemporaryCredentials.ChainableTemporaryCredentialsOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class expose the service
member which is an STS
service cient. Can't you access the service object and update the endpoint directly?
I'm raising this because exposing the client config is not consist with our other credentials providers config interface. For example: SharedIniCredentials only expose the httpOptions
config instead of the whole client config.
@workeitel To update the STS endpoint, you can actually do it as follows: const stsClient = chainableCredentials.service;
stsClient.setupEventListeners = (request) => {
request.on('afterBuild', (req) => {
request.httpRequest.endpoint = //endpoint you want
})
} |
Hey @AllanFly120 . Thanks for the quick reply. I tried multiple approaches but could not get it working:
approach 1As I originally suggested in the ticket #2673
did not set the endpoint approach 2as you suggested
did not set the endpoint approach 3as found somewhere else
did successfully override the endpoint - but not the region. So I end up with a I guess I'm doing something wrong. |
Hey @workeitel Sorry, I didn't make it clear in my previous response. The const stsClient = chainableCredentials.service;
stsClient.setupEventListeners = (request) => {
request.on('afterBuild', (req) => {
request.httpRequest.endpoint.host = "sts.us-west-1.amazonaws.com";
})
} Note here your host already contains the region. So setting region separately won't work. You need to insert the region when you construct the host uri, like |
Thanks @AllanFly120. I tried your version but I assume you mean
But it fails with:
since the
helps (alternative use
I think for signing the request the AWS SigV4 requires the region as well since the region is part of the signature. If we override the endpoint with another region we need to update the region for the signature as well. https://docs.aws.amazon.com/general/latest/gr/sigv4_elements.html#sigv4_elements_auth_params Overriding the region as well works but is not supported in typings: Final version:
But I don't think thats a nice solution. At least the |
@workeitel I see your point. I'm approving this PR. |
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. |
STS uses the global endpoint per default which does not work for
"opt-in" regions. The
ChainableTemporaryCredentials
wrapper forfetching credentials via
AssumeRole
orGetSessionToken
does notallow overriding the endpoint or set a different region.
This change will introduce another optional constructor parameter for
specifying the STS client configuration and forwarding it to the client
constructor.
In addition I remove the incorrect typing for the second
masterCredentials
constructor parameter. The parameter needs to bepassed as a nested value in
options
.issue: #2673
Checklist
npm run test
passes.d.ts
file is updatednpm run add-change