Skip to content

fix: Fix properly selecting workspace apps by agent #3684

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 12 commits into from
Aug 29, 2022
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/main' into stevenmasley/select_a…
…gent
  • Loading branch information
Emyrk committed Aug 26, 2022
commit 48ed5dbef223e9065a2102b00456ccd8a69ef9b3
68 changes: 26 additions & 42 deletions coderd/coderdtest/authtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,23 @@ func NewAuthTester(ctx context.Context, t *testing.T, options *Options) *AuthTes
require.NoError(t, err, "create template param")

urlParameters := map[string]string{
"{organization}": admin.OrganizationID.String(),
"{user}": admin.UserID.String(),
"{organizationname}": organization.Name,
"{workspace}": workspace.ID.String(),
"{workspacebuild}": workspace.LatestBuild.ID.String(),
"{workspacename}": workspace.Name,
"{workspacebuildname}": workspace.LatestBuild.Name,
"{workspaceagent}": workspaceResources[0].Agents[0].ID.String(),
"{buildnumber}": strconv.FormatInt(int64(workspace.LatestBuild.BuildNumber), 10),
"{template}": template.ID.String(),
"{hash}": file.Hash,
"{workspaceresource}": workspaceResources[0].ID.String(),
"{workspaceapp}": workspaceResources[0].Agents[0].Apps[0].Name,
"{templateversion}": version.ID.String(),
"{jobID}": templateVersionDryRun.ID.String(),
"{templatename}": template.Name,
"{organization}": admin.OrganizationID.String(),
"{user}": admin.UserID.String(),
"{organizationname}": organization.Name,
"{workspace}": workspace.ID.String(),
"{workspacebuild}": workspace.LatestBuild.ID.String(),
"{workspacename}": workspace.Name,
"{workspacebuildname}": workspace.LatestBuild.Name,
"{workspaceagent}": workspaceResources[0].Agents[0].ID.String(),
"{buildnumber}": strconv.FormatInt(int64(workspace.LatestBuild.BuildNumber), 10),
"{template}": template.ID.String(),
"{hash}": file.Hash,
"{workspaceresource}": workspaceResources[0].ID.String(),
"{workspaceapp}": workspaceResources[0].Agents[0].Apps[0].Name,
"{templateversion}": version.ID.String(),
"{jobID}": templateVersionDryRun.ID.String(),
"{templatename}": template.Name,
"workspacename_and_agent": workspace.Name + "." + workspaceResources[0].Agents[0].Name,
// Only checking template scoped params here
"parameters/{scope}/{id}": fmt.Sprintf("parameters/%s/%s",
string(templateParam.Scope), templateParam.ScopeID.String()),
Expand Down Expand Up @@ -178,13 +179,13 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
"POST:/api/v2/csp/reports": {NoAuthorize: true},
"GET:/api/v2/entitlements": {NoAuthorize: true},

"GET:/%40{user}/{workspacename_and_agent}/apps/{application}/*": {
AssertAction: rbac.ActionRead,
AssertObject: workspaceRBACObj,
"GET:/%40{user}/{workspacename_and_agent}/apps/{workspaceapp}/*": {
AssertAction: rbac.ActionCreate,
AssertObject: workspaceExecObj,
},
"GET:/@{user}/{workspacename_and_agent}/apps/{application}/*": {
AssertAction: rbac.ActionRead,
AssertObject: workspaceRBACObj,
"GET:/@{user}/{workspacename_and_agent}/apps/{workspaceapp}/*": {
AssertAction: rbac.ActionCreate,
AssertObject: workspaceExecObj,
},

// Has it's own auth
Expand Down Expand Up @@ -454,26 +455,9 @@ func (a *AuthTester) Test(ctx context.Context, assertRoute map[string]RouteCheck
delete(routeMissing, routeKey)

// Replace all url params with known values
route = strings.ReplaceAll(route, "{organization}", a.Admin.OrganizationID.String())
route = strings.ReplaceAll(route, "{user}", a.Admin.UserID.String())
route = strings.ReplaceAll(route, "{organizationname}", a.Organization.Name)
route = strings.ReplaceAll(route, "{workspace}", a.Workspace.ID.String())
route = strings.ReplaceAll(route, "{workspacebuild}", a.Workspace.LatestBuild.ID.String())
route = strings.ReplaceAll(route, "{workspacename}", a.Workspace.Name)
route = strings.ReplaceAll(route, "{workspacename_and_agent}", a.Workspace.Name+"."+a.WorkspaceResource.Agents[0].Name)
route = strings.ReplaceAll(route, "{workspacebuildname}", a.Workspace.LatestBuild.Name)
route = strings.ReplaceAll(route, "{workspaceagent}", a.WorkspaceResource.Agents[0].ID.String())
route = strings.ReplaceAll(route, "{buildnumber}", strconv.FormatInt(int64(a.Workspace.LatestBuild.BuildNumber), 10))
route = strings.ReplaceAll(route, "{template}", a.Template.ID.String())
route = strings.ReplaceAll(route, "{hash}", a.File.Hash)
route = strings.ReplaceAll(route, "{workspaceresource}", a.WorkspaceResource.ID.String())
route = strings.ReplaceAll(route, "{workspaceapp}", a.WorkspaceResource.Agents[0].Apps[0].Name)
route = strings.ReplaceAll(route, "{templateversion}", a.Version.ID.String())
route = strings.ReplaceAll(route, "{templateversiondryrun}", a.TemplateVersionDryRun.ID.String())
route = strings.ReplaceAll(route, "{templatename}", a.Template.Name)
// Only checking template scoped params here
route = strings.ReplaceAll(route, "{scope}", string(a.TemplateParam.Scope))
route = strings.ReplaceAll(route, "{id}", a.TemplateParam.ScopeID.String())
for k, v := range a.URLParams {
route = strings.ReplaceAll(route, k, v)
}

resp, err := a.Client.Request(ctx, method, route, nil)
require.NoError(t, err, "do req")
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.