You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: update the project or org named in the request id - #2062
UpdateProject and UpdateOrganization accept an id or a name in the request id.
The permission check always uses the request id. But when the id was a name, the update did not use it. It looked up the row by the name in the request body.
So the row that got updated could be a different one from the row the permission check approved. A caller with update rights on one project or org could change the title and metadata of another one.
This PR makes the update use the same row as the permission check.
Changes
project.Service.Update: if the id is not a uuid, look the project up by that name, then update by its id. An empty id returns ErrInvalidID.
organization.Service.Update: same change. An empty id returns ErrInvalidID.
UpdateOrganization handler: always pass the request id to the service. Before, it dropped the id when it was a name.
Org UpdateByID no longer requires a body name. It never wrote the name, and project updates never required it.
The update error and log for both handlers no longer include the body name. They name the request id only.
Remove UpdateByName from the project and org repositories. Nothing calls it any more.
Behavior changes
The body name is ignored on both the uuid path and the name path. Neither update ever writes the name column.
An org update with an empty body name now succeeds, like a project update. Before, the uuid path returned Internal and the name path returned NotFound.
A disabled project addressed by name returns NotFound. A disabled org addressed by name returns FailedPrecondition. This is the same as before the PR, and the new e2e test pins it.
Technical Details
The name lookup is the same one the permission check uses. Projects use GetByName, which is what project.Service.Get calls. Orgs use GetByName, which is what organization.Service.GetRaw calls.
The mock changes only remove the deleted method. They match mockery v2.53.5 output.
Why the name is looked up twice
The permission check turns the name into an id, and then the service does the same lookup again. In theory, the row could be soft deleted, and a new row could take the same name, in the short time between the two lookups.
I did not pass the id from the permission check down to the handler, because there is no clean way to do it today:
IsAuthorized and CheckAuthz return only allow or deny. The resolved id stays inside the resource service.
One option is for the authz interceptor to rewrite the request id to the uuid. No interceptor rewrites requests today, and it would quietly change what later code and logs see.
The other option is to put the resolved id in the context from the shared check that every RPC uses. That is new plumbing across all RPCs for two endpoints.
The window is milliseconds long. It also needs someone else to create a row with that exact name at that moment, which the caller cannot control. So this PR leaves it as a follow-up.
Test Plan
Unit tests for project.Service.Update and organization.Service.Update: uuid, name, unknown name, empty id.
Repository test: org UpdateByID works with an empty body name.
New e2e tests in update_by_name_test.go:
A user sends their own project or org in the id, and a different one in the body name. Only their own row changes. This fails on main and passes here.
A disabled project and a disabled org addressed by name.
make test, golangci-lint run, gofmt, and the e2e regression suite.
Backport
release-v0-117-x has the same code, so it needs this fix too. Cherry-pick the fix(...) commits and the two e2e test commits. The refactor(...) and test(store) commits are optional there, and may not apply cleanly.
Follow-ups (not in this PR)
UpdateUser by slug (core/user/service.go:128) still finds the row by the body name. Only superusers can call it, so it does not let anyone reach a row they could not already change. It should still use the request id, to match.
Pass the id that the permission check resolved down to the update, as described above.
UpdateProjectResource takes the resource namespace for the permission check from the request body. The write is by the request uuid only, so it cannot reach another row. The org version reads the stored namespace, which is cleaner.
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
Bug Fixes
Organization and project updates can resolve a resource name supplied as the request identifier, then update only that resolved resource.
Updates with an empty identifier now return an invalid-ID error. Unknown names return a not-found error without changing a resource.
Leaving an organization’s name blank during an update preserves its existing name.
Organization and project updates now resolve non-UUID request IDs as names, then update the resolved resource by ID. The repository update-by-name methods were removed. Service, API, repository, and end-to-end tests cover the updated paths.
The repository contracts, PostgreSQL implementations, and generated mocks no longer provide UpdateByName. Organization updates by ID accept a blank body name. Repository tests exercise metadata and other update behavior through UpdateByID.
Identifier resolution and API updates core/organization/service.go, core/organization/service_test.go, core/project/service.go, core/project/service_test.go, internal/api/v1beta1connect/organization.go, internal/api/v1beta1connect/organization_test.go, internal/api/v1beta1connect/project.go
Services reject empty IDs, resolve non-UUID IDs by name, and update by the resolved ID. The organization handler passes the request ID to the service. Organization error logging no longer includes the name; project error logging retains the ID and omits the name.
Tests check that updates affect the resource identified by the request ID, that users cannot directly update another user’s resource, and that disabled resources addressed by name return the expected errors.
Project and organization updates now change the resource named in the request ID rather than one selected by the body name. Disabled-resource responses are unchanged from before. The change is narrow, has regression coverage, and I see no remaining merge-blocking risk. The author's known follow-up on the lookup-race window can be handled separately.
Pre-merge checks: 2
Check name
Status
Explanation
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UpdateProjectandUpdateOrganizationaccept an id or a name in the requestid.The permission check always uses the request
id. But when theidwas a name, the update did not use it. It looked up the row by thenamein the request body.So the row that got updated could be a different one from the row the permission check approved. A caller with update rights on one project or org could change the title and metadata of another one.
This PR makes the update use the same row as the permission check.
Changes
project.Service.Update: if theidis not a uuid, look the project up by that name, then update by its id. An emptyidreturnsErrInvalidID.organization.Service.Update: same change. An emptyidreturnsErrInvalidID.UpdateOrganizationhandler: always pass the requestidto the service. Before, it dropped theidwhen it was a name.UpdateByIDno longer requires a body name. It never wrote the name, and project updates never required it.idonly.UpdateByNamefrom the project and org repositories. Nothing calls it any more.Behavior changes
nameis ignored on both the uuid path and the name path. Neither update ever writes thenamecolumn.Internaland the name path returnedNotFound.NotFound. A disabled org addressed by name returnsFailedPrecondition. This is the same as before the PR, and the new e2e test pins it.Technical Details
GetByName, which is whatproject.Service.Getcalls. Orgs useGetByName, which is whatorganization.Service.GetRawcalls.Why the name is looked up twice
The permission check turns the name into an id, and then the service does the same lookup again. In theory, the row could be soft deleted, and a new row could take the same name, in the short time between the two lookups.
I did not pass the id from the permission check down to the handler, because there is no clean way to do it today:
IsAuthorizedandCheckAuthzreturn only allow or deny. The resolved id stays inside the resource service.idto the uuid. No interceptor rewrites requests today, and it would quietly change what later code and logs see.The window is milliseconds long. It also needs someone else to create a row with that exact name at that moment, which the caller cannot control. So this PR leaves it as a follow-up.
Test Plan
project.Service.Updateandorganization.Service.Update: uuid, name, unknown name, empty id.UpdateByIDworks with an empty body name.update_by_name_test.go:id, and a different one in the bodyname. Only their own row changes. This fails onmainand passes here.make test,golangci-lint run,gofmt, and the e2e regression suite.Backport
release-v0-117-xhas the same code, so it needs this fix too. Cherry-pick thefix(...)commits and the two e2e test commits. Therefactor(...)andtest(store)commits are optional there, and may not apply cleanly.Follow-ups (not in this PR)
UpdateUserby slug (core/user/service.go:128) still finds the row by the body name. Only superusers can call it, so it does not let anyone reach a row they could not already change. It should still use the requestid, to match.UpdateProjectResourcetakes the resource namespace for the permission check from the request body. The write is by the request uuid only, so it cannot reach another row. The org version reads the stored namespace, which is cleaner.