Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when reserved-namespace engine labels are configured #36921

Merged
merged 1 commit into from
May 7, 2018
Merged

Warn when reserved-namespace engine labels are configured #36921

merged 1 commit into from
May 7, 2018

Conversation

cyli
Copy link
Contributor

@cyli cyli commented Apr 20, 2018

- What I did
Filter out engine labels that start with com.docker.*, io.docker.*, and org.dockerproject.* as per https://docs.docker.com/config/labels-custom-metadata/.

Warn when engine labels are configured that start with com.docker.*, io.docker.*, and org.dockerproject.* as per https://docs.docker.com/config/labels-custom-metadata/.

- How I did it
I filter out the labels every time SystemInfo() is called. The labels are left as defined by the daemon.json or daemon CLI args in the configStore. SystemInfo() labels are what is used by swarm.

Filtered out the labels when the configuration is loaded and issue a warning that the labels are being ignored. In the future an error can be returned, as suggested by @thaJeztah and as per this example: e4c9079#diff-a348195a1b645d5b477946b1efae728bR274

Added a label validation function that, when it errors, the daemon warns the user that label with a reserved namespace has been configured. In the future loading the configuration can just fail, as per this example: e4c9079#diff-a348195a1b645d5b477946b1efae728bR274

- How to verify it
daemon/info_test.go
cmd/dockerd/daemon_test.go
daemon/config_test.go and configuring a daemon with a com.docker.* label, and checking the daemon logs

- Description for the changelog
Enforce reserved namespaces in engine labels by filtering out any configured labels that start with com.docker.*, io.docker.*, or org.dockerproject.* as per https://docs.docker.com/config/labels-custom-metadata/.

Warn when an engine label using a reserved namespace (com.docker.*, io.docker.*, or org.dockerproject.*) is configured, as per https://docs.docker.com/config/labels-custom-metadata/.

- A picture of a cute animal (not mandatory but encouraged)
image

daemon/info.go Outdated
@@ -119,7 +134,7 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
MemTotal: meminfo.MemTotal,
GenericResources: daemon.genericResources,
DockerRootDir: daemon.configStore.Root,
Labels: daemon.configStore.Labels,
Labels: daemon.getFilteredLabels(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this filter should be applied when reading the configuration, or when changing/updating the configuration (i.e., filter out user-provided labels with the prefix)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly - I was wondering the same. I left it unchanged on the config.Config object, since that seems to be the configuration as specified by the user, but I wasn't sure. I'd be happy to make the change if you feel that'd be a better place to do it, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; so train of thought is that there's possibly other locations where we use this information, and those may not take the filtering into account.

Perhaps we should validate when loading, and print a warning that the label will be ignored; in future we could turn that warning into an error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@codecov
Copy link

codecov bot commented Apr 23, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@65c575f). Click here to learn what that means.
The diff coverage is 45%.

@@            Coverage Diff            @@
##             master   #36921   +/-   ##
=========================================
  Coverage          ?   35.09%           
=========================================
  Files             ?      614           
  Lines             ?    45707           
  Branches          ?        0           
=========================================
  Hits              ?    16041           
  Misses            ?    27561           
  Partials          ?     2105

@thaJeztah
Copy link
Member

Ugh; this hit the jackpot on flaky tests

Experimental (https://jenkins.dockerproject.org/job/Docker-PRs-experimental/40409/console) failing on TestLogsTail, which should not be related (wonder if it has the same root-cause as #36877)

00:54:05 FAIL: docker_cli_logs_test.go:92: DockerSuite.TestLogsTail
00:54:05 
00:54:05 docker_cli_logs_test.go:113:
00:54:05     c.Assert(lines, checker.HasLen, testLen+1)
00:54:05 ... obtained []string = []string{"=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", "=", ""}
00:54:05 ... n int = 101
00:54:05 

Janky (https://jenkins.dockerproject.org/job/Docker-PRs/49151/console) failing on TestAPISwarmRaftQuorum, which was marked flaky twice before #34988, #35039

01:32:15 FAIL: docker_api_swarm_test.go:359: DockerSwarmSuite.TestAPISwarmRaftQuorum
01:32:15 
01:32:15 [d2d439ed22d96] waiting for daemon to start
01:32:15 [d2d439ed22d96] daemon started
01:32:15 
01:32:15 [d3c0456111b19] waiting for daemon to start
01:32:15 [d3c0456111b19] daemon started
01:32:15 
01:32:15 [d9e4a1409e118] waiting for daemon to start
01:32:15 [d9e4a1409e118] daemon started
01:32:15 
01:32:15 [d3c0456111b19] exiting daemon
01:32:15 [d9e4a1409e118] exiting daemon
01:32:15 docker_api_swarm_test.go:385:
01:32:15     // d1 will eventually step down from leader because there is no longer an active quorum, wait for that to happen
01:32:15     waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
01:32:15         _, err = cli.ServiceCreate(context.Background(), service.Spec, types.ServiceCreateOptions{})
01:32:15         return err.Error(), nil
01:32:15     }, checker.Contains, "Make sure more than half of the managers are online.")
01:32:15 docker_utils_test.go:435:
01:32:15     c.Assert(v, checker, args...)
01:32:15 ... obtained string = "Error response from daemon: rpc error: code = DeadlineExceeded desc = context deadline exceeded"
01:32:15 ... substring string = "Make sure more than half of the managers are online."
01:32:15 
01:32:15 [d2d439ed22d96] exiting daemon
01:33:19 

