-
Notifications
You must be signed in to change notification settings - Fork 10.4k
grpc proxy serializable Range cache leaks protected keys across auth identities #22112
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
goingforstudying-ctrl
wants to merge
5
commits into
etcd-io:main
Choose a base branch
from
goingforstudying-ctrl:fix/grpcproxy-cache-auth-leak
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
35d2405
grpcproxy: scope serializable Range cache entries by caller auth iden…
goingforstudying-ctrl 297ac7e
grpcproxy: guard against overflow in cache key allocation
goingforstudying-ctrl 361b2d1
grpcproxy: unify cache key construction to avoid string(bytes) conver…
goingforstudying-ctrl 2f3ab5f
decouple auth proxy from concrete KvProxy type
goingforstudying-ctrl cb665e8
grpcproxy: document cache flush scope for direct backend auth changes
goingforstudying-ctrl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // Copyright 2026 The etcd Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package cache | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| pb "go.etcd.io/etcd/api/v3/etcdserverpb" | ||
| "go.etcd.io/etcd/api/v3/mvccpb" | ||
| ) | ||
|
|
||
| func TestCacheAuthKeyIsolation(t *testing.T) { | ||
| c := NewCache(10) | ||
| defer c.Close() | ||
|
|
||
| req := &pb.RangeRequest{Key: []byte("secret"), Serializable: true} | ||
| resp := &pb.RangeResponse{ | ||
| Header: &pb.ResponseHeader{Revision: 1}, | ||
| Kvs: []*mvccpb.KeyValue{{Key: []byte("secret"), Value: []byte("s3cr3t")}}, | ||
| } | ||
|
|
||
| // Store under identity "alice" | ||
| c.Add(req, resp, "alice") | ||
|
|
||
| // Same identity must hit | ||
| got, err := c.Get(req, "alice") | ||
| if err != nil { | ||
| t.Fatalf("expected cache hit for same identity, got %v", err) | ||
| } | ||
| if string(got.Kvs[0].Value) != "s3cr3t" { | ||
| t.Fatalf("unexpected value %q", got.Kvs[0].Value) | ||
| } | ||
|
|
||
| // Different identity must miss | ||
| _, err = c.Get(req, "bob") | ||
| if err == nil { | ||
| t.Fatal("expected cache miss for different identity") | ||
| } | ||
|
|
||
| // Empty identity must miss | ||
| _, err = c.Get(req, "") | ||
| if err == nil { | ||
| t.Fatal("expected cache miss for empty identity") | ||
| } | ||
|
|
||
| // Store under empty identity; other identities still miss | ||
| c.Add(req, resp, "") | ||
| if _, err = c.Get(req, ""); err != nil { | ||
| t.Fatalf("expected cache hit for empty identity, got %v", err) | ||
| } | ||
| // "alice" hits because her earlier Add(req,resp,"alice") entry is still | ||
| // resident, not because "" collides with a named identity. | ||
| if _, err = c.Get(req, "alice"); err != nil { | ||
| t.Fatalf("expected cache hit for alice after empty-identity add (same key), got %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestCacheClear(t *testing.T) { | ||
| c := NewCache(10) | ||
| defer c.Close() | ||
|
|
||
| req := &pb.RangeRequest{Key: []byte("k"), Serializable: true} | ||
| resp := &pb.RangeResponse{Header: &pb.ResponseHeader{Revision: 1}} | ||
|
|
||
| c.Add(req, resp, "alice") | ||
| c.Add(req, resp, "bob") | ||
| c.Add(req, resp, "") | ||
|
|
||
| if size := c.Size(); size != 3 { | ||
| t.Fatalf("expected 3 entries, got %d", size) | ||
| } | ||
|
|
||
| c.Clear() | ||
|
|
||
| if size := c.Size(); size != 0 { | ||
| t.Fatalf("expected 0 entries after Clear, got %d", size) | ||
| } | ||
| for _, id := range []string{"alice", "bob", ""} { | ||
| if _, err := c.Get(req, id); err == nil { | ||
| t.Fatalf("expected miss after Clear for identity %q", id) | ||
| } | ||
| } | ||
|
|
||
| // Cache must remain usable after Clear | ||
| c.Add(req, resp, "alice") | ||
| if _, err := c.Get(req, "alice"); err != nil { | ||
| t.Fatalf("expected hit after re-Add, got %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestKeyFuncDeterministic(t *testing.T) { | ||
| req := &pb.RangeRequest{Key: []byte("a"), Serializable: true} | ||
| k1 := keyFunc(req, "alice") | ||
| k2 := keyFunc(req, "alice") | ||
| k3 := keyFunc(req, "bob") | ||
| k4 := keyFunc(req, "") | ||
|
|
||
| if k1 != k2 { | ||
| t.Fatal("same inputs must produce same key") | ||
| } | ||
| if k1 == k3 { | ||
| t.Fatal("different identities must produce different keys") | ||
| } | ||
| if k1 == k4 { | ||
| t.Fatal("identity vs no-identity must produce different keys") | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.