Harden API-key model: per-key scoping + revocable keys, and configurable/whitelist-aware rate limiting (#16)

* API scope and rate limiting

* improvements from review
This commit is contained in:
Thijs Herman authored and GitHub committed 2026-05-28 11:45:16 +02:00
1 parent a400e07ae2
commit 495edffde3
11 files changed
+843 -42

No files matched your search

+7 -2
View File
@@ -107,14 +107,19 @@ func main() {
api := app.Group("/")
api.Use(ipWhitelist.Middleware())
api.Use(limiter.New(limiter.Config{
Max: 30,
Max: cfg.RateLimitMax,
Expiration: cfg.RateLimitWindow,
// Whitelisted/trusted IPs bypass rate limiting entirely.
Next: func(c *fiber.Ctx) bool {
return ipWhitelist.IsAllowed(c.IP())
},
LimitReached: func(c *fiber.Ctx) error {
return c.Status(fiber.StatusTooManyRequests).JSON(fiber.Map{
"error": "too many requests, please slow down",
})
},
}))
api.Use(auth.Middleware(cfg.APIKey))
api.Use(auth.Middleware(auth.NewStore(cfg.APIKeys)))
api.Get("/secret/:name", h.GetSecret)
api.Post("/refresh", h.RefreshCache)