Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: check agent API version on connection#11696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spikecurtis merged 1 commit intomainfromspike/10531-check-agent-api-version
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletionsagent/proto/version.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
package proto

import (
"github.com/coder/coder/v2/tailnet/proto"
)

// CurrentVersion is the current version of the agent API. It is tied to the
// tailnet API version to avoid confusion, since agents connect to the tailnet
// API over the same websocket.
var CurrentVersion = proto.CurrentVersion
3 changes: 2 additions & 1 deletioncoderd/workspaceagents.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,7 @@ import (
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/agentsdk"
"github.com/coder/coder/v2/tailnet"
"github.com/coder/coder/v2/tailnet/proto"
)

// @Summary Get workspace agent by ID
Expand DownExpand Up@@ -1162,7 +1163,7 @@ func (api *API) workspaceAgentClientCoordinate(rw http.ResponseWriter, r *http.R
if qv != "" {
version = qv
}
if err :=tailnet.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{
Expand Down
18 changes: 18 additions & 0 deletionscoderd/workspaceagentsrpc.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ import (
"nhooyr.io/websocket"

"cdr.dev/slog"
"github.com/coder/coder/v2/agent/proto"
"github.com/coder/coder/v2/coderd/agentapi"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbauthz"
Expand All@@ -37,6 +38,23 @@ import (
func (api *API) workspaceAgentRPC(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()

version := r.URL.Query().Get("version")
if version == "" {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Missing required query parameter: version",
})
return
}
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{
{Field: "version", Detail: err.Error()},
},
})
return
}

api.WebsocketWaitMutex.Lock()
api.WebsocketWaitGroup.Add(1)
api.WebsocketWaitMutex.Unlock()
Expand Down
13 changes: 9 additions & 4 deletionscodersdk/agentsdk/agentsdk.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ import (
"tailscale.com/tailcfg"

"cdr.dev/slog"
"github.com/coder/coder/v2/agent/proto"
"github.com/coder/coder/v2/codersdk"
drpcsdk "github.com/coder/coder/v2/codersdk/drpc"
"github.com/coder/retry"
Expand DownExpand Up@@ -281,18 +282,22 @@ func (c *Client) DERPMapUpdates(ctx context.Context) (<-chan DERPMapUpdate, io.C
}, nil
}

// Listen connects to the workspace agentcoordinate WebSocket
// Listen connects to the workspace agentAPI WebSocket
// that handles connection negotiation.
func (c *Client) Listen(ctx context.Context) (drpc.Conn, error) {
coordinateURL, err := c.SDK.URL.Parse("/api/v2/workspaceagents/me/rpc")
rpcURL, err := c.SDK.URL.Parse("/api/v2/workspaceagents/me/rpc")
if err != nil {
return nil, xerrors.Errorf("parse url: %w", err)
}
q := rpcURL.Query()
q.Add("version", proto.CurrentVersion.String())
rpcURL.RawQuery = q.Encode()

jar, err := cookiejar.New(nil)
if err != nil {
return nil, xerrors.Errorf("create cookie jar: %w", err)
}
jar.SetCookies(coordinateURL, []*http.Cookie{{
jar.SetCookies(rpcURL, []*http.Cookie{{
Name: codersdk.SessionTokenCookie,
Value: c.SDK.SessionToken(),
}})
Expand All@@ -301,7 +306,7 @@ func (c *Client) Listen(ctx context.Context) (drpc.Conn, error) {
Transport: c.SDK.HTTPClient.Transport,
}
// nolint:bodyclose
conn, res, err := websocket.Dial(ctx,coordinateURL.String(), &websocket.DialOptions{
conn, res, err := websocket.Dial(ctx,rpcURL.String(), &websocket.DialOptions{
HTTPClient: httpClient,
})
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletioncodersdk/workspaceagents.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,7 @@ import (
"cdr.dev/slog"
"github.com/coder/coder/v2/coderd/tracing"
"github.com/coder/coder/v2/tailnet"
"github.com/coder/coder/v2/tailnet/proto"
"github.com/coder/retry"
)

Expand DownExpand Up@@ -314,7 +315,7 @@ func (c *Client) DialWorkspaceAgent(dialCtx context.Context, agentID uuid.UUID,
return nil, xerrors.Errorf("parse url: %w", err)
}
q := coordinateURL.Query()
q.Add("version",tailnet.CurrentVersion.String())
q.Add("version",proto.CurrentVersion.String())
coordinateURL.RawQuery = q.Encode()
closedCoordinator := make(chan struct{})
// Must only ever be used once, send error OR close to avoid
Expand Down
4 changes: 2 additions & 2 deletionsenterprise/coderd/workspaceproxycoordinate.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand DownExpand Up@@ -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{
Expand Down
2 changes: 1 addition & 1 deletionenterprise/wsproxy/wsproxysdk/wsproxysdk.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
2 changes: 1 addition & 1 deletionenterprise/wsproxy/wsproxysdk/wsproxysdk_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
2 changes: 1 addition & 1 deletiontailnet/coordinator_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -460,7 +460,7 @@ func TestRemoteCoordination(t *testing.T) {

serveErr := make(chan error, 1)
go func() {
err := svc.ServeClient(ctx,tailnet.CurrentVersion.String(), sC, clientID, agentID)
err := svc.ServeClient(ctx,proto.CurrentVersion.String(), sC, clientID, agentID)
serveErr <- err
}()

Expand Down
12 changes: 12 additions & 0 deletionstailnet/proto/version.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
package proto

import (
"github.com/coder/coder/v2/coderd/util/apiversion"
)

const (
CurrentMajor = 2
CurrentMinor = 0
)

var CurrentVersion = apiversion.New(CurrentMajor, CurrentMinor).WithBackwardCompat(1)
7 changes: 0 additions & 7 deletionstailnet/service.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,13 +20,6 @@ import (
"golang.org/x/xerrors"
)

const (
CurrentMajor = 2
CurrentMinor = 0
)

var CurrentVersion = apiversion.New(CurrentMajor, CurrentMinor).WithBackwardCompat(1)

type streamIDContextKey struct{}

// StreamID identifies the caller of the CoordinateTailnet RPC. We store this
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp