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

feat: support HTTPS for Manager API #1824

Merged
merged 9 commits into from
Apr 29, 2021
Merged

feat: support HTTPS for Manager API #1824

merged 9 commits into from
Apr 29, 2021

Conversation

nic-chen
Copy link
Member

Please answer these questions before submitting a pull request, or your PR will get closed.

Why submit this pull request?

  • Bugfix
  • New feature provided
  • Improve performance
  • Backport patches

What changes will this PR take into?

Support for HTTPS by configuring SSL certificate.

Related issues

resolve #1706

Checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@netlify
Copy link

netlify bot commented Apr 25, 2021

Deploy preview for apisix-dashboard ready!

Built with commit 356ca4c

https://deploy-preview-1824--apisix-dashboard.netlify.app

@codecov-commenter
Copy link

codecov-commenter commented Apr 25, 2021

Codecov Report

Merging #1824 (9f7ebee) into master (2f3717f) will decrease coverage by 0.48%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1824      +/-   ##
==========================================
- Coverage   72.07%   71.59%   -0.49%     
==========================================
  Files         125      172      +47     
  Lines        2944     6119    +3175     
  Branches      711      711              
==========================================
+ Hits         2122     4381    +2259     
- Misses        822     1490     +668     
- Partials        0      248     +248     
Flag Coverage Δ
backend-e2e-test 45.98% <0.00%> (?)
backend-e2e-test-ginkgo 49.00% <0.00%> (?)
backend-unit-test 52.44% <ø> (?)
frontend-e2e-test 72.14% <ø> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
api/cmd/managerapi.go 48.35% <0.00%> (ø)
api/internal/conf/conf.go 61.03% <0.00%> (ø)
api/internal/route.go 85.29% <0.00%> (ø)
api/internal/handler/data_loader/route_export.go 73.18% <0.00%> (ø)
api/internal/log/zap.go 60.86% <0.00%> (ø)
api/internal/handler/tool/tool.go 94.44% <0.00%> (ø)
api/internal/handler/global_rule/global_rule.go 83.87% <0.00%> (ø)
api/internal/filter/recover.go 6.66% <0.00%> (ø)
api/internal/handler/healthz/healthz.go 100.00% <0.00%> (ø)
api/internal/handler/consumer/consumer.go 91.07% <0.00%> (ø)
... and 40 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5d6d7fc...9f7ebee. Read the comment docs.

}
}()
}

printInfo()
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to update the printInfo.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated.

@juzhiyuan juzhiyuan changed the title feat: support HTPS for Manager API feat: support HTTPS for Manager API Apr 25, 2021
Comment on lines 129 to 135
addrSSL := fmt.Sprintf("%s:%d", conf.ServerHost, conf.SSLPort)
serverSSL := &http.Server{
Addr: addrSSL,
Handler: r,
ReadTimeout: time.Duration(1000) * time.Millisecond,
WriteTimeout: time.Duration(5000) * time.Millisecond,
}
Copy link
Member

Choose a reason for hiding this comment

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

Hey, Nice work 👍 .
I think we should go with adding a custom TLS configuration to make it more secure. Also, a go server automatically upgrades requests to HTTP/2 if a tlsconfig is set with HTTPS.

Referring to an awesome blog from cloudflare.
Thanks :)

Copy link
Member Author

Choose a reason for hiding this comment

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

updated. thanks.

@@ -124,6 +128,29 @@ func NewManagerAPICommand() *cobra.Command {
}
}()

// HTTPS
if conf.SSLCert != "" && conf.SSLKey != "" {
addrSSL := fmt.Sprintf("%s:%d", conf.ServerHost, conf.SSLPort)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use net.JoinHostPort

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed.

@imjoey
Copy link
Member

imjoey commented Apr 27, 2021

@nic-chen FYI, the CI failure in FE e2e has been fixed in #1826. Please rebase the code to get through it.

@nic-chen
Copy link
Member Author

@nic-chen FYI, the CI failure in FE e2e has been fixed in #1826. Please rebase the code to get through it.

done, thanks.

err := serverSSL.ListenAndServeTLS(conf.SSLCert, conf.SSLKey)
if err != nil && err != http.ErrServerClosed {
utils.CloseAll()
log.Fatalf("listen and serv fail: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.Fatalf("listen and serv fail: %s", err)
log.Fatalf("listen and serve fail: %s", err)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed.


# ssl:
# host: 127.0.0.1 # the address on which the `Manager API` should listen for HTTPS.
# The default value is 0.0.0.0, if want to specify, please enable it.
Copy link
Contributor

Choose a reason for hiding this comment

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

We may also support the mTLS.

Copy link
Member Author

Choose a reason for hiding this comment

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

sure. we may support mTLS in the future.

Copy link
Member

@bisakhmondal bisakhmondal left a comment

Choose a reason for hiding this comment

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

Perfect 💯

Copy link
Member

@imjoey imjoey left a comment

Choose a reason for hiding this comment

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

/lgtm

@nic-chen nic-chen merged commit f146898 into apache:master Apr 29, 2021
@nic-chen nic-chen deleted the https branch April 29, 2021 16:57
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.

security: support HTTPS for dashboard
8 participants