make account web page configurable separately from admin, add http auth rate limiting

ideally both account & admin web pages should be on non-public ips (e.g. a
wireguard tunnel). but during setup, users may not have that set up, and they
may want to configure the admin/account pages on their public ip's. the auth
rate limiting should make it less of issue.

users can now also only put the account web page publicly available. useful for
if you're the admin and you have a vpn connection, but your other/external
users do not have a vpn into your mail server. to make the account page more
easily findable, the http root serves the account page. the admin page is still
at /admin/, to prevent clash with potential account pages, but if no account
page is present, you are helpfully redirected from / to /admin/.

this also adds a prometheus metric counting how often auth attempts have been
rate limited.
This commit is contained in:
Mechiel Lukkien
2023-02-13 13:53:47 +01:00
parent 2601766c2f
commit ad51ffc365
13 changed files with 154 additions and 64 deletions

View File

@ -6,7 +6,7 @@ import (
)
var (
metricAuthentication = promauto.NewCounterVec(
metricAuth = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "mox_authentication_total",
Help: "Authentication attempts and results.",
@ -18,8 +18,22 @@ var (
"result", // ok, baduser, badpassword, badcreds, error, aborted
},
)
metricAuthRatelimited = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "mox_authentication_ratelimited_total",
Help: "Authentication attempts that were refused due to rate limiting.",
},
[]string{
"kind", // submission, imap, httpaccount, httpadmin
},
)
)
func AuthenticationInc(kind, variant, result string) {
metricAuthentication.WithLabelValues(kind, variant, result).Inc()
metricAuth.WithLabelValues(kind, variant, result).Inc()
}
func AuthenticationRatelimitedInc(kind string) {
metricAuthRatelimited.WithLabelValues(kind).Inc()
}