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

Make encryption persistence timeout configurable via env var #25636

Merged
merged 6 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions changelog/25636.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
core: make the best effort timeout for encryption count tracking persistence configurable via an environment variable.
```
18 changes: 16 additions & 2 deletions vault/barrier_aes_gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"fmt"
"io"
"math"
"os"
"strconv"
"strings"
"sync"
Expand All @@ -38,7 +39,8 @@
autoRotateCheckInterval = 5 * time.Minute
legacyRotateReason = "legacy rotation"
// The keyring is persisted before the root key.
keyringTimeout = 1 * time.Second
defaultKeyringTimeout = 1 * time.Second
bestEffortKeyringTimeoutOverride = "VAULT_ENCRYPTION_COUNT_PERSIST_TIMEOUT"
)

// Versions of the AESGCM storage methodology
Expand Down Expand Up @@ -91,6 +93,8 @@
// Used only for testing
RemoteEncryptions *atomic.Int64
totalLocalEncryptions *atomic.Int64

bestEffortKeyringTimeout time.Duration
}

func (b *AESGCMBarrier) RotationConfig() (kc KeyRotationConfig, err error) {
Expand All @@ -115,6 +119,15 @@
// NewAESGCMBarrier is used to construct a new barrier that uses
// the provided physical backend for storage.
func NewAESGCMBarrier(physical physical.Backend) (*AESGCMBarrier, error) {
keyringTimeout := defaultKeyringTimeout
keyringTimeoutStr := os.Getenv(bestEffortKeyringTimeoutOverride)
if keyringTimeoutStr != "" {
t, err := time.ParseDuration(keyringTimeoutStr)
Fixed Show fixed Hide fixed
if err != nil {
return nil, err
sgmiller marked this conversation as resolved.
Show resolved Hide resolved
}
keyringTimeout = t
}
b := &AESGCMBarrier{
backend: physical,
sealed: true,
Expand All @@ -123,6 +136,7 @@
UnaccountedEncryptions: atomic.NewInt64(0),
RemoteEncryptions: atomic.NewInt64(0),
totalLocalEncryptions: atomic.NewInt64(0),
bestEffortKeyringTimeout: keyringTimeout,
}
return b, nil
}
Expand Down Expand Up @@ -256,7 +270,7 @@
// We reduce the timeout on the initial 'put' but if this succeeds we will
// allow longer later on when we try to persist the root key .
var cancelKeyring func()
ctxKeyring, cancelKeyring = context.WithTimeout(ctx, keyringTimeout)
ctxKeyring, cancelKeyring = context.WithTimeout(ctx, b.bestEffortKeyringTimeout)
defer cancelKeyring()
}

Expand Down
8 changes: 8 additions & 0 deletions website/content/docs/internals/rotation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ Operators can estimate the number of encryptions by summing the following:
- The `vault.token.creation` metric where the `token_type` label is `batch`.
- The `merkle.flushDirty.num_pages` metric.
- The WAL index.

Vault periodically persists the number of encryptions to support rotation.
This save operation has a 1 second timeout to prevent impact to performance
if Vault is under heavy load. Because persisting encryptions involves the
seal backend (if seal wrap is enabled), some seals (such as HSMs) may take
regularly longer than 1 second to respond. If this is the case, operators
may override that timeout by setting the environment variable
`VAULT_ENCRYPTION_COUNT_PERSIST_TIMEOUT` to a larger value, such as "5s".
Loading