Skip to content

Commit d0d6aad

Browse files
authored
Supports forced use of S3 virtual-hosted style (#30969)
Add a configuration item to enable S3 virtual-hosted style (V2) to solve the problem caused by some S3 service providers not supporting path style (V1).
1 parent db57843 commit d0d6aad

File tree

6 files changed

+46
-4
lines changed

6 files changed

+46
-4
lines changed

cmd/migrate_storage.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ var CmdMigrateStorage = &cli.Command{
9191
Value: "",
9292
Usage: "Minio checksum algorithm (default/md5)",
9393
},
94+
&cli.StringFlag{
95+
Name: "minio-bucket-lookup-type",
96+
Value: "",
97+
Usage: "Minio bucket lookup type",
98+
},
9499
},
95100
}
96101

@@ -220,6 +225,7 @@ func runMigrateStorage(ctx *cli.Context) error {
220225
UseSSL: ctx.Bool("minio-use-ssl"),
221226
InsecureSkipVerify: ctx.Bool("minio-insecure-skip-verify"),
222227
ChecksumAlgorithm: ctx.String("minio-checksum-algorithm"),
228+
BucketLookUpType: ctx.String("minio-bucket-lookup-type"),
223229
},
224230
})
225231
default:

custom/conf/app.example.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,9 @@ LEVEL = Info
18951895
;;
18961896
;; Minio checksum algorithm: default (for MinIO or AWS S3) or md5 (for Cloudflare or Backblaze)
18971897
;MINIO_CHECKSUM_ALGORITHM = default
1898+
;;
1899+
;; Minio bucket lookup method defaults to auto mode; set it to `dns` for virtual host style or `path` for path style, only available when STORAGE_TYPE is `minio`
1900+
;MINIO_BUCKET_LOOKUP_TYPE = auto
18981901

18991902
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19001903
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -2576,6 +2579,9 @@ LEVEL = Info
25762579
;;
25772580
;; Minio skip SSL verification available when STORAGE_TYPE is `minio`
25782581
;MINIO_INSECURE_SKIP_VERIFY = false
2582+
;;
2583+
;; Minio bucket lookup method defaults to auto mode; set it to `dns` for virtual host style or `path` for path style, only available when STORAGE_TYPE is `minio`
2584+
;MINIO_BUCKET_LOOKUP_TYPE = auto
25792585

25802586
;[proxy]
25812587
;; Enable the proxy, all requests to external via HTTP will be affected

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ Default templates for project boards:
851851
- `MINIO_USE_SSL`: **false**: Minio enabled ssl only available when STORAGE_TYPE is `minio`
852852
- `MINIO_INSECURE_SKIP_VERIFY`: **false**: Minio skip SSL verification available when STORAGE_TYPE is `minio`
853853
- `MINIO_CHECKSUM_ALGORITHM`: **default**: Minio checksum algorithm: `default` (for MinIO or AWS S3) or `md5` (for Cloudflare or Backblaze)
854+
- `MINIO_BUCKET_LOOKUP_TYPE`: **auto**: Minio bucket lookup method defaults to auto mode; set it to `dns` for virtual host style or `path` for path style, only available when STORAGE_TYPE is `minio`
854855

855856
## Log (`log`)
856857

