mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: ensure proper rbac permissions on 'Acquire' file in the cache (#18348)
The file cache was caching the `Unauthorized` errors if a user without the right perms opened the file first. So all future opens would fail. Now the cache always opens with a subject that can read files. And authz is checked on the Acquire per user.
This commit is contained in:
@ -47,14 +47,14 @@ func APIKey(r *http.Request) database.APIKey {
|
||||
|
||||
// UserAuthorizationOptional may return the roles and scope used for
|
||||
// authorization. Depends on the ExtractAPIKey handler.
|
||||
func UserAuthorizationOptional(r *http.Request) (rbac.Subject, bool) {
|
||||
return dbauthz.ActorFromContext(r.Context())
|
||||
func UserAuthorizationOptional(ctx context.Context) (rbac.Subject, bool) {
|
||||
return dbauthz.ActorFromContext(ctx)
|
||||
}
|
||||
|
||||
// UserAuthorization returns the roles and scope used for authorization. Depends
|
||||
// on the ExtractAPIKey handler.
|
||||
func UserAuthorization(r *http.Request) rbac.Subject {
|
||||
auth, ok := UserAuthorizationOptional(r)
|
||||
func UserAuthorization(ctx context.Context) rbac.Subject {
|
||||
auth, ok := UserAuthorizationOptional(ctx)
|
||||
if !ok {
|
||||
panic("developer error: ExtractAPIKey middleware not provided")
|
||||
}
|
||||
|
Reference in New Issue
Block a user