Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(coderd): add endpoint to list provisioner jobs#16029

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

Merged
mafredri merged 9 commits intomainfrommafredri/feat-coderd-provisioner-jobs-list
Jan 20, 2025

Conversation

mafredri
Copy link
Member

@mafredrimafredri commentedJan 3, 2025
edited
Loading

@mafredrimafredri changed the titlefeat(coderd): add endpoint to list provisioner jobs[2/2] feat(coderd): add endpoint to list provisioner jobsJan 3, 2025
@mafredrimafredri changed the base branch frommain tomafredri/feat-coderd-provisioner-listJanuary 3, 2025 15:48
@mafredrimafredri changed the title[2/2] feat(coderd): add endpoint to list provisioner jobs[2/3] feat(coderd): add endpoint to list provisioner jobsJan 3, 2025
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch 2 times, most recently from664d9b7 to77717c6CompareJanuary 3, 2025 16:08
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-list branch from346ca29 toebaf498CompareJanuary 3, 2025 16:08
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch from77717c6 to90a610aCompareJanuary 3, 2025 16:13
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-list branch 2 times, most recently fromed828f6 to8bee6f5CompareJanuary 3, 2025 16:25
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch 2 times, most recently fromacee984 toad6da75CompareJanuary 3, 2025 16:54
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-list branch from8bee6f5 tod76be47CompareJanuary 3, 2025 16:54
@mafredrimafredri changed the title[2/3] feat(coderd): add endpoint to list provisioner jobsfeat(coderd): add endpoint to list provisioner jobsJan 3, 2025
@mafredri
Copy link
MemberAuthor

mafredri commentedJan 3, 2025
edited
Loading

Would appreciate some rbac/dbauthz pointers here:

=== FAIL: coderd/database/dbauthz TestMethodTestSuite/TestExtraMethods/GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner/NotAuthorized (0.00s)    setup_test.go:250:         Error Trace:/home/runner/work/coder/coder/coderd/database/dbauthz/setup_test.go:250                    /home/runner/go/pkg/mod/github.com/stretchr/testify@v1.10.0/suite/suite.go:115        Error:      An error is expected but got nil.        Test:       TestMethodTestSuite/TestExtraMethods/GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner/NotAuthorized        Messages:   error string should have a good message    setup_test.go:251:         Error Trace:/home/runner/work/coder/coder/coderd/database/dbauthz/setup_test.go:251                    /home/runner/go/pkg/mod/github.com/stretchr/testify@v1.10.0/suite/suite.go:115        Error:      An error is expected but got nil.        Test:       TestMethodTestSuite/TestExtraMethods/GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner/NotAuthorized        Messages:   method should an error with disallow authz    setup_test.go:252:         Error Trace:/home/runner/work/coder/coder/coderd/database/dbauthz/setup_test.go:252                    /home/runner/go/pkg/mod/github.com/stretchr/testify@v1.10.0/suite/suite.go:115        Error:      Should be in error chain:                    expected: %!q(PANIC=Error method: runtime error: invalid memory address or nil pointer dereference)                    in chain:         Test:       TestMethodTestSuite/TestExtraMethods/GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner/NotAuthorized        Messages:   error should be NotAuthorizedError

I'm actually not sure what we should enforce here.

OrganizationID uuid.UUID `json:"organization_id" format:"uuid" table:"organization id"`
Input ProvisionerJobInput `json:"input" table:"input,recursive_inline"`
Type ProvisionerJobType `json:"type" table:"type"`
AvailableWorkers []uuid.UUID `json:"available_workers,omitempty" format:"uuid" table:"available workers"`
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about future use cases, should we transform worker UUIDs into structures?

Copy link
Member

Choose a reason for hiding this comment

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

Fair. You might be able to add some stats about them. Like their tags? Idk

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

