Merge pull request #36921 from cyli/filter-namespaced-labels
Warn when reserved-namespace engine labels are configured Upstream-commit: 57493cd60628ebf6e8b02725f44e1a4ef152a39e Component: engine
This commit is contained in:
@@ -262,6 +262,25 @@ func GetConflictFreeLabels(labels []string) ([]string, error) {
|
||||
return newLabels, nil
|
||||
}
|
||||
|
||||
// ValidateReservedNamespaceLabels errors if the reserved namespaces com.docker.*,
|
||||
// io.docker.*, org.dockerproject.* are used in a configured engine label.
|
||||
//
|
||||
// TODO: This is a separate function because we need to warn users first of the
|
||||
// deprecation. When we return an error, this logic can be added to Validate
|
||||
// or GetConflictFreeLabels instead of being here.
|
||||
func ValidateReservedNamespaceLabels(labels []string) error {
|
||||
for _, label := range labels {
|
||||
lowered := strings.ToLower(label)
|
||||
if strings.HasPrefix(lowered, "com.docker.") || strings.HasPrefix(lowered, "io.docker.") ||
|
||||
strings.HasPrefix(lowered, "org.dockerproject.") {
|
||||
return fmt.Errorf(
|
||||
"label %s not allowed: the namespaces com.docker.*, io.docker.*, and org.dockerproject.* are reserved for Docker's internal use",
|
||||
label)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reload reads the configuration in the host and reloads the daemon and server.
|
||||
func Reload(configFile string, flags *pflag.FlagSet, reload func(*Config)) error {
|
||||
logrus.Infof("Got signal to reload configuration, reloading from: %s", configFile)
|
||||
|
||||
@@ -193,6 +193,40 @@ func TestFindConfigurationConflictsWithMergedValues(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateReservedNamespaceLabels(t *testing.T) {
|
||||
for _, validLabels := range [][]string{
|
||||
nil, // no error if there are no labels
|
||||
{ // no error if there aren't any reserved namespace labels
|
||||
"hello=world",
|
||||
"label=me",
|
||||
},
|
||||
{ // only reserved namespaces that end with a dot are invalid
|
||||
"com.dockerpsychnotreserved.label=value",
|
||||
"io.dockerproject.not=reserved",
|
||||
"org.docker.not=reserved",
|
||||
},
|
||||
} {
|
||||
assert.Check(t, ValidateReservedNamespaceLabels(validLabels))
|
||||
}
|
||||
|
||||
for _, invalidLabel := range []string{
|
||||
"com.docker.feature=enabled",
|
||||
"io.docker.configuration=0",
|
||||
"org.dockerproject.setting=on",
|
||||
// casing doesn't matter
|
||||
"COM.docker.feature=enabled",
|
||||
"io.DOCKER.CONFIGURATION=0",
|
||||
"Org.Dockerproject.Setting=on",
|
||||
} {
|
||||
err := ValidateReservedNamespaceLabels([]string{
|
||||
"valid=label",
|
||||
invalidLabel,
|
||||
"another=valid",
|
||||
})
|
||||
assert.Check(t, is.ErrorContains(err, invalidLabel))
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateConfigurationErrors(t *testing.T) {
|
||||
minusNumber := -10
|
||||
testCases := []struct {
|
||||
|
||||
Reference in New Issue
Block a user