mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
refactor: consolidate template and workspace acl validation (#19192)
This commit is contained in:
@@ -5376,6 +5376,26 @@ func (q *querier) UpsertWorkspaceAppAuditSession(ctx context.Context, arg databa
|
||||
return q.db.UpsertWorkspaceAppAuditSession(ctx, arg)
|
||||
}
|
||||
|
||||
func (q *querier) ValidateGroupIDs(ctx context.Context, groupIDs []uuid.UUID) (database.ValidateGroupIDsRow, error) {
|
||||
// This check is probably overly restrictive, but the "correct" check isn't
|
||||
// necessarily obvious. It's only used as a verification check for ACLs right
|
||||
// now, which are performed as system.
|
||||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
|
||||
return database.ValidateGroupIDsRow{}, err
|
||||
}
|
||||
return q.db.ValidateGroupIDs(ctx, groupIDs)
|
||||
}
|
||||
|
||||
func (q *querier) ValidateUserIDs(ctx context.Context, userIDs []uuid.UUID) (database.ValidateUserIDsRow, error) {
|
||||
// This check is probably overly restrictive, but the "correct" check isn't
|
||||
// necessarily obvious. It's only used as a verification check for ACLs right
|
||||
// now, which are performed as system.
|
||||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
|
||||
return database.ValidateUserIDsRow{}, err
|
||||
}
|
||||
return q.db.ValidateUserIDs(ctx, userIDs)
|
||||
}
|
||||
|
||||
func (q *querier) GetAuthorizedTemplates(ctx context.Context, arg database.GetTemplatesWithFilterParams, _ rbac.PreparedAuthorized) ([]database.Template, error) {
|
||||
// TODO Delete this function, all GetTemplates should be authorized. For now just call getTemplates on the authz querier.
|
||||
return q.GetTemplatesWithFilter(ctx, arg)
|
||||
|
||||
@@ -623,6 +623,11 @@ func (s *MethodTestSuite) TestGroup() {
|
||||
ID: g.ID,
|
||||
}).Asserts(g, policy.ActionUpdate)
|
||||
}))
|
||||
s.Run("ValidateGroupIDs", s.Subtest(func(db database.Store, check *expects) {
|
||||
o := dbgen.Organization(s.T(), db, database.Organization{})
|
||||
g := dbgen.Group(s.T(), db, database.Group{OrganizationID: o.ID})
|
||||
check.Args([]uuid.UUID{g.ID}).Asserts(rbac.ResourceSystem, policy.ActionRead)
|
||||
}))
|
||||
}
|
||||
|
||||
func (s *MethodTestSuite) TestProvisionerJob() {
|
||||
@@ -2077,6 +2082,10 @@ func (s *MethodTestSuite) TestUser() {
|
||||
Interval: int32((time.Hour * 24).Seconds()),
|
||||
}).Asserts(rbac.ResourceUser, policy.ActionRead)
|
||||
}))
|
||||
s.Run("ValidateUserIDs", s.Subtest(func(db database.Store, check *expects) {
|
||||
u := dbgen.User(s.T(), db, database.User{})
|
||||
check.Args([]uuid.UUID{u.ID}).Asserts(rbac.ResourceSystem, policy.ActionRead)
|
||||
}))
|
||||
}
|
||||
|
||||
func (s *MethodTestSuite) TestWorkspace() {
|
||||
|
||||
Reference in New Issue
Block a user