Skip to content

Commit 8268a9c

Browse files
authored
Add proxy-ssl-termination option (#347)
Can be used when sish runs behind a reverse proxy to display HTTPS URLs despite running on the HTTP port Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
1 parent e08f49a commit 8268a9c

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

cmd/sish.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func init() {
9999
rootCmd.PersistentFlags().BoolP("proxy-protocol", "", false, "Use the proxy-protocol while proxying connections in order to pass-on IP address and port information")
100100
rootCmd.PersistentFlags().BoolP("proxy-protocol-use-timeout", "", false, "Use a timeout for the proxy-protocol read")
101101
rootCmd.PersistentFlags().BoolP("proxy-protocol-listener", "", false, "Use the proxy-protocol to resolve ip addresses from user connections")
102+
rootCmd.PersistentFlags().BoolP("proxy-ssl-termination", "", false, "Whether sish is running behind an SSL-terminated reverse proxy\nIf true, the displayed HTTP URL will use `https://` despite running on port 80")
102103
rootCmd.PersistentFlags().BoolP("https", "", false, "Listen for HTTPS connections. Requires a correct --https-certificate-directory")
103104
rootCmd.PersistentFlags().BoolP("force-all-https", "", false, "Redirect all requests to the https server")
104105
rootCmd.PersistentFlags().BoolP("force-https", "", false, "Allow indiviual binds to request for https to be enforced")

config.example.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ proxy-protocol-policy: use
7979
proxy-protocol-timeout: 200ms
8080
proxy-protocol-use-timeout: false
8181
proxy-protocol-version: "1"
82+
proxy-ssl-termination: false
8283
redirect-root: true
8384
redirect-root-location: https://github.com/antoniomika/sish
8485
rewrite-host-header: true

docs/posts/cli.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: CLI
3-
description: How use sish's CLI
3+
description: How use sish's CLI
44
keywords: [sish, cli]
55
---
66

@@ -107,6 +107,7 @@ Flags:
107107
--proxy-protocol-use-timeout Use a timeout for the proxy-protocol read
108108
-q, --proxy-protocol-version string What version of the proxy protocol to use. Can either be 1, 2, or userdefined.
109109
If userdefined, the user needs to add a command to SSH called proxyproto=version (ie proxyproto=1) (default "1")
110+
--proxy-ssl-termination Whether sish is running behind an SSL terminated reverse proxy
110111
--redirect-root Redirect the root domain to the location defined in --redirect-root-location (default true)
111112
-r, --redirect-root-location string The location to redirect requests to the root domain
112113
to instead of responding with a 404 (default "https://github.com/antoniomika/sish")
@@ -129,6 +130,7 @@ Flags:
129130
--verify-dns Verify DNS information for hosts and ensure it matches a connecting users sha256 key fingerprint (default true)
130131
--verify-ssl Verify SSL certificates made on proxied HTTP connections (default true)
131132
-v, --version version for sish
133+
--welcome-message string Message displayed to users upon connection (default "Press Ctrl-C to close the session.")
132134
-y, --whitelisted-countries string A comma separated list of whitelisted countries. Applies to HTTP, TCP, and SSH connections
133135
-w, --whitelisted-ips string A comma separated list of whitelisted ips. Applies to HTTP, TCP, and SSH connections
134136
```

sshmuxer/httphandler.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,17 @@ func handleHTTPListener(check *channelForwardMsg, _ string, requestMessages stri
121121
}
122122
}
123123

124-
httpPortString := ""
125-
if state.Ports.HTTPPort != 80 {
126-
httpPortString = fmt.Sprintf(":%d", state.Ports.HTTPPort)
127-
}
128-
129-
requestMessages += fmt.Sprintf("%s: http://%s%s%s%s\r\n", aurora.BgBlue("HTTP"), userPass, pH.HTTPUrl.Host, httpPortString, pH.HTTPUrl.Path)
124+
if !viper.GetBool("proxy-ssl-termination") {
125+
httpPortString := ""
126+
if state.Ports.HTTPPort != 80 {
127+
httpPortString = fmt.Sprintf(":%d", state.Ports.HTTPPort)
128+
}
130129

131-
log.Printf("%s forwarding started: http://%s%s%s%s -> %s for client: %s\n", aurora.BgBlue("HTTP"), userPass, pH.HTTPUrl.Host, httpPortString, pH.HTTPUrl.Path, listenerHolder.Addr().String(), sshConn.SSHConn.RemoteAddr().String())
130+
requestMessages += fmt.Sprintf("%s: http://%s%s%s%s\r\n", aurora.BgBlue("HTTP"), userPass, pH.HTTPUrl.Host, httpPortString, pH.HTTPUrl.Path)
131+
log.Printf("%s forwarding started: http://%s%s%s%s -> %s for client: %s\n", aurora.BgBlue("HTTP"), userPass, pH.HTTPUrl.Host, httpPortString, pH.HTTPUrl.Path, listenerHolder.Addr().String(), sshConn.SSHConn.RemoteAddr().String())
132+
}
132133

133-
if viper.GetBool("https") {
134+
if viper.GetBool("https") || viper.GetBool("proxy-ssl-termination") {
134135
httpsPortString := ""
135136
if state.Ports.HTTPSPort != 443 {
136137
httpsPortString = fmt.Sprintf(":%d", state.Ports.HTTPSPort)

0 commit comments

Comments
 (0)