Skip to content

Commit 425f1e5

Browse files
committed
feat: add agentapi endpoint to report connections for audit
This change adds a new `ReportConnection` endpoint to the `agentapi` and bumps the protocol version. This allows the agent to report connection events, for example when the user connects to the workspace via SSH or VS Code. Updates #15139
1 parent b5329ae commit 425f1e5

File tree

14 files changed

+1447
-705
lines changed

14 files changed

+1447
-705
lines changed

agent/agent.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ func (a *agent) collectMetadata(ctx context.Context, md codersdk.WorkspaceAgentM
372372
// Important: if the command times out, we may see a misleading error like
373373
// "exit status 1", so it's important to include the context error.
374374
err = errors.Join(err, ctx.Err())
375-
376375
if err != nil {
377376
result.Error = fmt.Sprintf("run cmd: %+v", err)
378377
}

agent/agenttest/client.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"golang.org/x/exp/slices"
1616
"golang.org/x/xerrors"
1717
"google.golang.org/protobuf/types/known/durationpb"
18+
"google.golang.org/protobuf/types/known/emptypb"
1819
"storj.io/drpc/drpcmux"
1920
"storj.io/drpc/drpcserver"
2021
"tailscale.com/tailcfg"
@@ -170,6 +171,7 @@ type FakeAgentAPI struct {
170171
lifecycleStates []codersdk.WorkspaceAgentLifecycle
171172
metadata map[string]agentsdk.Metadata
172173
timings []*agentproto.Timing
174+
connections []*agentproto.Connection
173175

174176
getAnnouncementBannersFunc func() ([]codersdk.BannerConfig, error)
175177
getResourcesMonitoringConfigurationFunc func() (*agentproto.GetResourcesMonitoringConfigurationResponse, error)
@@ -338,12 +340,20 @@ func (f *FakeAgentAPI) BatchCreateLogs(ctx context.Context, req *agentproto.Batc
338340

339341
func (f *FakeAgentAPI) ScriptCompleted(_ context.Context, req *agentproto.WorkspaceAgentScriptCompletedRequest) (*agentproto.WorkspaceAgentScriptCompletedResponse, error) {
340342
f.Lock()
341-
f.timings = append(f.timings, req.Timing)
343+
f.timings = append(f.timings, req.GetTiming())
342344
f.Unlock()
343345

344346
return &agentproto.WorkspaceAgentScriptCompletedResponse{}, nil
345347
}
346348

349+
func (f *FakeAgentAPI) ReportConnection(_ context.Context, req *agentproto.ReportConnectionRequest) (*emptypb.Empty, error) {
350+
f.Lock()
351+
f.connections = append(f.connections, req.GetConnection())
352+
f.Unlock()
353+
354+
return &emptypb.Empty{}, nil
355+
}
356+
347357
func NewFakeAgentAPI(t testing.TB, logger slog.Logger, manifest *agentproto.Manifest, statsCh chan *agentproto.Stats) *FakeAgentAPI {
348358
return &FakeAgentAPI{
349359
t: t,

0 commit comments

Comments
 (0)