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

Add ssl command to download mkcert and generate ssl certificates #465

Merged
merged 45 commits into from
May 6, 2022

Conversation

shadyvb
Copy link
Contributor

@shadyvb shadyvb commented Apr 22, 2022

Copy link
Contributor

@roborourke roborourke left a comment

Choose a reason for hiding this comment

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

Nice start, pretty cool that it works like that. There's a few potential gotchas around the platform installation I've commented on and some linter errors to fix up (some dumb ones but hey).

I think next steps are:

  • Add support for reading TLDs to generate certs for from config, default to altis.dev and maybe local and localhost for now
  • Update docs, plus FAQ as noted in inline comments
  • Run the install and generate subcommands on server start (maybe an option flag or config option to not do this would be useful?)

I'm also thinking in this instance it might be worth punting the code to another class, and making the subcommands into class methods. The same can be said for more of the other commands too so we can maybe refactor at some point. Don't do anything for now, I'm just thinking about code reuse or some of the checks & output.

inc/composer/class-command.php Show resolved Hide resolved
break;
# Windows
case 'Windows':
$binary_arch = 'windows-amd64.exe';
Copy link
Contributor

Choose a reason for hiding this comment

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

Will need to check what the situation with this and WSL is. If you can run .exe from WSL, or global commands from there we might be ok. @missjwo might be able to assist in testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, testing cross-platform was supposed to be the next step. I can do that in a VM.

Copy link
Member

Choose a reason for hiding this comment

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

WSL won’t replicate accurately within a VM so far as I know, since it’s a VM itself.

For WSL though, the arch will be Linux because it’s literally a Linux VM you’re running inside of.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If composer is running within WSL, the certificate would be automatically installed to Windows store itself, which is a problem. We'll need to add docs on manually accepting the root CA.

Also, does this mean we do not support Windows itself but rather WSL ? ( I have not used WSL nor Docker on Windows )

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah there was a PR to support windows natively but I think there were some limitations to that. We do have a way to check it’s a WSL environment at least.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Happy to test stuff - just let me know when the PR is ready to be tested and what i should be looking out for.

Copy link
Member

Choose a reason for hiding this comment

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

@shadyvb Correct, only WSL is supported, per https://docs.altis-dxp.com/local-server/windows/

You can execute exe files, yeah; WSL will transparently map execution of those, and execute them. Note though, php_uname( 's' ) will return Linux because it is Linux. We need to use the Command::is_wsl() function to detect WSL, not uname.

Also happy to test with my WSL env, and screenshare as needed.

Copy link
Member

Choose a reason for hiding this comment

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

Happy to test on my windows machine. Let me know when the PR is ready to be tested.

inc/composer/class-command.php Outdated Show resolved Hide resolved
inc/composer/class-command.php Show resolved Hide resolved
inc/composer/class-command.php Show resolved Hide resolved
inc/composer/class-command.php Outdated Show resolved Hide resolved
inc/composer/class-command.php Outdated Show resolved Hide resolved
inc/composer/class-command.php Outdated Show resolved Hide resolved
inc/composer/class-command.php Outdated Show resolved Hide resolved
inc/composer/class-command.php Outdated Show resolved Hide resolved
@shadyvb
Copy link
Contributor Author

shadyvb commented Apr 25, 2022

@roborourke the domain detection and programmatic generation has been added to #466 , does not factor localhost and local though, unsure how would those be used, but should be easy enough to add.

@roborourke
Copy link
Contributor

@shadyvb yeah sorry - I was just looking there and realised that. Also verified what I was thinking about localhost and local - I was incorrect. I've linked to an avahi-daemon container that we may be able to use alongside the traefik proxy.

My thinking is if we can support .localhost and maybe .local OOTB and document how to add hosts entries for anything else that might be enough.

@shadyvb
Copy link
Contributor Author

shadyvb commented Apr 25, 2022

We can support ANY TLD when it comes to SSL certificates, if .local / .localhost would alleviate the need for DNS resolution then let's do that, unsure about that though. Either way, outside of the scope here.

Copy link
Contributor

@roborourke roborourke left a comment

Choose a reason for hiding this comment

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

Something just occurred to me re. the DNS resolution etc... right now anything .altis.dev resolves to 127.0.0.1, including sub sub domains like foo.bar.altis.dev.

So - we can keep using altis.dev as the default TLD for local dev, but, we can now generate a certificate for it locally rather than having to purchase or update a real one that only works for *.altis.dev. Not only can we generate a local cert for *.altis.dev, but also for *.<project>.altis.dev. Boom, sub sub domains with https, no need to worry about avahi/zeroconf etc etc...

