Skip to content

Commit dff949c

Browse files
committed
fix: add validation for s3.bucket_lookup_type
1 parent 67dbda2 commit dff949c

File tree

7 files changed

+31
-7
lines changed

7 files changed

+31
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ OPTIONS:
264264
[$BAZEL_REMOTE_S3_BUCKET]
265265
266266
--s3.bucket_lookup_type value The S3/minio bucket lookup type to use when
267-
using S3 proxy backend. (default: auto, types: auto|dns|path)
267+
using S3 proxy backend. (default: auto, Allowed values: auto, dns, path.)
268268
[$BAZEL_REMOTE_S3_BUCKET_LOOKUP_TYPE]
269269
270270
--s3.prefix value The S3/minio object prefix to use when using S3 proxy
@@ -466,6 +466,7 @@ http_address: 0.0.0.0:8080
466466
# bucket: test-bucket
467467
# prefix: test-prefix
468468
# disable_ssl: true
469+
# bucket_lookup_type: auto
469470
#
470471
# Provide exactly one auth_method (access_key, iam_role, or credentials_file) and accompanying configuration.
471472
#

config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/buchgr/bazel-remote/v2/cache/s3proxy"
2020

2121
"github.com/urfave/cli/v2"
22+
"golang.org/x/exp/slices"
2223
yaml "gopkg.in/yaml.v3"
2324
)
2425

@@ -349,6 +350,11 @@ func validateConfig(c *Config) error {
349350
if c.S3CloudStorage.KeyVersion != nil && *c.S3CloudStorage.KeyVersion != 2 {
350351
return fmt.Errorf("s3.key_version (deprecated) must be 2, found %d", c.S3CloudStorage.KeyVersion)
351352
}
353+
354+
if c.S3CloudStorage.BucketLookupType != "" && !slices.Contains([]string{"auto", "dns", "path"}, c.S3CloudStorage.BucketLookupType) {
355+
return fmt.Errorf("s3.bucket_lookup_type must be one of: [auto,dns,path] or be empty, found %s",
356+
c.S3CloudStorage.BucketLookupType)
357+
}
352358
}
353359

354360
if c.AzBlobConfig != nil {

config/proxy.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config
22

33
import (
4+
"fmt"
45
"net/http"
56
"net/url"
67

@@ -47,10 +48,14 @@ func (c *Config) setProxy() error {
4748
return err
4849
}
4950

51+
bucketLookupType, err := parseBucketLookupType(c.S3CloudStorage.BucketLookupType)
52+
if err != nil {
53+
return err
54+
}
5055
c.ProxyBackend = s3proxy.New(
5156
c.S3CloudStorage.Endpoint,
5257
c.S3CloudStorage.Bucket,
53-
parseBucketLookupType(c.S3CloudStorage.BucketLookupType),
58+
bucketLookupType,
5459
c.S3CloudStorage.Prefix,
5560
creds,
5661
c.S3CloudStorage.DisableSSL,
@@ -81,13 +86,18 @@ func (c *Config) setProxy() error {
8186
return nil
8287
}
8388

84-
func parseBucketLookupType(typeStr string) minio.BucketLookupType {
89+
func parseBucketLookupType(typeStr string) (minio.BucketLookupType, error) {
8590
valMap := map[string]minio.BucketLookupType{
8691
"auto": minio.BucketLookupAuto,
8792
"dns": minio.BucketLookupDNS,
8893
"path": minio.BucketLookupPath,
8994
}
9095

9196
// also when not found the type, return "auto" type.
92-
return valMap[typeStr]
97+
val, ok := valMap[typeStr]
98+
if !ok {
99+
return 0, fmt.Errorf("Unsupported value: %s", typeStr)
100+
}
101+
102+
return val, nil
93103
}

deps.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,8 +1281,8 @@ def go_dependencies():
12811281
go_repository(
12821282
name = "org_golang_x_exp",
12831283
importpath = "golang.org/x/exp",
1284-
sum = "h1:QE6XYQK6naiK1EPAe1g/ILLxN5RBoH5xkJk3CqlMI/Y=",
1285-
version = "v0.0.0-20200224162631-6cc2880d07d6",
1284+
sum = "h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=",
1285+
version = "v0.0.0-20230522175609-2e198f4a06a1",
12861286
)
12871287
go_repository(
12881288
name = "org_golang_x_image",

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ require (
3030
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0
3131
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.4.1
3232
github.com/valyala/gozstd v1.19.1
33+
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
3334
)
3435

3536
require (

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,12 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
185185
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
186186
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
187187
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
188+
github.com/klauspost/compress v1.14.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
189+
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
188190
github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI=
189191
github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
192+
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
193+
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
190194
github.com/klauspost/cpuid/v2 v2.1.1 h1:t0wUqjowdm8ezddV5k0tLWVklVuvLJpoHeb4WBdydm0=
191195
github.com/klauspost/cpuid/v2 v2.1.1/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
192196
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -316,6 +320,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
316320
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
317321
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
318322
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
323+
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
324+
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
319325
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
320326
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
321327
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=

utils/flags/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func GetCliFlags() []cli.Flag {
222222
&cli.StringFlag{
223223
Name: "s3.bucket_lookup_type",
224224
Value: "auto",
225-
Usage: "The S3/minio bucket lookup type(auto|dns|path) to use when using S3 proxy backend.",
225+
Usage: "The S3/minio bucket lookup type to use when using S3 proxy backend. Allowed values: auto, dns, path.",
226226
EnvVars: []string{"BAZEL_REMOTE_S3_BUCKET_LOOKUP_TYPE"},
227227
},
228228
&cli.StringFlag{

0 commit comments

Comments
 (0)