diff --git a/pkg/tool/kubectl/common.go b/pkg/tool/kubectl/common.go index bcaa132..e694cf1 100644 --- a/pkg/tool/kubectl/common.go +++ b/pkg/tool/kubectl/common.go @@ -21,6 +21,7 @@ import ( "crypto/tls" "fmt" "io/ioutil" + "math/rand" "net" "net/http" "os" @@ -160,6 +161,20 @@ func ServerAccountRequest(opts K8sRequestOption) (string, error) { request.Header.Set("Authorization", "Bearer "+token) } + // Anonymous mode,add random ip addresses to confuse ip addresses + if opts.Anonymous { + rand.Seed(time.Now().UnixNano()) + ips := make([]string, 100) + + for i := 0; i < 100; i++ { + ip := fmt.Sprintf("10.%d.%d.%d", rand.Intn(256), rand.Intn(256), rand.Intn(256)) + ips[i] = ip + } + + randIpStr := strings.Join(ips, ",") + request.Header.Set("X-Forwarded-For", randIpStr) + } + resp, err := client.Do(request) if err != nil { return "", &errors.CDKRuntimeError{Err: err, CustomMsg: "err found in post request."}