Skip to content

feat(coderd): add filters and fix template for provisioner daemons #16558

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 1 commit into from
Feb 14, 2025

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Feb 13, 2025

This change adds provisioner daemon ID filter to the provisioner daemons
endpoint, and also implements the limiting to 50 results.

Test coverage is greatly improved and template information for jobs
associated to the daemon was also fixed.

Updates #15084
Updates #15192
Related #16532

This change adds provisioner daemon ID filter to the provisioner daemons
endpoint, and also implements the limiting to 50 results.

Test coverage is greatly improved and template information for jobs
associated to the daemon was also fixed.
@mafredri mafredri requested review from johnstcn and BrunoQuaresma and removed request for johnstcn February 13, 2025 18:12
Comment on lines +78 to +93
-- Current job information.
LEFT JOIN
template_versions version ON version.id = (current_job.input->>'template_version_id')::uuid
workspace_builds current_build ON current_build.id = CASE WHEN current_job.input ? 'workspace_build_id' THEN (current_job.input->>'workspace_build_id')::uuid END
LEFT JOIN
templates tmpl ON tmpl.id = version.template_id
-- We should always have a template version, either explicitly or implicitly via workspace build.
template_versions current_version ON current_version.id = CASE WHEN current_job.input ? 'template_version_id' THEN (current_job.input->>'template_version_id')::uuid ELSE current_build.template_version_id END
LEFT JOIN
templates current_template ON current_template.id = current_version.template_id
-- Previous job information.
LEFT JOIN
workspace_builds previous_build ON previous_build.id = CASE WHEN previous_job.input ? 'workspace_build_id' THEN (previous_job.input->>'workspace_build_id')::uuid END
LEFT JOIN
-- We should always have a template version, either explicitly or implicitly via workspace build.
template_versions previous_version ON previous_version.id = CASE WHEN previous_job.input ? 'template_version_id' THEN (previous_job.input->>'template_version_id')::uuid ELSE previous_build.template_version_id END
LEFT JOIN
templates previous_template ON previous_template.id = previous_version.template_id
Copy link
Member Author

@mafredri mafredri Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: I completed this because it was missing some things. But I wonder if we need to take RBAC into consideration now?

The endpoint previously returned a job ID/status only, now it also returns information regarding the template that job is associated with.

This has some implications considering regular members are allowed to view provisioner daemon resources. WDYT @johnstcn?

I'm not particularly fond of it, but we could add the same authorization to the API endpoint as for jobs:

	// For now, only owners and template admins can access provisioner jobs.
	if !api.Authorize(r, policy.ActionRead, rbac.ResourceProvisionerJobs.InOrg(org.ID)) {
		httpapi.ResourceNotFound(rw)
		return nil, false
	}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how sensitive template or template_version fields can be, but a red flag for me would be if this could cross org boundaries.

I think some further questions we need to answer before we can even update the RBAC rules are:

  • Who can view a template import job not linked to any workspace? (Suggestion: anyone who can read the linked template)
  • Who can view a workspace build job? (Suggestion: anyone who can read the linked workspace)

To be safe, I think we should promote the same level of access control as for provisioner jobs for now. We should add a follow-up issue to take provisioner job ownership and template-level ACLs into account.

Does that sound reasonable to you?

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit you nailed the test coverage in this PR :) LGTM but defer the final call to @johnstcn 👍

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good to me 👍 I'm not going to block on the RBAC change you suggested.

Comment on lines +48 to +58
tags := database.StringMap{}
if tagsRaw != "" {
if err := tags.Scan([]byte(tagsRaw)); err != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Invalid tags query parameter",
Detail: err.Error(),
})
return
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking, suggestion: qp.StringMap could be a nice QoL feature to have here!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up implementing that here: #16578

@mafredri
Copy link
Member Author

Thanks for the reviews @johnstcn and @mtojek!

I’ll merge this now to unblock @BrunoQuaresma and follow-up on Monday on both the RBAC change and open an issue for improvements. As well as that qp.StringMap (nice suggestion!)

@mafredri mafredri merged commit 77306f3 into main Feb 14, 2025
37 of 39 checks passed
@mafredri mafredri deleted the mafredri/feat-coderd-provisioner-id-filter branch February 14, 2025 15:26
@github-actions github-actions bot locked and limited conversation to collaborators Feb 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants