pomerium/pkg/ssh/manager.go
Joe Kralicky b216b7a135
ssh: stream management api (#5670)
## Summary

This implements the StreamManagement API defined at 

https://github.com/pomerium/envoy-custom/blob/main/api/extensions/filters/network/ssh/ssh.proto#L46-L60.
Policy evaluation and authorization logic is stubbed out here, and
implemented in https://github.com/pomerium/pomerium/pull/5665.

## Related issues

<!-- For example...
- #159
-->

## User Explanation

<!-- How would you explain this change to the user? If this
change doesn't create any user-facing changes, you can leave
this blank. If filled out, add the `docs` label -->

## Checklist

- [ ] reference any related issues
- [ ] updated unit tests
- [ ] add appropriate label (`enhancement`, `bug`, `breaking`,
`dependencies`, `ci`)
- [ ] ready for review
2025-07-01 13:57:19 -04:00

53 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 {
auth AuthInterface
mu sync.Mutex
activeStreams map[uint64]*StreamHandler
}
func NewStreamManager(auth AuthInterface) *StreamManager {
return &StreamManager{
auth: auth,
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, 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: sm.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
}