-
Notifications
You must be signed in to change notification settings - Fork 930
chore: ensure proper rbac permissions on 'Acquire' file in the cache #18348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Acquire
file in cache
coderd/files/cache.go
Outdated
"github.com/coder/coder/v2/coderd/util/lazy" | ||
) | ||
|
||
type AuthorizeFile func(ctx context.Context, subject rbac.Subject, action policy.Action, object rbac.Object) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing about this is "file" specific. it takes an rbac.Object
. is this not a type def somewhere already? could we move this to a move general place with a more general name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Actually, I can just pass in an rbac.Authorizer
. Not just the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I did it because it's an import loop
imports github.com/coder/coder/v2/coderd/coderdtest from cache_internal_test.go
imports github.com/coder/coder/v2/coderd from authorize.go
I fixed it because it was in a internal
test, but I had to export the cacheEntryValue
.
If we do our solution discussed in slack, this will be cleaned up.
coderd/files/cache.go
Outdated
@@ -101,6 +111,7 @@ type Cache struct { | |||
lock sync.Mutex | |||
data map[uuid.UUID]*cacheEntry | |||
fetcher | |||
authz AuthorizeFile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
authz AuthorizeFile | |
authorize AuthorizeFile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is now
authz rbac.Authorizer
coderd/files/cache.go
Outdated
return nil, dbauthz.ErrNoActor | ||
} | ||
// Always check the caller can actually read the file. | ||
if err := c.authz(ctx, subject, policy.ActionRead, it.object); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err := c.authz(ctx, subject, policy.ActionRead, it.object); err != nil { | |
if err := c.authorize(ctx, subject, policy.ActionRead, it.object); err != nil { |
This reverts commit 2015837.
Co-authored-by: ケイラ <[email protected]>
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.