Browse Source

[PM-6116] Update AWS key service to handle authentication with instance metadata (#117)

* Updated constructor of AWS service client to test using instance metadata

* Added check to handle instance metadata only if configuration isn't supplied.
pull/130/head
Todd Martin 2 years ago committed by GitHub
parent
commit
9109a6b8e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 17
      src/KeyConnector/Services/AwsKmsRsaKeyService.cs

17
src/KeyConnector/Services/AwsKmsRsaKeyService.cs

@ -17,8 +17,21 @@ namespace Bit.KeyConnector.Services @@ -17,8 +17,21 @@ namespace Bit.KeyConnector.Services
KeyConnectorSettings settings)
{
_settings = settings;
_kmsClient = new AmazonKeyManagementServiceClient(settings.RsaKey.AwsAccessKeyId,
settings.RsaKey.AwsAccessKeySecret, RegionEndpoint.GetBySystemName(settings.RsaKey.AwsRegion));
if(UseInstanceMetadataForCredentials())
{
_kmsClient = new AmazonKeyManagementServiceClient(RegionEndpoint.GetBySystemName(settings.RsaKey.AwsRegion));
} else {
_kmsClient = new AmazonKeyManagementServiceClient(settings.RsaKey.AwsAccessKeyId, settings.RsaKey.AwsAccessKeySecret, RegionEndpoint.GetBySystemName(settings.RsaKey.AwsRegion));
}
}
/// <summary>
/// AWS will default to use the instance metadata for credentials if we initialize the client without credentials, per their documentation here: https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/creds-assign.html.
/// We will infer that we should use the instance metadata if the AwsAccessKeyId and AwsAccessKeySecret are not set in the Key Connector configuration.
/// </summary>
private bool UseInstanceMetadataForCredentials()
{
return string.IsNullOrWhiteSpace(_settings.RsaKey.AwsAccessKeyId) && string.IsNullOrWhiteSpace(_settings.RsaKey.AwsAccessKeySecret);
}
public async Task<byte[]> EncryptAsync(byte[] data)

Loading…
Cancel
Save