Files
certctl/internal/service/config_helpers.go
T
shankar0123 e6088c79a3 feat(M35): dynamic target configuration with encrypted config, test connection, and GUI updates
Mirror M34's dynamic issuer config pattern for deployment targets: AES-256-GCM
encrypted config storage, sensitive field redaction in API responses, agent
heartbeat-based test connection endpoint, and full frontend updates including
test status indicators, source badges, and removal of stale hostname/status
fields from the Target interface.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-04 01:09:53 -04:00

43 lines
1.0 KiB
Go

package service
import (
"encoding/json"
"strings"
)
// sensitiveKeys are config key substrings that should be redacted in API responses.
var sensitiveKeys = []string{"password", "secret", "token", "key", "hmac", "private", "credentials"}
// isSensitiveConfigKey checks if a config key contains sensitive substrings.
func isSensitiveConfigKey(key string) bool {
lower := strings.ToLower(key)
for _, s := range sensitiveKeys {
if strings.Contains(lower, s) {
return true
}
}
return false
}
// redactConfigJSON replaces sensitive values in a JSON config with "********".
func redactConfigJSON(configJSON json.RawMessage) json.RawMessage {
var m map[string]interface{}
if err := json.Unmarshal(configJSON, &m); err != nil {
return configJSON // Not a JSON object, return as-is
}
for k, v := range m {
if isSensitiveConfigKey(k) {
if str, ok := v.(string); ok && str != "" {
m[k] = "********"
}
}
}
redacted, err := json.Marshal(m)
if err != nil {
return configJSON
}
return json.RawMessage(redacted)
}