Add support for requesting ngrok remote address (#436)
This commit is contained in:
@@ -66,6 +66,8 @@ Routes Minecraft client connections to backend servers based upon the requested
|
|||||||
any extra tags to be included with all reported metrics (env METRICS_BACKEND_CONFIG_INFLUXDB_TAGS)
|
any extra tags to be included with all reported metrics (env METRICS_BACKEND_CONFIG_INFLUXDB_TAGS)
|
||||||
-metrics-backend-config-influxdb-username string
|
-metrics-backend-config-influxdb-username string
|
||||||
(env METRICS_BACKEND_CONFIG_INFLUXDB_USERNAME)
|
(env METRICS_BACKEND_CONFIG_INFLUXDB_USERNAME)
|
||||||
|
-ngrok-remote-addr string
|
||||||
|
If set, the TCP address to request for this edge (env NGROK_REMOTE_ADDR)
|
||||||
-ngrok-token string
|
-ngrok-token string
|
||||||
If set, an ngrok tunnel will be established. It is HIGHLY recommended to pass as an environment variable. (env NGROK_TOKEN)
|
If set, an ngrok tunnel will be established. It is HIGHLY recommended to pass as an environment variable. (env NGROK_TOKEN)
|
||||||
-port port
|
-port port
|
||||||
@@ -353,6 +355,16 @@ metadata:
|
|||||||
name: mc-forge
|
name: mc-forge
|
||||||
spec:
|
spec:
|
||||||
serviceName: mc-forge
|
serviceName: mc-forge
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: mc-forge
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: mc-forge
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: mc
|
||||||
```
|
```
|
||||||
|
|
||||||
## REST API
|
## REST API
|
||||||
|
|||||||
+6
-1
@@ -17,6 +17,11 @@ type RoutesConfig struct {
|
|||||||
ConfigWatch bool `usage:"Watch for config file changes"`
|
ConfigWatch bool `usage:"Watch for config file changes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NgrokConfig struct {
|
||||||
|
Token string `usage:"If set, an ngrok tunnel will be established. It is HIGHLY recommended to pass as an environment variable."`
|
||||||
|
RemoteAddr string `usage:"If set, the TCP address to request for this edge"`
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Port int `default:"25565" usage:"The [port] bound to listen for Minecraft client connections"`
|
Port int `default:"25565" usage:"The [port] bound to listen for Minecraft client connections"`
|
||||||
Default string `usage:"host:port of a default Minecraft server to use when mapping not found"`
|
Default string `usage:"host:port of a default Minecraft server to use when mapping not found"`
|
||||||
@@ -39,7 +44,7 @@ type Config struct {
|
|||||||
TrustedProxies []string `usage:"Comma delimited list of CIDR notation IP blocks to trust when receiving PROXY protocol"`
|
TrustedProxies []string `usage:"Comma delimited list of CIDR notation IP blocks to trust when receiving PROXY protocol"`
|
||||||
RecordLogins bool `default:"false" usage:"Log and generate metrics on player logins. Metrics only supported with influxdb or prometheus backend"`
|
RecordLogins bool `default:"false" usage:"Log and generate metrics on player logins. Metrics only supported with influxdb or prometheus backend"`
|
||||||
Routes RoutesConfig
|
Routes RoutesConfig
|
||||||
NgrokToken string `usage:"If set, an ngrok tunnel will be established. It is HIGHLY recommended to pass as an environment variable."`
|
Ngrok NgrokConfig
|
||||||
AutoScale AutoScale
|
AutoScale AutoScale
|
||||||
|
|
||||||
ClientsToAllow []string `usage:"Zero or more client IP addresses or CIDRs to allow. Takes precedence over deny."`
|
ClientsToAllow []string `usage:"Zero or more client IP addresses or CIDRs to allow. Takes precedence over deny."`
|
||||||
|
|||||||
+14
-6
@@ -80,6 +80,11 @@ func NewConnector(ctx context.Context, metrics *ConnectorMetrics, sendProxyProto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NgrokConnector struct {
|
||||||
|
token string
|
||||||
|
remoteAddr string
|
||||||
|
}
|
||||||
|
|
||||||
type Connector struct {
|
type Connector struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
state mcproto.State
|
state mcproto.State
|
||||||
@@ -91,7 +96,7 @@ type Connector struct {
|
|||||||
totalActiveConnections int32
|
totalActiveConnections int32
|
||||||
activeConnections *ActiveConnections
|
activeConnections *ActiveConnections
|
||||||
connectionsCond *sync.Cond
|
connectionsCond *sync.Cond
|
||||||
ngrokToken string
|
ngrok NgrokConnector
|
||||||
clientFilter *ClientFilter
|
clientFilter *ClientFilter
|
||||||
autoScaleUpAllowDenyConfig *AllowDenyConfig
|
autoScaleUpAllowDenyConfig *AllowDenyConfig
|
||||||
connectionNotifier ConnectionNotifier
|
connectionNotifier ConnectionNotifier
|
||||||
@@ -117,10 +122,12 @@ func (c *Connector) StartAcceptingConnections(listenAddress string, connRateLimi
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connector) createListener(listenAddress string) (net.Listener, error) {
|
func (c *Connector) createListener(listenAddress string) (net.Listener, error) {
|
||||||
if c.ngrokToken != "" {
|
if c.ngrok.token != "" {
|
||||||
ngrokTun, err := ngrok.Listen(c.ctx,
|
ngrokTun, err := ngrok.Listen(c.ctx,
|
||||||
config.TCPEndpoint(),
|
config.TCPEndpoint(
|
||||||
ngrok.WithAuthtoken(c.ngrokToken),
|
config.WithRemoteAddr(c.ngrok.remoteAddr),
|
||||||
|
),
|
||||||
|
ngrok.WithAuthtoken(c.ngrok.token),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Fatal("Unable to start ngrok tunnel")
|
logrus.WithError(err).Fatal("Unable to start ngrok tunnel")
|
||||||
@@ -608,8 +615,9 @@ func (c *Connector) pumpFrames(incoming io.Reader, outgoing io.Writer, errors ch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connector) UseNgrok(token string) {
|
func (c *Connector) UseNgrok(config NgrokConfig) {
|
||||||
c.ngrokToken = token
|
c.ngrok.token = config.Token
|
||||||
|
c.ngrok.remoteAddr = config.RemoteAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connector) UseReceiveProxyProto(trustedProxyNets []*net.IPNet) {
|
func (c *Connector) UseReceiveProxyProto(trustedProxyNets []*net.IPNet) {
|
||||||
|
|||||||
+2
-2
@@ -99,8 +99,8 @@ func NewServer(ctx context.Context, config *Config) (*Server, error) {
|
|||||||
NewWebhookNotifier(config.Webhook.Url, config.Webhook.RequireUser))
|
NewWebhookNotifier(config.Webhook.Url, config.Webhook.RequireUser))
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.NgrokToken != "" {
|
if config.Ngrok.Token != "" {
|
||||||
connector.UseNgrok(config.NgrokToken)
|
connector.UseNgrok(config.Ngrok)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.ReceiveProxyProtocol {
|
if config.ReceiveProxyProtocol {
|
||||||
|
|||||||
Reference in New Issue
Block a user