- Notifications
You must be signed in to change notification settings - Fork927
refactor(dbauthz): add authz for system-level functions#6513
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
4da9a94
a11fed5
6f40cf6
7fd66f4
2a0746d
970b717
e5a7cad
29f1d5d
8a975fc
018b804
7ecb2f0
14a25a6
177cbe1
3a003e7
ebd0ef5
116613e
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -963,6 +963,18 @@ func (q *querier) GetUserByID(ctx context.Context, id uuid.UUID) (database.User, | ||
return fetch(q.log, q.auth, q.db.GetUserByID)(ctx, id) | ||
} | ||
// GetUsersByIDs is only used for usernames on workspace return data. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Note: Moved this to querier from system and set a simple authz check here. I can move it back to system but it's probably better to use rbac.ResourceUser here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Fair 👍. | ||
// This function should be replaced by joining this data to the workspace query | ||
// itself. | ||
func (q *querier) GetUsersByIDs(ctx context.Context, ids []uuid.UUID) ([]database.User, error) { | ||
for _, uid := range ids { | ||
if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceUser.WithID(uid)); err != nil { | ||
return nil, err | ||
} | ||
} | ||
return q.db.GetUsersByIDs(ctx, ids) | ||
} | ||
func (q *querier) GetAuthorizedUserCount(ctx context.Context, arg database.GetFilteredUserCountParams, prepared rbac.PreparedAuthorized) (int64, error) { | ||
return q.db.GetAuthorizedUserCount(ctx, arg, prepared) | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -282,11 +282,6 @@ func (s *MethodTestSuite) TestProvsionerJob() { | ||
check.Args(database.UpdateProvisionerJobWithCancelByIDParams{ID: j.ID}). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Note: most of the changes here are just moving the respective tests to | ||
Asserts(v.RBACObject(tpl), []rbac.Action{rbac.ActionRead, rbac.ActionUpdate}).Returns() | ||
})) | ||
s.Run("GetProvisionerLogsByIDBetween", s.Subtest(func(db database.Store, check *expects) { | ||
w := dbgen.Workspace(s.T(), db, database.Workspace{}) | ||
j := dbgen.ProvisionerJob(s.T(), db, database.ProvisionerJob{ | ||
@@ -619,22 +614,6 @@ func (s *MethodTestSuite) TestTemplate() { | ||
}) | ||
check.Args(tv.ID).Asserts(t1, rbac.ActionRead).Returns(tv) | ||
})) | ||
s.Run("GetTemplateVersionsByTemplateID", s.Subtest(func(db database.Store, check *expects) { | ||
t1 := dbgen.Template(s.T(), db, database.Template{}) | ||
a := dbgen.TemplateVersion(s.T(), db, database.TemplateVersion{ | ||
@@ -784,6 +763,13 @@ func (s *MethodTestSuite) TestUser() { | ||
u := dbgen.User(s.T(), db, database.User{}) | ||
check.Args(u.ID).Asserts(u, rbac.ActionRead).Returns(u) | ||
})) | ||
s.Run("GetUsersByIDs", s.Subtest(func(db database.Store, check *expects) { | ||
a := dbgen.User(s.T(), db, database.User{CreatedAt: database.Now().Add(-time.Hour)}) | ||
b := dbgen.User(s.T(), db, database.User{CreatedAt: database.Now()}) | ||
check.Args([]uuid.UUID{a.ID, b.ID}). | ||
Asserts(a, rbac.ActionRead, b, rbac.ActionRead). | ||
Returns(slice.New(a, b)) | ||
})) | ||
s.Run("GetAuthorizedUserCount", s.Subtest(func(db database.Store, check *expects) { | ||
_ = dbgen.User(s.T(), db, database.User{}) | ||
check.Args(database.GetFilteredUserCountParams{}, emptyPreparedAuthorized{}).Asserts().Returns(int64(1)) | ||
@@ -803,13 +789,6 @@ func (s *MethodTestSuite) TestUser() { | ||
b := dbgen.User(s.T(), db, database.User{CreatedAt: database.Now()}) | ||
check.Args(database.GetUsersParams{}).Asserts(a, rbac.ActionRead, b, rbac.ActionRead) | ||
})) | ||
s.Run("InsertUser", s.Subtest(func(db database.Store, check *expects) { | ||
check.Args(database.InsertUserParams{ | ||
ID: uuid.New(), | ||
@@ -977,14 +956,6 @@ func (s *MethodTestSuite) TestWorkspace() { | ||
agt := dbgen.WorkspaceAgent(s.T(), db, database.WorkspaceAgent{ResourceID: res.ID}) | ||
check.Args(agt.AuthInstanceID.String).Asserts(ws, rbac.ActionRead).Returns(agt) | ||
})) | ||
s.Run("UpdateWorkspaceAgentLifecycleStateByID", s.Subtest(func(db database.Store, check *expects) { | ||
ws := dbgen.Workspace(s.T(), db, database.Workspace{}) | ||
build := dbgen.WorkspaceBuild(s.T(), db, database.WorkspaceBuild{WorkspaceID: ws.ID, JobID: uuid.New()}) | ||
@@ -1026,23 +997,6 @@ func (s *MethodTestSuite) TestWorkspace() { | ||
check.Args(agt.ID).Asserts(ws, rbac.ActionRead).Returns(slice.New(a, b)) | ||
})) | ||
s.Run("GetWorkspaceBuildByID", s.Subtest(func(db database.Store, check *expects) { | ||
ws := dbgen.Workspace(s.T(), db, database.Workspace{}) | ||
build := dbgen.WorkspaceBuild(s.T(), db, database.WorkspaceBuild{WorkspaceID: ws.ID}) | ||
@@ -1096,15 +1050,6 @@ func (s *MethodTestSuite) TestWorkspace() { | ||
res := dbgen.WorkspaceResource(s.T(), db, database.WorkspaceResource{JobID: build.JobID}) | ||
check.Args(res.ID).Asserts(ws, rbac.ActionRead).Returns(res) | ||
})) | ||
s.Run("Build/GetWorkspaceResourcesByJobID", s.Subtest(func(db database.Store, check *expects) { | ||
ws := dbgen.Workspace(s.T(), db, database.Workspace{}) | ||
build := dbgen.WorkspaceBuild(s.T(), db, database.WorkspaceBuild{WorkspaceID: ws.ID, JobID: uuid.New()}) | ||
@@ -1117,18 +1062,6 @@ func (s *MethodTestSuite) TestWorkspace() { | ||
job := dbgen.ProvisionerJob(s.T(), db, database.ProvisionerJob{ID: v.JobID, Type: database.ProvisionerJobTypeTemplateVersionImport}) | ||
check.Args(job.ID).Asserts(v.RBACObject(tpl), []rbac.Action{rbac.ActionRead, rbac.ActionRead}).Returns([]database.WorkspaceResource{}) | ||
})) | ||
s.Run("InsertWorkspace", s.Subtest(func(db database.Store, check *expects) { | ||
u := dbgen.User(s.T(), db, database.User{}) | ||
o := dbgen.Organization(s.T(), db, database.Organization{}) | ||
Uh oh!
There was an error while loading.Please reload this page.