Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ Server:
GatewayAddress: localhost
# port to listen on (change to 80 or equivalent if not using TLS)
Port: 443
# local address to bind both the gateway and automatic TLS challenge listeners.
# Empty binds to all interfaces. IPv4 and IPv6 addresses are supported.
# BindAddress: 127.0.0.1
# list of acceptable desktop hosts to connect to
Hosts:
- localhost:3389
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 @@ -82,6 +82,7 @@ type Configuration struct {
type ServerConfig struct {
GatewayAddress string `koanf:"gatewayaddress"`
Port int `koanf:"port"`
BindAddress string `koanf:"bindaddress"`
CertFile string `koanf:"certfile"`
KeyFile string `koanf:"keyfile"`
Hosts []string `koanf:"hosts"`
Expand Down Expand Up @@ -215,6 +216,7 @@ func Load(configFile string) Configuration {
k.Load(confmap.Provider(map[string]interface{}{
"Server.Tls": "auto",
"Server.Port": 443,
"Server.BindAddress": "",
"Server.SessionStore": "cookie",
"Server.HostSelection": "roundrobin",
"Server.Authentication": "openid",
Expand Down
9 changes: 7 additions & 2 deletions cmd/rdpgw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"fmt"
"log"
"net"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -37,6 +38,10 @@ var opts struct {

var conf config.Configuration

func listenAddress(bindAddress string, port int) string {
return net.JoinHostPort(bindAddress, strconv.Itoa(port))
}

func initOIDC(callbackUrl *url.URL) *web.OIDC {
// set oidc config
provider, err := oidc.NewProvider(context.Background(), conf.OpenId.ProviderUrl)
Expand Down Expand Up @@ -177,7 +182,7 @@ func main() {
cfg.GetCertificate = certMgr.GetCertificate

go func() {
http.ListenAndServe(":80", certMgr.HTTPHandler(nil))
http.ListenAndServe(listenAddress(conf.Server.BindAddress, 80), certMgr.HTTPHandler(nil))
}()
}
}
Expand Down Expand Up @@ -326,7 +331,7 @@ func main() {

// setup server
server := http.Server{
Addr: ":" + strconv.Itoa(conf.Server.Port),
Addr: listenAddress(conf.Server.BindAddress, conf.Server.Port),
Handler: r,
TLSConfig: cfg,
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)), // disable http2
Expand Down
24 changes: 24 additions & 0 deletions cmd/rdpgw/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import "testing"

func TestListenAddress(t *testing.T) {
tests := []struct {
name string
bindAddress string
port int
want string
}{
{name: "all interfaces", port: 443, want: ":443"},
{name: "IPv4", bindAddress: "127.0.0.1", port: 443, want: "127.0.0.1:443"},
{name: "IPv6", bindAddress: "::1", port: 443, want: "[::1]:443"},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if got := listenAddress(test.bindAddress, test.port); got != test.want {
t.Fatalf("listenAddress(%q, %d) = %q, want %q", test.bindAddress, test.port, got, test.want)
}
})
}
}
4 changes: 4 additions & 0 deletions dev/docker/rdpgw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Server:
KeyFile: /opt/rdpgw/key.pem
GatewayAddress: localhost:9443
Port: 9443
# BindAddress: "" # Binds to all interfaces (default)
# BindAddress: "127.0.0.1" # Localhost only (IPv4)
# BindAddress: "::1" # Localhost only (IPv6)
# BindAddress: "192.168.1.10" # Specific IP
Hosts:
- xrdp:3389
RoundRobin: false
Expand Down
Loading