Skip to content
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

Add proxy_connection_token option to call connect proxy with token #612

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions internal/client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (h *Handler) OnClientConnecting(

var processClientChannels bool

if e.Token != "" {
if e.Token != "" && !ruleConfig.ProxyConnectionToken {
token, err := h.tokenVerifier.VerifyConnectToken(e.Token)
if err != nil {
if err == jwtverify.ErrTokenExpired {
Expand Down Expand Up @@ -483,7 +483,7 @@ func (h *Handler) OnClientConnecting(
Credentials: credentials,
Subscriptions: subscriptions,
Data: data,
ClientSideRefresh: !refreshProxyEnabled,
ClientSideRefresh: !refreshProxyEnabled || ruleConfig.ProxyConnectionToken,
}
if newCtx != nil {
finalReply.Context = newCtx
Expand All @@ -499,6 +499,11 @@ type RefreshExtra struct {

// OnRefresh ...
func (h *Handler) OnRefresh(c Client, e centrifuge.RefreshEvent, refreshProxyHandler proxy.RefreshHandlerFunc, d proxy.PerCallData) (centrifuge.RefreshReply, RefreshExtra, error) {
ruleConfig := h.ruleContainer.Config()
if refreshProxyHandler == nil && ruleConfig.ProxyConnectionToken {
h.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelWarn, "no refresh proxy to refresh custom token", map[string]interface{}{"user": c.UserID(), "client": c.ID()}))
return centrifuge.RefreshReply{Expired: true}, RefreshExtra{}, nil
}
if refreshProxyHandler != nil {
r, extra, err := refreshProxyHandler(c, e, d)
return r, RefreshExtra{Meta: extra.Meta}, err
Expand Down
1 change: 1 addition & 0 deletions internal/proxy/connect_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (h *ConnectHandler) Handle(node *centrifuge.Node) ConnectingHandlerFunc {
Name: e.Name,
Version: e.Version,
Channels: e.Channels,
Token: e.Token,
}
if !h.config.Proxy.UseBase64() {
req.Data = e.Data
Expand Down
3 changes: 2 additions & 1 deletion internal/proxy/refresh_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (h *RefreshHandler) Handle(node *centrifuge.Node) RefreshHandlerFunc {
Transport: client.Transport().Name(),
Encoding: getEncoding(h.config.Proxy.UseBase64()),

User: client.UserID(),
User: client.UserID(),
Token: e.Token,
}
if h.config.Proxy.IncludeMeta() && pcd.Meta != nil {
req.Meta = proxyproto.Raw(pcd.Meta)
Expand Down
610 changes: 314 additions & 296 deletions internal/proxyproto/proxy.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions internal/proxyproto/proxy.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ message ConnectRequest {
string name = 12;
string version = 13;
repeated string channels = 14;
string token = 15;
}

message SubscribeOptions {
Expand Down Expand Up @@ -80,6 +81,7 @@ message RefreshRequest {

string user = 10;
bytes meta = 11;
string token = 12;
}

message RefreshResult {
Expand Down
3 changes: 3 additions & 0 deletions internal/rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type Config struct {
// ClientConnectionRateLimit sets the maximum number of new connections a single Centrifugo
// node will accept per second.
ClientConnectionRateLimit int

// ProxyConnectionToken bool
ProxyConnectionToken bool
}

// DefaultConfig has default config options.
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,7 @@ func ruleConfig() rule.Config {
cfg.RpcNamespaces = rpcNamespacesFromConfig(v)
cfg.ClientConnectionLimit = v.GetInt("client_connection_limit")
cfg.ClientConnectionRateLimit = v.GetInt("client_connection_rate_limit")
cfg.ProxyConnectionToken = v.GetBool("proxy_connection_token")
return cfg
}

Expand Down