inc/composer/class-command.php Outdated Show resolved Hide resolved
docker/conf/traefik.toml Outdated Show resolved Hide resolved
@@ -211,6 +220,8 @@ protected function get_env() : array {
protected function start( InputInterface $input, OutputInterface $output ) {
$output->writeln( '<info>Starting...</>' );

$this->check_ssl_certificate( $input, $output );
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to do this if the module config has secure set to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, Traefik will still expect the SSL certificate to exist, so it's safer to just generate the file either way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah right. Hmm. That's based on the current static traefik.toml file right. I was more conscious of this code running on codespaces, not sure if it'll work or not there.

break;
case 'generate':
// TODO figure out how to programmatically detect the domains to use.
$domains = $input->getArgument( 'options' )[1] ?? '*.altis.dev';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the default behaviour here should be the following:

  • Always generate certs for <project>.<tld> and *.<project>.<tld> (no harm in them being there by default, even if someone calls the function with other domains, its better to avoid surprises here IMO than assume someone knows it might be a deleterious action if we don't explicitly call that out)
  • Add support for a list of hosts in the config and merge those in by default too, we can document that custom ones must be pointed to localhost

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Traefik will need to know about the extra domains too 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the extra domains support to nginx ⬆️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also added the configured domain(s) to the domains within generate() command as discussed, also altis.dev *.altis.dev.

inc/composer/class-command.php Show resolved Hide resolved
@shadyvb
Copy link
Contributor Author

shadyvb commented May 3, 2022

@roborourke there is a dilemma here, when the site name is changed in composer.json, the naming convention for containers changes, and that brings new containers instead of reusing old ones, and leaves the old ones running.

Related to the custom domain configuration rather than SSL.

@shadyvb
Copy link
Contributor Author

shadyvb commented May 3, 2022

Related to the above ^, we can instruct people to destroy containers before changing domains, so we don't have to programmatically do that ( we do have a reference to the previous domain, but don't think it's worth the effort ).

@shadyvb
Copy link
Contributor Author

shadyvb commented May 3, 2022

Ah, another issue, since we're generating Traefik's certificate based on the project parameters ( name, tld, extra domains ), the resulting certificate won't really work for other projects (other local-server instances running on the same host), so it'll stop working there IF they're not using the default altis.dev ( which is included in certificate generation now ).

@shadyvb
Copy link
Contributor Author

shadyvb commented May 4, 2022

Labels on the proxy? Not sure I follow completely, but definitely have a play around!

Not on the proxy itself, but on containers, i.e. you put the domains as labels on web containers, and then query them while regenerating the certificate via something like docker ps -q --filter 'label=traefik.port' | xargs -I{} docker inspect {} --format='{{index .Config.Labels "traefik.port"}}' (substituting traefik.port with our custom key e.g. traefik.domain).

@shadyvb
Copy link
Contributor Author

shadyvb commented May 4, 2022

.. same can be done if we decide to manage the hosts entry automagically as well, we'd have the list of domains that needs to be added.

@shadyvb
Copy link
Contributor Author

shadyvb commented May 4, 2022

S3, Tachyon, and Analytics services are now working as expected after 81ab150 and 90ce957

@shadyvb
Copy link
Contributor Author

shadyvb commented May 4, 2022

Added a notice about missing hosts entries with a full line to copy/paste into /etc/hosts.

Next:

  • Figure out complexity of managing custom domains across all running instances of Altis local-server > Should be straight-forward by labeling containers with domains and collecting those labels via the command above to generate the certificate, will defer that to a new issue though so we can ship this change here sooner.
  • Fix tests
  • Document the changes

@shadyvb shadyvb requested a review from roborourke May 4, 2022 12:19
Copy link
Contributor

@roborourke roborourke left a comment

Choose a reason for hiding this comment

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

One very minor suggestion to just return the exit codes versus using exit( 1 ); but it's up to you, the result is exactly the same.

This is really thorough, well thought out and makes this feature about as helpful for devs as it can possibly be. Great work bud

inc/composer/class-command.php Outdated Show resolved Hide resolved
inc/composer/class-command.php Outdated Show resolved Hide resolved
@shadyvb
Copy link
Contributor Author

shadyvb commented May 5, 2022

Further actions:

You may find that file sharing performance or server response times are slower than you would like on Windows or MacOS. Local Server provides an experimental integration with [Mutagen](https://mutagen.io/) to resolve this.

See the [Mutagen set up guide for detailed instructions on how to install and run it](./mutagen-file-sharing.md).

#### Subdomain and Custom domains in multisites
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want this under experimental features? Custom domains / codespaces perhaps but I think the SSL stuff itself doesn't need to be considered experimental as we need it to work for the default TLD at the very least.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's experimental in the sense that it is tied to custom domains which is experimental 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, and we might want to remove it altogether in favor of Traefik managing it on its own, given the centralization needed. I'm writing the issue around that that would explain my suggested approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #475

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it’s fine to not list it as experimental personally, codespaces definitely will be to start with

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@roborourke Updated docs in 2f11c98 , should be ready for a final review.

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

Successfully merging this pull request may close these issues.

4 participants