mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: allow proxy version mismatch (with warning) (#12433)
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"database/sql"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -15,7 +14,6 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"cdr.dev/slog"
|
||||
"github.com/coder/coder/v2/buildinfo"
|
||||
agpl "github.com/coder/coder/v2/coderd"
|
||||
"github.com/coder/coder/v2/coderd/audit"
|
||||
"github.com/coder/coder/v2/coderd/database"
|
||||
@@ -552,36 +550,18 @@ func (api *API) workspaceProxyRegister(rw http.ResponseWriter, r *http.Request)
|
||||
var (
|
||||
ctx = r.Context()
|
||||
proxy = httpmw.WorkspaceProxy(r)
|
||||
// TODO: This audit log does not work because it has no user id
|
||||
// associated with it. The audit log commitAudit() function ignores
|
||||
// the audit log if there is no user id. We should find a solution
|
||||
// to make sure this event is tracked.
|
||||
// auditor = api.AGPL.Auditor.Load()
|
||||
// aReq, commitAudit = audit.InitRequest[database.WorkspaceProxy](rw, &audit.RequestParams{
|
||||
// Audit: *auditor,
|
||||
// Log: api.Logger,
|
||||
// Request: r,
|
||||
// Action: database.AuditActionWrite,
|
||||
// })
|
||||
)
|
||||
// aReq.Old = proxy
|
||||
// defer commitAudit()
|
||||
|
||||
var req wsproxysdk.RegisterWorkspaceProxyRequest
|
||||
if !httpapi.Read(ctx, rw, r, &req) {
|
||||
return
|
||||
}
|
||||
|
||||
// Version check should be forced in non-dev builds and when running in
|
||||
// tests. Only Major + minor versions are checked.
|
||||
shouldForceVersion := !buildinfo.IsDev() || flag.Lookup("test.v") != nil
|
||||
if shouldForceVersion && !buildinfo.VersionsMatch(req.Version, buildinfo.Version()) {
|
||||
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
|
||||
Message: "Version mismatch.",
|
||||
Detail: fmt.Sprintf("Proxy version %q does not match primary server version %q", req.Version, buildinfo.Version()),
|
||||
})
|
||||
return
|
||||
}
|
||||
// NOTE: we previously enforced version checks when registering, but this
|
||||
// will cause proxies to enter crash loop backoff if the server is updated
|
||||
// and the proxy is not. Most releases do not make backwards-incompatible
|
||||
// changes to the proxy API, so instead of blocking requests we will show
|
||||
// healthcheck warnings.
|
||||
|
||||
if err := validateProxyURL(req.AccessURL); err != nil {
|
||||
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
|
||||
@@ -718,7 +698,6 @@ func (api *API) workspaceProxyRegister(rw http.ResponseWriter, r *http.Request)
|
||||
siblingsRes = append(siblingsRes, convertReplica(replica))
|
||||
}
|
||||
|
||||
// aReq.New = updatedProxy
|
||||
httpapi.Write(ctx, rw, http.StatusCreated, wsproxysdk.RegisterWorkspaceProxyResponse{
|
||||
AppSecurityKey: api.AppSecurityKey.String(),
|
||||
DERPMeshKey: api.DERPServer.MeshKey(),
|
||||
|
||||
@@ -168,7 +168,6 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
|
||||
client.SDKClient.HTTPClient = opts.HTTPClient
|
||||
}
|
||||
|
||||
// TODO: Probably do some version checking here
|
||||
info, err := client.SDKClient.BuildInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("buildinfo: %w", errors.Join(
|
||||
@@ -179,6 +178,15 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
|
||||
if info.WorkspaceProxy {
|
||||
return nil, xerrors.Errorf("%q is a workspace proxy, not a primary coderd instance", opts.DashboardURL)
|
||||
}
|
||||
// We don't want to crash the proxy if the versions don't match because
|
||||
// it'll enter crash loop backoff (and most patches don't make any backwards
|
||||
// incompatible changes to the proxy API anyways)
|
||||
if !buildinfo.VersionsMatch(info.Version, buildinfo.Version()) {
|
||||
opts.Logger.Warn(ctx, "workspace proxy version doesn't match Minor.Major version of the primary, please keep them in sync",
|
||||
slog.F("primary_version", info.Version),
|
||||
slog.F("proxy_version", buildinfo.Version()),
|
||||
)
|
||||
}
|
||||
|
||||
meshTLSConfig, err := replicasync.CreateDERPMeshTLSConfig(opts.AccessURL.Hostname(), opts.TLSCertificates)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user