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

[fixing] subscription issue when subscribing to a super set of deny_i… #2101

Merged
merged 1 commit into from
Apr 13, 2021
Merged
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
19 changes: 19 additions & 0 deletions server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,25 @@ func (c *client) setPermissions(perms *Permissions) {
}
}

// Merge client.perms structure with additional pub deny permissions
// Lock is held on entry.
func (c *client) mergePubDenyPermissions(denyPubs []string) {
if len(denyPubs) == 0 {
return
}
if c.perms == nil {
c.perms = &permissions{}
c.perms.pcache = make(map[string]bool)
}
if c.perms.pub.deny == nil {
c.perms.pub.deny = NewSublistWithCache()
}
for _, pubSubject := range denyPubs {
sub := &subscription{subject: []byte(pubSubject)}
c.perms.pub.deny.Insert(sub)
}
}

// Check to see if we have an expiration for the user JWT via base claims.
// FIXME(dlc) - Clear on connect with new JWT.
func (c *client) setExpiration(claims *jwt.ClaimsData, validFor time.Duration) {
Expand Down
16 changes: 12 additions & 4 deletions server/leafnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ func (c *client) sendLeafConnect(clusterName string, tlsRequired, headers bool)
Hub: c.leaf.remote.Hub,
Cluster: clusterName,
Headers: headers,
DenyPub: c.leaf.remote.DenyImports,
}

// Check for credentials first, that will take precedence..
Expand Down Expand Up @@ -1092,9 +1093,9 @@ type leafConnectInfo struct {
Hub bool `json:"is_hub,omitempty"`
Cluster string `json:"cluster,omitempty"`
Headers bool `json:"headers,omitempty"`

// Just used to detect wrong connection attempts.
Gateway string `json:"gateway,omitempty"`
Gateway string `json:"gateway,omitempty"`
DenyPub []string `json:"deny_pub,omitempty"`
}

// processLeafNodeConnect will process the inbound connect args.
Expand Down Expand Up @@ -1154,6 +1155,9 @@ func (c *client) processLeafNodeConnect(s *Server, arg []byte, lang string) erro
// Set the Ping timer
s.setFirstPingTimer(c)

// If we received pub deny permissions from the other end, merge with existing ones.
c.mergePubDenyPermissions(proto.DenyPub)

c.mu.Unlock()

// Add in the leafnode here since we passed through auth at this point.
Expand Down Expand Up @@ -1830,8 +1834,12 @@ func (c *client) processInboundLeafMsg(msg []byte) {
c.in.bytes += int32(len(msg) - LEN_CR_LF)

// Check pub permissions
if c.perms != nil && (c.perms.pub.allow != nil || c.perms.pub.deny != nil) && c.isHubLeafNode() && !c.pubAllowed(string(c.pa.subject)) {
c.leafPubPermViolation(c.pa.subject)
if c.perms != nil && (c.perms.pub.allow != nil || c.perms.pub.deny != nil) && !c.pubAllowed(string(c.pa.subject)) {
if c.isHubLeafNode() {
c.leafPubPermViolation(c.pa.subject)
} else {
c.Debugf("Not permitted to receive from %q", c.pa.subject)
}
return
}

Expand Down