Skip to content

Commit a9cf8f4

Browse files
committed
Plumb through WithID on rbac objects (complete)
1 parent 257701f commit a9cf8f4

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

coderd/database/modelmethods.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,15 @@ func (f File) RBACObject() rbac.Object {
8383

8484
// RBACObject returns the RBAC object for the site wide user resource.
8585
// If you are trying to get the RBAC object for the UserData, use
86-
// rbac.ResourceUserData
86+
// u.UserDataRBACObject() instead.
8787
func (u User) RBACObject() rbac.Object {
8888
return rbac.ResourceUser.WithID(u.ID)
8989
}
9090

91+
func (u User) UserDataRBACObject() rbac.Object {
92+
return rbac.ResourceUser.WithID(u.ID).WithOwner(u.ID.String())
93+
}
94+
9195
func (License) RBACObject() rbac.Object {
9296
return rbac.ResourceLicense
9397
}

coderd/gitsshkey.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (api *API) regenerateGitSSHKey(rw http.ResponseWriter, r *http.Request) {
3434
)
3535
defer commitAudit()
3636

37-
if !api.Authorize(r, rbac.ActionUpdate, rbac.ResourceUserData.WithOwner(user.ID.String())) {
37+
if !api.Authorize(r, rbac.ActionUpdate, user.UserDataRBACObject()) {
3838
httpapi.ResourceNotFound(rw)
3939
return
4040
}
@@ -93,7 +93,7 @@ func (api *API) gitSSHKey(rw http.ResponseWriter, r *http.Request) {
9393
ctx := r.Context()
9494
user := httpmw.UserParam(r)
9595

96-
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceUserData.WithOwner(user.ID.String())) {
96+
if !api.Authorize(r, rbac.ActionRead, user.UserDataRBACObject()) {
9797
httpapi.ResourceNotFound(rw)
9898
return
9999
}

coderd/users.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func (api *API) userByName(rw http.ResponseWriter, r *http.Request) {
416416
user := httpmw.UserParam(r)
417417
organizationIDs, err := userOrganizationIDs(ctx, api, user)
418418

419-
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceUser) {
419+
if !api.Authorize(r, rbac.ActionRead, user) {
420420
httpapi.ResourceNotFound(rw)
421421
return
422422
}
@@ -457,7 +457,7 @@ func (api *API) putUserProfile(rw http.ResponseWriter, r *http.Request) {
457457
defer commitAudit()
458458
aReq.Old = user
459459

460-
if !api.Authorize(r, rbac.ActionUpdate, rbac.ResourceUser) {
460+
if !api.Authorize(r, rbac.ActionUpdate, user) {
461461
httpapi.ResourceNotFound(rw)
462462
return
463463
}
@@ -563,7 +563,7 @@ func (api *API) putUserStatus(status database.UserStatus) func(rw http.ResponseW
563563
defer commitAudit()
564564
aReq.Old = user
565565

566-
if !api.Authorize(r, rbac.ActionDelete, rbac.ResourceUser) {
566+
if !api.Authorize(r, rbac.ActionDelete, user) {
567567
httpapi.ResourceNotFound(rw)
568568
return
569569
}
@@ -640,7 +640,7 @@ func (api *API) putUserPassword(rw http.ResponseWriter, r *http.Request) {
640640
defer commitAudit()
641641
aReq.Old = user
642642

643-
if !api.Authorize(r, rbac.ActionUpdate, rbac.ResourceUserData.WithOwner(user.ID.String())) {
643+
if !api.Authorize(r, rbac.ActionUpdate, user.UserDataRBACObject()) {
644644
httpapi.ResourceNotFound(rw)
645645
return
646646
}
@@ -665,7 +665,7 @@ func (api *API) putUserPassword(rw http.ResponseWriter, r *http.Request) {
665665

666666
// admins can change passwords without sending old_password
667667
if params.OldPassword == "" {
668-
if !api.Authorize(r, rbac.ActionUpdate, rbac.ResourceUser) {
668+
if !api.Authorize(r, rbac.ActionUpdate, user) {
669669
httpapi.Forbidden(rw)
670670
return
671671
}
@@ -753,7 +753,7 @@ func (api *API) userRoles(rw http.ResponseWriter, r *http.Request) {
753753
ctx := r.Context()
754754
user := httpmw.UserParam(r)
755755

756-
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceUserData.WithOwner(user.ID.String())) {
756+
if !api.Authorize(r, rbac.ActionRead, user.UserDataRBACObject()) {
757757
httpapi.ResourceNotFound(rw)
758758
return
759759
}
@@ -832,7 +832,7 @@ func (api *API) putUserRoles(rw http.ResponseWriter, r *http.Request) {
832832
return
833833
}
834834

835-
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceUser) {
835+
if !api.Authorize(r, rbac.ActionRead, user) {
836836
httpapi.ResourceNotFound(rw)
837837
return
838838
}

enterprise/coderd/workspacequota.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (c *committer) CommitQuota(
110110
func (api *API) workspaceQuota(rw http.ResponseWriter, r *http.Request) {
111111
user := httpmw.UserParam(r)
112112

113-
if !api.AGPL.Authorize(r, rbac.ActionRead, rbac.ResourceUser) {
113+
if !api.AGPL.Authorize(r, rbac.ActionRead, user) {
114114
httpapi.ResourceNotFound(rw)
115115
return
116116
}

0 commit comments

Comments
 (0)