Repository navigation
Static configuration of webserver and dbserver localhost ports, bind only to localhost, fixes #1491, fixes #941, #642 too - #1502
Conversation
|
Artifacts for this round are at https://circleci.com/gh/drud/ddev/10976#artifacts/containers/0 and testing would be fantastic. @tmotyl and @t3easy |
d4e31e8 to
a0c8451
Compare
|
@andrewfrench this one requires a significant effort both with the code review and manual testing and your review of the basic approach. I think it's good, but sure look forward to your opinion. I guess the biggest basic design question is whether the host database should be kept in global_config.yaml (as currently) or split into a different file. We'll see what you think. I also took a few minutes to think about docs and decided it didn't need extra, but interested in your opinion. The new items for the host db and web ports are documented in the text at the bottom of config.yaml. |
fff68fb to
971778f
Compare
|
Hey @rfay, I'm working through review of this now and it adds a huge amount of both immediate utility and future potential for expanding on the local database of projects idea. Managing port claims in global_config.ddev works for me, but I was able to spot some issues regarding the way project ports are claimed in global_config.ddev: after a project is configured and its ports are claimed under the project's name, the normal methods of changing the project name cause failed starts, like editing the "name" field in .ddev/config.yaml or I can imagine a few solutions to this:
|
|
Wow @andrewfrench I think you just saved a lot of people a lot of pain. Thanks for checking that carefully. I think the fundamental error I've introduced is reserving the port for every single project, when only a few people have actually requested it. I'll experiment with only reserving globally when explicitly specified in project config.yaml. It was just wrong to have a second global reservation at this point (besides project name) My initial response to the general issue is that we've always used project name as the unique systemwide identifier, but we haven't ever enforced it. As a result of this undocumented assumption, we have occasional failures like
I suspect we can solve both of those pretty easily as this functionality gets fleshed out. In the next sprint we can add the project directory and it will solve an enormous amount of this kind of trouble, and also allow |
|
@andrewfrench I changed the logic so that the port is dynamic unless specified in the config.yaml, and not reserved in the global_config.yaml unless it's set as static in config.yaml. I think this is far more in keeping with the request, and should solve the problem you described. |
| // ReservePorts() adds the ProjectInfo if necessary and assigns the reserved ports | ||
| func ReservePorts(projectName string, ports []string) error { | ||
| // If the project doesn't exist, add it. | ||
| _, ok := DdevGlobalConfig.ProjectList[projectName] |
There was a problem hiding this comment.
After playing around with this post-update, I think there should be a check either here or perhaps in the caller that returns early if len(ports) == 0. As written, an empty ProjectInfo struct and usedhostports list are written to global_config.yaml, even if no ports are reserved -- not the end of the world, but adds some unneeded clutter to that config file.
There was a problem hiding this comment.
This sounded like a great idea, and I started working on it... but since I was a good boy and used a struct instead of a map, I can't do it without removing the entire ProjectInfo, which would mess up future uses of the list.
|
I noticed that |
andrewfrench
left a comment
There was a problem hiding this comment.
Approving after confirming that this works quite well, especially after only reserving ports when requested. I've left a couple notes about non-blocking preferences, but this does a great job of:
- Reserving a webserver/db port when requested in .ddev/config.yaml
- Preventing other projects from reserving the ports already reserved by another project in global_config.yaml
- Running containers on their requested ports
- Removing port reservations from global_config.yaml on
ddev rm --remove-data
We can't actually use it because it assumes binding to localhost This reverts commit 7d42cb6.
f4cf414 to
fe9e614
Compare
|
I added the config flags and some test coverage. Couldn't get rid of the empty used_host_ports in global_config unless you have a suggestion about how to do that @andrewfrench . Thanks for the careful review. Saved an enormous amount of future pain. |
|
|
||
| type ProjectInfo struct { | ||
| UsedHostPorts []string `yaml:"used_host_ports,flow"` | ||
| UsedHostPorts []string `yaml:"used_host_ports,omitempty,flow"` |
There was a problem hiding this comment.
I confirmed that this will hide the used_host_ports list when none were requested, but also played around with the logic in CheckAndReserveHostPorts (ddevapp/config.go) that prevents the project info map record from being generated when no relevant port information was provided, I'll comment there as well.
| return err | ||
| } | ||
| } | ||
| err := globalconfig.ReservePorts(app.Name, portsToReserve) |
There was a problem hiding this comment.
If this call to globalconfig.ReservePorts is moved up inside the if block right before it (if len(portsToReserve) > 0 {), the project info map won't be written to the global config file in the case where no ports are requested. There may be some unintended consequences there that I'm not considering, but it does seem a touch cleaner in the general case from what I can tell.
There was a problem hiding this comment.
Yeah, but I want the project info map always, for future use. I'm expecting it to be there for every project by the next sprint, containing a minimum of the approot. Given that I want it in the projectlist, are you good with it?
There was a problem hiding this comment.
Yep, in that case it's totally fine after your most recent commit.
The Problem/Issue/Bug:
fixes #1491, fixes #941
OP #1491: For security reasons, host binding of the dbserver should only be localhost (127.0.0.1) not 0.0.0.0 (the default, all interfaces), because this allows other people on the network to possibly probe for the database connection, depending on firewall configuration.
OP #941: Keep a stable port number for the localhost ephemeral ports so that people can use standard techniques to access them.
#642: We've long talked about keeping a catalog of metadata even for projects that aren't running. This PR introduces that.
How this PR Solves The Problem:
host_db_portandhost_webserver_portto config.yaml, use those values in the docker-compose.yaml.This is actually an amazing step forward for us. For the first time it provides a global database of projects, as requested in #642 . It's now trivial to add additional project information in the global_config.yaml.
Manual Testing Instructions:
ifconfigon macOS and Linux to view other interfaces). You can test withtelnet localhost 33434for port 33434,telnet 172.28.99.33 33434for a denied access to the same port on the 172.28.99.33 IP address (you must use the one that pertains to your system). Alternately, check from another machine on your network, but this requires the firewall to be turned off for correctness.Automated Testing Overview:
Release/Deployment notes:
We'll probably want to tell people to do a
ddev configon existing projects, which will add the new items in config.yaml.