Skip to content

fix: update the project or org named in the request id - #2062

Open
rohilsurana wants to merge 12 commits into
mainfrom
fix/update-project-by-name-authz
Open

rohilsurana wants to merge 12 commits into
mainfrom
fix/update-project-by-name-authz

Conversation

@rohilsurana

@rohilsurana rohilsurana commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

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.

@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
frontier Ready Ready Preview Nov 25, 2026 8:05am UTC

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.

Changes: Resource update flow

Layer / File(s) Summary
Update-by-ID repository contract and storage
core/organization/service.go, core/project/project.go, internal/store/postgres/organization_repository.go, internal/store/postgres/project_repository.go, internal/store/postgres/*_repository_test.go, core/organization/mocks/repository.go, core/project/mocks/repository.go
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.
End-to-end update regressions
test/e2e/regression/update_by_name_test.go
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.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

  • raystack/frontier#2019: It changes organization update handling and repository methods that this PR also changes or removes.
  • raystack/frontier#2058: It changes project update methods and tests that this PR also changes.

Suggested reviewers: mabdh, amangit07, whoabhisheksah

Merge Risk: Minimal · up to b6ce5

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: Passed 2

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4e33f29 and b6ce594.

Files selected for processing: 15

  • core/organization/mocks/repository.go
  • core/organization/service.go
  • core/organization/service_test.go
  • core/project/mocks/repository.go
  • core/project/project.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
  • internal/store/postgres/organization_repository.go
  • internal/store/postgres/organization_repository_test.go
  • internal/store/postgres/project_repository.go
  • internal/store/postgres/project_repository_test.go
  • test/e2e/regression/update_by_name_test.go
Files with no reviewable changes: 5

  • core/organization/mocks/repository.go
  • core/project/mocks/repository.go
  • core/project/project.go
  • internal/store/postgres/organization_repository.go
  • internal/store/postgres/project_repository.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@coveralls

coveralls commented Nov 25, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 45573236033

Coverage increased (+0.002%) to 56.47%

Details

  • Coverage increased (+0.002%) from the base build.
  • Patch coverage: 28 of 28 lines across 4 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 42412
Covered Lines: 23950
Line Coverage: 56.47%
Coverage Strength: 22.0 hits per line

💛 - Coveralls

This branch was successfully deployed

1 active deployment
Preview — b6ce5945 Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants