Skip to content

Commit

Permalink
apis/nfd/validate: loosen validation of feature annotations
Browse files Browse the repository at this point in the history
Don't require that the annotation value must conform to the (strict)
requirements of label values. In the Kubernetes API annotation values do
not have other restrictions than that the total size (keys and values)
of _all_ annotations combined of an object must not exceed 256kB.

This patch sets a maximum size limit of 1kB for the value of a single
feature annotation created by NFD. This limit is rather arbitrary but
should be enough for the NFD usage scenarios (until proven wrong).
  • Loading branch information
marquiz committed Mar 19, 2024
1 parent 0ad5e50 commit 547a17a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/nfd/v1alpha1/annotations_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@ const (

// FeatureAnnotationSubNsSuffix is the suffix for allowed feature annotation sub-namespaces.
FeatureAnnotationSubNsSuffix = "." + FeatureAnnotationNs

// FeatureAnnotationValueSizeLimit is the maximum allowed length for the value of a feature annotation.
FeatureAnnotationValueSizeLimit = 1 << 10
)
4 changes: 2 additions & 2 deletions pkg/apis/nfd/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ func Annotation(key, value string) error {
}

// Validate annotation value
if errs := k8svalidation.IsValidLabelValue(value); len(errs) > 0 {
return fmt.Errorf("invalid value %q: %s", value, strings.Join(errs, "; "))
if len(value) > nfdv1alpha1.FeatureAnnotationValueSizeLimit {
return fmt.Errorf("invalid value: too long: feature annotations must not be longer than %d characters", nfdv1alpha1.FeatureAnnotationValueSizeLimit)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/nfd/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestAnnotation(t *testing.T) {
{
name: "Invalid annotation value",
key: "feature.node.kubernetes.io/feature",
value: "invalid value",
want: "invalid value \"invalid value\": ",
value: string(make([]byte, 1100)),
want: "invalid value: too long:",
},
{
name: "Denied annotation key",
Expand Down

0 comments on commit 547a17a

Please sign in to comment.