pomerium/pkg/ssh/manager.go
Kenneth Jenkins 9678e6a231
ssh: implement authorization policy evaluation (#5665)
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.
2025-07-01 12:04:00 -07:00

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
}