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 c1e61c2 commit c26bb9b
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 @@ -337,7 +337,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 @@ -349,7 +349,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 @@ -16,7 +16,6 @@ import (
"sort"
"strconv"
"strings"
"sync"
"time"
"unicode"

Expand All @@ -29,6 +28,7 @@ import (
semver "github.com/hashicorp/go-version"
"github.com/hashicorp/vault/helper/hostutil"
"github.com/hashicorp/vault/helper/identity"
"github.com/hashicorp/vault/helper/locking"

Check failure on line 31 in vault/logical_system.go

View workflow job for this annotation

GitHub Actions / Other (openbsd, arm) / Vault openbsd arm v1.12.7

no required module provides package github.com/hashicorp/vault/helper/locking; to add it:

Check failure on line 31 in vault/logical_system.go

View workflow job for this annotation

GitHub Actions / Other (netbsd, 386) / Vault netbsd 386 v1.12.7

no required module provides package github.com/hashicorp/vault/helper/locking; to add it:

Check failure on line 31 in vault/logical_system.go

View workflow job for this annotation

GitHub Actions / Darwin (darwin, arm64) / Vault darwin arm64 v1.12.7

no required module provides package github.com/hashicorp/vault/helper/locking; to add it:

Check failure on line 31 in vault/logical_system.go

View workflow job for this annotation

GitHub Actions / Linux (linux, arm) / Vault linux arm v1.12.7

no required module provides package github.com/hashicorp/vault/helper/locking; to add it:

Check failure on line 31 in vault/logical_system.go

View workflow job for this annotation

GitHub Actions / Linux (linux, arm64) / Vault linux arm64 v1.12.7

no required module provides package github.com/hashicorp/vault/helper/locking; to add it:

Check failure on line 31 in vault/logical_system.go

View workflow job for this annotation

GitHub Actions / Linux (linux, 386) / Vault linux 386 v1.12.7

no required module provides package github.com/hashicorp/vault/helper/locking; to add it:
"github.com/hashicorp/vault/helper/logging"
"github.com/hashicorp/vault/helper/metricsutil"
"github.com/hashicorp/vault/helper/monitor"
Expand Down Expand Up @@ -1676,7 +1676,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 @@ -973,11 +973,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 @@ -1117,7 +1115,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 c26bb9b

Please sign in to comment.