Skip to content

Commit 94df26d

Browse files
ncwyuval-cloudinary
authored andcommitted
s3: fix rclone ignoring static credentials when env_auth=true
The SDKv2 conversion introduced a regression to do with setting credentials with env_auth=true. The rclone documentation explicitly states that env_auth only applies if secret_access_key and access_key_id are blank and users had been relying on that. However after the SDKv2 conversion we were ignoring static credentials if env_auth=true. This fixes the problem by ignoring env_auth=true if secret_access_key and access_key_id are both provided. This brings rclone back into line with the documentation and users expectations. Fixes rclone#8067
1 parent 4ee1c14 commit 94df26d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

backend/s3/s3.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3052,9 +3052,16 @@ func (s3logger) Logf(classification logging.Classification, format string, v ...
30523052
func s3Connection(ctx context.Context, opt *Options, client *http.Client) (s3Client *s3.Client, err error) {
30533053
ci := fs.GetConfig(ctx)
30543054
var awsConfig aws.Config
3055+
// Make the default static auth
3056+
v := aws.Credentials{
3057+
AccessKeyID: opt.AccessKeyID,
3058+
SecretAccessKey: opt.SecretAccessKey,
3059+
SessionToken: opt.SessionToken,
3060+
}
3061+
awsConfig.Credentials = &credentials.StaticCredentialsProvider{Value: v}
30553062

30563063
// Try to fill in the config from the environment if env_auth=true
3057-
if opt.EnvAuth {
3064+
if opt.EnvAuth && opt.AccessKeyID == "" && opt.SecretAccessKey == "" {
30583065
configOpts := []func(*awsconfig.LoadOptions) error{}
30593066
// Set the name of the profile if supplied
30603067
if opt.Profile != "" {
@@ -3079,13 +3086,7 @@ func s3Connection(ctx context.Context, opt *Options, client *http.Client) (s3Cli
30793086
case opt.SecretAccessKey == "":
30803087
return nil, errors.New("secret_access_key not found")
30813088
default:
3082-
// Make the static auth
3083-
v := aws.Credentials{
3084-
AccessKeyID: opt.AccessKeyID,
3085-
SecretAccessKey: opt.SecretAccessKey,
3086-
SessionToken: opt.SessionToken,
3087-
}
3088-
awsConfig.Credentials = &credentials.StaticCredentialsProvider{Value: v}
3089+
// static credentials are already set
30893090
}
30903091
}
30913092

0 commit comments

Comments
 (0)