@@ -20,6 +20,7 @@ import (
20
20
"github.com/coder/coder/v2/coderd/database"
21
21
"github.com/coder/coder/v2/coderd/database/dbauthz"
22
22
"github.com/coder/coder/v2/coderd/rbac"
23
+ "github.com/coder/coder/v2/coderd/rbac/policy"
23
24
"github.com/coder/coder/v2/coderd/rbac/regosql"
24
25
"github.com/coder/coder/v2/codersdk"
25
26
"github.com/coder/coder/v2/cryptorand"
@@ -84,7 +85,7 @@ func (a RBACAsserter) AllCalls() []AuthCall {
84
85
// AssertChecked will assert a given rbac check was performed. It does not care
85
86
// about order of checks, or any other checks. This is useful when you do not
86
87
// care about asserting every check that was performed.
87
- func (a RBACAsserter ) AssertChecked (t * testing.T , action rbac .Action , objects ... interface {}) {
88
+ func (a RBACAsserter ) AssertChecked (t * testing.T , action policy .Action , objects ... interface {}) {
88
89
converted := a .convertObjects (t , objects ... )
89
90
pairs := make ([]ActionObjectPair , 0 , len (converted ))
90
91
for _ , obj := range converted {
@@ -95,7 +96,7 @@ func (a RBACAsserter) AssertChecked(t *testing.T, action rbac.Action, objects ..
95
96
96
97
// AssertInOrder must be called in the correct order of authz checks. If the objects
97
98
// or actions are not in the correct order, the test will fail.
98
- func (a RBACAsserter ) AssertInOrder (t * testing.T , action rbac .Action , objects ... interface {}) {
99
+ func (a RBACAsserter ) AssertInOrder (t * testing.T , action policy .Action , objects ... interface {}) {
99
100
converted := a .convertObjects (t , objects ... )
100
101
pairs := make ([]ActionObjectPair , 0 , len (converted ))
101
102
for _ , obj := range converted {
@@ -155,13 +156,13 @@ type RecordingAuthorizer struct {
155
156
}
156
157
157
158
type ActionObjectPair struct {
158
- Action rbac .Action
159
+ Action policy .Action
159
160
Object rbac.Object
160
161
}
161
162
162
163
// Pair is on the RecordingAuthorizer to be easy to find and keep the pkg
163
164
// interface smaller.
164
- func (* RecordingAuthorizer ) Pair (action rbac .Action , object rbac.Objecter ) ActionObjectPair {
165
+ func (* RecordingAuthorizer ) Pair (action policy .Action , object rbac.Objecter ) ActionObjectPair {
165
166
return ActionObjectPair {
166
167
Action : action ,
167
168
Object : object .RBACObject (),
@@ -248,7 +249,7 @@ func (r *RecordingAuthorizer) AssertActor(t *testing.T, actor rbac.Subject, did
248
249
}
249
250
250
251
// recordAuthorize is the internal method that records the Authorize() call.
251
- func (r * RecordingAuthorizer ) recordAuthorize (subject rbac.Subject , action rbac .Action , object rbac.Object ) {
252
+ func (r * RecordingAuthorizer ) recordAuthorize (subject rbac.Subject , action policy .Action , object rbac.Object ) {
252
253
r .Lock ()
253
254
defer r .Unlock ()
254
255
@@ -283,15 +284,15 @@ func caller(skip int) string {
283
284
return str
284
285
}
285
286
286
- func (r * RecordingAuthorizer ) Authorize (ctx context.Context , subject rbac.Subject , action rbac .Action , object rbac.Object ) error {
287
+ func (r * RecordingAuthorizer ) Authorize (ctx context.Context , subject rbac.Subject , action policy .Action , object rbac.Object ) error {
287
288
r .recordAuthorize (subject , action , object )
288
289
if r .Wrapped == nil {
289
290
panic ("Developer error: RecordingAuthorizer.Wrapped is nil" )
290
291
}
291
292
return r .Wrapped .Authorize (ctx , subject , action , object )
292
293
}
293
294
294
- func (r * RecordingAuthorizer ) Prepare (ctx context.Context , subject rbac.Subject , action rbac .Action , objectType string ) (rbac.PreparedAuthorized , error ) {
295
+ func (r * RecordingAuthorizer ) Prepare (ctx context.Context , subject rbac.Subject , action policy .Action , objectType string ) (rbac.PreparedAuthorized , error ) {
295
296
r .RLock ()
296
297
defer r .RUnlock ()
297
298
if r .Wrapped == nil {
@@ -325,7 +326,7 @@ type PreparedRecorder struct {
325
326
rec * RecordingAuthorizer
326
327
prepped rbac.PreparedAuthorized
327
328
subject rbac.Subject
328
- action rbac .Action
329
+ action policy .Action
329
330
330
331
rw sync.Mutex
331
332
usingSQL bool
@@ -357,11 +358,11 @@ type FakeAuthorizer struct {
357
358
358
359
var _ rbac.Authorizer = (* FakeAuthorizer )(nil )
359
360
360
- func (d * FakeAuthorizer ) Authorize (_ context.Context , _ rbac.Subject , _ rbac .Action , _ rbac.Object ) error {
361
+ func (d * FakeAuthorizer ) Authorize (_ context.Context , _ rbac.Subject , _ policy .Action , _ rbac.Object ) error {
361
362
return d .AlwaysReturn
362
363
}
363
364
364
- func (d * FakeAuthorizer ) Prepare (_ context.Context , subject rbac.Subject , action rbac .Action , _ string ) (rbac.PreparedAuthorized , error ) {
365
+ func (d * FakeAuthorizer ) Prepare (_ context.Context , subject rbac.Subject , action policy .Action , _ string ) (rbac.PreparedAuthorized , error ) {
365
366
return & fakePreparedAuthorizer {
366
367
Original : d ,
367
368
Subject : subject ,
@@ -377,7 +378,7 @@ type fakePreparedAuthorizer struct {
377
378
sync.RWMutex
378
379
Original * FakeAuthorizer
379
380
Subject rbac.Subject
380
- Action rbac .Action
381
+ Action policy .Action
381
382
}
382
383
383
384
func (f * fakePreparedAuthorizer ) Authorize (ctx context.Context , object rbac.Object ) error {
@@ -392,7 +393,7 @@ func (*fakePreparedAuthorizer) CompileToSQL(_ context.Context, _ regosql.Convert
392
393
393
394
// Random rbac helper funcs
394
395
395
- func RandomRBACAction () rbac .Action {
396
+ func RandomRBACAction () policy .Action {
396
397
all := rbac .AllActions ()
397
398
return all [must (cryptorand .Intn (len (all )))]
398
399
}
@@ -403,10 +404,10 @@ func RandomRBACObject() rbac.Object {
403
404
Owner : uuid .NewString (),
404
405
OrgID : uuid .NewString (),
405
406
Type : randomRBACType (),
406
- ACLUserList : map [string ][]rbac .Action {
407
+ ACLUserList : map [string ][]policy .Action {
407
408
namesgenerator .GetRandomName (1 ): {RandomRBACAction ()},
408
409
},
409
- ACLGroupList : map [string ][]rbac .Action {
410
+ ACLGroupList : map [string ][]policy .Action {
410
411
namesgenerator .GetRandomName (1 ): {RandomRBACAction ()},
411
412
},
412
413
}
0 commit comments