Enhancement: Add strict format validation for yurthub storage keys - #2776
Open
mohammd-khalil wants to merge 1 commit into
Open
Enhancement: Add strict format validation for yurthub storage keys#2776mohammd-khalil wants to merge 1 commit into
mohammd-khalil wants to merge 1 commit into
Conversation
|
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 enhancement
/sig storage
What this PR does / why we need it:
ValidateKeyinpkg/yurthub/storage/utils/validate.gocurrently only checksthat a
storage.Keyis non-nil/non-empty and has the expected concrete Gotype (via
reflect.TypeOf). It does not validate the internal format of thekey's path, as noted by an existing TODO comment:
// TODO: should also valid the key formatThis means a key with the correct type but a malformed internal path (e.g.
missing segments, invalid resource/version/group format) passes validation
silently, and only fails later when it is actually parsed/used (e.g. by
disk.ExtractKeyBuildInfo).This PR completes the TODO by:
KeyFormatValidatorinterface (Validate() error) inpkg/yurthub/storage, kept separate from the existing minimalKeyinterface so it stays backward compatible for key types that don't need
format validation (e.g.
ClusterInfoKey).Validate()ondisk.storageKey, reusing the same parsingrules already used by
ExtractKeyBuildInfo.ValidateKeyinutils/validate.goto callValidate()via atype assertion, only when the key implements it.
disk.storageKey.Validate()and theupdated
utils.ValidateKey.Which issue(s) this PR fixes:
Fixes #2775
Special notes for your reviewer:
Keyinterface itself (Key() string) was left unchanged;KeyFormatValidatoris an additive, opt-in interface, so no existing implementation is broken.
etcdstorage key was not modified in this PR since its key format/needsweren't covered — happy to follow up separately if a similar check is
wanted there.
Does this PR introduce a user-facing change?
other Note