Skip to content

Conversation

@youknowriad
Copy link
Contributor

@youknowriad youknowriad commented Mar 8, 2025

Related issues

Summary

This PR adds SSL/HTTPS support to WordPress Studio, allowing users to create sites with custom domains and secure connections. Key features include:

  • Added HTTPS to WordPress Studio sites
  • Implemented certificate management system with auto-generation and trust helpers
  • Updated the proxy server to handle HTTPS

Details

  • Certificate authority generation and site certificate issuance
  • Automatic certificate trust helpers with OS-specific instructions
  • UI updates to site creation form for enabling HTTPS
  • Menu option to help users trust certificates

These changes make WordPress Studio sites more realistic for local development by supporting custom domains with proper HTTPS, closely mimicking production environments.

Testing instructions

  • Create a new site
  • Check "use custom domaine" and "use https" (they go hand in hand)
  • On newer MacOS versions, it seems it's not possible to install the root certificate automatically, so you can open the "Help > Trust certificate" dialog which provides instructions on how to do so.
  • If you don't install the certificate, you'll see the warning in the browser when trying to access the site.

I didn't test Windows yet.

The PR is largely unpolished at the moment but I believe it's a decent start, so we can start looking at polishing the UI and the implementation.

@youknowriad youknowriad requested review from a team and mcsf March 8, 2025 12:38
@youknowriad youknowriad self-assigned this Mar 8, 2025
@youknowriad youknowriad requested a review from matt-west March 8, 2025 12:43
@andreilupu
Copy link

andreilupu commented Mar 8, 2025

Yaaaay 😃 I can't wait for this feature to land in production.

As far as I can see, this feature prefers to use only one Certificate for all the sites, opposed to LocalWP which creates one for each site. This is already better.

Trying to help somehow, I've built this branch and started a new WP instance with HTTPS checked. On my end, macOS, the site is not accessible(ERR_CONNECTION_CLOSED) even if I trust the certificate. After I find how to debug PHP/nginx logs, I'll be back with more details. <- scratch this, it was a port conflict with LocalWp.

Some feedback about the Your connection is not private warning when the certificate is not trusted yet. Some people might not know how to deal with it, and the small notice on the site creation is not enough. Maybe we can put another alert box in the Overview tab to inform the user that they haven't trusted the certificate yet?
I'm pretty sure this error can be matched when the Theme preview thumbnail is updated.

@youknowriad
Copy link
Contributor Author

As far as I can see, this feature prefers to use only one Certificate for all the sites, opposed to LocalWP which creates one for each site. This is already better.

