-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(NODE-6051): only provide expected allowed keys to libmongocrypt a…
…fter fetching aws kms credentials (#4057)
- Loading branch information
1 parent
0e3d6ea
commit c604e74
Showing
7 changed files
with
110 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
import { getAwsCredentialProvider } from '../../deps'; | ||
import { AWSSDKCredentialProvider } from '../../cmap/auth/aws_temporary_credentials'; | ||
import { type KMSProviders } from '.'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export async function loadAWSCredentials(kmsProviders: KMSProviders): Promise<KMSProviders> { | ||
const credentialProvider = getAwsCredentialProvider(); | ||
const credentialProvider = new AWSSDKCredentialProvider(); | ||
|
||
if ('kModuleError' in credentialProvider) { | ||
return kmsProviders; | ||
} | ||
// We shouldn't ever receive a response from the AWS SDK that doesn't have a `SecretAccessKey` | ||
// or `AccessKeyId`. However, TS says these fields are optional. We provide empty strings | ||
// and let libmongocrypt error if we're unable to fetch the required keys. | ||
const { | ||
SecretAccessKey = '', | ||
AccessKeyId = '', | ||
Token | ||
} = await credentialProvider.getCredentials(); | ||
const aws: NonNullable<KMSProviders['aws']> = { | ||
secretAccessKey: SecretAccessKey, | ||
accessKeyId: AccessKeyId | ||
}; | ||
// the AWS session token is only required for temporary credentials so only attach it to the | ||
// result if it's present in the response from the aws sdk | ||
Token != null && (aws.sessionToken = Token); | ||
|
||
const { fromNodeProviderChain } = credentialProvider; | ||
const provider = fromNodeProviderChain(); | ||
// The state machine is the only place calling this so it will | ||
// catch if there is a rejection here. | ||
const aws = await provider(); | ||
return { ...kmsProviders, aws }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters