diff --git a/README.md b/README.md index bad1fe8e52..e588e5b736 100644 --- a/README.md +++ b/README.md @@ -237,7 +237,7 @@ k8sgpt analyze --explain --filter=Service --output=json --anonymize With this option, the data is anonymized before being sent to the AI Backend. During the analysis execution, `k8sgpt` retrieves sensitive data (Kubernetes object names, labels, etc.). This data is masked when sent to the AI backend and replaced by a key that can be used to de-anonymize the data when the solution is returned to the user. -For example: +
1. Error reported during analysis: ```bash diff --git a/pkg/util/util.go b/pkg/util/util.go index ee02c1f5fd..ffa052b751 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -2,6 +2,7 @@ package util import ( "context" + "encoding/base64" "fmt" "math/rand" "regexp" @@ -10,6 +11,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +var anonymizePattern = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{}|;':\",./<>?") + func GetParent(client *kubernetes.Client, meta metav1.ObjectMeta) (string, bool) { if meta.OwnerReferences != nil { for _, owner := range meta.OwnerReferences { @@ -101,12 +104,13 @@ func SliceDiff(source, dest []string) []string { } func MaskString(input string) string { - letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") + key := make([]byte, len(input)) result := make([]rune, len(input)) + rand.Read(key) for i := range result { - result[i] = letters[rand.Intn(len(letters))] + result[i] = anonymizePattern[int(key[i])%len(anonymizePattern)] } - return string(result) + return base64.StdEncoding.EncodeToString([]byte(string(result))) } func ReplaceIfMatch(text string, pattern string, replacement string) string {