Skip to content

Commit f4aa239

Browse files
committed
cmd/coordinator: fix authentication to not require a user token
Buildlets have regular builder tokens, not "user-" prefixed ones. So don't use the auth helper function. Just inline what we need in the proxy handler. Fix from testing CL 165779. Updates golang/go#14594 Change-Id: Ie2d8d7a21f5660d24e929c932571b8df61895374 Reviewed-on: https://go-review.googlesource.com/c/build/+/165780 Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 2f7a8c1 commit f4aa239

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

cmd/coordinator/coordinator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func (httpRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
224224
return
225225
}
226226
if r.Header.Get("X-Proxy-Service") == "module-cache" {
227-
requireBuildletProxyAuth(http.HandlerFunc(proxyModuleCache)).ServeHTTP(w, r)
227+
proxyModuleCache(w, r)
228228
return
229229
}
230230
http.DefaultServeMux.ServeHTTP(w, r)

cmd/coordinator/modproxy.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,46 @@ import (
1111
"strings"
1212
)
1313

14-
// proxyModuleCache proxies from https://farmer.golang.org (with Auth
15-
// & a magic header, as handled by coordinator.go's httpRouter type)
16-
// to Go's private module proxy server running on GKE. The module proxy protocol
17-
// does not define authentication, so we do it ourselves.
14+
// proxyModuleCache proxies from https://farmer.golang.org (with a
15+
// magic header, as handled by coordinator.go's httpRouter type) to
16+
// Go's private module proxy server running on GKE. The module proxy
17+
// protocol does not define authentication, so we do it ourselves.
1818
//
1919
// The complete path is the buildlet listens on localhost:3000 to run
2020
// an unauthenticated module proxy server for the cmd/go binary to use
2121
// via GOPROXY=http://localhost:3000. That localhost:3000 server
2222
// proxies it to https://farmer.golang.org with auth headers and a
2323
// sentinel X-Proxy-Service:module-cache header. Then coordinator.go's
24-
// httpRouter sends it here after the auth has been checked.
24+
// httpRouter sends it here.
2525
//
2626
// This code then does the final reverse proxy, sent without auth.
2727
//
2828
// In summary:
2929
//
3030
// cmd/go -> localhost:3000 -> buildlet -> coordinator --> GKE server
3131
func proxyModuleCache(w http.ResponseWriter, r *http.Request) {
32+
if r.TLS == nil {
33+
http.Error(w, "https required", http.StatusBadRequest)
34+
return
35+
}
36+
builder, pass, ok := r.BasicAuth()
37+
if !ok {
38+
http.Error(w, "missing required authentication", http.StatusBadRequest)
39+
return
40+
}
41+
if !strings.Contains(builder, "-") || builderKey(builder) != pass {
42+
http.Error(w, "bad username or password", http.StatusUnauthorized)
43+
return
44+
}
45+
3246
target := moduleProxy()
3347
if !strings.HasPrefix(target, "http") {
34-
http.Error(w, "module proxy not configured", 500)
48+
http.Error(w, "module proxy not configured", http.StatusInternalServerError)
3549
return
3650
}
3751
backend, err := url.Parse(target)
3852
if err != nil {
39-
http.Error(w, "module proxy misconfigured", 500)
53+
http.Error(w, "module proxy misconfigured", http.StatusInternalServerError)
4054
return
4155
}
4256
// TODO: maybe only create this once early. But probably doesn't matter.

0 commit comments

Comments
 (0)