mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-06 10:21:05 +02:00
Implement the pkg/ssh.AuthInterface. Add logic for converting from the ssh stream state to an evaluator request, and for interpreting the results of policy evaluation. Refactor some of the existing authorize logic to make it easier to reuse.
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package ssh
|
|
|
|
import (
|
|
"sync"
|
|
|
|
extensions_ssh "github.com/pomerium/envoy-custom/api/extensions/filters/network/ssh"
|
|
"github.com/pomerium/pomerium/config"
|
|
)
|
|
|
|
type StreamManager struct {
|
|
mu sync.Mutex
|
|
activeStreams map[uint64]*StreamHandler
|
|
}
|
|
|
|
func NewStreamManager() *StreamManager {
|
|
return &StreamManager{
|
|
activeStreams: map[uint64]*StreamHandler{},
|
|
}
|
|
}
|
|
|
|
func (sm *StreamManager) LookupStream(streamID uint64) *StreamHandler {
|
|
sm.mu.Lock()
|
|
defer sm.mu.Unlock()
|
|
stream := sm.activeStreams[streamID]
|
|
if stream == nil {
|
|
return nil
|
|
}
|
|
return stream
|
|
}
|
|
|
|
func (sm *StreamManager) NewStreamHandler(
|
|
cfg *config.Config,
|
|
auth AuthInterface,
|
|
downstream *extensions_ssh.DownstreamConnectEvent,
|
|
) *StreamHandler {
|
|
sm.mu.Lock()
|
|
defer sm.mu.Unlock()
|
|
streamID := downstream.StreamId
|
|
writeC := make(chan *extensions_ssh.ServerMessage, 32)
|
|
sh := &StreamHandler{
|
|
auth: auth,
|
|
config: cfg,
|
|
downstream: downstream,
|
|
readC: make(chan *extensions_ssh.ClientMessage, 32),
|
|
writeC: writeC,
|
|
close: func() {
|
|
sm.mu.Lock()
|
|
defer sm.mu.Unlock()
|
|
delete(sm.activeStreams, streamID)
|
|
close(writeC)
|
|
},
|
|
}
|
|
sm.activeStreams[streamID] = sh
|
|
return sh
|
|
}
|