Skip to content

fix: the logic of the protocol in loadListeners#44823

Closed
tao12345666333 wants to merge 1 commit intomoby:masterfrom
tao12345666333:fix-proto
Closed

fix: the logic of the protocol in loadListeners#44823
tao12345666333 wants to merge 1 commit intomoby:masterfrom
tao12345666333:fix-proto

Conversation

@tao12345666333
Copy link
Copy Markdown
Contributor

Signed-off-by: Jintao Zhang zhangjintao9020@gmail.com

- What I did

Here introduced a judgment in 5008409

This will result in the following error.

➜  moby sudo /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock                                                                                                                       
INFO[2023-01-15T00:56:52.640211255+08:00] Starting up                                  
WARN[2023-01-15T00:56:52.640525792+08:00] Running experimental build                          
failed to load listeners: bad format fd://, expected PROTO://ADDR

The configuration fd:// is the default configuration for docker.service.
we shouldn't break it
https://github.com/moby/moby/blob/master/contrib/init/systemd/docker.service#LL13C31-L13C36

- How I did it

- How to verify it

- Description for the changelog

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

Signed-off-by: Jintao Zhang <zhangjintao9020@gmail.com>
Copy link
Copy Markdown
Member

@neersighted neersighted left a comment

Choose a reason for hiding this comment

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

Hmm, good catch, though I'm not convinced this is the right place to carve out this special case. This also definitely requires a regression test to prevent the same mistake again.

@neersighted
Copy link
Copy Markdown
Member

neersighted commented Jan 14, 2023

Actually, something fishy is going on:

moby/opts/hosts_test.go

Lines 30 to 31 in d62a88e

"fd://": "fd://",
"fd://something": "fd://something",

We have a test case explicitly for this -- so we need to investigate why that is failing to catch the regression.

@tao12345666333
Copy link
Copy Markdown
Contributor Author

Thanks! Even though we have this test case, it doesn't use the parseHost or parseDaemonHost functions at this point in my modification.

In the previous code, it is not judged whether addr is empty.
5008409#diff-eab6997069d2fc9fd3e50c0721e88a363570b9d3ed03facd987373ab1ac9405bL665-L666

I think I should change the function called to parseDaemonHost to clean up a bit here, what do you think?

@thaJeztah
Copy link
Copy Markdown
Member

Could it be the subtests here not capturing the variable?

moby/opts/hosts_test.go

Lines 50 to 51 in d62a88e

for value, expectedError := range invalid {
t.Run(value, func(t *testing.T) {

@tao12345666333
Copy link
Copy Markdown
Contributor Author

no, fd:// is a valid configuration.

@thaJeztah
Copy link
Copy Markdown
Member

I'm personally fine with the check added in this PR (this was indeed an oversight of mine), or perhaps remove the check altogether (if we already validate these before this).

That said, we should refactor some of this (I recall I looked at this code as well, when working on #43459); I think there's too much handling happening in loadListeners(); it would be better if we did all the parsing and handling before we reach that code, to allow validating the configuration before we even try to start the daemon, and so that dockerd --validate already returns configuration errors (if we don't validate this specific case already);

serverConfig, err := newAPIServerConfig(cli.Config)
if err != nil {
return err
}
if opts.Validate {
// If config wasn't OK we wouldn't have made it this far.
_, _ = fmt.Fprintln(os.Stderr, "configuration OK")
return nil
}

@thaJeztah
Copy link
Copy Markdown
Member

no, fd:// is a valid configuration.

Ah, yea, you're right; was wondering for a bit if the test was broken.

@thaJeztah
Copy link
Copy Markdown
Member

Looks like fd://something should not be valid though; so some validation is missing in that part;

// default to all fds just like unix:// and tcp://
if addr == "" || addr == "*" {
return listeners, nil
}
fdNum, err := strconv.Atoi(addr)
if err != nil {
return nil, errors.Errorf("failed to parse systemd fd address: should be a number: %v", addr)
}

@thaJeztah
Copy link
Copy Markdown
Member

Removed the cherry-pick label because it looks like 5008409 (#44381) is only in master

@tao12345666333
Copy link
Copy Markdown
Contributor Author

tao12345666333 commented Jan 15, 2023

Then I plan to do this:

  • Modify the current PR, and remove the check on addr. Since the previous code didn't have this check either, here's a quick fix. Or leave this PR unchanged, since we really only need to cover fd for one scenario.
  • Create a new PR to refactor this:
    • Replace the processing logic here with parseDaemonHost
    • Add validation for fd://something

WDYT?

@neersighted
Copy link
Copy Markdown
Member

I'd split the difference: use this PR, but change the implementation to the second, and add e2e testing of this area of code (not just parseDaemonHost).

@tao12345666333
Copy link
Copy Markdown
Contributor Author

OK, let me add some e2e test cases, thanks

@thaJeztah
Copy link
Copy Markdown
Member

and add e2e testing of this area of code (not just parseDaemonHost).

Agreed; There's also quite a bit more to look at w.r.t. validation in general. Some quick thoughts on some of that;

  • Make sure we're more consistent in where validation (needs to) happen
  • Important there is that not all validation has to be a full validation (for better words). What I mean is that validating "format" and "valid input" is sometimes a separate concern; e.g. https://hello.world/blabla/blablabla is validly formatted URL, but the URL may not exist. Same as unix:///no/such/socket being a valid formatted "unix" socket path, but may not exist.
  • This distinction is sometimes important. For example, it's OK to validate for a valid formatted input in some areas (e.g. could be the docker CLI), but in some areas you don't want to (or are not able to) validate everything.
  • Not validating everything is fine as long as we catch errors (and ideally "as early as possible")/
  • Some things will always remain a bit of a "grey" area (e.g. socket paths may be "too long", but the allowed length may depend on how the host is configured. For such cases we must decide (probably on a per-case basis) wether we (dockerd) should validate, or if that's something to delegate to the system itself.

@tao12345666333
Copy link
Copy Markdown
Contributor Author

Thanks for your reply, I will do some thinking.

I'll be back from vacation in two days.

@neersighted
Copy link
Copy Markdown
Member

Thanks for working on this! @cpuguy83 ended up picking it up in #45132, and addressed the testing concern there.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants