craftcms / nitro

Speedy local dev environment for @craftcms.
https://getnitro.sh
MIT License
178 stars 24 forks source link

Command from Nitro to trust certificate - syntax incorrect #460

Closed darylknight closed 2 years ago

darylknight commented 2 years ago

Description

Following the instructions here: https://craftcms.com/docs/nitro/2.x/windows.html#manually-trust-certificates-and-edit-the-hosts-file I ran nitro trust, and was told to enter this:

image

I opened an Administrator Command Prompty and entered certutil -addstore -f "Root" \\wsl$\Ubuntu-20.04\home\darylknight\.nitro\nitro.crt82 <nil> and got this error:

image

Additional info

jasonmccallister commented 2 years ago

@darylknight I see what the issue is an I will work on getting that into the next release... It appears we are not trimming the string correctly on the URL. If you remove the trailing 82 it should work. Can you verify it works when removing that and I will look at fixing it ASAP.

darylknight commented 2 years ago

Thanks Jason - it looks like this command worked:

certutil -addstore -f "Root" \\wsl$\Ubuntu-20.04\home\darylknight\.nitro\nitro.crt so also removing the <nil> mentioned in the instructions

The confirmation I get is:

C:\Windows\system32>certutil -addstore -f "Root" \\wsl$\Ubuntu-20.04\home\darylknight\.nitro\nitro.crt
Root "Trusted Root Certification Authorities"
Signature matches Public Key
Certificate "Caddy Local Authority - 2022 ECC Root" added to store.
CertUtil: -addstore command completed successfully.

I assume it works now, but can't actually test it - running any of my sites in the browser at http://sitename.nitro (or https) is still showing me this:

image

I have no idea why that's happening, and was hoping it was the certificate step but looks like that wasn't the cause.

darylknight commented 2 years ago

Problem solved. I just ran nitro apply and saw this:

image

This step is not mentioned anywhere in the docs for running Nitro on Windows

jasonmccallister commented 2 years ago

@darylknight created a new issue to track that bug.

@mattstein maybe worth looking at the docs for Windows?

mattstein commented 2 years ago

It is mentioned with an explanation of why it’s required:

The first time you add a Craft site, you’ll need to manually run a command on the Windows host machine to import a certificate file so SSL will work. You can follow the terminal output for exact instructions.

Nitro cannot edit the Windows hosts file at C:\Windows\system32\drivers\etc\hosts and will provide you with copy+paste instructions when it needs the file updated.

Will add an output example so it’s harder to miss and easier to search.

darylknight commented 2 years ago

Ok - so it looks like there are two points where things have to be manually added on Windows:

The first time you add a Craft site, you’ll need to manually run a command on the Windows host machine to import a certificate file so SSL will work. You can follow the terminal output for exact instructions. This works - Nitro tells you that you have to run the certutil command, which is when I created this issue

Nitro cannot edit the Windows hosts file at C:\Windows\system32\drivers\etc\hosts and will provide you with copy+paste instructions when it needs the file updated. The first time you add a site, Nitro doesn't tell you that you have to edit the hosts file. I only saw these copy/paste instructions when I ran nitro apply for a different reason

mattstein commented 2 years ago

I think that’s expected because of when Nitro gets to certain internal updates—but @jasonmccallister can correct me if I’m wrong.

I’ll add a tip to the docs since it’s kind of confusing / unexpected.

jasonmccallister commented 2 years ago

That is correct. Running nitro add only updates the ~/.nitro/nitro.yaml file. Nothing gets "applied" to Docker until nitro apply is ran. It will look at the nitro.yaml and add/remove containers based on whatever is in the configuration.

jasonmccallister commented 2 years ago

@darylknight in your terminal, can you provide the output of the following commands?

echo $WSL_DISTRO_NAME
echo $USER
darylknight commented 2 years ago

I'm sorry, I don't have this all set up anymore. I was just playing around trying to get Nitro set up on Windows, but am back on Mac now.

jasonmccallister commented 2 years ago

Ok, no worries!