Skip to content

Commit cf07eab

Browse files
authored
TLS Support by Reverse-Proxy for Basicstation (#241)
1 parent 48bd5d0 commit cf07eab

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

cmd/chirpstack-gateway-bridge/cmd/configfile.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ type="{{ .Backend.Type }}"
111111
# ip:port to bind the Websocket listener to.
112112
bind="{{ .Backend.BasicStation.Bind }}"
113113
114+
# TLS support by a Reverse-Proxy
115+
#
116+
# When set to true, the websocket listener will use TLS to secure the connections
117+
# between the gateways and a reverse-proxy (optional).
118+
tls_support_proxy={{ .Backend.BasicStation.TLSSupportProxy }}
119+
114120
# TLS certificate and key files.
115121
#
116122
# When set, the websocket listener will use TLS to secure the connections

internal/backend/basicstation/backend.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ var upgrader = websocket.Upgrader{
4141
type Backend struct {
4242
sync.RWMutex
4343

44-
caCert string
45-
tlsCert string
46-
tlsKey string
44+
tlsSupportProxy bool
45+
caCert string
46+
tlsCert string
47+
tlsKey string
4748

4849
server *http.Server
4950
ln net.Listener
@@ -84,9 +85,10 @@ func NewBackend(conf config.Config) (*Backend, error) {
8485
gateways: make(map[lorawan.EUI64]*connection),
8586
},
8687

87-
caCert: conf.Backend.BasicStation.CACert,
88-
tlsCert: conf.Backend.BasicStation.TLSCert,
89-
tlsKey: conf.Backend.BasicStation.TLSKey,
88+
tlsSupportProxy: conf.Backend.BasicStation.TLSSupportProxy,
89+
caCert: conf.Backend.BasicStation.CACert,
90+
tlsCert: conf.Backend.BasicStation.TLSCert,
91+
tlsKey: conf.Backend.BasicStation.TLSKey,
9092

9193
statsInterval: conf.Backend.BasicStation.StatsInterval,
9294
pingInterval: conf.Backend.BasicStation.PingInterval,
@@ -262,14 +264,19 @@ func (b *Backend) RawPacketForwarderCommand(pl *gw.RawPacketForwarderCommand) er
262264
func (b *Backend) Start() error {
263265
go func() {
264266
log.WithFields(log.Fields{
265-
"bind": b.ln.Addr(),
266-
"ca_cert": b.caCert,
267-
"tls_cert": b.tlsCert,
268-
"tls_key": b.tlsKey,
267+
"bind": b.ln.Addr(),
268+
"tls_support_proxy": b.tlsSupportProxy,
269+
"ca_cert": b.caCert,
270+
"tls_cert": b.tlsCert,
271+
"tls_key": b.tlsKey,
269272
}).Info("backend/basicstation: starting websocket listener")
270273

271274
if b.tlsCert == "" && b.tlsKey == "" && b.caCert == "" {
272275
// no tls
276+
if b.tlsSupportProxy {
277+
log.Info("backend/basicstation: TLS support handled by reverse-proxy")
278+
b.scheme = "wss"
279+
}
273280
if err := b.server.Serve(b.ln); err != nil && !b.isClosed {
274281
log.WithError(err).Fatal("backend/basicstation: server error")
275282
}

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Config struct {
2929

3030
BasicStation struct {
3131
Bind string `mapstructure:"bind"`
32+
TLSSupportProxy bool `mapstructure:"tls_support_proxy"`
3233
TLSCert string `mapstructure:"tls_cert"`
3334
TLSKey string `mapstructure:"tls_key"`
3435
CACert string `mapstructure:"ca_cert"`

0 commit comments

Comments
 (0)