mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 00:06:38 +00:00
Start Management if external IdP is down (#5367)
Set ContinueOnConnectorFailure: true in the embedded Dex config so that the Management server starts successfully even when an external IdP connector is unreachable at boot time.
This commit is contained in:
@@ -99,15 +99,16 @@ func NewProvider(ctx context.Context, config *Config) (*Provider, error) {
|
|||||||
|
|
||||||
// Build Dex server config - use Dex's types directly
|
// Build Dex server config - use Dex's types directly
|
||||||
dexConfig := server.Config{
|
dexConfig := server.Config{
|
||||||
Issuer: issuer,
|
Issuer: issuer,
|
||||||
Storage: stor,
|
Storage: stor,
|
||||||
SkipApprovalScreen: true,
|
SkipApprovalScreen: true,
|
||||||
SupportedResponseTypes: []string{"code"},
|
SupportedResponseTypes: []string{"code"},
|
||||||
Logger: logger,
|
ContinueOnConnectorFailure: true,
|
||||||
PrometheusRegistry: prometheus.NewRegistry(),
|
Logger: logger,
|
||||||
RotateKeysAfter: 6 * time.Hour,
|
PrometheusRegistry: prometheus.NewRegistry(),
|
||||||
IDTokensValidFor: 24 * time.Hour,
|
RotateKeysAfter: 6 * time.Hour,
|
||||||
RefreshTokenPolicy: refreshPolicy,
|
IDTokensValidFor: 24 * time.Hour,
|
||||||
|
RefreshTokenPolicy: refreshPolicy,
|
||||||
Web: server.WebConfig{
|
Web: server.WebConfig{
|
||||||
Issuer: "NetBird",
|
Issuer: "NetBird",
|
||||||
},
|
},
|
||||||
@@ -260,6 +261,7 @@ func buildDexConfig(yamlConfig *YAMLConfig, stor storage.Storage, logger *slog.L
|
|||||||
if len(cfg.SupportedResponseTypes) == 0 {
|
if len(cfg.SupportedResponseTypes) == 0 {
|
||||||
cfg.SupportedResponseTypes = []string{"code"}
|
cfg.SupportedResponseTypes = []string{"code"}
|
||||||
}
|
}
|
||||||
|
cfg.ContinueOnConnectorFailure = true
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package dex
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -195,3 +196,64 @@ enablePasswordDB: true
|
|||||||
|
|
||||||
t.Logf("User lookup successful: rawID=%s, connectorID=%s", rawID, connID)
|
t.Logf("User lookup successful: rawID=%s, connectorID=%s", rawID, connID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewProvider_ContinueOnConnectorFailure(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
tmpDir, err := os.MkdirTemp("", "dex-connector-failure-*")
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
config := &Config{
|
||||||
|
Issuer: "http://localhost:5556/dex",
|
||||||
|
Port: 5556,
|
||||||
|
DataDir: tmpDir,
|
||||||
|
}
|
||||||
|
|
||||||
|
provider, err := NewProvider(ctx, config)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer func() { _ = provider.Stop(ctx) }()
|
||||||
|
|
||||||
|
// The provider should have started successfully even though
|
||||||
|
// ContinueOnConnectorFailure is an internal Dex config field.
|
||||||
|
// We verify the provider is functional by performing a basic operation.
|
||||||
|
assert.NotNil(t, provider.dexServer)
|
||||||
|
assert.NotNil(t, provider.storage)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildDexConfig_ContinueOnConnectorFailure(t *testing.T) {
|
||||||
|
tmpDir, err := os.MkdirTemp("", "dex-build-config-*")
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
yamlContent := `
|
||||||
|
issuer: http://localhost:5556/dex
|
||||||
|
storage:
|
||||||
|
type: sqlite3
|
||||||
|
config:
|
||||||
|
file: ` + filepath.Join(tmpDir, "dex.db") + `
|
||||||
|
web:
|
||||||
|
http: 127.0.0.1:5556
|
||||||
|
enablePasswordDB: true
|
||||||
|
`
|
||||||
|
configPath := filepath.Join(tmpDir, "config.yaml")
|
||||||
|
err = os.WriteFile(configPath, []byte(yamlContent), 0644)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
yamlConfig, err := LoadConfig(configPath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
stor, err := yamlConfig.Storage.OpenStorage(slog.New(slog.NewTextHandler(os.Stderr, nil)))
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer stor.Close()
|
||||||
|
|
||||||
|
err = initializeStorage(ctx, stor, yamlConfig)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
||||||
|
cfg := buildDexConfig(yamlConfig, stor, logger)
|
||||||
|
|
||||||
|
assert.True(t, cfg.ContinueOnConnectorFailure,
|
||||||
|
"buildDexConfig must set ContinueOnConnectorFailure to true so management starts even if an external IdP is down")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user