mirror of
https://github.com/versity/versitygw.git
synced 2026-08-17 04:36:19 +00:00
feat: allow anonymous access for s3proxy backend
* Update client.go to support anonymous S3 access * Update s3.go to make access and secret parameters optional * Update example.conf for more clear S3 access and secret usage Fixes #1836
This commit is contained in:
@@ -17,6 +17,7 @@ package s3proxy
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
@@ -48,7 +49,16 @@ func (s *S3Proxy) getClientWithCtx(ctx context.Context) (*s3.Client, error) {
|
||||
}
|
||||
|
||||
func (s *S3Proxy) getConfig(ctx context.Context, access, secret string) (aws.Config, error) {
|
||||
creds := credentials.NewStaticCredentialsProvider(access, secret, "")
|
||||
if (access != "" && secret == "") || (access == "" && secret != "") {
|
||||
return aws.Config{}, fmt.Errorf("both access and secret must be set or none at all")
|
||||
}
|
||||
|
||||
var creds aws.CredentialsProvider
|
||||
if access != "" {
|
||||
creds = credentials.NewStaticCredentialsProvider(access, secret, "")
|
||||
} else {
|
||||
creds = aws.AnonymousCredentials{}
|
||||
}
|
||||
|
||||
tr := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: s.sslSkipVerify},
|
||||
|
||||
@@ -45,7 +45,6 @@ to an s3 storage backend service.`,
|
||||
Name: "access",
|
||||
Usage: "s3 proxy server access key id",
|
||||
Value: "",
|
||||
Required: true,
|
||||
EnvVars: []string{"VGW_S3_ACCESS_KEY"},
|
||||
Destination: &s3proxyAccess,
|
||||
Aliases: []string{"a"},
|
||||
@@ -54,7 +53,6 @@ to an s3 storage backend service.`,
|
||||
Name: "secret",
|
||||
Usage: "s3 proxy server secret access key",
|
||||
Value: "",
|
||||
Required: true,
|
||||
EnvVars: []string{"VGW_S3_SECRET_KEY"},
|
||||
Destination: &s3proxySecret,
|
||||
Aliases: []string{"s"},
|
||||
|
||||
+3
-2
@@ -524,8 +524,9 @@ ROOT_SECRET_ACCESS_KEY=
|
||||
# S3 service.
|
||||
|
||||
# When s3 backend selected, the VGW_S3_ACCESS_KEY and VGW_S3_SECRET_KEY must
|
||||
# be defined. The VGW_S3_REGION and VGW_S3_ENDPOINT are optional, and will
|
||||
# default to "us-east-1" and "https://s3.amazonaws.com" respectively.
|
||||
# be defined for an authorized access or both empty for an anonymous access.
|
||||
# The VGW_S3_REGION and VGW_S3_ENDPOINT are optional, and will default to
|
||||
# "us-east-1" and "https://s3.amazonaws.com" respectively.
|
||||
#VGW_S3_ACCESS_KEY=
|
||||
#VGW_S3_SECRET_KEY=
|
||||
#VGW_S3_REGION=
|
||||
|
||||
Reference in New Issue
Block a user