chore: add global caching to rbac (#7439)

Co-authored-by: Steven Masley <stevenmasley@coder.com>
This commit is contained in:
Ammar Bandukwala
2023-05-08 08:59:01 -05:00
committed by GitHub
parent 643a9efea9
commit 8899dd89ca
13 changed files with 121 additions and 125 deletions

View File

@ -6,7 +6,6 @@ import (
"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
@ -36,16 +35,3 @@ 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))
})
}