Skip to content

Commit 0cfeb2e

Browse files
authored
feat: allow user set forcePathStyle for s3 storage (#731)
* feat: update storage lib and export cmd params Signed-off-by: warjiang <1096409085@qq.com> * feat: upgrade chartmuseum/storage to v0.14.1 Signed-off-by: warjiang <1096409085@qq.com> * doc: update usage of force-path-style Signed-off-by: warjiang <1096409085@qq.com> --------- Signed-off-by: warjiang <1096409085@qq.com>
1 parent 73e75ce commit 0cfeb2e

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,20 @@ You need at least the following permissions inside your IAM Policy
188188
In order to work with AWS service accounts you may need to set `AWS_SDK_LOAD_CONFIG=1` in your environment.
189189
For more context, please see [here](https://github.com/helm/chartmuseum/issues/280#issuecomment-592292527).
190190

191+
If you are using S3-Compatible storage, provider of S3 storage has [disabled path-style and force virtual hosted-style](https://aws.amazon.com/cn/blogs/aws/amazon-s3-path-deprecation-plan-the-rest-of-the-story/), you can use specify `storage-amazon-force-path-style` options as following example:
192+
```
193+
export AWS_ACCESS_KEY_ID=""
194+
export AWS_SECRET_ACCESS_KEY=""
195+
chartmuseum --debug --port=8080 \
196+
--storage="amazon" \
197+
--storage-amazon-bucket="my-s3-bucket" \
198+
--storage-amazon-prefix="" \
199+
--storage-amazon-region="us-east-1" \
200+
--storage-amazon-endpoint="my-s3-compatible-service-endpoint"
201+
--storage-amazon-force-path-style=false
202+
```
203+
204+
191205
For DigitalOcean, set the credentials using environment variable and pass the `endpoint`.
192206
Note below, that the region `us-east-1` needs to be set, since that is how the DigitalOcean cli implementation functions. The actual region of your spaces location is defined by the endpoint. Below we are using Frankfurt as an example.
193207
```bash

cmd/chartmuseum/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,16 @@ func amazonBackendFromConfig(conf *config.Config) storage.Backend {
176176
conf.Set("storage.amazon.region", "us-east-1")
177177
}
178178
crashIfConfigMissingVars(conf, []string{"storage.amazon.bucket", "storage.amazon.region"})
179-
return storage.NewAmazonS3Backend(
179+
forcePathStyle := conf.GetBool("storage.amazon.forcepathstyle")
180+
return storage.NewAmazonS3BackendWithOptions(
180181
conf.GetString("storage.amazon.bucket"),
181182
conf.GetString("storage.amazon.prefix"),
182183
conf.GetString("storage.amazon.region"),
183184
conf.GetString("storage.amazon.endpoint"),
184185
conf.GetString("storage.amazon.sse"),
186+
&storage.AmazonS3Options{
187+
S3ForcePathStyle: &forcePathStyle,
188+
},
185189
)
186190
}
187191

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.20
55
require (
66
github.com/alicebob/miniredis v2.5.0+incompatible
77
github.com/chartmuseum/auth v0.5.0
8-
github.com/chartmuseum/storage v0.14.0
8+
github.com/chartmuseum/storage v0.14.1
99
github.com/gin-contrib/size v0.0.0-20230212012657-e14a14094dc4
1010
github.com/gin-gonic/gin v1.9.1
1111
github.com/go-redis/redis v6.15.9+incompatible

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj
111111
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
112112
github.com/chartmuseum/auth v0.5.0 h1:ENNmoxvjxcR/JR0HrghAEtGQe7hToMNj16+UoS5CK9Y=
113113
github.com/chartmuseum/auth v0.5.0/go.mod h1:BvoSXHyvbsq+/bbhNgVTDQsModM+HERBTNY5o9Vyrig=
114-
github.com/chartmuseum/storage v0.14.0 h1:R/Mp4fRaY5HCtLIEJomrsT415kEi6QumertR74cbHZU=
115-
github.com/chartmuseum/storage v0.14.0/go.mod h1:LB+/k4kZkOu2AW3myaOw/AQt0JtjcNLwL1ktKxoWVug=
114+
github.com/chartmuseum/storage v0.14.1 h1:Az+YUopt+GjEg4r4kdq59ZMxuwuytaDbRIeWE6tghbU=
115+
github.com/chartmuseum/storage v0.14.1/go.mod h1:LB+/k4kZkOu2AW3myaOw/AQt0JtjcNLwL1ktKxoWVug=
116116
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
117117
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
118118
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=

pkg/config/vars.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,15 @@ var configVars = map[string]configVar{
355355
EnvVar: "STORAGE_AMAZON_SSE",
356356
},
357357
},
358+
"storage.amazon.forcepathstyle": {
359+
Type: boolType,
360+
Default: true,
361+
CLIFlag: cli.StringFlag{
362+
Name: "storage-amazon-force-path-style",
363+
Usage: "whether to force path style for amazon storage backend",
364+
EnvVar: "STORAGE_AMAZON_FORCE_PATH_STYLE",
365+
},
366+
},
358367
"storage.google.bucket": {
359368
Type: stringType,
360369
Default: "",

0 commit comments

Comments
 (0)