Skip to content

Commit 1473dac

Browse files
authored
Seal HA Improvements, CE side (#25171)
* add fully_wrapped to seal-backend-status, try to find in-common seals in all cases * changelog
1 parent aab7210 commit 1473dac

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

changelog/25171.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:improvement
2+
core (enterprise): Improve seal unwrap performance when in degraded mode with one or more unhealthy seals.
3+
```

vault/logical_system.go

+8
Original file line numberDiff line numberDiff line change
@@ -5420,6 +5420,7 @@ type SealBackendStatusResponse struct {
54205420
Healthy bool `json:"healthy"`
54215421
UnhealthySince string `json:"unhealthy_since,omitempty"`
54225422
Backends []SealBackendStatus `json:"backends"`
5423+
FullyWrapped bool `json:"fully_wrapped"`
54235424
}
54245425

54255426
func (core *Core) GetSealStatus(ctx context.Context, lock bool) (*SealStatusResponse, error) {
@@ -5545,6 +5546,13 @@ func (c *Core) GetSealBackendStatus(ctx context.Context) (*SealBackendStatusResp
55455546
}
55465547
r.Healthy = true
55475548
}
5549+
5550+
pps, err := GetPartiallySealWrappedPaths(ctx, c.physical)
5551+
if err != nil {
5552+
return nil, fmt.Errorf("could not list partially seal wrapped values: %w", err)
5553+
}
5554+
genInfo := c.seal.GetAccess().GetSealGenerationInfo()
5555+
r.FullyWrapped = genInfo.IsRewrapped() && len(pps) == 0
55485556
return &r, nil
55495557
}
55505558

vault/seal/seal.go

+21-16
Original file line numberDiff line numberDiff line change
@@ -724,26 +724,31 @@ func (a *access) Decrypt(ctx context.Context, ciphertext *MultiWrapValue, option
724724
}
725725

726726
// Start goroutines to decrypt the value
727-
728727
first := wrappersByPriority[0]
729-
// First, if we only have one slot, try matching by keyId
730-
if len(blobInfoMap) == 1 {
731-
outer:
732-
for k := range blobInfoMap {
733-
for _, sealWrapper := range wrappersByPriority {
734-
keyId, err := sealWrapper.Wrapper.KeyId(ctx)
735-
if err != nil {
736-
resultWg.Add(1)
737-
go reportResult(sealWrapper.Name, nil, false, err)
738-
continue
739-
}
740-
if keyId == k {
741-
first = sealWrapper
742-
break outer
743-
}
728+
found := false
729+
outer:
730+
// This loop finds the highest priority seal with a keyId in common with the blobInfoMap,
731+
// and ensures we'll use it first. This should equal the highest priority wrapper in the nominal
732+
// case, but may not if a seal is unhealthy. This ensures we try the highest priority healthy
733+
// seal first if available, and warn if we don't think we have one in common.
734+
for k := range blobInfoMap {
735+
for _, sealWrapper := range wrappersByPriority {
736+
keyId, err := sealWrapper.Wrapper.KeyId(ctx)
737+
if err != nil {
738+
resultWg.Add(1)
739+
go reportResult(sealWrapper.Name, nil, false, err)
740+
continue
741+
}
742+
if keyId == k {
743+
found = true
744+
first = sealWrapper
745+
break outer
744746
}
745747
}
746748
}
749+
if !found {
750+
a.logger.Warn("while unwrapping, value has no key-id in common with currently healthy seals. Trying all healthy seals")
751+
}
747752

748753
resultWg.Add(1)
749754
go decrypt(first)

0 commit comments

Comments
 (0)