Skip to content

Commit b3b285a

Browse files
aportillo83aportillo-fingercheckdluc
authored
Update AWS S3 Extension to allow for use of credential chain. (#969)
## Motivation and Context (Why the change? What's the scenario?) Allow the use of [instance metadata](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html) for authentication and the proper use of [credential chain](https://docs.aws.amazon.com/sdkref/latest/guide/standardized-credentials.html). ## High level description (Approach, Design) Added AWS S3 Extension CredentialChain authentication method to use default credentials --------- Co-authored-by: Armando Portill <[email protected]> Co-authored-by: Devis Lucato <[email protected]> Co-authored-by: Devis Lucato <[email protected]>
1 parent 6c3f50a commit b3b285a

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

extensions/AWS/S3/AWSS3Config.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22

33
using System.Text.Json.Serialization;
44

@@ -13,6 +13,7 @@ public enum AuthTypes
1313
{
1414
Unknown = -1,
1515
AccessKey,
16+
CredentialChain,
1617
}
1718

1819
public AuthTypes Auth { get; set; } = AuthTypes.Unknown;
@@ -45,14 +46,17 @@ public void Validate()
4546
throw new ConfigurationException($"Authentication type '{this.Auth}' undefined or not supported");
4647
}
4748

48-
if (string.IsNullOrWhiteSpace(this.AccessKey))
49+
if (this.Auth == AuthTypes.AccessKey)
4950
{
50-
throw new ConfigurationException("S3 Access Key is undefined");
51-
}
51+
if (string.IsNullOrWhiteSpace(this.AccessKey))
52+
{
53+
throw new ConfigurationException("S3 Access Key is undefined");
54+
}
5255

53-
if (string.IsNullOrWhiteSpace(this.SecretAccessKey))
54-
{
55-
throw new ConfigurationException("S3 Secret Key Access undefined");
56+
if (string.IsNullOrWhiteSpace(this.SecretAccessKey))
57+
{
58+
throw new ConfigurationException("S3 Secret Key Access undefined");
59+
}
5660
}
5761

5862
if (string.IsNullOrWhiteSpace(this.BucketName))

extensions/AWS/S3/AWSS3Storage.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22

33
using System;
44
using System.Collections.Generic;
@@ -43,6 +43,15 @@ public AWSS3Storage(
4343
);
4444
break;
4545
}
46+
case AWSS3Config.AuthTypes.CredentialChain:
47+
{
48+
this._client = new AmazonS3Client(new AmazonS3Config
49+
{
50+
ServiceURL = config.Endpoint,
51+
LogResponse = true
52+
});
53+
break;
54+
}
4655

4756
default:
4857
this._log.LogCritical("Authentication type '{0}' undefined or not supported", config.Auth);

service/Service/appsettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
"HttpClientName": ""
243243
},
244244
"AWSS3": {
245+
// "AccessKey" or "CredentialChain". For other options see <AWSS3Config>.
245246
"Auth": "AccessKey",
246247
// AccessKey ID, required when using AccessKey auth
247248
// Note: you can use an env var 'KernelMemory__Services__AWSS3__AccessKey' to set this

0 commit comments

Comments
 (0)