Problem: can't use anonymous S3 credentials

When trying to use S3 cache with anonymous credentials (for example, for importing publicly available layers), the cache is not used.

Solution: enable anonymous credentials

According to the API documentation:

"If using the `NewFromConfig` constructor you'll need to explicitly set
the `Credentials` member to nil, if the external config resolved a
credential provider."

Signed-off-by: Yurii Rashkovskii <yrashk@gmail.com>
This commit is contained in:
Yurii Rashkovskii
2023-03-13 04:41:27 -07:00
parent 75123c6965
commit b70350975a

View File

@@ -360,6 +360,10 @@ func newS3Client(ctx context.Context, config Config) (*s3Client, error) {
client := s3.NewFromConfig(cfg, func(options *s3.Options) {
if config.AccessKeyID != "" && config.SecretAccessKey != "" {
options.Credentials = credentials.NewStaticCredentialsProvider(config.AccessKeyID, config.SecretAccessKey, config.SessionToken)
} else {
// Setting `nil` for anonymous credentials as per
// https://pkg.go.dev/github.com/aws/aws-sdk-go-v2@v1.17.6/aws#AnonymousCredentials
options.Credentials = nil
}
if config.EndpointURL != "" {
options.UsePathStyle = config.UsePathStyle