Bindadress (#196)

* add bind feature

* Apply bind address to ACME listener

* Refresh apt metadata before installing PAM

* Keep bind address change focused
This commit is contained in:
Markus Häll
2026-08-18 11:31:26 +02:00
committed by GitHub
parent bbcab4cd26
commit 135a39158a
5 changed files with 40 additions and 2 deletions
+2
View File
@@ -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"`
@@ -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",
+7 -2
View File
@@ -5,6 +5,7 @@ import (
"crypto/tls"
"fmt"
"log"
"net"
"net/http"
"net/url"
"os"
@@ -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)
@@ -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))
}()
}
}
@@ -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
+24
View File
@@ -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)
}
})
}
}