- Notifications
You must be signed in to change notification settings - Fork912
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Acquire
file in cachefunc (r *RecordingAuthorizer) AssertActor(t *testing.T, actor rbac.Subject, did ...ActionObjectPair) { | ||
r.AssertActorID(t, actor.ID, did...) | ||
} |
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.
what if we just got rid of this function rather than have the indirection? how many instances would we need to fix?
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.
Eh, it is all in a test package. It is kinda convient to callAssertActor
with the subject if you have it:
b:=coderdtest.RandomRBACSubject()bPairs:=fuzzAuthz(t,b,rec,10)rec.AssertActor(t,b,bPairs...)
I would have to dob.ID
. Which is not bad, but sinceID
is just a string, it is not type safe. I don't mind having the extra handle 🤷
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 anrbac.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 anrbac.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.goimports github.com/coder/coder/v2/coderd from authorize.go
I fixed it because it was in ainternal
test, but I had to export thecacheEntryValue
.
If we do our solution discussed in slack, this will be cleaned up.
Uh oh!
There was an error while loading.Please reload this page.
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.
authzAuthorizeFile | |
authorizeAuthorizeFile |
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.
iferr:=c.authz(ctx,subject,policy.ActionRead,it.object);err!=nil { | |
iferr:=c.authorize(ctx,subject,policy.ActionRead,it.object);err!=nil { |
Uh oh!
There was an error while loading.Please reload this page.
This reverts commit2015837.
Uh oh!
There was an error while loading.Please reload this page.
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.