This might work similarly to Local (although I don't know Local very well). You have to trust what is called the "root" certificate but we do generate a certificate for each site internally, but they will just work when you trust the "root" certificate.

@youknowriad youknowriad changed the title Add SSL Support STU-19: Add SSL Support Mar 9, 2025
Base automatically changed from add/custom-domain-support to trunk March 10, 2025 10:09
Copy link
Contributor

@matt-west matt-west left a comment

Choose a reason for hiding this comment

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

Thanks @youknowriad!

The dialog with the instructions for trusting a certificate disappears once you click the "Open Certificate File" button. If you didn’t read the instructions fully—which many won’t—you’ll now have to go back and open the dialog again to find out what to do next.

Screenshot 2025-03-10 at 11 37 05

Perhaps we could show these instructions in the site creation modal once you click the link instead?

Let’s add a row to the Settings tab that shows if SSL is enabled. If it is, we should display a Trust link that shows a modal with the instructions for trusting the certificate.

Screenshot 2025-03-10 at 11 25 13

It would be great to have an option to enable SSL for existing sites too. I assume that will require the ability to add custom domains to existing sites first though.

@youknowriad
Copy link
Contributor Author

Let’s add a row to the Settings tab that shows if SSL is enabled. If it is, we should display a Trust link that shows a modal with the instructions for trusting the certificate.

I'll add a row to just show the value but no link at the moment. We need a generic solution to be able to change the url of the WP site. We should create a dedicate issue for that. It applies to both changing the domain and when you trust/untrust a site.

@youknowriad
Copy link
Contributor Author

Perhaps we could show these instructions in the site creation modal once you click the link instead?

Do you mean show the instructions inline? I can do that, I'm wondering if it's too much information inline though.

@matt-west
Copy link
Contributor

@youknowriad Yes. We can keep the existing link, then show the instructions inline once it’s clicked.

@youknowriad
Copy link
Contributor Author

Screen.Recording.2025-03-11.at.10.27.50.AM.mov

Is this what you had in mind @matt-west ? I find it a bit weird that you have to click and scroll multiple times. What if instead we keep the dialog but ensure it stays open when you open the certificate.

Let me know what you prefer.

@matt-west
Copy link
Contributor

@youknowriad Yes, that’s what I thinking. I agree that it feels a bit to have all these extra section appear though.

If we can keep the dialog open, that’s a good compromise.

// macOS - Use sudo to add to system keychain
await new Promise< void >( ( resolve, reject ) => {
sudo.exec(
`security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "${ CA_CERT_PATH }"`,
Copy link
Member

Choose a reason for hiding this comment

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

TLS is way out of my comfort zone, so please bear with me.

Why add the CA as a trusted certificate to the system-wide keychain? Wouldn't it be enough (and more conservative) to add it to the current user's (~/Library/Keychains/login.keychain-db)? If so, I don't think you need sudo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my test it was necessary to install the certificate system wide. But could use more testing.

@mcsf
Copy link
Member

mcsf commented Mar 14, 2025

Something that I think is worth trying in the certificate manager:

  1. Generate a Root CA, self-sign it, and trust it system-wide
  2. Using the Root CA, generate an Intermediate CA restricted to only issue certificates in the *.wp.local domain
  3. Delete the Root CA's private key
  4. Ensure the Intermediate CA's files are only accessible to the user (chmod -go $f)
  5. From that moment on, only use the Intermediate CA to issue/manage local sites' certificates

First I thought of simply setting chmod 000 on the Root CA, but now I think it's worth trying this more drastic approach. It seems to me that, theoretically, this would guarantee that any unwanted access to these keys could only be used to impersonate Studio sites, nothing else.

I believe the procedure goes like this:

  • Issue a Root CA, as we already do
  • Generate a private key for the Intermediate CA
  • Create a Certificate Signing Request (CSR) for the Intermediate CA:
    • Set up a configuration including the Subject Alternative Name (SAN) extension for *.wp.local
    • Generate a CSR for that configuration
  • Sign the Intermediate CA's CSR with the Root CA
    • In OpenSSL, the new CA can be verified with openssl x509 -in intermediateCA.crt -noout -text, which should reveal the correct SAN
  • Hopefully, then, delete the Root CA's private key

@matt-west
Copy link
Contributor

Testing this again, it feels like there are way too many pop-ups if I try to trust the certificate while creating the site. I get lost in all the different dialogs and windows that appear.

Screenshot 2025-03-14 at 11 31 30

I don’t think we should introduce the flow for trusting a certificate as part of the site creation flow. Instead this link should open the browser with a help doc containing the instructions. I can easily keep that alongside Studio while I set up the site, whereas the current dialog prevents me from interacting with the Studio UI.

Screenshot 2025-03-14 at 11 13 39

We then need a link on the site settings tab to open the certificate file. We can include a brief explanation of why the certificate needs to be trusted and a link to the help doc too.

image

Is this possible @youknowriad?

@youknowriad
Copy link
Contributor Author

A link on the site settings tab is possible but only after this other PR lands #1064 :)

@matt-west
Copy link
Contributor

@youknowriad Why? That PR allows you to change the custom domain, but my suggestion is just to display the "Trust certificate" link + copy for sites that already have SSL enabled. We would hide it for sites that don’t have SSL enabled.

We can follow up in another PR to add the ability to enable SSL on an existing site.

@fredrikekelund
Copy link
Contributor

@mcsf, your proposal seems quite sound, but two questions popped up for me:

  1. Do we need the intermediate certificate? Can't we put the same domain restrictions on the root certificate?
  2. If we make it so *.wp.local are the only domains that support HTTPS, we'd need to update the custom domains feature accordingly. I think this is a reasonable limitation from a security perspective, but we need to consider this from a UI standpoint, @youknowriad.

@youknowriad
Copy link
Contributor Author

@matt-west because that PR introduces the code that updates the domain name when you edit site settings which is required when the url moves from http to https.

@youknowriad
Copy link
Contributor Author

That PR allows you to change the custom domain, but my suggestion is just to display the "Trust certificate" link + copy for sites that already have SSL enabled. We would hide it for sites that don’t have SSL enabled.

So you're saying we should keep the "toggle" on the creation modal, I thought you wanted to remove it from there. Ok, yes, this change we can do here, without waiting for the other PR :) Sorry for the confusion.

@youknowriad
Copy link
Contributor Author

When the domain is not under wp.local, the Overview screen is rendered as if it is still loading, with flashing placeholders (see screenshot below).

I can't reproduce this.

There is nothing either preventing or explaining to the user what happens when they choose a non-wp.local domain with SSL enabled.

Yes, this is pending a decision above, either limit the creation of such domains or add a message.

Site initialisation is feeling a lot slower to me (and on a new machine). I can't guarantee it's directly tied to this PR, or its original base (custom domains), or just a coincidence.

I've noticed this before in other PRs too.


Seems like all the comments are addressed. The last blocker is a decision on what to do here https://github.com/Automattic/studio/pull/1034/files/cbbabe32b15459d1e8a7ac0a72e59f58c6eb46ad#diff-e2be6df548f75063abd8db0f241c35626f7af6a1c6a10c429935de5f902dbbc6

@fredrikekelund
Copy link
Contributor

I can't reproduce this.

Was that before making the change to src/screenshot-window.ts?

@mcsf
Copy link
Member

mcsf commented Mar 21, 2025

I can't reproduce this.

Was that before making the change to src/screenshot-window.ts?

You're right, the issue is gone. ✅

@wojtekn
Copy link
Contributor

wojtekn commented Mar 21, 2025

This is a significant change! 🥳 I haven't looked into code much yet, but I reviewed the discussion and tried to approach it as a general Studio user:

  1. Start Studio
  2. Click 'Add site', enable custom domain and HTTPS
  3. Provide the password to let Studio add a hosts entry
  4. Click a screenshot to open the site

The site is started, opens in the browser, and displays a certificate error. I was not sure how to proceed further.

As I read the thread above and found some clues, I navigated to Settings and located "HTTP Enabled Trust Certificate. I opened a .crtfile and was asked to add the certificate to a keychain. I approved, restarted the browser, and still couldn't make it work. Then, I tested Local's flow and discovered that I needed to locate my certificate in the keychain and mark it as trusted. I restarted the browser, and it works fine now.

Questions related to UX:

  1. I can't see any easy transition from the "Add a site" step to the "Trust Certificate". The site starts and doesn't work in the browser. Should we automatically open Settings and highlight the part with the certificate when the user adds or starts a site configured to use HTTPS and the certificate is not trusted yet? Or display dialog asking user to do so?
  2. Should we add a 'Learn more' link near the 'Enable HTTPS' field, what could also improve UX issue from the previous point?
  3. I noticed that the Trust Certificate link and all instructions are hidden for sites with HTTPS disabled, which makes sense. Should we hide it also for those with HTTPS enabled when the certificate is already trusted?

@fredrikekelund
Copy link
Contributor

I can't see any easy transition from the "Add a site" step to the "Trust Certificate". The site starts and doesn't work in the browser. Should we automatically open Settings and highlight the part with the certificate when the user adds or starts a site configured to use HTTPS and the certificate is not trusted yet? Or display dialog asking user to do so?

Displaying a dialog seems like a good approach. Trusting the certificate is required, and dialogs can't be missed. This could be a separate PR, because we only want to open that dialog when the root certificate isn't already trusted, and we need to figure out the best way for determining that.

Should we add a 'Learn more' link near the 'Enable HTTPS' field, what could also improve UX issue from the previous point?

I agree we should do this. I previously suggested adding an explainer text below that checkbox.

I noticed that the Trust Certificate link and all instructions are hidden for sites with HTTPS disabled, which makes sense. Should we hide it also for those with HTTPS enabled when the certificate is already trusted?

Seems like a good idea 👍 This could also be a follow-up PR together with the dialog that opens after adding or editing a site.

@youknowriad
Copy link
Contributor Author

Since this PR is getting big and to track the improvements we can make later, I opened this follow-up issue to address the different points that require detection of whether the root certificate is trusted.

Copy link
Contributor

@fredrikekelund fredrikekelund left a comment

Choose a reason for hiding this comment

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

Great work, @youknowriad 👍 I left a couple of final comments, but they are all minor concerns.

@youknowriad youknowriad enabled auto-merge (squash) March 21, 2025 16:02
@youknowriad youknowriad merged commit 2b5023d into trunk Mar 21, 2025
4 of 7 checks passed
@youknowriad youknowriad deleted the add/ssl-support branch March 21, 2025 16:03
@youknowriad
Copy link
Contributor Author

Thanks all for the help landing this. I'm very excited about this one. The project is not done yet, there's a few related issues, you can follow on Linear.

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.

Feature Request: SSL

7 participants