@@ -724,26 +724,31 @@ func (a *access) Decrypt(ctx context.Context, ciphertext *MultiWrapValue, option
724
724
}
725
725
726
726
// Start goroutines to decrypt the value
727
-
728
727
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
744
746
}
745
747
}
746
748
}
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
+ }
747
752
748
753
resultWg .Add (1 )
749
754
go decrypt (first )
0 commit comments