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

MergeCertificateAsync does not serialize request body #9986

Closed
twsouthwick opened this issue Feb 14, 2020 · 1 comment
Closed

MergeCertificateAsync does not serialize request body #9986

twsouthwick opened this issue Feb 14, 2020 · 1 comment
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. KeyVault
Milestone

Comments

@twsouthwick
Copy link

Describe the bug
When trying to call MergeCertificateAsync an exception is thrown.

Expected behavior
That the API is called with no error.

Actual behavior (include Exception or Stack Trace)

Azure.RequestFailedException: Service request failed.
Status: 400 (Bad Request)

Content:
{"error":{"code":"BadParameter","message":"Request body not specified"}}

Headers:
Cache-Control: no-cache
Pragma: no-cache
Server: Microsoft-IIS/10.0
x-ms-keyvault-region: eastasia
x-ms-request-id: dc7f7126-a161-4911-9094-957355609fa9
x-ms-keyvault-service-version: 1.1.0.893
x-ms-keyvault-network-info: addr=131.107.159.246;act_addr_fam=InterNetwork;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Strict-Transport-Security: max-age=31536000;includeSubDomains
X-Content-Type-Options: nosniff
Date: Fri, 14 Feb 2020 19:58:04 GMT
Content-Length: 72
Content-Type: application/json; charset=utf-8
Expires: -1

   at Azure.Security.KeyVault.KeyVaultPipeline.SendRequestAsync(Request request, CancellationToken cancellationToken)
   at Azure.Security.KeyVault.KeyVaultPipeline.SendRequestAsync[TResult](RequestMethod method, Func`1 resultFactory, CancellationToken cancellationToken, String[] path)
   at Azure.Security.KeyVault.Certificates.CertificateClient.MergeCertificateAsync(MergeCertificateOptions mergeCertificateOptions, CancellationToken cancellationToken)
   at McMaster.AspNetCore.LetsEncrypt.AzureKeyVaultCertificateRepository.SaveAsync(X509Certificate2 certificate, CancellationToken cancellationToken) in C:\Users\tasou\Projects\Software\LetsEncrypt\src\LetsEncrypt.Azure\AzureKeyVaultCertificateRepository.cs:line 103

To Reproduce

public async Task SaveAsync(X509Certificate2 certificate, CancellationToken cancellationToken)
{
    var domainName = certificate.GetNameInfo(X509NameType.DnsName, false);

    _logger.LogInformation("Saving certificate for {Domain} in Azure KeyVault.", domainName);

    if (!(await ShouldImportVersionAsync(domainName, certificate, cancellationToken)))
    {
        _logger.LogInformation("Certificate for {Domain} is already up-to-date in Azure KeyVault. Skipping importing.", domainName);
        return;
    }

    var exported = certificate.Export(X509ContentType.Pfx);

    var options = new MergeCertificateOptions(NormalizeHostName(domainName),new[] { exported });

    try
    {
        await _client.MergeCertificateAsync(options, cancellationToken);

        _logger.LogInformation("Imported certificate into Azure KeyVault for {Domain}", domainName);
    }
    catch (RequestFailedException ex)
    {
        _logger.LogWarning(ex, "Failed to save {Domain} certificate to Azure KeyVault", domainName);
    }
}

Environment:

  • Name and version of the Library package used: Azure.Security.KeyVault.Certificates v4.0.0
  • Hosting platform or OS and .NET runtime version (dotnet --info output for .NET Core projects):
$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.101
 Commit:    b377529961

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.101\

Host (useful for support):
  Version: 3.1.1
  Commit:  a1388f194c

.NET Core SDKs installed:
  2.2.103 [C:\Program Files\dotnet\sdk]
  3.1.101 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  • IDE and version : Visual Studio 16.4.4
@triage-new-issues triage-new-issues bot added the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Feb 14, 2020
@twsouthwick
Copy link
Author

@heaths I found this while exploring #9963, but is different in that

Response<KeyVaultCertificateWithPolicy> certificate = await _pipeline.SendRequestAsync(RequestMethod.Post, () => new KeyVaultCertificateWithPolicy(), cancellationToken, CertificatesPath, mergeCertificateOptions.Name, "/pending/merge").ConfigureAwait(false);

does not pass through the options. It appears that the sync version has the same issue.

@heaths heaths added Client This issue points to a problem in the data-plane of the library. KeyVault customer-reported Issues that are reported by GitHub users external to the Azure organization. and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Feb 14, 2020
@heaths heaths self-assigned this Feb 14, 2020
@heaths heaths added this to the [2020] March milestone Feb 14, 2020
@heaths heaths added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Feb 15, 2020
heaths added a commit to heaths/azure-sdk-for-net that referenced this issue Feb 19, 2020
Fixes Azure#9986 by passing the model to the request method.
Fixes Azure#7893 by adding tests for merge (tests for import were added in a previous commit)
@heaths heaths closed this as completed in 4f61603 Feb 19, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. KeyVault
Projects
None yet
Development

No branches or pull requests

2 participants