-
Notifications
You must be signed in to change notification settings - Fork 32
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
Feature: Add enforce HTTPS middleware #27
Conversation
5ed6c17
to
6738279
Compare
a22b01b
to
02a19de
Compare
6738279
to
9f17631
Compare
05e1464
to
6b094ef
Compare
9f17631
to
c35b4b2
Compare
Codecov ReportBase: 91.78% // Head: 91.52% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## feature/authenticator #27 +/- ##
=========================================================
- Coverage 91.78% 91.52% -0.26%
=========================================================
Files 192 193 +1
Lines 2494 2548 +54
Branches 293 304 +11
=========================================================
+ Hits 2289 2332 +43
- Misses 158 168 +10
- Partials 47 48 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
9f31a85
to
c95709b
Compare
c35b4b2
to
8f5e50d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
packages/serve/src/lib/server.ts
Outdated
*/ | ||
private runServer(app: VulcanApplication, port: number, httpsPort: number) { | ||
const options = getEnforceHttpsOptions(this.config['enforce-https']); | ||
if (options && this.config.ssl) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we create https server without enforce-https middleware enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @oscar60310 for reviewing and suggestion, but I could not understand why we need also to create https server when enforcec-https
options are disabled ? ( I need you tell more reason ~ )
In general, we usually open http server in the local machine, if user would like to create https server, it could use the reverse proxy ?
If you would like to create local https server, it should set the LOCAL
undertans the enforce-https
options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @oscar60310 thanks for discussing with me, after discussion, I have made the HTTPS server open when enforce-https
options use defualt value ( default is LOCAL type with
enabled` ).
Besides user setup the disable for enforce-https
options, or the http server and https server will run both.
packages/serve/src/lib/server.ts
Outdated
* @param port the http port for server start, default is 3000 | ||
* @param httpsPort the https port for https server start when you set "type" = LOCAL in "enforce-https" middleware and provide ssl file, default port is 3001 | ||
*/ | ||
public async start(port = 3000, httpsPort = 3001) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: We'll need to set https port here and the option of koa sslify, maybe we can find a way the share it. e.g. store them in config file ...
NIT: Would you update CLI too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @oscar60310 for reviewing and suggestion, I have moved the httpsPort
setting into config under enforce-https
options, because the https server is only created when enforce-https
set LOCAL
type.
Btw, after I moved to the config, seems CLI no need to update too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @oscar60310, thanks for discussing with me, I have also move the http port into config for reading!
packages/serve/src/lib/server.ts
Outdated
const options = { | ||
key: fs.readFileSync(this.config.ssl.keyFile), | ||
cert: fs.readFileSync(this.config.ssl.certFile), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should provide "ca" property for CA bundle/chain.
Ref
https://medium.com/@superseb/get-your-certificate-chain-right-4b117a9c0fce
https://www.namecheap.com/support/knowledgebase/article.aspx/9705/33/installing-an-ssl-certificate-on-nodejs/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @oscar60310 for reviewing and suggestion, also thanks for sharing the document to let me know we should also provide CA bundle chain!
- add "EnforceHttpsMiddleware" to support enforcing https request. - add enforcing https middleware test cases. - add "ssl-sslify" package. - provide "runServer" method for "VulcanApplication" to start server for local https according config provide ssl file and set LOCAL mode or not.
- move the run server method from app to server class. - make the local enforce https provide http and https server. - update app test cases.
8f5e50d
to
1a62af2
Compare
- setup the https port by config when enable enforce-https with LOCAL type. - make the https server open when enforce-https options is enabled and type is LOCAL - add ca bundle file for creating https server.
0351e1f
to
1437c32
Compare
Hi @oscar60310 thanks for reviewing, suggesting and discussed with me, the PR has been fixed, please check it :) |
Description
Provide the enforce HTTPS middleware, the enforce https provide two different solution:
With Reverse Proxy
If you have a reverse proxy in the front of vulcan-sql server, then you could choose the solution to enforce request must be https.
In yaml, you could setup options in
enforce-https
( Will move out to theoptions
for following Unite extension loaders dicussion after first extension loader finished), like below:The above detail options could see in sslify. Also we change the
resolver
options totype
and addproto
forCUSTOM
type.Otherwise, the all type shown below to match different reverse proxies:
Without Reverse Proxy
If you only would like to run in the local, you could set type to
LOCAL
and providessl
options in theyaml
:Then the server will open HTTP and HTTP server to make you redirect when request with HTTP to the server, the HTTP default port is
3000
, the HTTPS default port is3001
How To Test / Expected Results
For the test result, please see the below test cases that passed the unit test:
Serve Package
Commit Message
EnforceHttpsMiddlewares
to support enforcing https request.ssl-sslify
package.runServer
method for "VulcanApplication" to start server for local https according to config provide ssl file and set LOCAL mode or not.