microsoft / mindaro

Bridge to Kubernetes - for Visual Studio and Visual Studio Code
MIT License
307 stars 106 forks source link

Debugging in VSCode causes WindowsCryptographicException #232

Open mike-geiger opened 2 years ago

mike-geiger commented 2 years ago

I used the configure task to copy settings from a working "Run" launch configuration. When I start debugging, Bridge connects to my cluster, the project builds, but when it launches i get an exception that generates two log messages (below).

Especially odd is that, even though my original configuration had https, the configuration generated by bridge has "ASPNETCORE_URLS": "http://+5014", so I'm not even sure why Kestrel is looking for the certificate. I'm not getting environment variables from the service. I'm still able to launch the original configuration with and without https urls, and bridge is working with an "Attach" launch configuration.

Any Ideas? I'd like to have an F5 experience ;-)

{
    "@t": "2021-09-18T23:10:50.2123737Z",
    "@m": "Unable to start Kestrel.",
    "@i": "fc6a528d",
    "@l": "Fatal",
    "@x": "Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The system cannot find the path specified.\r\n   at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(ReadOnlySpan`1 rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)\r\n   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)\r\n   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password)\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Certificates.CertificateConfigLoader.LoadCertificate(CertificateConfig certInfo, String endpointName)\r\n   at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.LoadDefaultCert()\r\n   at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Reload()\r\n   at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)",
    "SourceContext": "Microsoft.AspNetCore.Server.Kestrel",
    "MachineName": "DESKTOP-O6UNJBB",
    "ThreadId": 1,
    "Application": "product",
    "ExceptionDetail": {
        "HResult": -2147024893,
        "Message": "The system cannot find the path specified.",
        "Source": "System.Security.Cryptography.X509Certificates",
        "StackTrace": "   at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(ReadOnlySpan`1 rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)\r\n   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)\r\n   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password)\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Certificates.CertificateConfigLoader.LoadCertificate(CertificateConfig certInfo, String endpointName)\r\n   at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.LoadDefaultCert()\r\n   at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Reload()\r\n   at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)",
        "Type": "Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException"
    }
}

and

{
    "@t": "2021-09-18T23:10:50.3914029Z",
    "@m": "Host terminated unexpectedly",
    "@i": "2eab722c",
    "@l": "Fatal",
    "@x": "Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The system cannot find the path specified.\r\n   at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(ReadOnlySpan`1 rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)\r\n   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)\r\n   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password)\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Certificates.CertificateConfigLoader.LoadCertificate(CertificateConfig certInfo, String endpointName)\r\n   at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.LoadDefaultCert()\r\n   at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Reload()\r\n   at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)\r\n   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)\r\n   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)\r\n   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)\r\n   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)\r\n   at HP.Eclipse.Services.Product.API.Program.Main(String[] args) in D:\\source\\eclipse\\product-service\\src\\Product.API\\Program.cs:line 31",
    "MachineName": "DESKTOP-O6UNJBB",
    "ThreadId": 1,
    "Application": "product",
    "ExceptionDetail": {
        "HResult": -2147024893,
        "Message": "The system cannot find the path specified.",
        "Source": "System.Security.Cryptography.X509Certificates",
        "StackTrace": "   at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(ReadOnlySpan`1 rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)\r\n   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)\r\n   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password)\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Certificates.CertificateConfigLoader.LoadCertificate(CertificateConfig certInfo, String endpointName)\r\n   at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.LoadDefaultCert()\r\n   at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Reload()\r\n   at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)\r\n   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)\r\n   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)\r\n   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)\r\n   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)\r\n   at HP.Eclipse.Services.Product.API.Program.Main(String[] args) in D:\\source\\eclipse\\product-service\\src\\Product.API\\Program.cs:line 31",
        "Type": "Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException"
    }
}
pragyamehta commented 2 years ago

Hi @mike-geiger, the ASPNETCORE_URLS value is missing a ":". Can you please update it to "http://+:5014". Could you also update the port value to one that your app actually listens on and try again? You also mention that you are able to launch with the original configuration. What changes have you made to the original configuration since then?

mike-geiger commented 2 years ago

@pragyamehta sorry, that was my own typo, I should have just copy pasted to begin with. here is the full launch.json after running running the bridge configuration. the original still works, the generated "with Kubernetes" one gives the error

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (console) with Kubernetes",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "bridge-to-kubernetes.compound",
            "program": "${workspaceFolder}/src/API/bin/Debug/net5.0/API.dll",
            "args": [],
            "cwd": "${workspaceFolder}/src/API/",
            "stopAtEntry": false,
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development",
                "ASPNETCORE_URLS": "http://+:5014"
            }
        },
        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/src/API/bin/Debug/net5.0/API.dll",
            "args": [],
            "cwd": "${workspaceFolder}/src/API/",
            "stopAtEntry": false,
            "serverReadyAction": {
                "action": "openExternally",
                "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development",
                "ASPNETCORE_URLS": "https://localhost:5014"
            }
        }
    ]
}