Skip to content

Commit bdc62a0

Browse files
authored
Fix authentication error when using --baseurl
1 parent 81e56a3 commit bdc62a0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gofakes3.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type GoFakeS3 struct {
3939
autoBucket bool
4040
uploader *uploader
4141
log Logger
42-
42+
baseURL string
4343
// simple v4 signature
4444
mu sync.RWMutex // protects vAuthPair map only
4545
v4AuthPair map[string]string
@@ -56,6 +56,7 @@ func New(backend Backend, options ...Option) *GoFakeS3 {
5656
integrityCheck: true,
5757
uploader: newUploader(),
5858
requestID: 0,
59+
baseURL: "",
5960
}
6061

6162
// versioned MUST be set before options as one of the options disables it:
@@ -123,7 +124,11 @@ func (g *GoFakeS3) authMiddleware(handler http.Handler) http.Handler {
123124
haveAuth := len(g.v4AuthPair) > 0
124125
g.mu.RUnlock()
125126
if haveAuth {
126-
if result := signature.V4SignVerify(rq); result != signature.ErrNone {
127+
authReq := rq
128+
if g.baseURL != "" {
129+
authReq.URL.Path = g.baseURL + rq.URL.Path
130+
}
131+
if result := signature.V4SignVerify(authReq); result != signature.ErrNone {
127132
g.log.Print(LogWarn, "Access Denied:", rq.RemoteAddr, "=>", rq.URL)
128133

129134
resp := signature.GetAPIError(result)

0 commit comments

Comments
 (0)