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

Feature request : Patch a secret (real patch, not delete / post ) #269

Closed
stephdep opened this issue Jul 14, 2022 · 5 comments · Fixed by #273
Closed

Feature request : Patch a secret (real patch, not delete / post ) #269

stephdep opened this issue Jul 14, 2022 · 5 comments · Fixed by #273
Milestone

Comments

@stephdep
Copy link

Due to security settings, we need to be able to patch a secret.
The current Patch method in the library seems to do a delete / Post, and we don't have Post rights, so this Patch method cannot be used.
Therefore we wrote a patch method ourselves, it would be nice to include this in the library.

`
public const string VaultDataPath = "/v1/secret/data/";

    private async Task PatchKey(string path, string key, string value)
    {
        _logger.LogDebug("Patch Vault key {Key} at {VaultPath}", key, path);
        var requestUri = new Uri(VaultConstants.VaultDataPath + path, UriKind.Relative);
        var httpRequestMessage = new HttpRequestMessage(HttpMethod.Patch, requestUri);
        httpRequestMessage.Headers.Add(VaultConstants.VaultRequestHeaderKey, "true");
        httpRequestMessage.Headers.Add(VaultConstants.VaultTokenHeaderKey, _options.Token);

        var postKey = new JObject();
        postKey[key] = value;
        var postData = new JObject();
        postData["data"] = postKey;

        httpRequestMessage.Content = new StringContent(JsonConvert.SerializeObject(postData), Encoding.UTF8, "application/merge-patch+json");
        var httpResponseMessage = await _httpClient.SendAsync(httpRequestMessage);
        if (httpResponseMessage.IsSuccessStatusCode)
        {
            _logger.LogDebug("Patched Vault key {Key} at {VaultPath} successfully", key, path);
        }
        else
        {
            _logger.LogError("Error patching Vault key {Key} at {VaultPath}, statusCode: {StatusCode}", key, path, httpResponseMessage.StatusCode);
            throw new Exception($"Error patching Vault key {key} at {path}");
        }
    }

`

@konidev20
Copy link
Collaborator

Hey @stephdep,

I've created a draft PR for this Issue. It needs to be reviewed and also tested.

@stephdep
Copy link
Author

stephdep commented Jul 24, 2022 via email

konidev20 added a commit to konidev20/VaultSharp that referenced this issue Jul 31, 2022
@ric-sec
Copy link

ric-sec commented Nov 3, 2022

Hey @konidev20,

Any update on this?

Thanks.

Rick

@konidev20
Copy link
Collaborator

Hey @ric-sec,

The review for the PR is still pending. You can take a build from the branch and check it out. Let me know if you want help with that.

Thanks,
@konidev20

rajanadar pushed a commit that referenced this issue Dec 6, 2022
* feat gh-269: Http method to patch a secret

* chore : added PatchSecretDataRequest

* chore : updated XML docs

* chore : fixed Program.cs tests for Patch Secret Async

* fix : updated the documentation in README.md

* chore : udpated the Changelog.md for 1.9.0 TBD
@rajanadar rajanadar added this to the 1.7.2 milestone Dec 6, 2022
@rajanadar
Copy link
Owner

Available here: https://www.nuget.org/packages/VaultSharp/1.7.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants