Add trusted_proxies config

This commit is contained in:
kayos@tcp.direct 2022-07-18 04:22:26 -07:00
parent f2671025c8
commit cf50063e57
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
3 changed files with 11 additions and 0 deletions

View File

@ -51,6 +51,7 @@ var (
KVMaxValueSizeMB int
UnixSocketPermissions uint32
UseUnixSocket bool
TrustedProxies []string
)
var usage = fmt.Sprintf(`
@ -271,6 +272,10 @@ func processOpts() {
"admin.key": &AdminKey,
}
stringSliceOpt := map[string]*[]string{
"http.trusted_proxies": &TrustedProxies,
}
if !strings.HasSuffix(BaseURL, "/") {
BaseURL += "/"
}
@ -307,6 +312,9 @@ func processOpts() {
for key, opt := range uint32Opt {
*opt = snek.GetUint32(key)
}
for key, opt := range stringSliceOpt {
*opt = snek.GetStringSlice(key)
}
}
func associateExportedVariables() {

View File

@ -31,6 +31,7 @@ func initDefaults() {
"unix_socket_permissions": uint32(0644),
"bind_addr": "127.0.0.1",
"bind_port": "8080",
"trusted_proxies": []string{"127.0.0.1"},
},
"data": {
"directory": home + "/.local/share/tcp.ac/data",

View File

@ -83,6 +83,8 @@ func httpRouter() *http.Server {
Str("Port", config.HTTPPort).
Msg("done; tcp.ac is live.")
router.SetTrustedProxies(config.TrustedProxies)
srv := &http.Server{
Addr: config.HTTPBind + ":" + config.HTTPPort,
Handler: router,