The provisioner daemons endpoint (#16028) supports filtering by IDs, so you could request them from there. I don't think we should prematurely add data/structure until we know what/if it's needed.

var input codersdk.ProvisionerJobInput
_ = json.Unmarshal(p.Input, &input) // Best effort.

// TODO(mafredri): Do we need to check provisioner permissions as well (p.AvailableProvisioners?).
Copy link
Member

Choose a reason for hiding this comment

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

The only case I could imagine needing to check the permissions on the provisioner is if you are taking into account user-scoped provisioners{"scope": "user", "owner": "abc123..."}.

The questions I'd raise here are:

  1. Do we want organization members to be able to view provisioners/jobs owned by other users?
  2. Do we want organization members to be able to view provisioners/jobs in other organizations?

For provisionerjobs, the answer for 1) should probably be no, as there may be inputs to provisioners that they're not meant to see.
For provisionerdaemons, I don't think there's as much of a potential for information leakage.

Copy link
Member

Choose a reason for hiding this comment

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

Do we want organization members to be able to view provisioners/jobs owned by other users?

Provisioners are owned by an organization. All org members can read all provisioners today:

// All users can see the provisioner daemons for workspace
// creation.
ResourceProvisionerDaemon.Type: {policy.ActionRead},

We have organizations to isolate provisioners if needed. No more granularity is currently supported.

Seeing other jobs should not be allowed. Checking permission of a list of jobs is a slow process.

Do we want organization members to be able to view provisioners/jobs in other organizations?

no we do not.

Copy link
MemberAuthor

@mafredrimafredriJan 15, 2025
edited
Loading

Choose a reason for hiding this comment

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

I just realized the premise for thisRBACObject is a bit broken. Essentially we would need access to template ID or workspace ID to check user-level permissions, but we only have templateversion ID and workspacebuild ID.

I don't think we want to introduce new RBAC resources for either of these so what would be a good way to solve it? Have a customdatabase.ProvisionerJobWithRBAC or something where we have/join in the required IDs?

Copy link
Member

Choose a reason for hiding this comment

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

@mafredri it is a limitation that we currently have.

template_version inherits the permissions from thetemplate. We do not have a resource for the version. The same is true for theworkspace_build. So you have to fetch the related resource to check the permissions.

To check atemplate_importprovisioner_job, you need to fetch the template version, then the template, then check the perms.

This is done because if you add a new resource, there is no method today to add related permissions. Meaning, you cannot say "If you can read template A, then you can read version B and job C". So without the related permissions, we have to duplicate the perms consistently. Which can lead to bugs, so we just do the data relation fetched 🤷‍♂️

It is a limitation we have today, and I do not see it changing anytime soon.

or something where we have/join in the required IDs

We'd have to go this way. Maybe some newVIEW. Right now we just pay the round trip costs of multiple fetches 😢. I'd support a newVIEW that joins in the right resource IDs if we need it for listing purposes.

johnstcn reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Thanks for the detailed info@Emyrk. For now I decided to limit jobs to owners and template admins as it simplifies the RBAC. I've opened#16160 to track future work improving this. Feel free to post on the issue if I've missed something.

// cc@johnstcn

Copy link
Member

Choose a reason for hiding this comment

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

I do not love leaving this open, but I get it.

As long as we don't break any existing APIs that might fetch a provisioner job today, I can be ok with it.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@Emyrk fair. Most of the existing APIs don't apply any RBAC at all AFAICT, the just call directly out to DB in dbauthz.

The exception isGetProvisionerJobByID fetches workspace/template based on job type, but this one wasn't updated to take into account the newrbac.ResourceProvisionerJobs which would break existing functionality.

Copy link
Member

Choose a reason for hiding this comment

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

Most of the existing APIs don't apply any RBAC at all AFAICT, the just call directly out to DB in dbauthz.

Yup, ideally all RBAC checks live in the dbauthz.

// owner := coderdtest.CreateFirstUser(t, client)
// _, memberUser := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)

db, ps := dbtestutil.NewDB(t, dbtestutil.WithDumpOnFailure())
Copy link
Member

Choose a reason for hiding this comment

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

Disgusting idea: usedbtestutil.NewDBWithSQLDB and just insert the raw rows you want 😅

