From 69494d189fa777546f09f6c6db0931cb5508d896 Mon Sep 17 00:00:00 2001 From: lufei Date: Thu, 14 Nov 2024 00:10:02 +0800 Subject: [PATCH] =?UTF-8?q?kcurl=20anonymous=20mode=EF=BC=8Cadd=20random?= =?UTF-8?q?=20ip=20addresses=20to=20confuse=20ip=20addresses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/tool/kubectl/common.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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."}