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

Vault 2256: fix lease count quotas causing panics on dr secondaries #11742

Merged
merged 2 commits into from
Jun 2, 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
2 changes: 1 addition & 1 deletion vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2724,7 +2724,7 @@ func (c *Core) setupQuotas(ctx context.Context, isPerfStandby bool) error {
return nil
}

return c.quotaManager.Setup(ctx, c.systemBarrierView, isPerfStandby)
return c.quotaManager.Setup(ctx, c.systemBarrierView, isPerfStandby, c.IsDRSecondary())
}

// ApplyRateLimitQuota checks the request against all the applicable quota rules.
Expand Down
49 changes: 32 additions & 17 deletions vault/quotas/quotas.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,11 @@ func (m *Manager) Invalidate(key string) {
qType := splitKeys[0]
name := splitKeys[1]

if qType == TypeLeaseCount.String() && m.isDRSecondary {
// lease count invalidation not supported on DR Secondary
return
}

// Read quota rule from storage
quota, err := Load(m.ctx, m.storage, qType, name)
if err != nil {
Expand Down Expand Up @@ -844,13 +849,14 @@ func Load(ctx context.Context, storage logical.Storage, qType, name string) (Quo

// Setup loads the quota configuration and all the quota rules into the
// quota manager.
func (m *Manager) Setup(ctx context.Context, storage logical.Storage, isPerfStandby bool) error {
func (m *Manager) Setup(ctx context.Context, storage logical.Storage, isPerfStandby, isDRSecondary bool) error {
m.lock.Lock()
defer m.lock.Unlock()

m.storage = storage
m.ctx = ctx
m.isPerfStandby = isPerfStandby
m.isDRSecondary = isDRSecondary

// Load the quota configuration from storage and load it into the quota
// manager.
Expand Down Expand Up @@ -887,27 +893,36 @@ func (m *Manager) Setup(ctx context.Context, storage logical.Storage, isPerfStan
return err
}

// Load the quota rules for all supported types from storage and load it in
// the quota manager.
for _, qType := range quotaTypes() {
names, err := logical.CollectKeys(ctx, logical.NewStorageView(storage, StoragePrefix+qType+"/"))
m.setupQuotaType(ctx, storage, qType)
}

return nil
}

func (m *Manager) setupQuotaType(ctx context.Context, storage logical.Storage, quotaType string) error {
if quotaType == TypeLeaseCount.String() && m.isDRSecondary {
m.logger.Trace("lease count quotas are not processed on DR Secondaries")
return nil
}

names, err := logical.CollectKeys(ctx, logical.NewStorageView(storage, StoragePrefix+quotaType+"/"))
if err != nil {
swayne275 marked this conversation as resolved.
Show resolved Hide resolved
return err
}
for _, name := range names {
quota, err := Load(ctx, m.storage, quotaType, name)
if err != nil {
return nil
return err
}
for _, name := range names {
quota, err := Load(ctx, m.storage, qType, name)
if err != nil {
return err
}

if quota == nil {
continue
}
if quota == nil {
continue
}

err = m.setQuotaLocked(ctx, qType, quota, true)
if err != nil {
return err
}
err = m.setQuotaLocked(ctx, quotaType, quota, true)
if err != nil {
return err
}
}

Expand Down
1 change: 1 addition & 0 deletions vault/quotas/quotas_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (m *Manager) inLeasePathCache(path string) bool {

type entManager struct {
isPerfStandby bool
isDRSecondary bool
}

func (*entManager) Reset() error {
Expand Down