From 809eed400a4ef27e56b144807fa41897c1e2b374 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Fri, 22 Jan 2021 23:53:56 +0100 Subject: [PATCH] Add a warning when node exporter runs as root Signed-off-by: Julien Pivotto --- .promu.yml | 2 +- node_exporter.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.promu.yml b/.promu.yml index 8797d4b9..0697b5bc 100644 --- a/.promu.yml +++ b/.promu.yml @@ -7,7 +7,7 @@ repository: build: binaries: - name: node_exporter - flags: -a -tags 'netgo static_build' + flags: -a -tags 'netgo osusergo static_build' ldflags: | -X github.com/prometheus/common/version.Version={{.Version}} -X github.com/prometheus/common/version.Revision={{.Revision}} diff --git a/node_exporter.go b/node_exporter.go index a604f1c0..2347a490 100644 --- a/node_exporter.go +++ b/node_exporter.go @@ -18,6 +18,7 @@ import ( "net/http" _ "net/http/pprof" "os" + "os/user" "sort" "github.com/prometheus/common/promlog" @@ -176,6 +177,9 @@ func main() { } level.Info(logger).Log("msg", "Starting node_exporter", "version", version.Info()) level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext()) + if user, err := user.Current(); err == nil && user.Uid == "0" { + level.Warn(logger).Log("msg", "Node Exporter is running as root user. This exporter is designed to run as unpriviledged user, root is not required.") + } http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests, logger)) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {