Skip to content

Commit

Permalink
backport of commit 0de67d5 (#16868)
Browse files Browse the repository at this point in the history
  • Loading branch information
hc-github-team-secure-vault-core authored Aug 24, 2022
1 parent 90b1f3b commit 20d1660
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/16794.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
api: Fixed erroneous warnings of unrecognized parameters when unwrapping data.
```
15 changes: 15 additions & 0 deletions http/sys_wrapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ func TestHTTP_Wrapping(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if secret.Warnings != nil {
t.Fatalf("Warnings found: %v", secret.Warnings)
}
if secret == nil || secret.Data == nil {
t.Fatal("secret or secret data is nil")
}
Expand Down Expand Up @@ -222,6 +225,9 @@ func TestHTTP_Wrapping(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if secret.Warnings != nil {
t.Fatalf("Warnings found: %v", secret.Warnings)
}
ret4 := secret
// Should be expired and fail
_, err = client.Logical().Unwrap(wrapInfo.Token)
Expand Down Expand Up @@ -286,10 +292,16 @@ func TestHTTP_Wrapping(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if secret.Warnings != nil {
t.Fatalf("Warnings found: %v", secret.Warnings)
}
secret, err = client.Logical().Unwrap(secret.WrapInfo.Token)
if err != nil {
t.Fatal(err)
}
if secret.Warnings != nil {
t.Fatalf("Warnings found: %v", secret.Warnings)
}
if !reflect.DeepEqual(data, secret.Data) {
t.Fatalf("custom wrap did not match expected: %#v", secret.Data)
}
Expand Down Expand Up @@ -320,6 +332,9 @@ func TestHTTP_Wrapping(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if secret.Warnings != nil {
t.Fatalf("Warnings found: %v", secret.Warnings)
}

// Check for correct Creation path after rewrap
if wrapInfo.CreationPath != "secret/foo" {
Expand Down
2 changes: 1 addition & 1 deletion sdk/framework/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (b *Backend) HandleRequest(ctx context.Context, req *logical.Request) (*log
var ignored []string
for k, v := range req.Data {
raw[k] = v
if path.Fields[k] == nil {
if !path.TakesArbitraryInput && path.Fields[k] == nil {
ignored = append(ignored, k)
}
}
Expand Down
6 changes: 6 additions & 0 deletions sdk/framework/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ type Path struct {
// DisplayAttrs provides hints for UI and documentation generators. They
// will be included in OpenAPI output if set.
DisplayAttrs *DisplayAttributes

// TakesArbitraryInput is used for endpoints that take arbitrary input, instead
// of or as well as their Fields. This is taken into account when printing
// warnings about ignored fields. If this is set, we will not warn when data is
// provided that is not part of the Fields declaration.
TakesArbitraryInput bool
}

// OperationHandler defines and describes a specific operation handler.
Expand Down
2 changes: 2 additions & 0 deletions vault/logical_system_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,8 @@ func (b *SystemBackend) wrappingPaths() []*framework.Path {

HelpSynopsis: strings.TrimSpace(sysHelp["wrap"][0]),
HelpDescription: strings.TrimSpace(sysHelp["wrap"][1]),

TakesArbitraryInput: true,
},

{
Expand Down

0 comments on commit 20d1660

Please sign in to comment.