From 35578b23236dcfe3970a365a8229e065d08cc101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Tue, 30 Jan 2024 13:33:40 +0100 Subject: [PATCH] kubernetes: Add useragent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In kubernetes' audit logs you'll see: "userAgent":"coredns/v0.0.0 (linux/amd64) kubernetes/$Format" This change adds a userAgent to the requests made by CoreDNS against the kubernetes API: "userAgent":"CoreDNS/v1.11.1 git_commit:ae2bbc29be1aaae0b3ded5d188968a6c97bb3144 (linux/amd64/go1.22)" Signed-off-by: Manuel RĂ¼ger --- coremain/run.go | 2 +- coremain/version.go | 2 +- plugin/kubernetes/kubernetes.go | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/coremain/run.go b/coremain/run.go index 31b791c8ea0..b3ee02a24e5 100644 --- a/coremain/run.go +++ b/coremain/run.go @@ -31,7 +31,7 @@ func init() { flag.StringVar(&dnsserver.Port, serverType+".port", dnsserver.DefaultPort, "Default port") flag.StringVar(&dnsserver.Port, "p", dnsserver.DefaultPort, "Default port") - caddy.AppName = coreName + caddy.AppName = CoreName caddy.AppVersion = CoreVersion } diff --git a/coremain/version.go b/coremain/version.go index 232941fbaa0..553f360eda5 100644 --- a/coremain/version.go +++ b/coremain/version.go @@ -3,6 +3,6 @@ package coremain // Various CoreDNS constants. const ( CoreVersion = "1.11.3" - coreName = "CoreDNS" + CoreName = "CoreDNS" serverType = "dns" ) diff --git a/plugin/kubernetes/kubernetes.go b/plugin/kubernetes/kubernetes.go index cea23d860fa..e4733c6f2ff 100644 --- a/plugin/kubernetes/kubernetes.go +++ b/plugin/kubernetes/kubernetes.go @@ -6,9 +6,11 @@ import ( "errors" "fmt" "net" + "runtime" "strings" "time" + "github.com/coredns/coredns/coremain" "github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin/etcd/msg" "github.com/coredns/coredns/plugin/kubernetes/object" @@ -192,6 +194,7 @@ func (k *Kubernetes) getClientConfig() (*rest.Config, error) { return nil, err } cc.ContentType = "application/vnd.kubernetes.protobuf" + cc.UserAgent = fmt.Sprintf("%s/%s git_commit:%s (%s/%s/%s)", coremain.CoreName, coremain.CoreVersion, coremain.GitCommit, runtime.GOOS, runtime.GOARCH, runtime.Version()) return cc, err } @@ -218,6 +221,7 @@ func (k *Kubernetes) getClientConfig() (*rest.Config, error) { return nil, err } cc.ContentType = "application/vnd.kubernetes.protobuf" + cc.UserAgent = fmt.Sprintf("%s/%s git_commit:%s (%s/%s/%s)", coremain.CoreName, coremain.CoreVersion, coremain.GitCommit, runtime.GOOS, runtime.GOARCH, runtime.Version()) return cc, err }