-
Notifications
You must be signed in to change notification settings - Fork 782
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
VAULT-528 Fix issue with consul-template not rendering secrets with delete_version_after set on them #1879
VAULT-528 Fix issue with consul-template not rendering secrets with delete_version_after set on them #1879
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -176,7 +176,20 @@ func (d *VaultReadQuery) readSecret(clients *ClientSet) (*api.Secret, error) { | |||||
func deletedKVv2(s *api.Secret) bool { | ||||||
switch md := s.Data["metadata"].(type) { | ||||||
case map[string]interface{}: | ||||||
return md["deletion_time"] != "" | ||||||
deletionTime, ok := md["deletion_time"].(string) | ||||||
if !ok { | ||||||
// Not a string, end early | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're casting to a string, we'll only go down the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated! Please let me know if there's anything else you'd need before approving :) |
||||||
return false | ||||||
} | ||||||
t, err := time.Parse(time.RFC3339, deletionTime) | ||||||
if err != nil { | ||||||
// Deletion time is either empty, or not a valid string. | ||||||
return false | ||||||
} | ||||||
|
||||||
// If now is 'after' the deletion time, then the secret | ||||||
// should be deleted. | ||||||
return time.Now().After(t) | ||||||
} | ||||||
return false | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -711,3 +711,63 @@ func TestShimKVv2Path(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
// TestDeletedKVv2 tests that deletedKVv2 returns true and false | ||
// in the correct scenarios. | ||
func TestDeletedKVv2(t *testing.T) { | ||
// Intentionally using string literals here since they are taken | ||
// directly from Vault's API. | ||
assert.True(t, deletedKVv2(&api.Secret{ | ||
Data: map[string]interface{}{ | ||
"metadata": map[string]interface{}{ | ||
"deletion_time": "2022-06-15T20:23:40.067093Z", | ||
}, | ||
}, | ||
})) | ||
assert.True(t, deletedKVv2(&api.Secret{ | ||
Data: map[string]interface{}{ | ||
"metadata": map[string]interface{}{ | ||
"deletion_time": "2019-06-19T20:56:35.662563Z", | ||
}, | ||
}, | ||
})) | ||
|
||
// It should work with any RFC3339 formatted string | ||
assert.True(t, deletedKVv2(&api.Secret{ | ||
Data: map[string]interface{}{ | ||
"metadata": map[string]interface{}{ | ||
"deletion_time": time.Now().Add(-1 * time.Hour).Format(time.RFC3339), | ||
}, | ||
}, | ||
})) | ||
|
||
assert.False(t, deletedKVv2(&api.Secret{ | ||
Data: map[string]interface{}{ | ||
"metadata": map[string]interface{}{ | ||
"deletion_time": time.Now().Add(time.Hour).String(), | ||
}, | ||
}, | ||
})) | ||
|
||
// Edge cases: | ||
assert.False(t, deletedKVv2(&api.Secret{})) | ||
assert.False(t, deletedKVv2(&api.Secret{ | ||
Data: map[string]interface{}{ | ||
"metadata": map[string]interface{}{}, | ||
}, | ||
})) | ||
assert.False(t, deletedKVv2(&api.Secret{ | ||
Data: map[string]interface{}{ | ||
"metadata": map[string]interface{}{ | ||
"deletion_time": "", | ||
}, | ||
}, | ||
})) | ||
assert.False(t, deletedKVv2(&api.Secret{ | ||
Data: map[string]interface{}{ | ||
"metadata": map[string]interface{}{ | ||
"deletion_time": "foo", | ||
}, | ||
}, | ||
})) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add two more tests that confirm:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! Added both :) |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spotted this as part of researching the bug. I've been doing the work under VAULT-528, but I'm happy to close NET-3777 as a duplicate or something once I merge this. However you folks want to handle it and whatever best fits your process!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do close NET-3777, this essentially fixes what has been reported.