[management,signal,proxy,relay,misc] Restore legacy config wiring

This commit is contained in:
jnfrati
2026-09-02 17:58:29 +02:00
parent ac1e9b86db
commit 27d39916f7
10 changed files with 114 additions and 44 deletions
+45 -8
View File
@@ -1,19 +1,24 @@
package cmd
import (
"fmt"
"os"
"strconv"
"github.com/spf13/cobra"
"golang.org/x/crypto/acme"
"github.com/netbirdio/netbird/proxy"
"github.com/netbirdio/netbird/trustedproxy"
configloader "github.com/netbirdio/netbird/util/config"
)
type commandConfig struct {
proxy.Config `yaml:",squash"`
proxy.Config `yaml:",inline"`
LogLevel string `yaml:"logLevel" env:"NB_PROXY_LOG_LEVEL" flag:"log-level"`
PreallocatedBuffers *uint32 `yaml:"preallocatedBuffers" env:"NB_PROXY_PREALLOCATED_BUFFERS"`
MaxBatchSize *uint32 `yaml:"maxBatchSize" env:"NB_PROXY_MAX_BATCH_SIZE"`
PreallocatedBuffers *uint32 `yaml:"preallocatedBuffers" env:"-"`
MaxBatchSize *uint32 `yaml:"maxBatchSize" env:"-"`
}
func defaultConfig() *commandConfig {
@@ -28,7 +33,9 @@ func defaultConfig() *commandConfig {
ACMEDirectory: acme.LetsEncryptURL,
ACMEChallengeType: "tls-alpn-01",
CertLockMethod: "auto",
DebugEndpointAddress: "localhost:8444",
HealthAddr: "localhost:8080",
TrustedProxies: trustedproxy.FromPrefixes(nil),
ForwardedProto: "auto",
SupportsCustomPorts: true,
GeoDataDir: "/var/lib/netbird/geolocation",
@@ -38,10 +45,40 @@ func defaultConfig() *commandConfig {
}
func loadConfig(cmd *cobra.Command, configPath string) (*commandConfig, error) {
return configloader.Load(configPath, defaultConfig(), configloader.Options{
TagName: "yaml",
AllowMissing: configPath == "",
FlagSet: cmd.Flags(),
Strict: true,
cfg, err := configloader.Load(configPath, defaultConfig(), configloader.Options{
TagName: "yaml",
AllowMissing: configPath == "",
FlagSet: cmd.Flags(),
Strict: true,
InvalidEnvironment: configloader.InvalidEnvironmentIgnore,
})
if err != nil {
return nil, err
}
if err := applyPerformanceEnvironment(cfg); err != nil {
return nil, err
}
return cfg, nil
}
func applyPerformanceEnvironment(cfg *commandConfig) error {
for _, setting := range []struct {
name string
target **uint32
}{
{name: envPreallocatedBuffers, target: &cfg.PreallocatedBuffers},
{name: envMaxBatchSize, target: &cfg.MaxBatchSize},
} {
raw := os.Getenv(setting.name)
if raw == "" {
continue
}
parsed, err := strconv.ParseUint(raw, 10, 32)
if err != nil {
return fmt.Errorf("invalid %s %q: %w", setting.name, raw, err)
}
value := uint32(parsed)
*setting.target = &value
}
return nil
}
+13 -7
View File
@@ -19,9 +19,12 @@ import (
"github.com/netbirdio/netbird/util"
)
// envPreallocatedBuffers caps the per-tunnel buffer pool. Zero (unset)
// keeps the upstream uncapped default.
const envPreallocatedBuffers = "NB_PROXY_PREALLOCATED_BUFFERS"
const (
// envPreallocatedBuffers caps the per-tunnel buffer pool. Zero (unset)
// keeps the upstream uncapped default.
envPreallocatedBuffers = "NB_PROXY_PREALLOCATED_BUFFERS"
envMaxBatchSize = "NB_PROXY_MAX_BATCH_SIZE"
)
const DefaultManagementURL = "https://api.netbird.io:443"
@@ -138,16 +141,19 @@ func SetVersionInfo(version, commit, buildDate, goVersion string) {
}
func runServer(cmd *cobra.Command, args []string) error {
proxyToken := os.Getenv(envProxyToken)
if proxyToken == "" {
return fmt.Errorf("proxy token is required: set %s environment variable", envProxyToken)
}
cfg, err := loadConfig(cmd, configPath)
if err != nil {
return fmt.Errorf("load config: %w", err)
}
if cfg.ProxyToken == "" {
return fmt.Errorf("proxy token is required: set proxyToken or %s", envProxyToken)
}
cfg.ProxyToken = proxyToken
level := cfg.LogLevel
if debugLogs && (!cmd.Flags().Changed("log-level") || cmd.Flags().Changed("debug")) {
if debugLogs {
level = "debug"
}
logger := log.New()
+1 -1
View File
@@ -24,7 +24,7 @@ type Config struct {
// ID identifies this proxy instance to management. Empty values are
// replaced with a timestamped default at Server.Start time (see
// initDefaults), not in New.
ID string `yaml:"id" env:"NB_PROXY_ID"`
ID string `yaml:"id" env:"-"`
// Logger is the logrus logger used everywhere. Empty values fall
// back to log.StandardLogger() at Server.Start time (see
// initDefaults), not in New.