Skip to content

Commit

Permalink
iam-verify: add region param when provided in user.yaml (#229)
Browse files Browse the repository at this point in the history
Signed-off-by: haorenfsa <[email protected]>
  • Loading branch information
haorenfsa authored Jan 10, 2025
1 parent 646fbe9 commit 117dc0e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pkg/external/iam/aliyun.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/pkg/errors"
)

func VerifyAliyun(ctx context.Context, bucketName, address string, secure bool) error {
func VerifyAliyun(ctx context.Context, bucketName, region, address string, secure bool) error {
credProvider, err := NewCredentialProvider()
if err != nil {
return errors.Wrap(err, "failed to create credential provider")
Expand All @@ -19,6 +19,7 @@ func VerifyAliyun(ctx context.Context, bucketName, address string, secure bool)
opts := minio.Options{
Creds: creds,
Secure: secure,
Region: region,
BucketLookup: minio.BucketLookupDNS,
}
client, err := minio.New(address, &opts)
Expand Down
3 changes: 2 additions & 1 deletion pkg/external/iam/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"github.com/pkg/errors"
)

func VerifyAWS(ctx context.Context, bucketName, address string, secure bool) error {
func VerifyAWS(ctx context.Context, bucketName, region, address string, secure bool) error {
// Initialize minio client object.
client, err := minio.New(address, &minio.Options{
Creds: credentials.NewIAM(""),
Secure: secure,
Region: region,
})
if err != nil {
return errors.Wrap(err, "init minio client failed")
Expand Down
3 changes: 2 additions & 1 deletion pkg/external/iam/tencent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
)

func VerifyTencent(ctx context.Context, bucketName, address string, secure bool) error {
func VerifyTencent(ctx context.Context, bucketName, region, address string, secure bool) error {
credProvider, err := NewTencentCredentialProvider()
if err != nil {
return errors.Wrap(err, "failed to create credential provider")
Expand All @@ -18,6 +18,7 @@ func VerifyTencent(ctx context.Context, bucketName, address string, secure bool)
opts := minio.Options{
Creds: creds,
Secure: secure,
Region: region,
BucketLookup: minio.BucketLookupDNS,
}
client, err := minio.New(address, &opts)
Expand Down
1 change: 1 addition & 0 deletions pkg/util/yamlparser/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type UserYaml struct {
CloudProvider string `yaml:"cloudProvider"`
AccessKeyID string `yaml:"accessKeyID"`
BucketName string `yaml:"bucketName"`
Region string `yaml:"region"`
} `yaml:"minio"`
}

Expand Down
1 change: 1 addition & 0 deletions pkg/util/yamlparser/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestParseUserYaml(t *testing.T) {
assert.Equal(t, "myakid", ret.Minio.AccessKeyID)
assert.Equal(t, "test", ret.Minio.BucketName)
assert.Equal(t, "gcp", ret.Minio.CloudProvider)
assert.Equal(t, "us-east-2", ret.Minio.Region)
assert.True(t, ret.Minio.UseIAM)
})

Expand Down
3 changes: 2 additions & 1 deletion test/user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ minio:
accessKeyID: myakid
bucketName: test
useIAM: true
cloudProvider: gcp
cloudProvider: gcp
region: us-east-2
6 changes: 3 additions & 3 deletions tool/iam-verify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ func main() {
case "aws":
verifyFunc = func(ctx context.Context) error {
address := fmt.Sprintf("%s:%d", userYaml.Minio.Address, userYaml.Minio.Port)
return iam.VerifyAWS(ctx, userYaml.Minio.BucketName, address, userYaml.Minio.UseSSL)
return iam.VerifyAWS(ctx, userYaml.Minio.BucketName, userYaml.Minio.Region, address, userYaml.Minio.UseSSL)
}
case "aliyun":
verifyFunc = func(ctx context.Context) error {
address := fmt.Sprintf("%s:%d", userYaml.Minio.Address, userYaml.Minio.Port)
return iam.VerifyAliyun(ctx, userYaml.Minio.BucketName, address, userYaml.Minio.UseSSL)
return iam.VerifyAliyun(ctx, userYaml.Minio.BucketName, userYaml.Minio.Region, address, userYaml.Minio.UseSSL)
}
case "tencent":
verifyFunc = func(ctx context.Context) error {
address := fmt.Sprintf("%s:%d", userYaml.Minio.Address, userYaml.Minio.Port)
return iam.VerifyTencent(ctx, userYaml.Minio.BucketName, address, userYaml.Minio.UseSSL)
return iam.VerifyTencent(ctx, userYaml.Minio.BucketName, userYaml.Minio.Region, address, userYaml.Minio.UseSSL)
}
default:
log.Printf("iam-verify for csp %s not implement, assume success\n", userYaml.Minio.CloudProvider)
Expand Down

0 comments on commit 117dc0e

Please sign in to comment.