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:
Steven Masley
2023-02-15 08:56:07 -06:00
committed by GitHub
parent fac7c02eeb
commit 4cbbd1376d
9 changed files with 61 additions and 9 deletions
+16 -2
View File
@@ -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))
})
}