* outpost: promote session end signal to non-provider specific Signed-off-by: Jens Langhammer <jens@goauthentik.io> * implement server-side logout in ldap Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix previous import Signed-off-by: Jens Langhammer <jens@goauthentik.io> * use better retry logic Signed-off-by: Jens Langhammer <jens@goauthentik.io> * log Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make more generic if we switch from ws to something else Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make it possible to e2e test WS Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix ldap session id Signed-off-by: Jens Langhammer <jens@goauthentik.io> * ok I actually need to go to bed this took me an hour to fix Signed-off-by: Jens Langhammer <jens@goauthentik.io> * format; add ldap test Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix leftover state Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove thread Signed-off-by: Jens Langhammer <jens@goauthentik.io> * use ws base for radius Signed-off-by: Jens Langhammer <jens@goauthentik.io> * separate test utils Signed-off-by: Jens Langhammer <jens@goauthentik.io> * rename Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix missing super calls Signed-off-by: Jens Langhammer <jens@goauthentik.io> * websocket tests with browser 🎉 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add proxy test for sign out Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix install_id issue with channels tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix proxy basic auth test Signed-off-by: Jens Langhammer <jens@goauthentik.io> * big code dedupe Signed-off-by: Jens Langhammer <jens@goauthentik.io> * allow passing go build args Signed-off-by: Jens Langhammer <jens@goauthentik.io> * improve waiting for outpost Signed-off-by: Jens Langhammer <jens@goauthentik.io> * rewrite ldap tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * ok actually fix the tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * undo a couple things that need more time to cook Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove unused lockfile-lint dependency since we use a shell script and SFE does not have a lockfile Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix session id for ldap Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix missing createTimestamp and modifyTimestamp ldap attributes closes #10474 Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
		
			
				
	
	
		
			128 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			128 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package rac
 | 
						|
 | 
						|
import (
 | 
						|
	"context"
 | 
						|
	"os/exec"
 | 
						|
	"strconv"
 | 
						|
	"sync"
 | 
						|
 | 
						|
	log "github.com/sirupsen/logrus"
 | 
						|
	"github.com/wwt/guac"
 | 
						|
 | 
						|
	"goauthentik.io/internal/outpost/ak"
 | 
						|
	"goauthentik.io/internal/outpost/rac/connection"
 | 
						|
	"goauthentik.io/internal/outpost/rac/metrics"
 | 
						|
)
 | 
						|
 | 
						|
type RACServer struct {
 | 
						|
	log   *log.Entry
 | 
						|
	ac    *ak.APIController
 | 
						|
	guacd *exec.Cmd
 | 
						|
	connm sync.RWMutex
 | 
						|
	conns map[string]connection.Connection
 | 
						|
}
 | 
						|
 | 
						|
func NewServer(ac *ak.APIController) ak.Outpost {
 | 
						|
	rs := &RACServer{
 | 
						|
		log:   log.WithField("logger", "authentik.outpost.rac"),
 | 
						|
		ac:    ac,
 | 
						|
		connm: sync.RWMutex{},
 | 
						|
		conns: map[string]connection.Connection{},
 | 
						|
	}
 | 
						|
	ac.AddEventHandler(rs.wsHandler)
 | 
						|
	return rs
 | 
						|
}
 | 
						|
 | 
						|
type WSMessage struct {
 | 
						|
	ConnID              string            `mapstructure:"conn_id"`
 | 
						|
	DestChannelID       string            `mapstructure:"dest_channel_id"`
 | 
						|
	Params              map[string]string `mapstructure:"params"`
 | 
						|
	Protocol            string            `mapstructure:"protocol"`
 | 
						|
	OptimalScreenWidth  string            `mapstructure:"screen_width"`
 | 
						|
	OptimalScreenHeight string            `mapstructure:"screen_height"`
 | 
						|
	OptimalScreenDPI    string            `mapstructure:"screen_dpi"`
 | 
						|
}
 | 
						|
 | 
						|
func parseIntOrZero(input string) int {
 | 
						|
	x, err := strconv.Atoi(input)
 | 
						|
	if err != nil {
 | 
						|
		return 0
 | 
						|
	}
 | 
						|
	return x
 | 
						|
}
 | 
						|
 | 
						|
func (rs *RACServer) wsHandler(ctx context.Context, msg ak.Event) error {
 | 
						|
	if msg.Instruction != ak.EventKindProviderSpecific {
 | 
						|
		return nil
 | 
						|
	}
 | 
						|
	wsm := WSMessage{}
 | 
						|
	err := msg.ArgsAs(&wsm)
 | 
						|
	if err != nil {
 | 
						|
		return err
 | 
						|
	}
 | 
						|
	config := guac.NewGuacamoleConfiguration()
 | 
						|
	config.Protocol = wsm.Protocol
 | 
						|
	config.Parameters = wsm.Params
 | 
						|
	config.OptimalScreenWidth = parseIntOrZero(wsm.OptimalScreenWidth)
 | 
						|
	config.OptimalScreenHeight = parseIntOrZero(wsm.OptimalScreenHeight)
 | 
						|
	config.OptimalResolution = parseIntOrZero(wsm.OptimalScreenDPI)
 | 
						|
	config.AudioMimetypes = []string{
 | 
						|
		"audio/L8",
 | 
						|
		"audio/L16",
 | 
						|
	}
 | 
						|
	cc, err := connection.NewConnection(rs.ac, wsm.DestChannelID, config)
 | 
						|
	if err != nil {
 | 
						|
		return err
 | 
						|
	}
 | 
						|
	cc.OnError = func(err error) {
 | 
						|
		rs.connm.Lock()
 | 
						|
		delete(rs.conns, wsm.ConnID)
 | 
						|
		_ = rs.ac.SendEventHello(map[string]interface{}{
 | 
						|
			"active_connections": len(rs.conns),
 | 
						|
		})
 | 
						|
		rs.connm.Unlock()
 | 
						|
	}
 | 
						|
	rs.connm.Lock()
 | 
						|
	rs.conns[wsm.ConnID] = *cc
 | 
						|
	_ = rs.ac.SendEventHello(map[string]interface{}{
 | 
						|
		"active_connections": len(rs.conns),
 | 
						|
	})
 | 
						|
	rs.connm.Unlock()
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
func (rs *RACServer) Start() error {
 | 
						|
	wg := sync.WaitGroup{}
 | 
						|
	wg.Add(2)
 | 
						|
	go func() {
 | 
						|
		defer wg.Done()
 | 
						|
		metrics.RunServer()
 | 
						|
	}()
 | 
						|
	go func() {
 | 
						|
		defer wg.Done()
 | 
						|
		err := rs.startGuac()
 | 
						|
		if err != nil {
 | 
						|
			panic(err)
 | 
						|
		}
 | 
						|
	}()
 | 
						|
	wg.Wait()
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
func (rs *RACServer) Stop() error {
 | 
						|
	if rs.guacd != nil {
 | 
						|
		return rs.guacd.Process.Kill()
 | 
						|
	}
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
func (rs *RACServer) TimerFlowCacheExpiry(context.Context) {}
 | 
						|
 | 
						|
func (rs *RACServer) Type() string {
 | 
						|
	return "rac"
 | 
						|
}
 | 
						|
 | 
						|
func (rs *RACServer) Refresh() error {
 | 
						|
	return nil
 | 
						|
}
 |