mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
feat: add WorkspaceUpdates tailnet RPC (#14847)
Closes #14716 Closes #14717 Adds a new user-scoped tailnet API endpoint (`api/v2/tailnet`) with a new RPC stream for receiving updates on workspaces owned by a specific user, as defined in #14716. When a stream is started, the `WorkspaceUpdatesProvider` will begin listening on the user-scoped pubsub events implemented in #14964. When a relevant event type is seen (such as a workspace state transition), the provider will query the DB for all the workspaces (and agents) owned by the user. This gets compared against the result of the previous query to produce a set of workspace updates. Workspace updates can be requested for any user ID, however only workspaces the authorised user is permitted to `ActionRead` will have their updates streamed. Opening a tunnel to an agent requires that the user can perform `ActionSSH` against the workspace containing it.
This commit is contained in:
@ -328,7 +328,13 @@ func TestRemoteCoordination(t *testing.T) {
|
||||
|
||||
serveErr := make(chan error, 1)
|
||||
go func() {
|
||||
err := svc.ServeClient(ctx, proto.CurrentVersion.String(), sC, clientID, agentID)
|
||||
err := svc.ServeClient(ctx, proto.CurrentVersion.String(), sC, tailnet.StreamID{
|
||||
Name: "client",
|
||||
ID: clientID,
|
||||
Auth: tailnet.ClientCoordinateeAuth{
|
||||
AgentID: agentID,
|
||||
},
|
||||
})
|
||||
serveErr <- err
|
||||
}()
|
||||
|
||||
@ -377,7 +383,13 @@ func TestRemoteCoordination_SendsReadyForHandshake(t *testing.T) {
|
||||
|
||||
serveErr := make(chan error, 1)
|
||||
go func() {
|
||||
err := svc.ServeClient(ctx, proto.CurrentVersion.String(), sC, clientID, agentID)
|
||||
err := svc.ServeClient(ctx, proto.CurrentVersion.String(), sC, tailnet.StreamID{
|
||||
Name: "client",
|
||||
ID: clientID,
|
||||
Auth: tailnet.ClientCoordinateeAuth{
|
||||
AgentID: agentID,
|
||||
},
|
||||
})
|
||||
serveErr <- err
|
||||
}()
|
||||
|
||||
@ -517,3 +529,36 @@ func (f *fakeCoordinatee) SetNodeCallback(callback func(*tailnet.Node)) {
|
||||
defer f.Unlock()
|
||||
f.callback = callback
|
||||
}
|
||||
|
||||
// TestCoordinatorPropogatedPeerContext tests that the context for a specific peer
|
||||
// is propogated through to the `Authorize“ method of the coordinatee auth
|
||||
func TestCoordinatorPropogatedPeerContext(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := testutil.Context(t, testutil.WaitShort)
|
||||
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
|
||||
|
||||
peerCtx := context.WithValue(ctx, test.FakeSubjectKey{}, struct{}{})
|
||||
peerCtx, peerCtxCancel := context.WithCancel(peerCtx)
|
||||
peerID := uuid.UUID{0x01}
|
||||
agentID := uuid.UUID{0x02}
|
||||
|
||||
c1 := tailnet.NewCoordinator(logger)
|
||||
t.Cleanup(func() {
|
||||
err := c1.Close()
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
ch := make(chan struct{})
|
||||
auth := test.FakeCoordinateeAuth{
|
||||
Chan: ch,
|
||||
}
|
||||
|
||||
reqs, _ := c1.Coordinate(peerCtx, peerID, "peer1", auth)
|
||||
|
||||
testutil.RequireSendCtx(ctx, t, reqs, &proto.CoordinateRequest{AddTunnel: &proto.CoordinateRequest_Tunnel{Id: tailnet.UUIDToByteSlice(agentID)}})
|
||||
_ = testutil.RequireRecvCtx(ctx, t, ch)
|
||||
// If we don't cancel the context, the coordinator close will wait until the
|
||||
// peer request loop finishes, which will be after the timeout
|
||||
peerCtxCancel()
|
||||
}
|
||||
|
Reference in New Issue
Block a user