rancher / fleet

Deploy workloads from Git to large fleets of Kubernetes clusters
https://fleet.rancher.io/
Apache License 2.0
1.5k stars 226 forks source link

Error with stacktrace in gitjob pod after sending a webhook event with wrong credentials #2472

Closed thehejik closed 2 months ago

thehejik commented 4 months ago

Is there an existing issue for this?

Current Behavior

After sending a webhook event with wrong credentials, for eg. from Azure DevOps on push, there is following error in gitjob logs with stacktrace:

{
  "level": "error",
  "ts": "2024-05-29T15:19:24Z",
  "logger": "webhook",
  "msg": "Webhook processing failed",
  "error": "basic auth verification failed",
  "stacktrace": "github.com/rancher/fleet/pkg/webhook.(*Webhook).logAndReturn\n\t/home/runner/work/fleet/fleet/pkg/webhook/webhook.go:301\ngithub.com/rancher/fleet/pkg/webhook.(*Webhook).ServeHTTP\n\t/home/runner/work/fleet/fleet/pkg/webhook/webhook.go:183\ngithub.com/gorilla/mux.(*Router).ServeHTTP\n\t/home/runner/go/pkg/mod/github.com/gorilla/mux@v1.8.1/mux.go:212\nnet/http.serverHandler.ServeHTTP\n\t/opt/hostedtoolcache/go/1.22.3/x64/src/net/http/server.go:3137\nnet/http.(*conn).serve\n\t/opt/hostedtoolcache/go/1.22.3/x64/src/net/http/server.go:2039"
}

Reproducer

Expected Behavior

The error itself makes sense, but the stacktrace is a bit too much.

weyfonk commented 3 months ago

This comes from the way errors are logged through logr. We could mitigate this by making these Info logs, but those basic auth logs refer to actual errors.

Not sure there's an easy fix for this.

manno commented 3 months ago

I think we can configure our loggers. Both controllers should have these args, where --debug controls --zap-devel:

      --debug                             Turn on debug logging
      --debug-level int                   If debugging is enabled, set klog -v
      --zap-devel                         Development Mode defaults(encoder=consoleEncoder,logLevel=Debug,stackTraceLevel=Warn). Production Mode defaults(encoder=jsonEncoder,logLevel=Info,stackTraceLevel=Error) (default true)
      --zap-encoder encoder               Zap log encoding (one of 'json' or 'console')
      --zap-log-level level               Zap Level to configure the verbosity of logging. Can be one of 'debug', 'info', 'error', or any integer value > 0 which corresponds to custom debug levels of increasing verbosity
      --zap-stacktrace-level level        Zap Level at and above which stacktraces are captured (one of 'info', 'error', 'panic').
      --zap-time-encoding time-encoding   Zap time encoding (one of 'epoch', 'millis', 'nano', 'iso8601', 'rfc3339' or 'rfc3339nano'). Defaults to 'epoch'.

However