mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-26 14:29:08 +01:00
[management] Create HttpConfig before applying TLS flag overrides (#8168)
With the embedded IdP, management.json can leave out the HttpConfig section, and ApplyEmbeddedIdPConfig creates it later. Command-line overrides run before that, so --letsencrypt-domain, or --cert-file with --cert-key, dereferenced a nil HttpConfig and management crashed at startup. Create the section only when one of those flags writes to it, so a config without TLS flags keeps HttpConfig unset.
This commit is contained in:
@@ -214,17 +214,27 @@ func LoadMgmtConfig(ctx context.Context, mgmtConfigPath string) (*nbconfig.Confi
|
||||
// ApplyCommandLineOverrides applies command-line flag overrides to the config
|
||||
func ApplyCommandLineOverrides(cfg *nbconfig.Config) {
|
||||
if mgmtLetsencryptDomain != "" {
|
||||
cfg.HttpConfig.LetsEncryptDomain = mgmtLetsencryptDomain
|
||||
ensureHttpConfig(cfg).LetsEncryptDomain = mgmtLetsencryptDomain
|
||||
}
|
||||
if mgmtDataDir != "" {
|
||||
cfg.Datadir = mgmtDataDir
|
||||
}
|
||||
if certKey != "" && certFile != "" {
|
||||
cfg.HttpConfig.CertFile = certFile
|
||||
cfg.HttpConfig.CertKey = certKey
|
||||
httpConfig := ensureHttpConfig(cfg)
|
||||
httpConfig.CertFile = certFile
|
||||
httpConfig.CertKey = certKey
|
||||
}
|
||||
}
|
||||
|
||||
// ensureHttpConfig creates the HttpConfig section only when a flag writes to
|
||||
// it, since the embedded IdP warns about any HttpConfig it finds.
|
||||
func ensureHttpConfig(cfg *nbconfig.Config) *nbconfig.HttpServerConfig {
|
||||
if cfg.HttpConfig == nil {
|
||||
cfg.HttpConfig = &nbconfig.HttpServerConfig{}
|
||||
}
|
||||
return cfg.HttpConfig
|
||||
}
|
||||
|
||||
// ApplyEmbeddedIdPConfig populates HttpConfig and EmbeddedIdP storage from config when embedded IdP is enabled.
|
||||
// This allows users to only specify EmbeddedIdP config without duplicating values in HttpConfig.
|
||||
func ApplyEmbeddedIdPConfig(ctx context.Context, cfg *nbconfig.Config) error {
|
||||
|
||||
Reference in New Issue
Block a user