Skip to content

Commit

Permalink
feature(agent,pkg): add features to SSH server initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybarreto authored and gustavosbarreto committed Jul 22, 2024
1 parent 1608a2d commit e495e07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/agent/modes.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (m *HostMode) Serve(agent *Agent) {
&server.Config{
PrivateKey: agent.config.PrivateKey,
KeepAliveInterval: agent.config.KeepAliveInterval,
Features: server.LocalPortForwardFeature,
},
)

Expand Down Expand Up @@ -98,6 +99,7 @@ func (m *ConnectorMode) Serve(agent *Agent) {
&server.Config{
PrivateKey: agent.config.PrivateKey,
KeepAliveInterval: agent.config.KeepAliveInterval,
Features: server.NoFeature,
},
)

Expand Down
17 changes: 15 additions & 2 deletions pkg/agent/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,25 @@ const (
ChannelDirectTcpip string = "direct-tcpip"
)

type Feature uint

const (
// NoFeature no features enable.
NoFeature Feature = 0
// LocalPortForwardFeature enable local port forward feature.
LocalPortForwardFeature Feature = iota << 1
// ReversePortForwardFeature enable reverse port forward feature.
ReversePortForwardFeature
)

// Config stores configuration needs for the SSH server.
type Config struct {
// PrivateKey is the path for the SSH server private key.
PrivateKey string
// KeepAliveInterval stores the time between each SSH keep alive request.
KeepAliveInterval uint
// Features list of featues on SSH server.
Features Feature
}

// NewServer creates a new server SSH agent server.
Expand Down Expand Up @@ -120,10 +133,10 @@ func NewServer(api client.Client, mode modes.Mode, cfg *Config) *Server {
return &sshConn{conn, closeCallback, ctx}
},
LocalPortForwardingCallback: func(ctx gliderssh.Context, destinationHost string, destinationPort uint32) bool {
return true
return cfg.Features&LocalPortForwardFeature > 0
},
ReversePortForwardingCallback: func(ctx gliderssh.Context, destinationHost string, destinationPort uint32) bool {
return false
return cfg.Features&ReversePortForwardFeature > 0
},
ChannelHandlers: map[string]gliderssh.ChannelHandler{
ChannelSession: gliderssh.DefaultSessionHandler,
Expand Down

0 comments on commit e495e07

Please sign in to comment.