Skip to content

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

Merged
merged 17 commits into from
Jun 16, 2025

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Jun 12, 2025

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.

@Emyrk Emyrk changed the title chore: check proper rbac perms on Acquire file in cache chore: ensure proper rbac permissions on 'Acquire' file in the cache Jun 12, 2025
@Emyrk Emyrk requested a review from aslilac June 12, 2025 19:28
"github.com/coder/coder/v2/coderd/util/lazy"
)

type AuthorizeFile func(ctx context.Context, subject rbac.Subject, action policy.Action, object rbac.Object) error
Copy link
Member

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?

Copy link
Member Author

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.

c9cf780

Copy link
Member Author

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.

@@ -101,6 +111,7 @@ type Cache struct {
lock sync.Mutex
data map[uuid.UUID]*cacheEntry
fetcher
authz AuthorizeFile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
authz AuthorizeFile
authorize AuthorizeFile

Copy link
Member Author

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

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err := c.authz(ctx, subject, policy.ActionRead, it.object); err != nil {
if err := c.authorize(ctx, subject, policy.ActionRead, it.object); err != nil {

@Emyrk Emyrk requested a review from aslilac June 13, 2025 17:36
@Emyrk Emyrk enabled auto-merge (squash) June 15, 2025 22:39
@Emyrk Emyrk merged commit 1d1070d into main Jun 16, 2025
34 checks passed
@Emyrk Emyrk deleted the stevenmasley/file_cache_perms branch June 16, 2025 13:40
@github-actions github-actions bot locked and limited conversation to collaborators Jun 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants