|
|
@ -13,6 +13,7 @@ import ( |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
"regexp" |
|
|
|
"runtime" |
|
|
|
"runtime" |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
@ -490,30 +491,70 @@ func RedactedValue(key, value string) string { |
|
|
|
"SECRET_KEY", |
|
|
|
"SECRET_KEY", |
|
|
|
"CERTIFICATE", |
|
|
|
"CERTIFICATE", |
|
|
|
"ACCOUNT_KEY", |
|
|
|
"ACCOUNT_KEY", |
|
|
|
|
|
|
|
"ENCRYPTION_KEY", |
|
|
|
|
|
|
|
"VAULT_TOKEN", |
|
|
|
|
|
|
|
"AWSKMS_.*_TOKEN", |
|
|
|
} { |
|
|
|
} { |
|
|
|
if strings.Contains(uppercased, pattern) { |
|
|
|
if match, err := regexp.MatchString(pattern, uppercased); match && err == nil { |
|
|
|
return RedactedPassword |
|
|
|
return RedactedPassword |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Sensitive URLs that might contain username and password
|
|
|
|
|
|
|
|
for _, pattern := range []string{ |
|
|
|
for _, exception := range []string{ |
|
|
|
"DATABASE_URL", |
|
|
|
"RUDDERSTACK", |
|
|
|
|
|
|
|
"APPLICATION_INSIGHTS", |
|
|
|
|
|
|
|
"SENTRY", |
|
|
|
} { |
|
|
|
} { |
|
|
|
if strings.Contains(uppercased, pattern) { |
|
|
|
if strings.Contains(uppercased, exception) { |
|
|
|
if u, err := url.Parse(value); err == nil { |
|
|
|
return value |
|
|
|
return u.Redacted() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Otherwise return unmodified value
|
|
|
|
|
|
|
|
|
|
|
|
if u, err := RedactedURL(value); err == nil { |
|
|
|
|
|
|
|
return u |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return value |
|
|
|
return value |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func RedactedURL(value string) (string, error) { |
|
|
|
|
|
|
|
// Value could be a list of URLs
|
|
|
|
|
|
|
|
chunks := util.SplitString(value) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i, chunk := range chunks { |
|
|
|
|
|
|
|
var hasTmpPrefix bool |
|
|
|
|
|
|
|
const tmpPrefix = "http://" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !strings.Contains(chunk, "://") { |
|
|
|
|
|
|
|
chunk = tmpPrefix + chunk |
|
|
|
|
|
|
|
hasTmpPrefix = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
u, err := url.Parse(chunk) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return "", err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redacted := u.Redacted() |
|
|
|
|
|
|
|
if hasTmpPrefix { |
|
|
|
|
|
|
|
redacted = strings.Replace(redacted, tmpPrefix, "", 1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chunks[i] = redacted |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if strings.Contains(value, ",") { |
|
|
|
|
|
|
|
return strings.Join(chunks, ","), nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return strings.Join(chunks, " "), nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func applyEnvVariableOverrides(file *ini.File) error { |
|
|
|
func applyEnvVariableOverrides(file *ini.File) error { |
|
|
|
appliedEnvOverrides = make([]string, 0) |
|
|
|
appliedEnvOverrides = make([]string, 0) |
|
|
|
for _, section := range file.Sections() { |
|
|
|
for _, section := range file.Sections() { |
|
|
|
for _, key := range section.Keys() { |
|
|
|
for _, key := range section.Keys() { |
|
|
|
envKey := envKey(section.Name(), key.Name()) |
|
|
|
envKey := EnvKey(section.Name(), key.Name()) |
|
|
|
envValue := os.Getenv(envKey) |
|
|
|
envValue := os.Getenv(envKey) |
|
|
|
|
|
|
|
|
|
|
|
if len(envValue) > 0 { |
|
|
|
if len(envValue) > 0 { |
|
|
@ -584,7 +625,7 @@ type AnnotationCleanupSettings struct { |
|
|
|
MaxCount int64 |
|
|
|
MaxCount int64 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func envKey(sectionName string, keyName string) string { |
|
|
|
func EnvKey(sectionName string, keyName string) string { |
|
|
|
sN := strings.ToUpper(strings.ReplaceAll(sectionName, ".", "_")) |
|
|
|
sN := strings.ToUpper(strings.ReplaceAll(sectionName, ".", "_")) |
|
|
|
sN = strings.ReplaceAll(sN, "-", "_") |
|
|
|
sN = strings.ReplaceAll(sN, "-", "_") |
|
|
|
kN := strings.ToUpper(strings.ReplaceAll(keyName, ".", "_")) |
|
|
|
kN := strings.ToUpper(strings.ReplaceAll(keyName, ".", "_")) |
|
|
@ -1107,7 +1148,7 @@ type DynamicSection struct { |
|
|
|
// Key dynamically overrides keys with environment variables.
|
|
|
|
// Key dynamically overrides keys with environment variables.
|
|
|
|
// As a side effect, the value of the setting key will be updated if an environment variable is present.
|
|
|
|
// As a side effect, the value of the setting key will be updated if an environment variable is present.
|
|
|
|
func (s *DynamicSection) Key(k string) *ini.Key { |
|
|
|
func (s *DynamicSection) Key(k string) *ini.Key { |
|
|
|
envKey := envKey(s.section.Name(), k) |
|
|
|
envKey := EnvKey(s.section.Name(), k) |
|
|
|
envValue := os.Getenv(envKey) |
|
|
|
envValue := os.Getenv(envKey) |
|
|
|
key := s.section.Key(k) |
|
|
|
key := s.section.Key(k) |
|
|
|
|
|
|
|
|
|
|
|