Skip to content

Commit

Permalink
kubernetes: Add useragent
Browse files Browse the repository at this point in the history
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)"

Signed-off-by: Manuel Rüger <manuel@rueg.eu>
  • Loading branch information
mrueg committed Mar 18, 2024
1 parent 5a1995c commit 6eb77bd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion coremain/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion coremain/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package coremain
// Various CoreDNS constants.
const (
CoreVersion = "1.11.2"
coreName = "CoreDNS"
CoreName = "CoreDNS"
serverType = "dns"
)
4 changes: 4 additions & 0 deletions plugin/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)", coremain.CoreName, coremain.CoreVersion, coremain.GitCommit, runtime.GOOS, runtime.GOARCH)
return cc, err
}

Expand All @@ -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)", coremain.CoreName, coremain.CoreVersion, coremain.GitCommit, runtime.GOOS, runtime.GOARCH)
return cc, err
}

Expand Down

0 comments on commit 6eb77bd

Please sign in to comment.