Repository navigation
fix: stop search failing across more than five projects on Spanner - #3031
Conversation
A search without project_id decides which of the newest ten projects the person may read in one statement, a UNION ALL arm per project with four joins each: 40 joins for ten projects. Spanner refuses a query with more than 20, so the search answered 500 "authz permission check failed" (TestSearchAcrossProjects on the Spanner Omni lane). Spanner's CheckAuthzProjects now asks in statements of four projects and wraps its error as its neighbours do. Postgres and SQLite keep one statement. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🦋 Changeset detectedLatest commit: 7094105 The changes in this PR will be included in the next version bump. This PR includes changesets to release 25 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🔵 Needs a closer look
The change depends on validating Spanner join-limit behavior in an integration lane/runtime that isn’t available in this review environment, so it can’t be confidently confirmed here.
No open issues 🎉
What changed in this PR
Fixes a Spanner-specific POST /search failure when no project_id is provided and the caller can act on more than five projects by chunking the project authorization check to stay under Spanner’s join limit while preserving per-project results and input order.
Changes:
- Chunk Spanner
CheckAuthzProjectsinto 4-project statements and wrap query errors consistently. - Expand portable statement tests to cover 10-project checks and validate per-project result ordering.
- Add a Spanner-specific unit test to ensure generated SQL stays within Spanner’s join limit.
- Add a patch changeset for
@zitadel/serverdocumenting the fix.
| File | Description |
|---|---|
| apps/api/internal/storage/stmttest/search_batch_test.go | Expands statement-level coverage to validate 10-project authorization checks and stable per-project result ordering across dialects. |
| apps/api/internal/storage/dialect/spanner/authz_resolver.go | Chunks CheckAuthzProjects execution on Spanner into 4-project batches to avoid join-limit failures and wraps query errors consistently. |
| apps/api/internal/storage/dialect/spanner/authz_resolver_test.go | Adds a regression test that counts joins in the generated CheckAuthzProjects SQL to ensure it stays within Spanner’s join limit. |
| .changeset/search-across-projects-spanner.md | Adds a @zitadel/server patch changeset describing the Spanner cross-project search fix. |
Review effort: Balanced
Summary
POST /searchwithoutproject_idanswered500 internal("authz permission check failed") for a person who can act on more than five projects.WriteCheckAuthzProjects, from feat(api): search every project a session can act on, each type from an index #2972): aUNION ALLarm per project, each with four joins. Ten projects are 40 joins, and Spanner refuses a query with more than 20.CheckAuthzProjectsnow asks in statements of four projects (16 joins) and puts each answer back in the order asked. Postgres and SQLite keep one statement.Validation
go test ./internal/storage/dialect/...(fromapps/api): passes. The newTestCheckAuthzProjectsStatementStaysWithinSpannersJoinLimitcounts the joins of one statement for each principal type, so a check that gains a join fails there before it fails on Spanner.go test -tags sqlite_integration -run TestSearchAcrossProjectsStatements ./internal/storage/stmttest/: passes. The portable suite now checks ten projects at once and compares each answer with the one-project check, so it covers the chunking on Spanner.go test -tags sqlite_integration -run TestSearchAcrossProjects ./internal/api/integration_test/: passes.go vet -tags spanner_integrationand the repo's analyzers on the two packages: clean.gofmt -l: clean.TestSearchAcrossProjectsthat read ten projects answered 500; the ones with two or three projects passed. The log does not show Spanner's own error, so the join limit was measured (40 joins in the statement, 20 allowed), not quoted.spanner.ymldispatched on this branch. Every subtest ofTestSearchAcrossProjectspasses, the two ten-project ones included, and so doesTestSearchAcrossProjectsStatementswith its ten-project check.internal/api/integration_test,dialect/spannerandstmttestareok.TestMigrationsRoundTrip/shard 4 of 4hit its package's 30-minute timeout, as it does on main. test(api): let the Spanner round-trip walks take migrations as they free up #2997 fixes that; this PR does not touch it.full-prruns it).Release notes / changeset
.changeset/search-across-projects-spanner.md:@zitadel/serverpatch.Notes
SearchEntriesInProjects,SearchUserIndex) write arms without joins, so they stay within Spanner's limits at ten projects.🤖 Generated with Claude Code