Skip to content

Commit

Permalink
Add BasicAuthTimeout setting versus static 5 seconds (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanblenis authored Dec 16, 2023
1 parent 017f338 commit f72613c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Server:
# The socket to connect to if using local auth. Ensure rdpgw auth is configured to
# use the same socket.
AuthSocket: /tmp/rdpgw-auth.sock
# Basic auth timeout (in seconds). Useful if you're planning on waiting for MFA
BasicAuthTimeout: 5
# The default option 'auto' uses a certificate file if provided and found otherwise
# it uses letsencrypt to obtain a certificate, the latter requires that the host is reachable
# from letsencrypt servers. If TLS termination happens somewhere else (e.g. a load balancer)
Expand Down
2 changes: 2 additions & 0 deletions cmd/rdpgw/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type ServerConfig struct {
Tls string `koanf:"tls"`
Authentication []string `koanf:"authentication"`
AuthSocket string `koanf:"authsocket"`
BasicAuthTimeout int `koanf:"basicauthtimeout"`
}

type KerberosConfig struct {
Expand Down Expand Up @@ -143,6 +144,7 @@ func Load(configFile string) Configuration {
"Server.HostSelection": "roundrobin",
"Server.Authentication": "openid",
"Server.AuthSocket": "/tmp/rdpgw-auth.sock",
"Server.BasicAuthTimeout": 5,
"Client.NetworkAutoDetect": 1,
"Client.BandwidthAutoDetect": 1,
"Security.VerifyClientIp": true,
Expand Down
2 changes: 1 addition & 1 deletion cmd/rdpgw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func main() {
// basic auth
if conf.Server.BasicAuthEnabled() {
log.Printf("enabling basic authentication")
q := web.BasicAuthHandler{SocketAddress: conf.Server.AuthSocket}
q := web.BasicAuthHandler{SocketAddress: conf.Server.AuthSocket, Timeout: conf.Server.BasicAuthTimeout}
rdp.NewRoute().HeadersRegexp("Authorization", "Basic").HandlerFunc(q.BasicAuth(gw.HandleGatewayProtocol))
auth.Register(`Basic realm="restricted", charset="UTF-8"`)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/rdpgw/web/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (

type BasicAuthHandler struct {
SocketAddress string
Timeout int
}

func (h *BasicAuthHandler) BasicAuth(next http.HandlerFunc) http.HandlerFunc {
Expand All @@ -38,7 +39,7 @@ func (h *BasicAuthHandler) BasicAuth(next http.HandlerFunc) http.HandlerFunc {
defer conn.Close()

c := auth.NewAuthenticateClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(h.Timeout))
defer cancel()

req := &auth.UserPass{Username: username, Password: password}
Expand Down

0 comments on commit f72613c

Please sign in to comment.