-
Notifications
You must be signed in to change notification settings - Fork 934
chore(coderd/rbac): add Action{Create,Delete}Agent
to ResourceWorkspace
#17932
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1925,6 +1925,22 @@ func (s *MethodTestSuite) TestWorkspace() { | |
}) | ||
check.Args(ws.ID).Asserts(ws, policy.ActionRead) | ||
})) | ||
s.Run("GetWorkspaceByResourceID", s.Subtest(func(db database.Store, check *expects) { | ||
u := dbgen.User(s.T(), db, database.User{}) | ||
o := dbgen.Organization(s.T(), db, database.Organization{}) | ||
j := dbgen.ProvisionerJob(s.T(), db, nil, database.ProvisionerJob{Type: database.ProvisionerJobTypeWorkspaceBuild}) | ||
tpl := dbgen.Template(s.T(), db, database.Template{CreatedBy: u.ID, OrganizationID: o.ID}) | ||
tv := dbgen.TemplateVersion(s.T(), db, database.TemplateVersion{ | ||
TemplateID: uuid.NullUUID{UUID: tpl.ID, Valid: true}, | ||
JobID: j.ID, | ||
OrganizationID: o.ID, | ||
CreatedBy: u.ID, | ||
}) | ||
ws := dbgen.Workspace(s.T(), db, database.WorkspaceTable{OwnerID: u.ID, TemplateID: tpl.ID, OrganizationID: o.ID}) | ||
_ = dbgen.WorkspaceBuild(s.T(), db, database.WorkspaceBuild{WorkspaceID: ws.ID, JobID: j.ID, TemplateVersionID: tv.ID}) | ||
res := dbgen.WorkspaceResource(s.T(), db, database.WorkspaceResource{JobID: j.ID}) | ||
check.Args(res.ID).Asserts(ws, policy.ActionRead) | ||
})) | ||
s.Run("GetWorkspaces", s.Subtest(func(_ database.Store, check *expects) { | ||
// No asserts here because SQLFilter. | ||
check.Args(database.GetWorkspacesParams{}).Asserts() | ||
|
@@ -4016,12 +4032,25 @@ func (s *MethodTestSuite) TestSystemFunctions() { | |
Returns(slice.New(a, b)) | ||
})) | ||
s.Run("InsertWorkspaceAgent", s.Subtest(func(db database.Store, check *expects) { | ||
dbtestutil.DisableForeignKeysAndTriggers(s.T(), db) | ||
u := dbgen.User(s.T(), db, database.User{}) | ||
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. Can we also add a test to validate:
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. Sure thing! |
||
o := dbgen.Organization(s.T(), db, database.Organization{}) | ||
j := dbgen.ProvisionerJob(s.T(), db, nil, database.ProvisionerJob{Type: database.ProvisionerJobTypeWorkspaceBuild}) | ||
tpl := dbgen.Template(s.T(), db, database.Template{CreatedBy: u.ID, OrganizationID: o.ID}) | ||
tv := dbgen.TemplateVersion(s.T(), db, database.TemplateVersion{ | ||
TemplateID: uuid.NullUUID{UUID: tpl.ID, Valid: true}, | ||
JobID: j.ID, | ||
OrganizationID: o.ID, | ||
CreatedBy: u.ID, | ||
}) | ||
ws := dbgen.Workspace(s.T(), db, database.WorkspaceTable{OwnerID: u.ID, TemplateID: tpl.ID, OrganizationID: o.ID}) | ||
_ = dbgen.WorkspaceBuild(s.T(), db, database.WorkspaceBuild{WorkspaceID: ws.ID, JobID: j.ID, TemplateVersionID: tv.ID}) | ||
res := dbgen.WorkspaceResource(s.T(), db, database.WorkspaceResource{JobID: j.ID}) | ||
check.Args(database.InsertWorkspaceAgentParams{ | ||
ID: uuid.New(), | ||
ResourceID: res.ID, | ||
Name: "dev", | ||
APIKeyScope: database.AgentKeyScopeEnumAll, | ||
}).Asserts(rbac.ResourceSystem, policy.ActionCreate) | ||
}).Asserts(ws, policy.ActionCreateAgent) | ||
})) | ||
s.Run("InsertWorkspaceApp", s.Subtest(func(db database.Store, check *expects) { | ||
dbtestutil.DisableForeignKeysAndTriggers(s.T(), db) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
If the err is
sql.ErrNoRows
, then this requires site wide permission. So onlyowner
,system
, andprovisioner
can do it. Is that ok?What does it mean to insert a workspace agent without a workspace build?
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.
With regards to our current test infrastructure, this happens quite often:
Unfortunately there is no way we can link back the resource to the workspace. We could always rewrite these tests but that might be a big change.
Another situation where this goes wrong is with workspace templates:
When attempting to update a workspace template, it will fail the job because it cannot insert a workspace agent. I'm not entirely sure why
InsertWorkspaceAgent
is invoked for the "Build" template flow but that is an example of where I don't think we have an actual workspace to link back to.