Skip to content

ValidateKey does not validate the internal format of storage keys #2775

Description

@mohammd-khalil

What happened:
The ValidateKey function in pkg/yurthub/storage/utils/validate.go only validates
that a storage.Key is non-nil/non-empty and has the correct concrete type
(via reflect.TypeOf). It does not validate the internal format of the key's
path (e.g. required segments, separators), as noted by an existing TODO comment:

// TODO: should also valid the key format
func ValidateKey(key storage.Key, validKeyType interface{}) error {

This means a key with a correct Go type but a malformed internal path
(e.g. missing segments, invalid GVR format) passes validation without error,
even though it would fail later when parsed (e.g. by disk.ExtractKeyBuildInfo).

What you expected to happen:
ValidateKey (and ValidateKV) should also validate the internal format of
the key, so malformed keys are rejected early with a clear error, rather than
failing later/silently when the key is actually used.

How to reproduce it (as minimally and precisely as possible):

  1. Construct a disk storage key with a malformed path, e.g.:
   key := storageKey{path: "component-only-no-resource"}
  1. Call utils.ValidateKey(key, storageKey{}).
  2. Observe that no error is returned, even though the path does not match
    the documented disk key format:
    /<Component>/<Resource.Version.Group>/<Namespace>/<Name>

Anything else we need to know?:
I'd like to work on this — proposed approach:

  • Add an optional KeyFormatValidator interface (Validate() error) in
    pkg/yurthub/storage, separate from the existing minimal Key interface,
    so this stays backward compatible for key types that don't need format
    validation (e.g. ClusterInfoKey).
  • Implement Validate() on disk.storageKey, reusing the same parsing
    rules already used in ExtractKeyBuildInfo.
  • Update ValidateKey in utils/validate.go to call Validate() via a
    type assertion, when the key implements it.

Happy to open a PR with this change if the approach sounds good.

Environment:

  • OpenYurt version: main branch
  • Kubernetes version (use kubectl version): N/A (not a runtime issue, source-code level)
  • OS (e.g: cat /etc/os-release): Ubuntu 24.04.4 LTS
  • Kernel (e.g. uname -a): 7.0.0-30-generic
  • Install tools: N/A

others
/kind cleanup

Activity

  1. added 2 commits that reference this issue on Aug 29, 2026
    99d22a8
    1a094a7
  2. mohammd-khalil commented on Aug 30, 2026

    @mohammd-khalil
    Author

    hi bro @AruneshDwivedi
    what are you doing ???
    find issues and assign your pr .
    close yours bro !!!

  3. stale commented on Dec 4, 2026

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions