Hi @adam , I have reconfigured appsettings.json to use thumbprint as per the documentation rather than using pfx with plain text password but the PowerShellUniversal service starts and stops shortly after.
I have imported the pfx successfully to Cert:\LocalMachine\My\ and i can see it in PowerShell. Thumbprint is correct but the service wont remain started.
I get this error in the log:
2022-10-25 15:41:25.748 +00:00 [FTL] Failed to start PowerShell Universal.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: ‘IServiceProvider’.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at UniversalAutomation.StartupService.RunInitializationScript() in C:\actions-runner_work\universal\universal\src\Universal.Server\Services\StartupService.cs:line 332
at UniversalAutomation.StartupService.RunStartup() in C:\actions-runner_work\universal\universal\src\Universal.Server\Services\StartupService.cs:line 234
at UniversalAutomation.StartupService.TryRunStartup() in C:\actions-runner_work\universal\universal\src\Universal.Server\Services\StartupService.cs:line 187
I think its trying to export the certificate from the certificate store, but the certificate is not exportable so its failing. This works when using pem and key so all good!
Sounds a bit like its not fixed, but rather worked around using another method.
I’m facing the same issue trying to use a Certificate from the cert store by its thumbprint
2022-10-31 13:13:51.223 +01:00 [FTL] Failed to start PowerShell Universal.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'IServiceProvider'.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at PowerShellUniversal.Client.get__config() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\Client.cs:line 33
at PowerShellUniversal.Client.StartAsync() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\Client.cs:line 48
at UniversalAutomation.StartupService.RunStartup() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\StartupService.cs:line 242
at UniversalAutomation.StartupService.TryRunStartup() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\StartupService.cs:line 187
Trying the example with a self signed cert works by subject, but generates the same error when using thumbnail.
Exporting the cert as PFX with password also generates the same error.
Any other errors in the logs? It’s actually past where we setup the cert and it’s attempting to run the initialization script. It leads me to believe the server is starting to shut down for some reason and has disposed the service provider which is causing this error.
Don’t know if its relevant that i’m running my site with a gSMA.
Here the log from C:\ProgramData\PowerShellUniversal, where I made an attempt with PFX, then the working localhost example based on subjectname, and an attempt with localhost based on thumbprint.
Not much to work with.
2022-10-31 13:29:43.867 +01:00 [FTL] Failed to start PowerShell Universal.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'IServiceProvider'.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at PowerShellUniversal.Client.get__config() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\Client.cs:line 33
at PowerShellUniversal.Client.StartAsync() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\Client.cs:line 48
at UniversalAutomation.StartupService.RunStartup() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\StartupService.cs:line 242
at UniversalAutomation.StartupService.TryRunStartup() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\StartupService.cs:line 187
2022-10-31 13:31:16.785 +01:00 [INF] User profile is available. Using 'C:\Users\S_PSU_ssdfgsdfg$\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-10-31 13:31:17.387 +01:00 [INF] Now listening on: http://[::]:5000
2022-10-31 13:31:17.387 +01:00 [INF] Now listening on: https://[::]:443
2022-10-31 13:31:17.389 +01:00 [INF] Application started. Hosting environment: Production; Content root path: C:\Program Files (x86)\Universal\
2022-10-31 13:32:25.757 +01:00 [INF] User profile is available. Using 'C:\Users\S_PSU_sdfgsdfg$\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-10-31 13:32:28.101 +01:00 [FTL] Failed to start PowerShell Universal.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'IServiceProvider'.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at PowerShellUniversal.Client.get__config() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\Client.cs:line 33
at PowerShellUniversal.Client.StartAsync() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\Client.cs:line 48
at UniversalAutomation.StartupService.RunStartup() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\StartupService.cs:line 242
at UniversalAutomation.StartupService.TryRunStartup() in C:\actions-runner\_work\universal\universal\src\Universal.Server\Services\StartupService.cs:line 187
Setting log level to debug adds nothing to the log when it errors out.
Application: Universal.Server.exe
CoreCLR Version: 6.0.1022.47605
.NET Version: 6.0.10
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Reload()
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at Universal.Server.Program.<>c__DisplayClass3_0.<Main>b__0(Options o) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Program.cs:line 76
at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
at Universal.Server.Program.Main(String[] args) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Program.cs:line 58
Using the example with the self signed cert, I’m not getting the same errors, as mentioned, but its not letting me get to the site with https:
2022-11-02 11:40:09.733 +01:00 [DBG] Failed to authenticate HTTPS connection.
System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> System.ComponentModel.Win32Exception (0x8009030D): The credentials supplied to the package were not recognized
at System.Net.SSPIWrapper.AcquireCredentialsHandle(ISSPIInterface secModule, String package, CredentialUse intent, SCH_CREDENTIALS* scc)
at System.Net.Security.SslStreamPal.AcquireCredentialsHandle(CredentialUse credUsage, SCH_CREDENTIALS* secureCredential)
at System.Net.Security.SslStreamPal.AcquireCredentialsHandleSchCredentials(SslStreamCertificateContext certificateContext, SslProtocols protocols, EncryptionPolicy policy, Boolean isServer)
at System.Net.Security.SslStreamPal.AcquireCredentialsHandle(SslStreamCertificateContext certificateContext, SslProtocols protocols, EncryptionPolicy policy, Boolean isServer)
--- End of inner exception stack trace ---
at System.Net.Security.SslStreamPal.AcquireCredentialsHandle(SslStreamCertificateContext certificateContext, SslProtocols protocols, EncryptionPolicy policy, Boolean isServer)
at System.Net.Security.SecureChannel.AcquireServerCredentials(Byte[]& thumbPrint)
at System.Net.Security.SecureChannel.GenerateToken(ReadOnlySpan`1 inputBuffer, Byte[]& output)
at System.Net.Security.SecureChannel.NextMessage(ReadOnlySpan`1 incomingBuffer)
at System.Net.Security.SslStream.ProcessBlob(Int32 frameSize)
at System.Net.Security.SslStream.ReceiveBlobAsync[TIOAdapter](TIOAdapter adapter)
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware.OnConnectionAsync(ConnectionContext context)
Running the service with LocalSystem instead of an gMSA works using the Localhost self signed example.
No luck on using thumbprint still. @adam, still getting the "Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
" error in event log
I managed to get my HTTPS site working (using exported cert) and gMSA, the issue being me using er certificate request template without server auth (stupid long template name cut off that part ), kestrel being a bit more verbose could probably have told me that.
Either way, still not able to use thumbprint, butat least now I can get on with it.