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

Commitc9a226f

Browse files
committed
feat: implement jetbrains agentssh tracking
Based on tcp forwarding instead of ssh connections
1 parent329aa45 commitc9a226f

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

‎agent/agentssh/agentssh.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
111111

112112
srv:=&ssh.Server{
113113
ChannelHandlers:map[string]ssh.ChannelHandler{
114-
"direct-tcpip":ssh.DirectTCPIPHandler,
114+
"direct-tcpip":func(srv*ssh.Server,conn*gossh.ServerConn,newChan gossh.NewChannel,ctx ssh.Context) {
115+
// wrapper is designed to find and track jetbrains gateway connections.
116+
wrapped:=NewChannelAcceptWatcher(s.logger,newChan,&s.connCountJetBrains)
117+
ssh.DirectTCPIPHandler(srv,conn,wrapped,ctx)
118+
},
115119
"direct-streamlocal@openssh.com":directStreamLocalHandler,
116120
"session":ssh.DefaultSessionHandler,
117121
},

‎agent/agentssh/jetbrainstrack.go‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package agentssh
2+
3+
import (
4+
"cdr.dev/slog"
5+
"go.uber.org/atomic"
6+
gossh"golang.org/x/crypto/ssh"
7+
)
8+
9+
typelocalForwardChannelDatastruct {
10+
DestAddrstring
11+
DestPortuint32
12+
13+
OriginAddrstring
14+
OriginPortuint32
15+
}
16+
17+
typeChannelAcceptWatcherstruct {
18+
gossh.NewChannel
19+
jetbrainsCounter*atomic.Int64
20+
}
21+
22+
funcNewChannelAcceptWatcher(logger slog.Logger,newChannel gossh.NewChannel,counter*atomic.Int64) gossh.NewChannel {
23+
d:=localForwardChannelData{}
24+
iferr:=gossh.Unmarshal(newChannel.ExtraData(),&d);err!=nil {
25+
// If the data fails to unmarshal, do nothing
26+
returnnewChannel
27+
}
28+
29+
//if !jetbrains {
30+
// If this isn't jetbrains, then we don't need to do anything special.
31+
//return newChannel
32+
//}
33+
34+
return&ChannelAcceptWatcher{
35+
NewChannel:newChannel,
36+
jetbrainsCounter:counter,
37+
}
38+
}
39+
40+
func (w*ChannelAcceptWatcher)Accept() (gossh.Channel,<-chan*gossh.Request,error) {
41+
c,r,err:=w.NewChannel.Accept()
42+
iferr!=nil {
43+
returnc,r,err
44+
}
45+
w.jetbrainsCounter.Add(1)
46+
47+
return&ChannelOnClose{
48+
Channel:c,
49+
done:func() {
50+
w.jetbrainsCounter.Add(-1)
51+
},
52+
},r,err
53+
}
54+
55+
typeChannelOnClosestruct {
56+
gossh.Channel
57+
donefunc()
58+
}
59+
60+
func (c*ChannelOnClose)Close()error {
61+
c.done()
62+
returnc.Channel.Close()
63+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp