Skip to content

TLS Support by Reverse-Proxy for Basicstation #241

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

Merged
merged 3 commits into from
May 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/chirpstack-gateway-bridge/cmd/configfile.go
Original file line number Diff line number Diff line change
@@ -111,6 +111,12 @@ type="{{ .Backend.Type }}"
# ip:port to bind the Websocket listener to.
bind="{{ .Backend.BasicStation.Bind }}"

# TLS support by a Reverse-Proxy
#
# When set to true, the websocket listener will use TLS to secure the connections
# between the gateways and a reverse-proxy (optional).
tls_support_proxy={{ .Backend.BasicStation.TLSSupportProxy }}

# TLS certificate and key files.
#
# When set, the websocket listener will use TLS to secure the connections
27 changes: 17 additions & 10 deletions internal/backend/basicstation/backend.go
Original file line number Diff line number Diff line change
@@ -41,9 +41,10 @@ var upgrader = websocket.Upgrader{
type Backend struct {
sync.RWMutex

caCert string
tlsCert string
tlsKey string
tlsSupportProxy bool
caCert string
tlsCert string
tlsKey string

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

caCert: conf.Backend.BasicStation.CACert,
tlsCert: conf.Backend.BasicStation.TLSCert,
tlsKey: conf.Backend.BasicStation.TLSKey,
tlsSupportProxy: conf.Backend.BasicStation.TLSSupportProxy,
caCert: conf.Backend.BasicStation.CACert,
tlsCert: conf.Backend.BasicStation.TLSCert,
tlsKey: conf.Backend.BasicStation.TLSKey,

statsInterval: conf.Backend.BasicStation.StatsInterval,
pingInterval: conf.Backend.BasicStation.PingInterval,
@@ -262,14 +264,19 @@ func (b *Backend) RawPacketForwarderCommand(pl *gw.RawPacketForwarderCommand) er
func (b *Backend) Start() error {
go func() {
log.WithFields(log.Fields{
"bind": b.ln.Addr(),
"ca_cert": b.caCert,
"tls_cert": b.tlsCert,
"tls_key": b.tlsKey,
"bind": b.ln.Addr(),
"tls_support_proxy": b.tlsSupportProxy,
"ca_cert": b.caCert,
"tls_cert": b.tlsCert,
"tls_key": b.tlsKey,
}).Info("backend/basicstation: starting websocket listener")

if b.tlsCert == "" && b.tlsKey == "" && b.caCert == "" {
// no tls
if b.tlsSupportProxy {
log.Info("backend/basicstation: TLS support handled by reverse-proxy")
b.scheme = "wss"
}
if err := b.server.Serve(b.ln); err != nil && !b.isClosed {
log.WithError(err).Fatal("backend/basicstation: server error")
}
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ type Config struct {

BasicStation struct {
Bind string `mapstructure:"bind"`
TLSSupportProxy bool `mapstructure:"tls_support_proxy"`
TLSCert string `mapstructure:"tls_cert"`
TLSKey string `mapstructure:"tls_key"`
CACert string `mapstructure:"ca_cert"`