feat(storage): add insecure_skip_tls_verify option for S3

Adds an opt-in toggle to skip TLS certificate verification when connecting
to the S3 endpoint, for self-hosted S3-compatible backends (e.g. rustfs,
MinIO) that use self-signed certificates. Exposed in both the store/API
protos and the storage settings UI, mirroring the existing use_path_style
toggle. When enabled, the AWS client uses an HTTP transport with
InsecureSkipVerify; default behavior is unchanged.

This governs backend-initiated S3 calls (uploads, deletes, thumbnails, and
image/document streaming). Video/audio playback redirects the browser to a
presigned URL, so that path still requires the browser to trust the cert.

Closes #6039
This commit is contained in:
boojack
2026-06-23 00:04:54 +08:00
parent 1e3ec38fa1
commit 20c19ef82d
10 changed files with 98 additions and 23 deletions
+15 -2
View File
@@ -2,10 +2,13 @@ package s3
import (
"context"
"crypto/tls"
"io"
"net/http"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/s3"
@@ -20,10 +23,20 @@ type Client struct {
}
func NewClient(ctx context.Context, s3Config *storepb.StorageS3Config) (*Client, error) {
cfg, err := config.LoadDefaultConfig(ctx,
loadOptions := []func(*config.LoadOptions) error{
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(s3Config.AccessKeyId, s3Config.AccessKeySecret, "")),
config.WithRegion(s3Config.Region),
)
}
if s3Config.InsecureSkipTlsVerify {
// Skip TLS certificate verification for endpoints using self-signed certificates.
// This is opt-in and removes protection against man-in-the-middle attacks.
httpClient := awshttp.NewBuildableClient().WithTransportOptions(func(tr *http.Transport) {
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} // #nosec G402 -- opt-in for self-signed S3 endpoints
})
loadOptions = append(loadOptions, config.WithHTTPClient(httpClient))
}
cfg, err := config.LoadDefaultConfig(ctx, loadOptions...)
if err != nil {
return nil, errors.Wrap(err, "failed to load s3 config")
}