|
@@ -259,13 +259,12 @@ func validateDomain(val string) (string, error) {
|
|
// and returns it.
|
|
// and returns it.
|
|
// Labels are in the form on key=value.
|
|
// Labels are in the form on key=value.
|
|
func ValidateLabel(val string) (string, error) {
|
|
func ValidateLabel(val string) (string, error) {
|
|
- if strings.Count(val, "=") < 1 {
|
|
|
|
|
|
+ kv := strings.SplitN(val, "=", 2)
|
|
|
|
+ if len(kv) != 2 {
|
|
return "", fmt.Errorf("bad attribute format: %s", val)
|
|
return "", fmt.Errorf("bad attribute format: %s", val)
|
|
}
|
|
}
|
|
|
|
|
|
- lowered := strings.ToLower(val)
|
|
|
|
- if strings.HasPrefix(lowered, "com.docker.") || strings.HasPrefix(lowered, "io.docker.") ||
|
|
|
|
- strings.HasPrefix(lowered, "org.dockerproject.") {
|
|
|
|
|
|
+ if IsReservedLabelNamespace(kv[0]) {
|
|
return "", fmt.Errorf(
|
|
return "", fmt.Errorf(
|
|
"label %s is not allowed: the namespaces com.docker.*, io.docker.*, and org.dockerproject.* are reserved for internal use",
|
|
"label %s is not allowed: the namespaces com.docker.*, io.docker.*, and org.dockerproject.* are reserved for internal use",
|
|
val)
|
|
val)
|
|
@@ -274,6 +273,21 @@ func ValidateLabel(val string) (string, error) {
|
|
return val, nil
|
|
return val, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+var reservedLabelNamespaces = []string{"com.docker", "io.docker", "org.dockerproject"}
|
|
|
|
+
|
|
|
|
+// IsReservedLabelNamespace checks if a given label uses a reserved namespace
|
|
|
|
+// Reserved namespaces are com.docker.*, io.docker.*, and org.dockerproject.*
|
|
|
|
+// (case insensitive).
|
|
|
|
+func IsReservedLabelNamespace(name string) bool {
|
|
|
|
+ lowered := strings.ToLower(name)
|
|
|
|
+ for _, ns := range reservedLabelNamespaces {
|
|
|
|
+ if lowered == ns || strings.HasPrefix(lowered, ns+".") {
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false
|
|
|
|
+}
|
|
|
|
+
|
|
// ValidateSingleGenericResource validates that a single entry in the
|
|
// ValidateSingleGenericResource validates that a single entry in the
|
|
// generic resource list is valid.
|
|
// generic resource list is valid.
|
|
// i.e 'GPU=UID1' is valid however 'GPU:UID1' or 'UID1' isn't
|
|
// i.e 'GPU=UID1' is valid however 'GPU:UID1' or 'UID1' isn't
|