Skip to content

support insecure registry in configuration reload#22337

Merged
LK4D4 merged 1 commit into
moby:masterfrom
allencloud:support-insecure-registry-config-reload
Oct 20, 2016
Merged

support insecure registry in configuration reload#22337
LK4D4 merged 1 commit into
moby:masterfrom
allencloud:support-insecure-registry-config-reload

Conversation

@allencloud
Copy link
Copy Markdown
Contributor

@allencloud allencloud commented Apr 26, 2016

Make docker support more configuration reload, like insecure-registry.

This pr did:

  1. add --insecure-registries configuration reload
  2. add unit test for --insecure-registries reload
  3. update docs about daemon's configuration reload
  4. fix bug that 127.0.0.0/8 will be duplicated when it is in daemon.json

fixed #22332

@allencloud allencloud force-pushed the support-insecure-registry-config-reload branch from d353874 to 95e671e Compare April 26, 2016 15:35
@allencloud allencloud force-pushed the support-insecure-registry-config-reload branch 5 times, most recently from ee2739d to 2a57374 Compare April 26, 2016 16:45
@allencloud
Copy link
Copy Markdown
Contributor Author

Any update?

@thaJeztah
Copy link
Copy Markdown
Member

design LGTM

@aaronlehmann @tiborvass wdyt? This keeps the --insecure-registries a daemon-level setting, but allows it to be set on a running daemon, which makes it easier for people to use.

@aaronlehmann
Copy link
Copy Markdown

Yeah, I like the concept. I don't really follow how the code changes work, though. Where does serviceConfig.InsecureRegistries get populated? See newServiceConfig in registry/config.go for how this happens on startup. This gets called by

registryService := registry.NewService(cli.Config.ServiceOptions)

from daemon's start function.

My apologies if I am missing something.

@allencloud allencloud force-pushed the support-insecure-registry-config-reload branch from 2a57374 to 01c7125 Compare May 6, 2016 08:59
@icecrime
Copy link
Copy Markdown
Contributor

Moving to code review.

@icecrime
Copy link
Copy Markdown
Contributor

@aaronlehmann
Copy link
Copy Markdown

@icecrime: See my question above.

@yank1
Copy link
Copy Markdown
Contributor

yank1 commented May 13, 2016

LGTM

@allencloud allencloud force-pushed the support-insecure-registry-config-reload branch 2 times, most recently from d0acf00 to 4aab6a4 Compare May 13, 2016 02:56
@thaJeztah
Copy link
Copy Markdown
Member

ping @allencloud could you answer @aaronlehmann's question?

@thaJeztah thaJeztah added this to the 1.12.0 milestone May 13, 2016
@allencloud
Copy link
Copy Markdown
Contributor Author

@thaJeztah @icecrime @aaronlehmann
Actually yesterday I compiled the docker binary within this pr, but it does not work for me. I will check more until it works.

Comment thread daemon/daemon_test.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would be better to check multiple entries as the interface supports it.

@thaJeztah
Copy link
Copy Markdown
Member

@allencloud were you still working on this?

@allencloud
Copy link
Copy Markdown
Contributor Author

@thaJeztah
Yes, Of source. Actually in the past several days, I am on a business trip. And I will work on it tomorrow.

@thaJeztah
Copy link
Copy Markdown
Member

No problem! Was going through PR's and noticed this one 👍

@allencloud allencloud force-pushed the support-insecure-registry-config-reload branch 5 times, most recently from e90b5a7 to 7a792fe Compare August 30, 2016 15:33
@pikeszfish
Copy link
Copy Markdown

+1 Any update? My friends.
It's quite a useful PR to me if merged.

@allencloud
Copy link
Copy Markdown
Contributor Author

Hi, My friends. PTAL, reloading insecure registry is really important for users to use registries. Really sorry for bothering you. @thaJeztah @aaronlehmann @icecrime @cpuguy83 @LK4D4

Comment thread registry/config.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think there are concurrency issues with writing to the live config struct without locking. It looks like it could race with isSecureIndex.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@allencloud could you address this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@thaJeztah @aaronlehmann
Oh, I am afraid race could exist. Since newRepositoryInfo would be called via ResolveRepository, while ResolveRepository would be called via daemon's field RegistryService, like repoInfo, err := daemon.RegistryService.ResolveRepository(ref).
Updated it soon.

Comment thread registry/config.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks sorta weird. You should use bytes.Equal or compare the output of (*IPNet).String() I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Definitely. In fact, when I put forward this PR, in api/types/resgistry/registry.go, there is no func (ipnet *NetIPNet) String() string implemented yet. And still separated in engine-api.

While now, I think it is better to use String(). And updated.

