-
Notifications
You must be signed in to change notification settings - Fork 542
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
Changes from 5 commits
f44863d
5c6ccb4
1e7bef8
216f0aa
ba1808f
dbdef86
9f7ebee
651cfe3
356ca4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ package cmd | |||||
|
||||||
import ( | ||||||
"context" | ||||||
"crypto/tls" | ||||||
"fmt" | ||||||
"net/http" | ||||||
"os" | ||||||
|
@@ -48,6 +49,9 @@ func printInfo() { | |||||
fmt.Fprint(os.Stdout, "The manager-api is running successfully!\n\n") | ||||||
printVersion() | ||||||
fmt.Fprintf(os.Stdout, "%-8s: %s:%d\n", "Listen", conf.ServerHost, conf.ServerPort) | ||||||
if conf.SSLCert != "" && conf.SSLKey != "" { | ||||||
fmt.Fprintf(os.Stdout, "%-8s: %s:%d\n", "HTTPS Listen", conf.SSLHost, conf.SSLPort) | ||||||
} | ||||||
fmt.Fprintf(os.Stdout, "%-8s: %s\n", "Loglevel", conf.ErrorLogLevel) | ||||||
fmt.Fprintf(os.Stdout, "%-8s: %s\n\n", "Logfile", conf.ErrorLogPath) | ||||||
} | ||||||
|
@@ -124,6 +128,29 @@ func NewManagerAPICommand() *cobra.Command { | |||||
} | ||||||
}() | ||||||
|
||||||
// HTTPS | ||||||
if conf.SSLCert != "" && conf.SSLKey != "" { | ||||||
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, | ||||||
TLSConfig: &tls.Config{ | ||||||
// Causes servers to use Go's default ciphersuite preferences, | ||||||
// which are tuned to avoid attacks. Does nothing on clients. | ||||||
PreferServerCipherSuites: true, | ||||||
}, | ||||||
} | ||||||
go func() { | ||||||
err := serverSSL.ListenAndServeTLS(conf.SSLCert, conf.SSLKey) | ||||||
if err != nil && err != http.ErrServerClosed { | ||||||
utils.CloseAll() | ||||||
log.Fatalf("listen and serv fail: %s", err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||||||
} | ||||||
}() | ||||||
} | ||||||
|
||||||
printInfo() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to update the printInfo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated. |
||||||
|
||||||
sig := <-quit | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,21 @@ | |
# limitations under the License. | ||
# | ||
|
||
# yamllint disable rule:comments-indentation | ||
conf: | ||
listen: # yamllint disable rule:comments-indentation | ||
gxthrj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
listen: | ||
# host: 127.0.0.1 # the address on which the `Manager API` should listen. | ||
# The default value is 0.0.0.0, if want to specify, please enable it. | ||
# This value accepts IPv4, IPv6, and hostname. | ||
port: 9000 # The port on which the `Manager API` should listen. | ||
|
||
# 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may also support the mTLS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. we may support mTLS in the future. |
||
# port: 9001 # The port on which the `Manager API` should listen for HTTPS. | ||
# cert: "/tmp/cert/example.crt" # Path of your SSL cert. | ||
# key: "/tmp/cert/example.key" # Path of your SSL key. | ||
|
||
allow_list: # If we don't set any IP list, then any IP access is allowed by default. | ||
- 127.0.0.1 # The rules are checked in sequence until the first match is found. | ||
- ::1 # In this example, access is allowed only for IPv4 network 127.0.0.1, and for IPv6 network ::1. | ||
|
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.
Use net.JoinHostPort
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.
fixed.