rajanadar / VaultSharp

A comprehensive cross-platform .NET Library for HashiCorp's Vault, a secret management tool
http://rajanadar.github.io/VaultSharp
Apache License 2.0
493 stars 134 forks source link

Unable to Patch Existing Secrets Map in VaultSharp #347

Closed ramyasrimartha closed 2 months ago

ramyasrimartha commented 7 months ago

Describe the bug When attempting to patch existing secrets in Vault using VaultSharp, we encounter an issue where patching to add new keys to an existing secrets map fails. While writing and patching secrets individually are successful, attempting to patch secrets to an existing map results in failure. This behavior is inconsistent with the expected functionality and prevents the seamless updating of secrets maps in Vault. As a result, we are unable to effectively manage and update secrets within the Vault environment.

VaultSharp Version 1.13.0.1

Vault Version 1.4.2

Does this work with Vault CLI? No

Sample Code Snippet // Successful patching of individual secrets var value = new Dictionary<string, object> { { "key1", "val1" }}; var writtenValue = await vaultClient.V1.Secrets.KeyValue.V2.WriteSecretAsync(secretPath, value, checkAndSet, mountpoint);

// Successful patching of individual secrets var valueToBeCombined = new Dictionary<string, object> { { "key1", "new-val1" }}; var patchSecretDataRequest = new PatchSecretDataRequest() { Data = valueToBeCombined }; var metadata = await vaultClient.V1.Secrets.KeyValue.V2.PatchSecretAsync(secretPath, valueToBeCombined, mountpoint);

// Attempt to patch secrets to existing secrets map - fails var valueToBeCombined = new Dictionary<string, object> { { "key3", "new-val3" }}; var patchSecretDataRequest = new PatchSecretDataRequest() { Data = valueToBeCombined }; var metadata = await vaultClient.V1.Secrets.KeyValue.V2.PatchSecretAsync(secretPath, valueToBeCombined, mountpoint);

Exception Details/Stack Trace/Error Message Error message, stack trace you see

Any additional info Helpful info

rajanadar commented 2 months ago

@ramyasrimartha This is not reproing for me. Can you please follow the sample here and let me know? https://github.com/rajanadar/VaultSharp/blob/master/test/VaultSharp.Samples/Backends/Secrets/KeyValueSecretsBackendSamples.cs#L177