mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Turn on rbac check caching (#6202)
* chore: Turn on rbac check caching. Should not affect much unless authz_querier experiment is enabled
This commit is contained in:
+16
-2
@@ -3,9 +3,10 @@ package httpmw
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/coder/coder/coderd/database/dbauthz"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"github.com/coder/coder/coderd/database/dbauthz"
|
||||
"github.com/coder/coder/coderd/rbac"
|
||||
)
|
||||
|
||||
// AsAuthzSystem is a chained handler that temporarily sets the dbauthz context
|
||||
@@ -35,3 +36,16 @@ func AsAuthzSystem(mws ...func(http.Handler) http.Handler) func(http.Handler) ht
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// AttachAuthzCache enables the authz cache for the authorizer. All rbac checks will
|
||||
// run against the cache, meaning duplicate checks will not be performed.
|
||||
//
|
||||
// Note the cache is safe for multiple actors. So mixing user and system checks
|
||||
// is ok.
|
||||
func AttachAuthzCache(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
ctx := rbac.WithCacheCtx(r.Context())
|
||||
|
||||
next.ServeHTTP(rw, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user