Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions framework/configstore/clientconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,14 @@ func GenerateKeyHash(key schemas.Key) (string, error) {
}
hash.Write(data)
}
// Hash BedrockMantleKeyConfig
if key.BedrockMantleKeyConfig != nil {
data, err := sonic.Marshal(key.BedrockMantleKeyConfig)
if err != nil {
return "", err
}
hash.Write(data)
}
Comment thread
Pratham-Mishra04 marked this conversation as resolved.
Resolved
// Hash Aliases
if key.Aliases != nil {
data, err := sonic.Marshal(key.Aliases)
Expand Down
211 changes: 108 additions & 103 deletions framework/configstore/rdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,52 +143,54 @@ func toolSyncIntervalDurationToStoredSeconds(interval time.Duration) (int, error
// schemaKeyFromTableKey converts a database key to a schema key.
func schemaKeyFromTableKey(dbKey tables.TableKey) schemas.Key {
return schemas.Key{
ID: dbKey.KeyID,
Name: dbKey.Name,
Value: dbKey.Value,
Models: dbKey.Models,
BlacklistedModels: dbKey.BlacklistedModels,
Weight: getWeight(dbKey.Weight),
Enabled: dbKey.Enabled,
UseForBatchAPI: dbKey.UseForBatchAPI,
AzureKeyConfig: dbKey.AzureKeyConfig,
VertexKeyConfig: dbKey.VertexKeyConfig,
BedrockKeyConfig: dbKey.BedrockKeyConfig,
Aliases: dbKey.Aliases,
VLLMKeyConfig: dbKey.VLLMKeyConfig,
ReplicateKeyConfig: dbKey.ReplicateKeyConfig,
OllamaKeyConfig: dbKey.OllamaKeyConfig,
SGLKeyConfig: dbKey.SGLKeyConfig,
ConfigHash: dbKey.ConfigHash,
Status: schemas.KeyStatusType(dbKey.Status),
Description: dbKey.Description,
ID: dbKey.KeyID,
Name: dbKey.Name,
Value: dbKey.Value,
Models: dbKey.Models,
BlacklistedModels: dbKey.BlacklistedModels,
Weight: getWeight(dbKey.Weight),
Enabled: dbKey.Enabled,
UseForBatchAPI: dbKey.UseForBatchAPI,
AzureKeyConfig: dbKey.AzureKeyConfig,
VertexKeyConfig: dbKey.VertexKeyConfig,
BedrockKeyConfig: dbKey.BedrockKeyConfig,
BedrockMantleKeyConfig: dbKey.BedrockMantleKeyConfig,
Aliases: dbKey.Aliases,
VLLMKeyConfig: dbKey.VLLMKeyConfig,
ReplicateKeyConfig: dbKey.ReplicateKeyConfig,
OllamaKeyConfig: dbKey.OllamaKeyConfig,
SGLKeyConfig: dbKey.SGLKeyConfig,
ConfigHash: dbKey.ConfigHash,
Status: schemas.KeyStatusType(dbKey.Status),
Description: dbKey.Description,
}
}

// tableKeyFromSchemaKey converts a schema key to a database key.
func tableKeyFromSchemaKey(provider tables.TableProvider, key schemas.Key) (tables.TableKey, error) {
dbKey := tables.TableKey{
Provider: provider.Name,
ProviderID: provider.ID,
KeyID: key.ID,
Name: key.Name,
Value: key.Value,
Models: key.Models,
BlacklistedModels: key.BlacklistedModels,
Weight: &key.Weight,
Enabled: key.Enabled,
UseForBatchAPI: key.UseForBatchAPI,
AzureKeyConfig: key.AzureKeyConfig,
VertexKeyConfig: key.VertexKeyConfig,
BedrockKeyConfig: key.BedrockKeyConfig,
Aliases: key.Aliases,
VLLMKeyConfig: key.VLLMKeyConfig,
ReplicateKeyConfig: key.ReplicateKeyConfig,
OllamaKeyConfig: key.OllamaKeyConfig,
SGLKeyConfig: key.SGLKeyConfig,
ConfigHash: key.ConfigHash,
Status: string(key.Status),
Description: key.Description,
Provider: provider.Name,
ProviderID: provider.ID,
KeyID: key.ID,
Name: key.Name,
Value: key.Value,
Models: key.Models,
BlacklistedModels: key.BlacklistedModels,
Weight: &key.Weight,
Enabled: key.Enabled,
UseForBatchAPI: key.UseForBatchAPI,
AzureKeyConfig: key.AzureKeyConfig,
VertexKeyConfig: key.VertexKeyConfig,
BedrockKeyConfig: key.BedrockKeyConfig,
BedrockMantleKeyConfig: key.BedrockMantleKeyConfig,
Aliases: key.Aliases,
VLLMKeyConfig: key.VLLMKeyConfig,
ReplicateKeyConfig: key.ReplicateKeyConfig,
OllamaKeyConfig: key.OllamaKeyConfig,
SGLKeyConfig: key.SGLKeyConfig,
ConfigHash: key.ConfigHash,
Status: string(key.Status),
Description: key.Description,
}

if key.AzureKeyConfig != nil {
Expand Down Expand Up @@ -699,27 +701,28 @@ func (s *RDBConfigStore) UpdateProvidersConfig(ctx context.Context, providers ma
}
}
dbKey := tables.TableKey{
Provider: dbProvider.Name,
ProviderID: dbProvider.ID,
KeyID: key.ID,
Name: key.Name,
Value: key.Value,
Models: key.Models,
BlacklistedModels: key.BlacklistedModels,
Weight: &key.Weight,
Enabled: key.Enabled,
UseForBatchAPI: key.UseForBatchAPI,
AzureKeyConfig: key.AzureKeyConfig,
VertexKeyConfig: key.VertexKeyConfig,
BedrockKeyConfig: key.BedrockKeyConfig,
Aliases: key.Aliases,
VLLMKeyConfig: key.VLLMKeyConfig,
ReplicateKeyConfig: key.ReplicateKeyConfig,
OllamaKeyConfig: key.OllamaKeyConfig,
SGLKeyConfig: key.SGLKeyConfig,
ConfigHash: keyHash,
Status: string(key.Status),
Description: key.Description,
Provider: dbProvider.Name,
ProviderID: dbProvider.ID,
KeyID: key.ID,
Name: key.Name,
Value: key.Value,
Models: key.Models,
BlacklistedModels: key.BlacklistedModels,
Weight: &key.Weight,
Enabled: key.Enabled,
UseForBatchAPI: key.UseForBatchAPI,
AzureKeyConfig: key.AzureKeyConfig,
VertexKeyConfig: key.VertexKeyConfig,
BedrockKeyConfig: key.BedrockKeyConfig,
BedrockMantleKeyConfig: key.BedrockMantleKeyConfig,
Aliases: key.Aliases,
VLLMKeyConfig: key.VLLMKeyConfig,
ReplicateKeyConfig: key.ReplicateKeyConfig,
OllamaKeyConfig: key.OllamaKeyConfig,
SGLKeyConfig: key.SGLKeyConfig,
ConfigHash: keyHash,
Status: string(key.Status),
Description: key.Description,
}

// Handle Azure config
Expand Down Expand Up @@ -927,27 +930,28 @@ func (s *RDBConfigStore) UpdateProvider(ctx context.Context, provider schemas.Mo
return fmt.Errorf("failed to generate key hash: %w", err)
}
dbKey := tables.TableKey{
Provider: dbProvider.Name,
ProviderID: dbProvider.ID,
KeyID: key.ID,
Name: key.Name,
Value: key.Value,
Models: key.Models,
BlacklistedModels: key.BlacklistedModels,
Weight: &key.Weight,
Enabled: key.Enabled,
UseForBatchAPI: key.UseForBatchAPI,
AzureKeyConfig: key.AzureKeyConfig,
VertexKeyConfig: key.VertexKeyConfig,
BedrockKeyConfig: key.BedrockKeyConfig,
Aliases: key.Aliases,
VLLMKeyConfig: key.VLLMKeyConfig,
ReplicateKeyConfig: key.ReplicateKeyConfig,
OllamaKeyConfig: key.OllamaKeyConfig,
SGLKeyConfig: key.SGLKeyConfig,
ConfigHash: keyHash,
Status: string(key.Status),
Description: key.Description,
Provider: dbProvider.Name,
ProviderID: dbProvider.ID,
KeyID: key.ID,
Name: key.Name,
Value: key.Value,
Models: key.Models,
BlacklistedModels: key.BlacklistedModels,
Weight: &key.Weight,
Enabled: key.Enabled,
UseForBatchAPI: key.UseForBatchAPI,
AzureKeyConfig: key.AzureKeyConfig,
VertexKeyConfig: key.VertexKeyConfig,
BedrockKeyConfig: key.BedrockKeyConfig,
BedrockMantleKeyConfig: key.BedrockMantleKeyConfig,
Aliases: key.Aliases,
VLLMKeyConfig: key.VLLMKeyConfig,
ReplicateKeyConfig: key.ReplicateKeyConfig,
OllamaKeyConfig: key.OllamaKeyConfig,
SGLKeyConfig: key.SGLKeyConfig,
ConfigHash: keyHash,
Status: string(key.Status),
Description: key.Description,
}

// Handle Azure config
Expand Down Expand Up @@ -1066,27 +1070,28 @@ func (s *RDBConfigStore) AddProvider(ctx context.Context, provider schemas.Model
// Create keys for this provider
for _, key := range configCopy.Keys {
dbKey := tables.TableKey{
Provider: dbProvider.Name,
ProviderID: dbProvider.ID,
KeyID: key.ID,
Name: key.Name,
Value: key.Value,
Models: key.Models,
BlacklistedModels: key.BlacklistedModels,
Weight: &key.Weight,
Enabled: key.Enabled,
UseForBatchAPI: key.UseForBatchAPI,
AzureKeyConfig: key.AzureKeyConfig,
VertexKeyConfig: key.VertexKeyConfig,
BedrockKeyConfig: key.BedrockKeyConfig,
Aliases: key.Aliases,
VLLMKeyConfig: key.VLLMKeyConfig,
ReplicateKeyConfig: key.ReplicateKeyConfig,
OllamaKeyConfig: key.OllamaKeyConfig,
SGLKeyConfig: key.SGLKeyConfig,
ConfigHash: key.ConfigHash,
Status: string(key.Status),
Description: key.Description,
Provider: dbProvider.Name,
ProviderID: dbProvider.ID,
KeyID: key.ID,
Name: key.Name,
Value: key.Value,
Models: key.Models,
BlacklistedModels: key.BlacklistedModels,
Weight: &key.Weight,
Enabled: key.Enabled,
UseForBatchAPI: key.UseForBatchAPI,
AzureKeyConfig: key.AzureKeyConfig,
VertexKeyConfig: key.VertexKeyConfig,
BedrockKeyConfig: key.BedrockKeyConfig,
BedrockMantleKeyConfig: key.BedrockMantleKeyConfig,
Aliases: key.Aliases,
VLLMKeyConfig: key.VLLMKeyConfig,
ReplicateKeyConfig: key.ReplicateKeyConfig,
OllamaKeyConfig: key.OllamaKeyConfig,
SGLKeyConfig: key.SGLKeyConfig,
ConfigHash: key.ConfigHash,
Status: string(key.Status),
Description: key.Description,
}
// Handle Azure config
if key.AzureKeyConfig != nil {
Expand Down
10 changes: 10 additions & 0 deletions framework/configstore/tables/virtualkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ func (pc *TableVirtualKeyProviderConfig) AfterFind(tx *gorm.DB) error {
key.BedrockRoleSessionName = nil
key.BedrockKeyConfig = nil

// Clear all Bedrock Mantle-related sensitive fields
key.BedrockMantleAccessKey = nil
key.BedrockMantleSecretKey = nil
key.BedrockMantleSessionToken = nil
key.BedrockMantleRegion = nil
key.BedrockMantleRoleARN = nil
key.BedrockMantleExternalID = nil
key.BedrockMantleRoleSessionName = nil
key.BedrockMantleKeyConfig = nil

pc.Keys[i] = *key
}
}
Expand Down
48 changes: 47 additions & 1 deletion transports/bifrost-http/lib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3399,7 +3399,53 @@ func TestGenerateKeyHash(t *testing.T) {
t.Error("Expected different hash for keys with different BedrockKeyConfig region")
}

t.Log("✓ Key hash generation works correctly for all fields including Azure, Vertex, and Bedrock configs")
// BedrockMantleKeyConfig should produce different hash
key9 := schemas.Key{
ID: "key-1",
Name: "test-key",
Value: *schemas.NewSecretVar("sk-123"),
Models: []string{"gpt-4", "gpt-3.5-turbo"},
Weight: 1.5,
BedrockMantleKeyConfig: &schemas.BedrockMantleKeyConfig{
AccessKey: *schemas.NewSecretVar("AKIAIOSFODNN7EXAMPLE"),
SecretKey: *schemas.NewSecretVar("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"),
Region: schemas.NewSecretVar(region),
},
}

hash9, err := configstore.GenerateKeyHash(key9)
if err != nil {
t.Fatalf("Failed to generate hash: %v", err)
}

if hash1 == hash9 {
t.Error("Expected different hash for keys with BedrockMantleKeyConfig")
}

// Different BedrockMantleKeyConfig should produce different hash
key9b := schemas.Key{
ID: "key-1",
Name: "test-key",
Value: *schemas.NewSecretVar("sk-123"),
Models: []string{"gpt-4", "gpt-3.5-turbo"},
Weight: 1.5,
BedrockMantleKeyConfig: &schemas.BedrockMantleKeyConfig{
AccessKey: *schemas.NewSecretVar("AKIAIOSFODNN7EXAMPLE"),
SecretKey: *schemas.NewSecretVar("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"),
Region: schemas.NewSecretVar(differentRegion), // Different region
},
}

hash9b, err := configstore.GenerateKeyHash(key9b)
if err != nil {
t.Fatalf("Failed to generate hash: %v", err)
}

if hash9 == hash9b {
t.Error("Expected different hash for keys with different BedrockMantleKeyConfig region")
}

t.Log("✓ Key hash generation works correctly for all fields including Azure, Vertex, Bedrock, and Bedrock Mantle configs")
}

// TestProviderHashComparison_MatchingHash tests that DB config is kept when hashes match
Expand Down
Loading