feat(api-keys): implement DenyAPIKeyPrincipal middleware and related tests

Add DenyAPIKeyPrincipal middleware to explicitly block API-key principals from accessing certain routes, ensuring security for endpoints outside the /api/v1 group. Introduce tests to validate that API keys are correctly denied access while allowing JWT sessions to pass through. This enhances the overall authorization model by reinforcing the default-deny approach for API keys.
This commit is contained in:
wizardchen
2026-07-06 17:57:50 +08:00
committed by lyingbug
parent d2ffc1b973
commit a6759d61b5
3 changed files with 68 additions and 0 deletions
+5
View File
@@ -1668,7 +1668,12 @@ func servePresignedPreview(r *gin.Engine, cfg *config.Config) {
}
absDir, _ := filepath.Abs(baseDir)
// This route is registered on the engine root, NOT the /api/v1 group,
// so the APIKeyGate never runs for it. RequireRole short-circuits
// API-key principals (deferring to that absent gate), which would let
// any valid key past the Admin check. Deny API keys explicitly first.
r.GET("/api/v1/files/presigned-preview",
middleware.DenyAPIKeyPrincipal(),
middleware.RequireRole(types.TenantRoleAdmin, cfg),
func(c *gin.Context) {
ctx := c.Request.Context()