chore: add x-authz-checks debug header when running in dev mode (#16873)

This commit is contained in:
ケイラ
2025-04-10 10:36:27 -07:00
committed by GitHub
parent 25fb34cabe
commit 46d4b28384
9 changed files with 162 additions and 11 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/go-chi/chi/v5"
"github.com/coder/coder/v2/coderd/database/dbauthz"
"github.com/coder/coder/v2/coderd/rbac"
)
// AsAuthzSystem is a chained handler that temporarily sets the dbauthz context
@ -35,3 +36,15 @@ func AsAuthzSystem(mws ...func(http.Handler) http.Handler) func(http.Handler) ht
})
}
}
// RecordAuthzChecks enables recording all of the authorization checks that
// occurred in the processing of a request. This is mostly helpful for debugging
// and understanding what permissions are required for a given action.
//
// Requires using a Recorder Authorizer.
func RecordAuthzChecks(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
r = r.WithContext(rbac.WithAuthzCheckRecorder(r.Context()))
next.ServeHTTP(rw, r)
})
}