mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: check agent API version on connection (#11696)
fixes #10531 Adds a check for `version` on connection to the Agent API websocket endpoint. This is primarily for future-proofing, so that up-level agents get a sensible error if they connect to a back-level Coderd. It also refactors the location of the `CurrentVersion` variables, to be part of the `proto` packages, since the versions refer to the APIs defined therein.
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/coder/coder/v2/coderd/util/apiversion"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
"github.com/coder/coder/v2/enterprise/wsproxy/wsproxysdk"
|
||||
agpl "github.com/coder/coder/v2/tailnet"
|
||||
"github.com/coder/coder/v2/tailnet/proto"
|
||||
)
|
||||
|
||||
// @Summary Agent is legacy
|
||||
@@ -59,7 +59,7 @@ func (api *API) workspaceProxyCoordinate(rw http.ResponseWriter, r *http.Request
|
||||
if qv != "" {
|
||||
version = qv
|
||||
}
|
||||
if err := agpl.CurrentVersion.Validate(version); err != nil {
|
||||
if err := proto.CurrentVersion.Validate(version); err != nil {
|
||||
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
|
||||
Message: "Unknown or unsupported API version",
|
||||
Validations: []codersdk.ValidationError{
|
||||
|
||||
@@ -439,7 +439,7 @@ func (c *Client) DialCoordinator(ctx context.Context) (agpl.MultiAgentConn, erro
|
||||
return nil, xerrors.Errorf("parse url: %w", err)
|
||||
}
|
||||
q := coordinateURL.Query()
|
||||
q.Add("version", agpl.CurrentVersion.String())
|
||||
q.Add("version", proto.CurrentVersion.String())
|
||||
coordinateURL.RawQuery = q.Encode()
|
||||
coordinateHeaders := make(http.Header)
|
||||
tokenHeader := codersdk.SessionTokenHeader
|
||||
|
||||
@@ -194,7 +194,7 @@ func TestDialCoordinator(t *testing.T) {
|
||||
return
|
||||
}
|
||||
version := r.URL.Query().Get("version")
|
||||
if !assert.Equal(t, version, agpl.CurrentVersion.String()) {
|
||||
if !assert.Equal(t, version, proto.CurrentVersion.String()) {
|
||||
return
|
||||
}
|
||||
nc := websocket.NetConn(r.Context(), conn, websocket.MessageBinary)
|
||||
|
||||
Reference in New Issue
Block a user