Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc9cf780

Browse files
committed
just pass the authorizer as a whole
1 parent4256a6c commitc9cf780

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

‎coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ func New(options *Options) *API {
572572
TemplateScheduleStore:options.TemplateScheduleStore,
573573
UserQuietHoursScheduleStore:options.UserQuietHoursScheduleStore,
574574
AccessControlStore:options.AccessControlStore,
575-
FileCache:files.NewFromStore(options.Database,options.PrometheusRegistry,options.Authorizer.Authorize),
575+
FileCache:files.NewFromStore(options.Database,options.PrometheusRegistry,options.Authorizer),
576576
Experiments:experiments,
577577
WebpushDispatcher:options.WebPushDispatcher,
578578
healthCheckGroup:&singleflight.Group[string,*healthsdk.HealthcheckReport]{},

‎coderd/files/cache.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ import (
1919
"github.com/coder/coder/v2/coderd/util/lazy"
2020
)
2121

22-
typeAuthorizeFilefunc(ctx context.Context,subject rbac.Subject,action policy.Action,object rbac.Object)error
23-
2422
// NewFromStore returns a file cache that will fetch files from the provided
2523
// database.
26-
funcNewFromStore(store database.Store,registerer prometheus.Registerer,authzAuthorizeFile)*Cache {
24+
funcNewFromStore(store database.Store,registerer prometheus.Registerer,authzrbac.Authorizer)*Cache {
2725
fetch:=func(ctx context.Context,fileID uuid.UUID) (cacheEntryValue,error) {
2826
// Make sure the read does not fail due to authorization issues.
2927
// Authz is checked on the Acquire call, so this is safe.
@@ -44,7 +42,7 @@ func NewFromStore(store database.Store, registerer prometheus.Registerer, authz
4442
returnNew(fetch,registerer,authz)
4543
}
4644

47-
funcNew(fetchfetcher,registerer prometheus.Registerer,authzAuthorizeFile)*Cache {
45+
funcNew(fetchfetcher,registerer prometheus.Registerer,authzrbac.Authorizer)*Cache {
4846
return (&Cache{
4947
lock: sync.Mutex{},
5048
data:make(map[uuid.UUID]*cacheEntry),
@@ -111,7 +109,7 @@ type Cache struct {
111109
lock sync.Mutex
112110
datamap[uuid.UUID]*cacheEntry
113111
fetcher
114-
authzAuthorizeFile
112+
authzrbac.Authorizer
115113

116114
// metrics
117115
cacheMetrics
@@ -164,7 +162,7 @@ func (c *Cache) Acquire(ctx context.Context, fileID uuid.UUID) (fs.FS, error) {
164162
returnnil,dbauthz.ErrNoActor
165163
}
166164
// Always check the caller can actually read the file.
167-
iferr:=c.authz(ctx,subject,policy.ActionRead,it.object);err!=nil {
165+
iferr:=c.authz.Authorize(ctx,subject,policy.ActionRead,it.object);err!=nil {
168166
c.Release(fileID)
169167
returnnil,err
170168
}

‎coderd/files/cache_internal_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,12 @@ import (
1212
"github.com/stretchr/testify/require"
1313
"golang.org/x/sync/errgroup"
1414

15+
"github.com/coder/coder/v2/coderd/coderdtest"
1516
"github.com/coder/coder/v2/coderd/coderdtest/promhelp"
1617
"github.com/coder/coder/v2/coderd/database/dbauthz"
17-
"github.com/coder/coder/v2/coderd/rbac"
18-
"github.com/coder/coder/v2/coderd/rbac/policy"
1918
"github.com/coder/coder/v2/testutil"
2019
)
2120

22-
funcauthzAlwaysTrue(_ context.Context,_ rbac.Subject,_ policy.Action,_ rbac.Object)error {
23-
returnnil
24-
}
25-
2621
funccachePromMetricName(metricstring)string {
2722
return"coderd_file_cache_"+metric
2823
}
@@ -42,7 +37,7 @@ func TestConcurrency(t *testing.T) {
4237
// will be waiting in line, ensuring that no one duplicated a fetch.
4338
time.Sleep(testutil.IntervalMedium)
4439
returncacheEntryValue{FS:emptyFS,size:fileSize},nil
45-
},reg,authzAlwaysTrue)
40+
},reg,&coderdtest.FakeAuthorizer{})
4641

4742
batches:=1000
4843
groups:=make([]*errgroup.Group,0,batches)
@@ -94,7 +89,7 @@ func TestRelease(t *testing.T) {
9489
FS:emptyFS,
9590
size:fileSize,
9691
},nil
97-
},reg,authzAlwaysTrue)
92+
},reg,&coderdtest.FakeAuthorizer{})
9893

9994
batches:=100
10095
ids:=make([]uuid.UUID,0,batches)

‎coderd/files/cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func cacheAuthzSetup(t *testing.T) (database.Store, *files.Cache, *coderdtest.Re
109109

110110
// Dbauthz wrap the db
111111
db=dbauthz.New(db,rec,logger,coderdtest.AccessControlStorePointer())
112-
c:=files.NewFromStore(db,reg,rec.Authorize)
112+
c:=files.NewFromStore(db,reg,rec)
113113
returndb,c,rec
114114
}
115115

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp