Repository navigation
fix(yurthub): reject dot segments when building disk storage keys - #2848
Open
Sharadhi-v98 wants to merge 1 commit into
Open
Sharadhi-v98 wants to merge 1 commit into
Sharadhi-v98 wants to merge 1 commit into
Conversation
KeyFunc joins the client component (from the User-Agent header) and the resource, namespace and name (from the request path) into the on-disk cache key. A "." or ".." in any of them moved the key out of its component dir, and in some setups out of the cache dir, so yurthub could write cached responses to, or serve files from, outside --disk-cache-path. Refuse "." and ".." elements in those fields and return ErrUnrecognizedKey, the same error used for cluster info keys.
|
Author
|
any update? |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



What type of PR is this?
/kind bug
What this PR does / why we need it:
diskStorage.KeyFuncbuilds the on-disk cache key withfilepath.Join(component, resource, namespace, name). The component is the client'sUser-Agent(cut at the first/), and resource, namespace and name come from the request path, which yurthub does not clean. Nothing rejected.or.., so a local client could move a key out of its component dir and, in two setups, out of--disk-cache-path:cache_agents: "*", a request withUser-Agent: ..is cacheable. Online, the response toGET /api/v1/namespaces/default/configmaps/foois written to<cache-dir>/../configmaps.v1.core/default/foo. With the cloud unreachable,GET /api/v1/namespaces/../configmaps/<file>is served from<cache-dir>/../<file>, so any JSON object file next to the cache dir is returned to the client.kubeletagent is enough:GET /api/v1/namespaces/../../<file>while offline resolves to<cache-dir>/../<file>.KeyFuncnow returnsstorage.ErrUnrecognizedKeywhen the component, resource, namespace or name has a.or..element. Create, Get, List, Update and ReplaceComponentList all build their keys here, so the one check covers them. Valid Kubernetes names and user agents never contain those elements, and a key error on the cache write path is only logged, so the proxied response is unchanged.Which issue(s) this PR fixes:
None
Special notes for your reviewer:
...WithRequestInfo+WithRequestClientComponentandcacheManager.CacheResponse/QueryCacheagainst a temp cache dir: before the fix both cases above read or write outside the cache dir, after it both getunrecognized key.TestKeyFunc; they fail before the fix and pass after.go build ./cmd/... ./pkg/...,go vet,golangci-lintv2.11.4 andgo test ./pkg/... ./cmd/...pass locally.Does this PR introduce a user-facing change?