Skip to content

Commit e86c575

Browse files
committed
Don't warn about insecure connections to localhost
This message isn't strictly required or beneficial when connecting to 127.0.0.1 or localhost, where certificates from Let's Encrypt are not applicable. If using Kubernetes or SSH port forwarding, then the connection is encrypted already. Tested by creating an SSH tunnel to a faasd instance, and seeing no warning, then connecting to the same faasd instance with its IP addresses, and continuing to see the error. The warning message has been updated since SSL is not applicable to HTTPS currently. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 3cfd4a0 commit e86c575

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

commands/errors.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ import (
99

1010
const (
1111
// NoTLSWarn Warning thrown when no SSL/TLS is used
12-
NoTLSWarn = "WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates."
12+
NoTLSWarn = "WARNING! You are not using an encrypted connection to the gateway, consider using HTTPS."
1313
)
1414

1515
// checkTLSInsecure returns a warning message if the given gateway does not have https.
1616
// Use tsInsecure to skip validations
1717
func checkTLSInsecure(gateway string, tlsInsecure bool) string {
1818
if !tlsInsecure {
19-
if !strings.HasPrefix(gateway, "https") {
19+
if strings.HasPrefix(gateway, "https") == false &&
20+
strings.HasPrefix(gateway, "http://127.0.0.1") == false &&
21+
strings.HasPrefix(gateway, "http://localhost") == false {
2022
return NoTLSWarn
2123
}
2224
}

commands/errors_test.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,30 @@ func Test_checkTLSInsecure(t *testing.T) {
1414
args args
1515
want string
1616
}{
17-
{name: "secure gateway and tls secure", args: args{gateway: "https://127.0.0.1:8080", tlsInsecure: false}, want: ""},
18-
{name: "secure gateway and tls insecure", args: args{gateway: "https://127.0.0.1:8080", tlsInsecure: true}, want: ""},
19-
{name: "insecure gateway and tls secure", args: args{gateway: "http://127.0.0.1:8080", tlsInsecure: false}, want: "WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates."},
20-
{name: "insecure gateway and tls insecure", args: args{gateway: "http://127.0.0.1:8080", tlsInsecure: true}, want: ""},
17+
{name: "HTTPS gateway",
18+
args: args{gateway: "https://192.168.0.101:8080", tlsInsecure: false},
19+
want: ""},
20+
{name: "HTTPS gateway with TLSInsecure",
21+
args: args{gateway: "https://192.168.0.101:8080", tlsInsecure: true},
22+
want: ""},
23+
{name: "HTTP gateway without TLSInsecure",
24+
args: args{gateway: "http://192.168.0.101:8080", tlsInsecure: false},
25+
want: "WARNING! You are not using an encrypted connection to the gateway, consider using HTTPS."},
26+
{name: "HTTP gateway to 127.0.0.1 without TLSInsecure",
27+
args: args{gateway: "http://127.0.0.1:8080", tlsInsecure: false},
28+
want: ""},
29+
{name: "HTTP gateway to localhost without TLSInsecure",
30+
args: args{gateway: "http://localhost:8080", tlsInsecure: false},
31+
want: ""},
32+
{name: "HTTP gateway to remote host with TLSInsecure", args: args{gateway: "http://192.168.0.101:8080", tlsInsecure: true},
33+
want: ""},
2134
}
35+
2236
for _, tt := range tests {
2337
t.Run(tt.name, func(t *testing.T) {
24-
if got := checkTLSInsecure(tt.args.gateway, tt.args.tlsInsecure); got != tt.want {
38+
got := checkTLSInsecure(tt.args.gateway, tt.args.tlsInsecure)
39+
40+
if got != tt.want {
2541
t.Errorf("checkTLSInsecure() = %v, want %v", got, tt.want)
2642
}
2743
})

commands/login.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func runLogin(cmd *cobra.Command, args []string) error {
8888

8989
gateway = getGatewayURL(gateway, defaultGateway, "", os.Getenv(openFaaSURLEnvironment))
9090

91-
if err := validateLogin(gateway, username, password, timeout); err != nil {
91+
if err := validateLogin(gateway, username, password, timeout, tlsInsecure); err != nil {
9292
return err
9393
}
9494

@@ -111,7 +111,12 @@ func runLogin(cmd *cobra.Command, args []string) error {
111111
return nil
112112
}
113113

114-
func validateLogin(gatewayURL string, user string, pass string, timeout time.Duration) error {
114+
func validateLogin(gatewayURL string, user string, pass string, timeout time.Duration, insecureTLS bool) error {
115+
116+
if len(checkTLSInsecure(gatewayURL, insecureTLS)) > 0 {
117+
fmt.Printf(NoTLSWarn)
118+
}
119+
115120
client := proxy.MakeHTTPClient(&timeout, tlsInsecure)
116121
req, err := http.NewRequest("GET", gatewayURL+"/system/functions", nil)
117122
if err != nil {
@@ -128,10 +133,6 @@ func validateLogin(gatewayURL string, user string, pass string, timeout time.Dur
128133
defer res.Body.Close()
129134
}
130135

131-
if res.TLS == nil {
132-
fmt.Println("WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.")
133-
}
134-
135136
switch res.StatusCode {
136137
case http.StatusOK:
137138
return nil

0 commit comments

Comments
 (0)