Add logging filter token

The token is used to filter out request logs when the user agent matches a randomly generated string.
This commit is contained in:
Maximilian Paß
2024-01-24 12:43:27 +01:00
committed by Sebastian Serth
parent 221a6ff1b2
commit 57590457a8
5 changed files with 52 additions and 3 deletions

View File

@ -1,7 +1,9 @@
package config
import (
"crypto/rand"
"crypto/tls"
"encoding/base64"
"errors"
"flag"
"fmt"
@ -37,6 +39,7 @@ var (
PrewarmingPoolThreshold: 0,
PrewarmingPoolReloadTimeout: 0,
},
LoggingFilterToken: randomFilterToken(),
},
Nomad: Nomad{
Enabled: true,
@ -100,6 +103,7 @@ type server struct {
InteractiveStderr bool
TemplateJobFile string
Alert alert
LoggingFilterToken string
}
// URL returns the URL of the Poseidon webserver.
@ -280,3 +284,14 @@ func loadValue(prefix string, value reflect.Value, logEntry *logrus.Entry) {
Warn("Setting configuration option via environment variables is not supported")
}
}
func randomFilterToken() string {
const tokenLength = 32
randomBytes := make([]byte, tokenLength) //nolint:all // length required to be filled by rand.Read.
n, err := rand.Read(randomBytes)
if n != tokenLength || err != nil {
log.WithError(err).WithField("byteCount", n).Fatal("Failed to generate random token")
}
return base64.URLEncoding.EncodeToString(randomBytes)
}