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

Backport of Fix: non-login requests shouldn't care about login roles for lease quotas. Also fix a potential deadlock into release/1.13.x #21187

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/21110.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
core/quotas (enterprise): Fix a case where we were applying login roles to lease count quotas in a non-login context.
Also fix a related potential deadlock.
```
4 changes: 2 additions & 2 deletions vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ type Core struct {

// mountsLock is used to ensure that the mounts table does not
// change underneath a calling function
mountsLock sync.RWMutex
mountsLock locking.DeadlockRWMutex

// mountMigrationTracker tracks past and ongoing remount operations
// against their migration ids
Expand All @@ -370,7 +370,7 @@ type Core struct {

// authLock is used to ensure that the auth table does not
// change underneath a calling function
authLock sync.RWMutex
authLock locking.DeadlockRWMutex

// audit is loaded after unseal since it is a protected
// configuration
Expand Down
4 changes: 2 additions & 2 deletions vault/logical_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"sort"
"strconv"
"strings"
"sync"
"time"
"unicode"

Expand All @@ -31,6 +30,7 @@ import (
"github.com/hashicorp/vault/helper/experiments"
"github.com/hashicorp/vault/helper/hostutil"
"github.com/hashicorp/vault/helper/identity"
"github.com/hashicorp/vault/helper/locking"
"github.com/hashicorp/vault/helper/logging"
"github.com/hashicorp/vault/helper/metricsutil"
"github.com/hashicorp/vault/helper/monitor"
Expand Down Expand Up @@ -1717,7 +1717,7 @@ func (b *SystemBackend) handleTuneWriteCommon(ctx context.Context, path string,
return nil, logical.ErrReadOnly
}

var lock *sync.RWMutex
var lock *locking.DeadlockRWMutex
switch {
case strings.HasPrefix(path, credentialRoutePrefix):
lock = &b.Core.authLock
Expand Down
4 changes: 1 addition & 3 deletions vault/request_handling.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,11 +1010,9 @@ func (c *Core) handleRequest(ctx context.Context, req *logical.Request) (retResp
}

leaseGenerated := false
loginRole := c.DetermineRoleFromLoginRequest(req.MountPoint, req.Data, ctx)
quotaResp, quotaErr := c.applyLeaseCountQuota(ctx, &quotas.Request{
Path: req.Path,
MountPath: strings.TrimPrefix(req.MountPoint, ns.Path),
Role: loginRole,
NamespacePath: ns.Path,
})
if quotaErr != nil {
Expand Down Expand Up @@ -1154,7 +1152,7 @@ func (c *Core) handleRequest(ctx context.Context, req *logical.Request) (retResp
return nil, auth, retErr
}

leaseID, err := registerFunc(ctx, req, resp, loginRole)
leaseID, err := registerFunc(ctx, req, resp, "")
if err != nil {
c.logger.Error("failed to register lease", "request_path", req.Path, "error", err)
retErr = multierror.Append(retErr, ErrInternalError)
Expand Down