Skip to content

Commit 41336ba

Browse files
authored
Merge pull request lightninglabs#67 from lightninglabs/rest-proxy-tls-fix
aperture: connect REST proxy correctly when insecure is set
2 parents cde5b71 + 9ffd5d8 commit 41336ba

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

aperture.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
"time"
1717

1818
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
19-
"github.com/prometheus/client_golang/prometheus/promhttp"
20-
2119
gateway "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
2220
flags "github.com/jessevdk/go-flags"
2321
"github.com/lightninglabs/aperture/auth"
@@ -30,6 +28,7 @@ import (
3028
"github.com/lightningnetwork/lnd/lnrpc"
3129
"github.com/lightningnetwork/lnd/signal"
3230
"github.com/lightningnetwork/lnd/tor"
31+
"github.com/prometheus/client_golang/prometheus/promhttp"
3332
clientv3 "go.etcd.io/etcd/client/v3"
3433
"golang.org/x/crypto/acme/autocert"
3534
"golang.org/x/net/http2"
@@ -733,12 +732,22 @@ func createHashMailServer(cfg *Config) ([]proxy.LocalService, func(), error) {
733732
cancel()
734733
}
735734

735+
// The REST proxy connects to our main listen address. If we're serving
736+
// TLS, we don't care about the certificate being valid, as we issue it
737+
// ourselves. If we are serving without TLS (for example when behind a
738+
// load balancer), we need to connect to ourselves without using TLS as
739+
// well.
740+
restProxyTLSOpt := grpc.WithTransportCredentials(credentials.NewTLS(
741+
&tls.Config{InsecureSkipVerify: true},
742+
))
743+
if cfg.Insecure {
744+
restProxyTLSOpt = grpc.WithInsecure()
745+
}
746+
736747
mux := gateway.NewServeMux(customMarshalerOption)
737748
err := hashmailrpc.RegisterHashMailHandlerFromEndpoint(
738749
ctxc, mux, cfg.ListenAddr, []grpc.DialOption{
739-
grpc.WithTransportCredentials(credentials.NewTLS(
740-
&tls.Config{InsecureSkipVerify: true},
741-
)),
750+
restProxyTLSOpt,
742751
},
743752
)
744753
if err != nil {

0 commit comments

Comments
 (0)