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

Support unwrapping tokens that does not contain data #8714

Merged
merged 3 commits into from Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions command/unwrap.go
Expand Up @@ -89,8 +89,10 @@ func (c *UnwrapCommand) Run(args []string) int {
return 2
}
if secret == nil {
c.UI.Error("Could not find wrapped response")
return 2
if Format(c.UI) == "table" {
c.UI.Info("Successfully unwrapped. There was no data in the wrapped secret.")
}
return 0
}

// Handle single field output
Expand Down
15 changes: 8 additions & 7 deletions vault/logical_system.go
Expand Up @@ -2404,6 +2404,11 @@ func (b *SystemBackend) handleWrappingUnwrap(ctx context.Context, req *logical.R
Data: map[string]interface{}{},
}

if len(response) == 0 {
resp.Data[logical.HTTPStatusCode] = 204
return resp, nil
}

// Most of the time we want to just send over the marshalled HTTP bytes.
// However there is a sad separate case: if the original response was using
// bare values we need to use those or else what comes back is garbled.
Expand Down Expand Up @@ -2449,13 +2454,9 @@ func (b *SystemBackend) handleWrappingUnwrap(ctx context.Context, req *logical.R
return resp, nil
}

if len(response) == 0 {
resp.Data[logical.HTTPStatusCode] = 204
} else {
resp.Data[logical.HTTPStatusCode] = 200
resp.Data[logical.HTTPRawBody] = []byte(response)
resp.Data[logical.HTTPContentType] = "application/json"
}
resp.Data[logical.HTTPStatusCode] = 200
resp.Data[logical.HTTPRawBody] = []byte(response)
resp.Data[logical.HTTPContentType] = "application/json"

return resp, nil
}
Expand Down