Emyrk reacted with eyes emoji
OrganizationID uuid.UUID `json:"organization_id" format:"uuid" table:"organization id"`
Input ProvisionerJobInput `json:"input" table:"input,recursive_inline"`
Type ProvisionerJobType `json:"type" table:"type"`
AvailableWorkers []uuid.UUID `json:"available_workers,omitempty" format:"uuid" table:"available workers"`
Copy link
Member

Choose a reason for hiding this comment

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

Fair. You might be able to add some stats about them. Like their tags? Idk

@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-list branch fromd76be47 to0383f34CompareJanuary 13, 2025 13:03
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch fromad6da75 toe4b4e2fCompareJanuary 13, 2025 13:03
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-list branch from0383f34 tobe53b25CompareJanuary 13, 2025 14:05
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch 2 times, most recently fromd967f4b tob1fbc82CompareJanuary 13, 2025 15:32
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-list branch from9d3635f to0bf651bCompareJanuary 13, 2025 15:35
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch froma37b1bd toc924457CompareJanuary 14, 2025 14:41
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-list branch fromf7b1083 tofb4c933CompareJanuary 14, 2025 14:42
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch fromc924457 to9525abdCompareJanuary 14, 2025 14:42
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-list branch fromfb4c933 toaed586bCompareJanuary 14, 2025 14:45
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch from9525abd to51f628cCompareJanuary 14, 2025 14:45
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-list branch fromaed586b to2ad4bb4CompareJanuary 14, 2025 16:21
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch from51f628c to1b40a44CompareJanuary 14, 2025 16:21
Base automatically changed frommafredri/feat-coderd-provisioner-list tomainJanuary 14, 2025 16:40
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch from1b40a44 tob6eb60dCompareJanuary 14, 2025 17:32
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch fromb6eb60d to8d5fca2CompareJanuary 15, 2025 15:50
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch 4 times, most recently fromd0477c6 todd49c08CompareJanuary 16, 2025 12:53
@mafredrimafredriforce-pushed themafredri/feat-coderd-provisioner-jobs-list branch fromdd49c08 to0fd9aa7CompareJanuary 16, 2025 12:54
Copy link
Member

@mtojekmtojek left a comment

Choose a reason for hiding this comment

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

I believe it is in a mergeable state now. Good job!

Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

Nice work! 👍

Comment on lines +50 to +54
var detail string
if e.Err != nil {
detail = ": " + e.Err.Error()
}
return "unauthorized" + detail
Copy link
Member

Choose a reason for hiding this comment

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

Nice 👍

// @Param status query codersdk.ProvisionerJobStatus false "Filter results by status" enums(pending,running,succeeded,canceling,canceled,failed)
// @Success 200 {array} codersdk.ProvisionerJob
// @Router /organizations/{organization}/provisionerjobs [get]
func (api *API) provisionerJobs(rw http.ResponseWriter, r *http.Request) {
Copy link
Member

Choose a reason for hiding this comment

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

nit, non-blocking:organizationProvisionerJobs perhaps?

Comment on lines +47 to +50
if !api.Authorize(r, policy.ActionRead, rbac.ResourceProvisionerJobs.InOrg(org.ID)) {
httpapi.ResourceNotFound(rw)
return
}
Copy link
Member

Choose a reason for hiding this comment

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

👍 This is fine for the moment.

@mafredrimafredri merged commit3864c7e intomainJan 20, 2025
36 checks passed
@mafredrimafredri deleted the mafredri/feat-coderd-provisioner-jobs-list branchJanuary 20, 2025 09:18
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJan 20, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@EmyrkEmyrkEmyrk left review comments

@johnstcnjohnstcnjohnstcn approved these changes

@mtojekmtojekmtojek approved these changes

Assignees

@mafredrimafredri

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Add an API endpoint that lists all provisioner jobs.
4 participants
@mafredri@johnstcn@Emyrk@mtojek

[8]ページ先頭

©2009-2025 Movatter.jp