Secure messenger with TLS identities, scoped OpenBao secrets and worker compromise experiments

This commit is contained in:
2026-12-02 17:29:35 +03:00
parent 20afc2c790
commit 047cef4c7f
128 changed files with 10569 additions and 49 deletions
+24
View File
@@ -0,0 +1,24 @@
package messenger
import (
"crypto/sha256"
"fmt"
"net/http"
)
// Shared PG counters, not per-process memory or untrusted forwarding headers.
// Unknown and known usernames use the same hash/bucket and admission rules.
func (s *Server) admitAuth(w http.ResponseWriter, r *http.Request, username string) bool {
key := fmt.Sprintf("%x", sha256.Sum256([]byte(username)))
var allowed bool
if e := s.db.QueryRow(r.Context(), "SELECT auth_admit($1)", key).Scan(&allowed); e != nil {
unavailable(w)
return false
}
if !allowed {
w.Header().Set("Retry-After", "60")
fail(w, 429, "rate_limited", "Authentication rate limit exceeded")
return false
}
return true
}