PowerPC (https://jenkins.dockerproject.org/job/Docker-PRs-powerpc/9592/console) failure is being tracked through #32673

01:41:08 FAIL: docker_api_swarm_test.go:296: DockerSwarmSuite.TestAPISwarmLeaderElection
01:41:08 
01:41:08 [d390edc66210d] waiting for daemon to start
01:41:08 [d390edc66210d] daemon started
01:41:08 
01:41:08 [dbe5c7aec85fb] waiting for daemon to start
01:41:08 [dbe5c7aec85fb] daemon started
01:41:08 
01:41:08 [d5cab43d8ef6f] waiting for daemon to start
01:41:08 [d5cab43d8ef6f] daemon started
01:41:08 
01:41:08 [d390edc66210d] exiting daemon
01:41:08 assertion failed: error is not nil: Error response from daemon: rpc error: code = DeadlineExceeded desc = context deadline exceeded
01:41:08 [dbe5c7aec85fb] exiting daemon
01:41:08 [d5cab43d8ef6f] exiting daemon
01:41:24 

And s390x (https://jenkins.dockerproject.org/job/Docker-PRs-s390x/9517/console) failure is being tracked through #36877

00:59:12 FAIL: docker_cli_exec_unix_test.go:18: DockerSuite.TestExecInteractiveStdinClose
00:59:12 
00:59:12 docker_cli_exec_unix_test.go:37:
00:59:12     c.Assert(strings.TrimSpace(output), checker.Equals, "hello")
00:59:12 ... obtained string = "hello\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
00:59:12 ... expected string = "hello"
00:59:12 

filtered = append(filtered, label)
}
if len(filtered) < len(labels) {
logrus.Warn("The com.docker.*, io.docker.*, and org.dockerprojects.* namespaces are reserved. Labels using these namespaces will be ignored.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

  • there's two spaces before Labels
  • perhaps s/will be ignored/are ignored/

Wondering if during the deprecation period we should still apply the labels, and only print the warning. Although "unlikely", there may be someone somewhere actually using labels with this prefix 😞

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's okay, given that this was already documented; would like some others to kick in on this though 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree with @thaJeztah and I think there is someone using labels with those prefixes.

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyli why all of those three ? Wouldn't just com.docker.* be enough ? (or maybe io.docker.* with it, but I don't see why we would reserve org.dockerprojects.* too)

@thaJeztah
Copy link
Member

These three were the ones originally decided on when implementing labels

@cyli
Copy link
Contributor Author

cyli commented Apr 24, 2018

@vdemeester Not sure - the documentation specifies all 3, so I was just following the stated warning. I'll update to just log the warning then.

@cyli cyli changed the title Filter reserved-namespace engine labels out Warn when reserved-namespace engine labels are configured Apr 24, 2018
@vdemeester
Copy link
Member

@cyli fair enough :)

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Do we want to reserve org.mobyproject.* as well maybe?

@thaJeztah
Copy link
Member

Do we want to reserve org.mobyproject.* as well maybe?

I'm ok with adding that as well, but let's do that in a follow-up (we may want to look at which moby prefixes to reserve, not entirely sure which domains are registered (I think there was a mo.by domain, possibly some .io domain(s)?)

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah thaJeztah merged commit 57493cd into moby:master May 7, 2018
@thaJeztah
Copy link
Member

@cyli can you do a follow-up to add this to the deprecation list? https://github.com/docker/cli/blob/master/docs/deprecated.md

@cyli cyli deleted the filter-namespaced-labels branch May 7, 2018 18:01
@cyli
Copy link
Contributor Author

cyli commented May 7, 2018

@thaJeztah Done: docker/cli#1040

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

Successfully merging this pull request may close these issues.

5 participants