@@ -1272,6 +1273,7 @@ is `data/lfs` and the default of `MINIO_BASE_PATH` is `lfs/`.
12721273
- `MINIO_BASE_PATH`: **lfs/**: Minio base path on the bucket only available when `STORAGE_TYPE` is `minio`
12731274
- `MINIO_USE_SSL`: **false**: Minio enabled ssl only available when `STORAGE_TYPE` is `minio`
12741275
- `MINIO_INSECURE_SKIP_VERIFY`: **false**: Minio skip SSL verification available when STORAGE_TYPE is `minio`
1276+
- `MINIO_BUCKET_LOOKUP_TYPE`: **auto**: Minio bucket lookup method defaults to auto mode; set it to `dns` for virtual host style or `path` for path style, only available when STORAGE_TYPE is `minio`
12751277

12761278
## Storage (`storage`)
12771279

@@ -1286,6 +1288,7 @@ Default storage configuration for attachments, lfs, avatars, repo-avatars, repo-
12861288
- `MINIO_LOCATION`: **us-east-1**: Minio location to create bucket only available when `STORAGE_TYPE` is `minio`
12871289
- `MINIO_USE_SSL`: **false**: Minio enabled ssl only available when `STORAGE_TYPE` is `minio`
12881290
- `MINIO_INSECURE_SKIP_VERIFY`: **false**: Minio skip SSL verification available when STORAGE_TYPE is `minio`
1291+
- `MINIO_BUCKET_LOOKUP_TYPE`: **auto**: Minio bucket lookup method defaults to auto mode; set it to `dns` for virtual host style or `path` for path style, only available when STORAGE_TYPE is `minio`
12891292

12901293
The recommended storage configuration for minio like below:
12911294

@@ -1307,6 +1310,8 @@ MINIO_USE_SSL = false
13071310
; Minio skip SSL verification available when STORAGE_TYPE is `minio`
13081311
MINIO_INSECURE_SKIP_VERIFY = false
13091312
SERVE_DIRECT = true
1313+
; Minio bucket lookup method defaults to auto mode; set it to `dns` for virtual host style or `path` for path style, only available when STORAGE_TYPE is `minio`
1314+
MINIO_BUCKET_LOOKUP_TYPE = auto
13101315
```
13111316

13121317
Defaultly every storage has their default base path like below
@@ -1353,6 +1358,8 @@ MINIO_LOCATION = us-east-1
13531358
MINIO_USE_SSL = false
13541359
; Minio skip SSL verification available when STORAGE_TYPE is `minio`
13551360
MINIO_INSECURE_SKIP_VERIFY = false
1361+
; Minio bucket lookup method defaults to auto mode; set it to `dns` for virtual host style or `path` for path style, only available when STORAGE_TYPE is `minio`
1362+
MINIO_BUCKET_LOOKUP_TYPE = auto
13561363
```
13571364

13581365
## Repository Archive Storage (`storage.repo-archive`)
@@ -1372,6 +1379,7 @@ is `data/repo-archive` and the default of `MINIO_BASE_PATH` is `repo-archive/`.
13721379
- `MINIO_BASE_PATH`: **repo-archive/**: Minio base path on the bucket only available when `STORAGE_TYPE` is `minio`
13731380
- `MINIO_USE_SSL`: **false**: Minio enabled ssl only available when `STORAGE_TYPE` is `minio`
13741381
- `MINIO_INSECURE_SKIP_VERIFY`: **false**: Minio skip SSL verification available when STORAGE_TYPE is `minio`
1382+
- `MINIO_BUCKET_LOOKUP_TYPE`: **auto**: Minio bucket lookup method defaults to auto mode; set it to `dns` for virtual host style or `path` for path style, only available when STORAGE_TYPE is `minio`
13751383

13761384
## Repository Archives (`repo-archive`)
13771385

docs/content/administration/config-cheat-sheet.zh-cn.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ Gitea 创建以下非唯一队列:
796796
- `MINIO_USE_SSL`: **false**: Minio 启用 SSL,仅当 STORAGE_TYPE 为 `minio` 时可用。
797797
- `MINIO_INSECURE_SKIP_VERIFY`: **false**: Minio 跳过 SSL 验证,仅当 STORAGE_TYPE 为 `minio` 时可用。
798798
- `MINIO_CHECKSUM_ALGORITHM`: **default**: Minio 校验算法:`default`(适用于 MinIO 或 AWS S3)或 `md5`(适用于 Cloudflare 或 Backblaze)
799+
- `MINIO_BUCKET_LOOKUP_TYPE`: **auto**: Minio的bucket查找方式默认为`auto`模式,可将其设置为`dns`(虚拟托管样式)或`path`(路径样式),仅当`STORAGE_TYPE``minio`时可用。
799800

800801
## 日志 (`log`)
801802

@@ -1201,6 +1202,7 @@ ALLOW_DATA_URI_IMAGES = true
12011202
- `MINIO_BASE_PATH`**lfs/**:桶上的 Minio 基本路径,仅在 `STORAGE_TYPE``minio` 时可用。
12021203
- `MINIO_USE_SSL`**false**:Minio 启用 ssl,仅在 `STORAGE_TYPE``minio` 时可用。
12031204
- `MINIO_INSECURE_SKIP_VERIFY`**false**:Minio 跳过 SSL 验证,仅在 `STORAGE_TYPE``minio` 时可用。
1205+
- `MINIO_BUCKET_LOOKUP_TYPE`: **auto**: Minio的bucket查找方式默认为`auto`模式,可将其设置为`dns`(虚拟托管样式)或`path`(路径样式),仅当`STORAGE_TYPE``minio`时可用。
12041206

12051207
## 存储 (`storage`)
12061208

@@ -1215,6 +1217,7 @@ ALLOW_DATA_URI_IMAGES = true
12151217
- `MINIO_LOCATION`**us-east-1**:创建桶的 Minio 位置,仅在 `STORAGE_TYPE``minio` 时可用。
12161218
- `MINIO_USE_SSL`**false**:Minio 启用 ssl,仅在 `STORAGE_TYPE``minio` 时可用。
12171219
- `MINIO_INSECURE_SKIP_VERIFY`**false**:Minio 跳过 SSL 验证,仅在 `STORAGE_TYPE``minio` 时可用。
1220+
- `MINIO_BUCKET_LOOKUP_TYPE`: **auto**: Minio的bucket查找方式默认为`auto`模式,可将其设置为`dns`(虚拟托管样式)或`path`(路径样式),仅当`STORAGE_TYPE``minio`时可用。
12181221

12191222
建议的 minio 存储配置如下:
12201223

@@ -1236,6 +1239,8 @@ MINIO_USE_SSL = false
12361239
; Minio skip SSL verification available when STORAGE_TYPE is `minio`
12371240
MINIO_INSECURE_SKIP_VERIFY = false
12381241
SERVE_DIRECT = true
1242+
; Minio bucket lookup method defaults to auto mode; set it to `dns` for virtual host style or `path` for path style, only available when STORAGE_TYPE is `minio`
1243+
MINIO_BUCKET_LOOKUP_TYPE = auto
12391244
```
12401245

12411246
默认情况下,每个存储都有其默认的基本路径,如下所示:
@@ -1282,6 +1287,8 @@ MINIO_LOCATION = us-east-1
12821287
MINIO_USE_SSL = false
12831288
; Minio skip SSL verification available when STORAGE_TYPE is `minio`
12841289
MINIO_INSECURE_SKIP_VERIFY = false
1290+
; Minio bucket lookup method defaults to auto mode; set it to `dns` for virtual host style or `path` for path style, only available when STORAGE_TYPE is `minio`
1291+
MINIO_BUCKET_LOOKUP_TYPE = auto
12851292
```
12861293

12871294
### 存储库归档存储 (`storage.repo-archive`)
@@ -1299,6 +1306,7 @@ MINIO_INSECURE_SKIP_VERIFY = false
12991306
- `MINIO_BASE_PATH`: **repo-archive/**:存储桶上的Minio基本路径,仅在`STORAGE_TYPE``minio`时可用。
13001307
- `MINIO_USE_SSL`: **false**:启用Minio的SSL,仅在`STORAGE_TYPE``minio`时可用。
13011308
- `MINIO_INSECURE_SKIP_VERIFY`: **false**:跳过Minio的SSL验证,仅在`STORAGE_TYPE``minio`时可用。
1309+
- `MINIO_BUCKET_LOOKUP_TYPE`: **auto**: Minio的bucket查找方式默认为`auto`模式,可将其设置为`dns`(虚拟托管样式)或`path`(路径样式),仅当`STORAGE_TYPE``minio`时可用。
13021310

13031311
### 存储库归档 (`repo-archive`)
13041312

modules/setting/storage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type MinioStorageConfig struct {
4747
InsecureSkipVerify bool `ini:"MINIO_INSECURE_SKIP_VERIFY"`
4848
ChecksumAlgorithm string `ini:"MINIO_CHECKSUM_ALGORITHM" json:",omitempty"`
4949
ServeDirect bool `ini:"SERVE_DIRECT"`
50+
BucketLookUpType string `ini:"MINIO_BUCKET_LOOKUP_TYPE" json:",omitempty"`
5051
}
5152

5253
// Storage represents configuration of storages
@@ -82,6 +83,7 @@ func getDefaultStorageSection(rootCfg ConfigProvider) ConfigSection {
8283
storageSec.Key("MINIO_USE_SSL").MustBool(false)
8384
storageSec.Key("MINIO_INSECURE_SKIP_VERIFY").MustBool(false)
8485
storageSec.Key("MINIO_CHECKSUM_ALGORITHM").MustString("default")
86+
storageSec.Key("MINIO_BUCKET_LOOKUP_TYPE").MustString("auto")
8587
return storageSec
8688
}
8789

modules/storage/minio.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,23 @@ func NewMinioStorage(ctx context.Context, cfg *setting.Storage) (ObjectStorage,
8585

8686
log.Info("Creating Minio storage at %s:%s with base path %s", config.Endpoint, config.Bucket, config.BasePath)
8787

88+
var lookup minio.BucketLookupType
89+
if config.BucketLookUpType == "auto" || config.BucketLookUpType == "" {
90+
lookup = minio.BucketLookupAuto
91+
} else if config.BucketLookUpType == "dns" {
92+
lookup = minio.BucketLookupDNS
93+
} else if config.BucketLookUpType == "path" {
94+
lookup = minio.BucketLookupPath
95+
} else {
96+
return nil, fmt.Errorf("invalid minio bucket lookup type: %s", config.BucketLookUpType)
97+
}
98+
8899
minioClient, err := minio.New(config.Endpoint, &minio.Options{
89-
Creds: credentials.NewStaticV4(config.AccessKeyID, config.SecretAccessKey, ""),
90-
Secure: config.UseSSL,
91-
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: config.InsecureSkipVerify}},
92-
Region: config.Location,
100+
Creds: credentials.NewStaticV4(config.AccessKeyID, config.SecretAccessKey, ""),
101+
Secure: config.UseSSL,
102+
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: config.InsecureSkipVerify}},
103+
Region: config.Location,
104+
BucketLookup: lookup,
93105
})
94106
if err != nil {
95107
return nil, convertMinioErr(err)

0 commit comments

Comments
 (0)