mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 02:42:11 +08:00

* everything is compiling * tests passing * remove used object * write a test for secret key upgrades * misc cleanup * clean up some wording * lint issues * fix a typo * import hashicorp dependency explicitly * simplify oss kmsprovider package structure * consolidate current provider and available providers * add a new manager configuration test * fix hashivault import * fix import issue * fix unit tests * Update go.mod Co-authored-by: Matheus Macabu <macabu@users.noreply.github.com> --------- Co-authored-by: Matheus Macabu <macabu@users.noreply.github.com>
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package setting
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
ProviderPrefix = "secrets_manager.encryption."
|
|
MisconfiguredProvider = "misconfigured"
|
|
)
|
|
|
|
type SecretsManagerSettings struct {
|
|
CurrentEncryptionProvider string
|
|
|
|
// ConfiguredKMSProviders is a map of KMS providers found in the config file. The keys are in the format of <provider>.<keyName>, and the values are a map of the properties in that section
|
|
// In OSS, the provider type can only be "secret_key". In Enterprise, it can additionally be one of: "aws_kms", "azure_keyvault", "google_kms", "hashicorp_vault"
|
|
ConfiguredKMSProviders map[string]map[string]string
|
|
}
|
|
|
|
func (cfg *Cfg) readSecretsManagerSettings() {
|
|
secretsMgmt := cfg.Raw.Section("secrets_manager")
|
|
cfg.SecretsManagement.CurrentEncryptionProvider = secretsMgmt.Key("encryption_provider").MustString(MisconfiguredProvider)
|
|
|
|
// Extract available KMS providers from configuration sections
|
|
providers := make(map[string]map[string]string)
|
|
for _, section := range cfg.Raw.Sections() {
|
|
sectionName := section.Name()
|
|
if strings.HasPrefix(sectionName, ProviderPrefix) {
|
|
// Extract the provider name (everything after the prefix)
|
|
providerName := strings.TrimPrefix(sectionName, ProviderPrefix)
|
|
if providerName != "" {
|
|
providers[providerName] = section.KeysHash()
|
|
}
|
|
}
|
|
}
|
|
cfg.SecretsManagement.ConfiguredKMSProviders = providers
|
|
}
|