Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
fix(providers): don't crash startup when a disabled provider's external config is unreadable
Sergey Kozyrenkof441ec1c4d26
diff --git a/backend/pkg/providers/build_configs_test.go b/backend/pkg/providers/build_configs_test.gonew file mode 100644index 00000000..51226dd8--- /dev/null+++ b/backend/pkg/providers/build_configs_test.go@@ -0,0 +1,43 @@+package providers++import (+ "path/filepath"+ "testing"++ "pentagi/pkg/config"+ "pentagi/pkg/providers/provider"++ "github.com/stretchr/testify/assert"+ "github.com/stretchr/testify/require"+)++// A disabled provider pointed at an unreadable external config must not abort+// startup. Only enabled providers gate construction on their config loading.+func TestBuildDefaultConfigs_DisabledProviderBadPathIsNotFatal(t *testing.T) {+ cfg := &config.Config{+ // External Bedrock config path that doesn't exist; no Bedrock auth set,+ // so the provider is disabled.+ BedrockConfig: filepath.Join(t.TempDir(), "missing.yml"),+ }++ configs, err := buildDefaultConfigs(cfg)++ require.NoError(t, err)+ _, hasBedrock := configs[provider.ProviderBedrock]+ assert.False(t, hasBedrock, "disabled provider with an unreadable config path is skipped")+ _, hasOpenAI := configs[provider.ProviderOpenAI]+ assert.True(t, hasOpenAI, "providers with a readable (embedded) default config still load")+}++// An enabled provider pointed at an unreadable external config must still fail+// loudly — the operator explicitly configured a file that can't be read.+func TestBuildDefaultConfigs_EnabledProviderBadPathIsFatal(t *testing.T) {+ cfg := &config.Config{+ BedrockConfig: filepath.Join(t.TempDir(), "missing.yml"),+ BedrockBearerToken: "token",+ }++ _, err := buildDefaultConfigs(cfg)++ require.Error(t, err)+}diff --git a/backend/pkg/providers/providers.go b/backend/pkg/providers/providers.goindex d83cf5e0..546fc6a2 100644--- a/backend/pkg/providers/providers.go+++ b/backend/pkg/providers/providers.go@@ -148,6 +148,25 @@ type providerController struct {provider.Providers}+func buildDefaultConfigs(cfg *config.Config) (provider.ProvidersConfig, error) {+ defaultConfigs := make(provider.ProvidersConfig)+ for _, e := range providerRegistry {+ config, err := e.NewConfig(cfg)+ if err != nil {+ // A disabled provider pointed at an unreadable external config path+ // must not abort startup — fail loudly only for providers the+ // operator actually enabled.+ if !e.Enabled(cfg) {+ logrus.WithError(err).Warnf("skipping config for disabled %s provider", e.Type)+ continue+ }+ return nil, fmt.Errorf("failed to create %s provider config: %w", e.Type, err)+ }+ defaultConfigs[e.Type] = config+ }+ return defaultConfigs, nil+}+func NewProviderController(cfg *config.Config,db database.Querier,@@ -163,15 +182,10 @@ func NewProviderController(}providers := make(provider.Providers)- defaultConfigs := make(provider.ProvidersConfig)-- for _, e := range providerRegistry {- config, err := e.NewConfig(cfg)- if err != nil {- return nil, fmt.Errorf("failed to create %s provider config: %w", e.Type, err)- }- defaultConfigs[e.Type] = config+ defaultConfigs, err := buildDefaultConfigs(cfg)+ if err != nil {+ return nil, err}for _, e := range providerRegistry {