Fix: Transit encrypt batch does not honor key_version (#11628)
* fix(secret/transit): #10232 Transit encrypt batch does not honor key_version * add changelog for 11628
This commit is contained in:
parent
6c726bde67
commit
9ebb14bab3
|
@ -3,6 +3,7 @@ package transit
|
|||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
|
@ -193,6 +194,14 @@ func decodeBatchRequestItems(src interface{}, dst *[]BatchRequestItem) error {
|
|||
if !reflect.ValueOf(v).IsValid() {
|
||||
} else if casted, ok := v.(int); ok {
|
||||
(*dst)[i].KeyVersion = casted
|
||||
} else if js, ok := v.(json.Number); ok {
|
||||
// https://github.com/hashicorp/vault/issues/10232
|
||||
// Because API server parses json request with UseNumber=true, logical.Request.Data can include json.Number for a number field.
|
||||
if casted, err := js.Int64(); err == nil {
|
||||
(*dst)[i].KeyVersion = int(casted)
|
||||
} else {
|
||||
errs.Errors = append(errs.Errors, fmt.Sprintf(`error decoding %T into [%d].key_version: strconv.ParseInt: parsing "%s": invalid syntax`, v, i, v))
|
||||
}
|
||||
} else {
|
||||
errs.Errors = append(errs.Errors, fmt.Sprintf("'[%d].key_version' expected type 'int', got unconvertible type '%T'", i, item["key_version"]))
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package transit
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
@ -634,6 +635,11 @@ func TestTransit_decodeBatchRequestItems(t *testing.T) {
|
|||
src: []interface{}{map[string]interface{}{"key_version": "666"}},
|
||||
dest: []BatchRequestItem{},
|
||||
},
|
||||
{
|
||||
name: "src_key_version_invalid-number-dest",
|
||||
src: []interface{}{map[string]interface{}{"plaintext": "dGhlIHF1aWNrIGJyb3duIGZveA==", "key_version": json.Number("1.1")}},
|
||||
dest: []BatchRequestItem{},
|
||||
},
|
||||
{
|
||||
name: "src_nonce-dest",
|
||||
src: []interface{}{map[string]interface{}{"nonce": "dGVzdGNvbnRleHQ="}},
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
secret: fix the bug where transit encrypt batch doesn't work with key_version
|
||||
```
|
Loading…
Reference in New Issue