Skip to content

Commit

Permalink
backport of commit 4654c15
Browse files Browse the repository at this point in the history
  • Loading branch information
ncabatoff committed Jun 13, 2023
1 parent a27c15a commit 22234c3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
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 @@ -1006,11 +1006,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 @@ -1150,7 +1148,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

0 comments on commit 22234c3

Please sign in to comment.