-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[IMPROVED] Secure consumer create #3409
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,9 @@ type ConsumerInfo struct { | |
} | ||
|
||
type ConsumerConfig struct { | ||
// Durable is deprecated. All consumers will have names. picked by clients. | ||
Durable string `json:"durable_name,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
derekcollison marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding a new property to check, why not simply just say all consumers are durable. And that durables can be reaped by the server based on their This would simplify the logic on clients, at the expense that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only other concern then becomes how to reflect the new use of the API. If the consumer specifies a filter in the config, and the server matches the version with the new API, the client could simply use the new API. Otherwise, it can use the old API, allowing security compliance of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Durables could not be reaped, so I prefer to not change that behavior and leave as is for existing clients. Going forward all consumers will have a name and optional inactive threshold. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good hygiene for older consumers and clients since it does not introduce this on the wire in those situations. |
||
Description string `json:"description,omitempty"` | ||
DeliverPolicy DeliverPolicy `json:"deliver_policy"` | ||
OptStartSeq uint64 `json:"opt_start_seq,omitempty"` | ||
|
@@ -353,10 +355,6 @@ func setConsumerConfigDefaults(config *ConsumerConfig, lim *JSLimitOpts, accLim | |
} | ||
} | ||
|
||
func (mset *stream) addConsumer(config *ConsumerConfig) (*consumer, error) { | ||
return mset.addConsumerWithAssignment(config, _EMPTY_, nil, false) | ||
} | ||
|
||
// Check the consumer config. If we are recovering don't check filter subjects. | ||
func checkConsumerCfg( | ||
config *ConsumerConfig, | ||
|
@@ -530,6 +528,10 @@ func checkConsumerCfg( | |
return nil | ||
} | ||
|
||
func (mset *stream) addConsumer(config *ConsumerConfig) (*consumer, error) { | ||
return mset.addConsumerWithAssignment(config, _EMPTY_, nil, false) | ||
} | ||
|
||
func (mset *stream) addConsumerWithAssignment(config *ConsumerConfig, oname string, ca *consumerAssignment, isRecovering bool) (*consumer, error) { | ||
mset.mu.RLock() | ||
s, jsa, tierName, cfg, acc := mset.srv, mset.jsa, mset.tier, mset.cfg, mset.acc | ||
|
@@ -589,8 +591,14 @@ func (mset *stream) addConsumerWithAssignment(config *ConsumerConfig, oname stri | |
} | ||
|
||
// If this one is durable and already exists, we let that be ok as long as only updating what should be allowed. | ||
var cName string | ||
if isDurableConsumer(config) { | ||
if eo, ok := mset.consumers[config.Durable]; ok { | ||
cName = config.Durable | ||
} else if config.Name != _EMPTY_ { | ||
cName = config.Name | ||
} | ||
derekcollison marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if cName != _EMPTY_ { | ||
if eo, ok := mset.consumers[cName]; ok { | ||
mset.mu.Unlock() | ||
err := eo.updateConfig(config) | ||
if err == nil { | ||
|
@@ -674,11 +682,17 @@ func (mset *stream) addConsumerWithAssignment(config *ConsumerConfig, oname stri | |
} else if oname != _EMPTY_ { | ||
o.name = oname | ||
} else { | ||
for { | ||
o.name = createConsumerName() | ||
if _, ok := mset.consumers[o.name]; !ok { | ||
break | ||
if config.Name != _EMPTY_ { | ||
o.name = config.Name | ||
} else { | ||
// Legacy ephemeral auto-generated. | ||
for { | ||
o.name = createConsumerName() | ||
if _, ok := mset.consumers[o.name]; !ok { | ||
break | ||
} | ||
} | ||
config.Name = o.name | ||
} | ||
} | ||
// Create ackMsgs queue now that we have a consumer name | ||
|
@@ -768,6 +782,8 @@ func (mset *stream) addConsumerWithAssignment(config *ConsumerConfig, oname stri | |
// Ephemerals will always have inactive thresholds. | ||
// Add in 1 sec of jitter above and beyond the default of 5s. | ||
o.dthresh = JsDeleteWaitTimeDefault + time.Duration(rand.Int63n(1000))*time.Millisecond | ||
// Only stamp config with default sans jitter. | ||
o.cfg.InactiveThreshold = JsDeleteWaitTimeDefault | ||
kozlovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if o.isPushMode() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is still deprecated...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could soften if you like..