Comment thread daemon/daemon.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure how it's in other place, but it looks quite bad to ignore errors from Marshal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, Great. Thanks for your review. @LK4D4
I will update the PR soon.

Copy link
Copy Markdown
Contributor Author

@allencloud allencloud Oct 10, 2016

Choose a reason for hiding this comment

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

Added the err judging, and add several other places related to this issue.

@allencloud
Copy link
Copy Markdown
Contributor Author

Thanks for all your reviews. And I am really sorry for my delay.
Actually now I tried to updated the PR. Please let me know if we make some place better.

PTAL @thaJeztah @aaronlehmann @icecrime @cpuguy83 @LK4D4

Comment thread docs/reference/commandline/dockerd.md Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

typo: daemom's

Comment thread registry/config.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lowercase skip

@aaronlehmann
Copy link
Copy Markdown

I see some other places where there may be concurrency problems:

  • newIndexInfo reads config.IndexConfigs without locking
  • (*DefaultService).ServiceConfig exposes s.config.ServiceConfig to callers. The callers won't be able to lock s.config while reading from the maps.
@allencloud
Copy link
Copy Markdown
Contributor Author

@aaronlehmann
Thanks again for reviews. Concurrency is really important. I updated the PR, PTAL. Thanks.

Comment thread registry/service.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This doesn't help. s.config.ServiceConfig is returned by the function, and then it can be read by the caller while being modified by LoadInsecureRegistries.

This function either needs to return a deep copy of ServiceConfig, or be refactored so that callers do not retrieve ServiceConfig directly (i.e. methods to look up items in the maps, which hold locks while doing the lookups).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for review @aaronlehmann
I tried the second way. PTAL

@aaronlehmann
Copy link
Copy Markdown

Thanks for making the changes. I think the locking is correct now. But I'm concerned it will be hard to maintain. It's not obvious which functions should acquire the lock and which ones should not. For example isSecureIndex shouldn't acquire the lock because it's called by a function that already has the lock.

It might be better to push all the locking to the methods on DefaultService. Then every exported method that touches s.config will hold the lock. I think this would make the locking scheme clearer.

@allencloud
Copy link
Copy Markdown
Contributor Author

allencloud commented Oct 17, 2016

@aaronlehmann Thanks a lot for your suggestion.
I tried what you suggestion. And I think it indeed makes the locking scheme clearer.
In addition, to avoid inner call of exported functions, I add some unexported functions like tlsConfig.
PTAL, thanks.

Comment thread registry/service.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

servConfig.InsecureRegistryCIDRs = append(servConfig.InsecureRegistryCIDRs, s.config.ServiceConfig.InsecureRegistryCIDRs...)

Or allocate servConfig.InsecureRegistryCIDRs with the right size and use copy.

Comment thread registry/service.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

servConfig.Mirrors = append(servConfig.Mirrors, s.config.ServiceConfig.Mirrors...)

Comment thread registry/service.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I know I suggested this, but now I'm not so sure. It means only one search can run at once, for example. And a running search will block calls to other DefaultService methods. I didn't realize that some of these methods are long-running.

I guess the general strategy of locking s.config in every exported method is okay as long as we release the lock before any long-running operation. Not sure if this just an issue for Search, or if it also applies to other methods.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it is my mistake to lock the entire func Search. It will block others.
Now I try to only lock s.config in Search. Like this:

        s.mu.Lock()
    index, err := newIndexInfo(s.config, indexName)
    s.mu.Unlock()

PTAL, thanks @aaronlehmann

@aaronlehmann
Copy link
Copy Markdown

LGTM

@dmcgowan @LK4D4 Could you please review as well?

My main concern with this one is getting the locking correct. It's been through a few passes and I think it's correct now (thanks @allencloud for sticking with it). There are some cases where the lock could be held for an extended period, for example isSecureIndex appears to do a hostname lookup. I don't expect this would be a big deal in practice, but I'm curious what other people think.

Signed-off-by: allencloud <allen.sun@daocloud.io>
@LK4D4
Copy link
Copy Markdown
Contributor

LK4D4 commented Oct 20, 2016

LGTM

@thaJeztah
Copy link
Copy Markdown
Member

Yay! Thanks @allencloud!

@allencloud
Copy link
Copy Markdown
Contributor Author

🤗 Thanks for all of your help and guide.

@fsword
Copy link
Copy Markdown

fsword commented Nov 7, 2016

Thanks for the pr, but it cannot do the thing well on docker for Mac. The gui app just has apple&restart button and not reload button here.

@thaJeztah
Copy link
Copy Markdown
Member

@fsword this PR will be in docker 1.13, so isn't available yet; also, for enhancements for the docker for mac ui, please use https://github.com/docker/for-mac/issues

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