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

[AUTH-1236] Optionally support accepting HTTPS connections in addition to HTTP #472

Merged
merged 11 commits into from
Mar 12, 2022

Conversation

timdawborn
Copy link
Contributor

@timdawborn timdawborn commented Feb 28, 2022

Under certain situations, we want the proxay server to accept connections over HTTPS instead of over HTTP for CORS reasons. This PR adds an option to optionally supply a HTTPS key and cert on the CLI, and if both are provided, HTTPS support is enabled. Both HTTP and HTTPS run side by side in this situation.

@CLAassistant
Copy link

CLAassistant commented Feb 28, 2022

CLA assistant check
All committers have signed the CLA.

@timdawborn timdawborn changed the title [AUTH-1236] Supporting running the server in HTTPS mode instead of HTTP mode [AUTH-1236] Support running the server in HTTPS mode instead of HTTP mode Feb 28, 2022
@timdawborn timdawborn changed the title [AUTH-1236] Support running the server in HTTPS mode instead of HTTP mode [AUTH-1236] Optionally support accepting HTTPS connections in addition to HTTP Feb 28, 2022
Copy link
Contributor

@fwouts fwouts left a comment

Choose a reason for hiding this comment

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

A wild @fwouts appears!

Super interesting stuff!

httpsServer = https.createServer(httpsOptions, handler);
}

// Copied from https://stackoverflow.com/a/42019773/16286019
Copy link
Contributor

Choose a reason for hiding this comment

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

🤯

src/server.ts Show resolved Hide resolved
@@ -113,6 +169,7 @@ export class RecordReplayServer {
request.path === "/__proxay"
) {
res.end("Proxay!");
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bug fix.

@@ -154,7 +211,12 @@ export class RecordReplayServer {
this.unloadTape();
res.end(`Unloaded tape`);
}
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is also a bug fix.


// If we got here, we don't know what to do. Return a 404.
res.statusCode = 404;
res.end(`Unhandled proxay request.\n\n${JSON.stringify(request)}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is also a bug fix. Currently if a __proxay/blah request is made for an unhandled route, the server hangs indefinitely. This adds a 404 response and logs out the request for debugging.

src/server.ts Show resolved Hide resolved
@timdawborn
Copy link
Contributor Author

A wild @fwouts appears!
Super interesting stuff!

Holy crap, Batman! G'day, stranger.

@timdawborn timdawborn marked this pull request as ready for review March 10, 2022 00:55
Copy link

@rickyrattlesnake rickyrattlesnake left a comment

Choose a reason for hiding this comment

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

👍 just some questions for my own understanding.

src/cli.ts Outdated
Comment on lines 22 to 25
.option(
"--https-ca <filename.pem>",
"Enable HTTPS server with this CA certificate. Also requires --https-key and --https-cert."
)

Choose a reason for hiding this comment

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

question: Are there any issues around invalid certificates detected by the browser (and throwing the warning screen)? A readme section would be awesome on how to use this feature.

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll add a README around this.

// Pause the socket
socket.pause();

// Determine if this is an HTTP(s) request

Choose a reason for hiding this comment

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

nit: Can we encapsulate this https determination logic to a separate function/module? Makes it easier to understand the intent

src/server.ts Show resolved Hide resolved
httpsServer = https.createServer(httpsOptions, handler);
}

// Copied from https://stackoverflow.com/a/42019773/16286019

Choose a reason for hiding this comment

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

question: Why do we have the requirement to server Https and Https over the same port?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, now that is an excellent question. The short answer is cypress. The slightly longer answer is during web testing, requests are made to proxay directly and via an nginx rewrite. The former (will shortly be) HTTPS and the later is HTTP. The later can't easily be made HTTPS due to docker-compose circular dependency reasons.

Choose a reason for hiding this comment

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

Cheers for the context!

I assume we can't point nginx -> proxay to a http port (using docker), and still have cypress -> proxay using the https port.

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 might be possible, I'd have to check again. I was having issues with that earlier but I may have solved them now.

@timdawborn timdawborn merged commit f3ca466 into master Mar 12, 2022
@timdawborn timdawborn deleted the AUTH-1236-support-incoming-https-connections branch March 12, 2022 07:19
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.

None yet

5 participants