-
Notifications
You must be signed in to change notification settings - Fork 905
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 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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4da9a94
refactor(dbauthz): add authz for system-level functions
johnstcn a11fed5
replace short names
johnstcn 6f40cf6
fix: add dbauthz.AsSystemRestricted in updatecheck, when creating fir…
johnstcn 7fd66f4
replicasync: use dbauthz.AsSystemRestricted for system funcs
johnstcn 2a0746d
make linter happy
johnstcn 970b717
add required authz system inovcations in enterprise/coderd
johnstcn e5a7cad
dbauthz: move GetUsersByIDs out of system, modify RBAC check to Resou…
johnstcn 29f1d5d
fix updatecheck
johnstcn 8a975fc
avoid index out of bounds in api.workspaceBuild
johnstcn 018b804
use dbauthz system in workspaceBuildsData
johnstcn 7ecb2f0
remove system auth requirement on provisionerjob / provisionerdaemon …
johnstcn 14a25a6
Add dbauthz system to api.provisionerJobResources
johnstcn 177cbe1
workspaceapps: add test case for when owner of app is not found
johnstcn 3a003e7
replicasync: use dbauthz system ctx directly in package instead of pa…
johnstcn ebd0ef5
fix tabs vs spaces
johnstcn 116613e
Merge remote-tracking branch 'origin/main' into cj/dbauthz-system
johnstcn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("GetProvisionerJobsByIDs", s.Subtest(func(db database.Store, check *expects) { | ||
a := dbgen.ProvisionerJob(s.T(), db, database.ProvisionerJob{}) | ||
b := dbgen.ProvisionerJob(s.T(), db, database.ProvisionerJob{}) | ||
check.Args([]uuid.UUID{a.ID, b.ID}).Asserts().Returns(slice.New(a, b)) | ||
})) | ||
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("GetTemplateVersionsByIDs", s.Subtest(func(db database.Store, check *expects) { | ||
t1 := dbgen.Template(s.T(), db, database.Template{}) | ||
t2 := dbgen.Template(s.T(), db, database.Template{}) | ||
tv1 := dbgen.TemplateVersion(s.T(), db, database.TemplateVersion{ | ||
TemplateID: uuid.NullUUID{UUID: t1.ID, Valid: true}, | ||
}) | ||
tv2 := dbgen.TemplateVersion(s.T(), db, database.TemplateVersion{ | ||
TemplateID: uuid.NullUUID{UUID: t2.ID, Valid: true}, | ||
}) | ||
tv3 := dbgen.TemplateVersion(s.T(), db, database.TemplateVersion{ | ||
TemplateID: uuid.NullUUID{UUID: t2.ID, Valid: true}, | ||
}) | ||
check.Args([]uuid.UUID{tv1.ID, tv2.ID, tv3.ID}). | ||
Asserts( /*t1, rbac.ActionRead, t2, rbac.ActionRead*/ ). | ||
Returns(slice.New(tv1, tv2, tv3)) | ||
})) | ||
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("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("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("GetWorkspaceAgentsByResourceIDs", 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()}) | ||
res := dbgen.WorkspaceResource(s.T(), db, database.WorkspaceResource{JobID: build.JobID}) | ||
agt := dbgen.WorkspaceAgent(s.T(), db, database.WorkspaceAgent{ResourceID: res.ID}) | ||
check.Args([]uuid.UUID{res.ID}).Asserts( /*ws, rbac.ActionRead*/ ). | ||
Returns([]database.WorkspaceAgent{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("GetWorkspaceAppsByAgentIDs", s.Subtest(func(db database.Store, check *expects) { | ||
aWs := dbgen.Workspace(s.T(), db, database.Workspace{}) | ||
aBuild := dbgen.WorkspaceBuild(s.T(), db, database.WorkspaceBuild{WorkspaceID: aWs.ID, JobID: uuid.New()}) | ||
aRes := dbgen.WorkspaceResource(s.T(), db, database.WorkspaceResource{JobID: aBuild.JobID}) | ||
aAgt := dbgen.WorkspaceAgent(s.T(), db, database.WorkspaceAgent{ResourceID: aRes.ID}) | ||
a := dbgen.WorkspaceApp(s.T(), db, database.WorkspaceApp{AgentID: aAgt.ID}) | ||
|
||
bWs := dbgen.Workspace(s.T(), db, database.Workspace{}) | ||
bBuild := dbgen.WorkspaceBuild(s.T(), db, database.WorkspaceBuild{WorkspaceID: bWs.ID, JobID: uuid.New()}) | ||
bRes := dbgen.WorkspaceResource(s.T(), db, database.WorkspaceResource{JobID: bBuild.JobID}) | ||
bAgt := dbgen.WorkspaceAgent(s.T(), db, database.WorkspaceAgent{ResourceID: bRes.ID}) | ||
b := dbgen.WorkspaceApp(s.T(), db, database.WorkspaceApp{AgentID: bAgt.ID}) | ||
|
||
check.Args([]uuid.UUID{a.AgentID, b.AgentID}). | ||
Asserts( /*aWs, rbac.ActionRead, bWs, rbac.ActionRead*/ ). | ||
Returns([]database.WorkspaceApp{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("GetWorkspaceResourceMetadataByResourceIDs", 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()}) | ||
_ = dbgen.ProvisionerJob(s.T(), db, database.ProvisionerJob{ID: build.JobID, Type: database.ProvisionerJobTypeWorkspaceBuild}) | ||
a := dbgen.WorkspaceResource(s.T(), db, database.WorkspaceResource{JobID: build.JobID}) | ||
b := dbgen.WorkspaceResource(s.T(), db, database.WorkspaceResource{JobID: build.JobID}) | ||
check.Args([]uuid.UUID{a.ID, b.ID}). | ||
Asserts( /*ws, []rbac.Action{rbac.ActionRead, rbac.ActionRead}*/ ) | ||
})) | ||
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("GetWorkspaceResourcesByJobIDs", s.Subtest(func(db database.Store, check *expects) { | ||
tpl := dbgen.Template(s.T(), db, database.Template{}) | ||
v := dbgen.TemplateVersion(s.T(), db, database.TemplateVersion{TemplateID: uuid.NullUUID{UUID: tpl.ID, Valid: true}, JobID: uuid.New()}) | ||
tJob := dbgen.ProvisionerJob(s.T(), db, database.ProvisionerJob{ID: v.JobID, Type: database.ProvisionerJobTypeTemplateVersionImport}) | ||
|
||
ws := dbgen.Workspace(s.T(), db, database.Workspace{}) | ||
build := dbgen.WorkspaceBuild(s.T(), db, database.WorkspaceBuild{WorkspaceID: ws.ID, JobID: uuid.New()}) | ||
wJob := dbgen.ProvisionerJob(s.T(), db, database.ProvisionerJob{ID: build.JobID, Type: database.ProvisionerJobTypeWorkspaceBuild}) | ||
check.Args([]uuid.UUID{tJob.ID, wJob.ID}). | ||
Asserts( /*v.RBACObject(tpl), rbac.ActionRead, ws, 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{}) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Fair 👍.