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

Add missing read unlock calls in transit backend code #12652

Merged
merged 4 commits into from
Sep 28, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions builtin/logical/transit/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ func (b *backend) GetPolicy(ctx context.Context, polReq keysutil.PolicyRequest,
currentCacheSize := b.lm.GetCacheSize()
storedCacheSize, err := GetCacheSizeFromStorage(ctx, polReq.Storage)
if err != nil {
b.configMutex.RUnlock()
divyapola5 marked this conversation as resolved.
Show resolved Hide resolved
return nil, false, err
}
if currentCacheSize != storedCacheSize {
err = b.lm.InitCache(storedCacheSize)
if err != nil {
b.configMutex.RUnlock()
return nil, false, err
}
}
Expand All @@ -135,6 +137,8 @@ func (b *backend) GetPolicy(ctx context.Context, polReq keysutil.PolicyRequest,
b.configMutex.Lock()
defer b.configMutex.Unlock()
b.cacheSizeChanged = false
} else {
b.configMutex.RUnlock()
}
p, _, err := b.lm.GetPolicy(ctx, polReq, rand)
if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions builtin/logical/transit/path_cache_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,19 @@ func (b *backend) pathCacheConfigRead(ctx context.Context, req *logical.Request,
return nil, err
}

if currentCacheSize != storedCacheSize {
err = b.lm.InitCache(storedCacheSize)
if err != nil {
return nil, err
}
}

resp := &logical.Response{
Data: map[string]interface{}{
"size": storedCacheSize,
},
}

if currentCacheSize != storedCacheSize {
resp.Warnings = []string{"This cache size will not be applied until the transit mount is reloaded"}
}

return resp, nil
}

Expand Down
5 changes: 2 additions & 3 deletions changelog/12418.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
```release-note:bug
Enforce minimum cache size for transit backend.
Init cache size on transit backend without restart.
```
secrets/transit: Enforce minimum cache size for transit backend and init cache size on transit backend without restart.
```