aspnetcore: `dotnet dev-certs https` no longer creates a folder if one does not exist
Describe the Bug
dotnet dev-certs https no longer creates a folder if one does not exist
Steps to Reproduce
Previously, running the following code worked:
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
RUN dotnet dev-certs https -v -ep /aspnet/https/aspnetapp.pfx -p somepassword
Now, it produces an error:
2.418 [26] An error has occurred while exporting the certificate: System.InvalidOperationException: The directory '/aspnet/https' does not exist. Choose permissions carefully when creating it.
2.418 at Microsoft.AspNetCore.Certificates.Generation.CertificateManager.EnsureAspNetCoreHttpsDevelopmentCertificate(DateTimeOffset notBefore, DateTimeOffset notAfter, String path, Boolean trust, Boolean includePrivateKey, String password, CertificateKeyExportFormat keyExportFormat, Boolean isInteractive).
2.419 There was an error exporting the HTTPS developer certificate to a file.
Workaround - this works:
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
RUN mkdir -p /aspnet/https
RUN dotnet dev-certs https -v -ep /aspnet/https/aspnetapp.pfx -p somepassword
Other Information
Deployment at Oct 8, 2024 10:12 AM (UTC-5:00) worked Deployment at Oct 9, 2024 11:21 AM (UTC-5:00) failed
Working output
1227 | Step 5/15 : RUN dotnet dev-certs https -ep /aspnet/https/aspnetapp.pfx -p somepassword
1228 | ---> Running in 040e6bd771d1
1229 | The HTTPS developer certificate was generated successfully.
1230 | Removing intermediate container 040e6bd771d1
1231 | ---> d021e0e54e7b
Failed output
Step 5/15 : RUN dotnet dev-certs https -ep /aspnet/https/aspnetapp.pfx -p somepassword
---> Running in 83d22d459576
There was an error exporting the HTTPS developer certificate to a file.
The command '/bin/sh -c dotnet dev-certs https -ep /aspnet/https/aspnetapp.pfx -p somepassword' returned a non-zero code: 3
Output of docker version
N/A happened on both Windows Docker Desktop & in Ubuntu CI build
Output of docker info
N/A happened on both Windows Docker Desktop & in Ubuntu CI build
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 11
- Comments: 38 (21 by maintainers)
Commits related to this issue
- Improve dev-certs export error message During a recent security review of the dev-certs tool, we observed that on export it would create a directory that was potentially world-readable (e.g. based on... — committed to amcasey/aspnetcore by amcasey 2 years ago
- Improve dev-certs export error message During a recent security review of the dev-certs tool, we observed that on export it would create a directory that was potentially world-readable (e.g. based on... — committed to dotnet/aspnetcore by amcasey 2 years ago
- Improve dev-certs export error message During a recent security review of the dev-certs tool, we observed that on export it would create a directory that was potentially world-readable (e.g. based on... — committed to dotnet/aspnetcore by amcasey 2 years ago
- [release/8.0] Improve dev-certs export error message (#58470) * Improve dev-certs export error message During a recent security review of the dev-certs tool, we observed that on export it would cr... — committed to dotnet/aspnetcore by amcasey 2 years ago
- [release/9.0] Improve dev-certs export error message (#58471) * Improve dev-certs export error message During a recent security review of the dev-certs tool, we observed that on export it would cr... — committed to dotnet/aspnetcore by github-actions[bot] 2 years ago
- Improve dev-certs export error message (#58472) * Improve dev-certs export error message During a recent security review of the dev-certs tool, we observed that on export it would create a directo... — committed to dotnet/aspnetcore by github-actions[bot] 2 years ago
- Improve dev-certs export error message (#58472) * Improve dev-certs export error message During a recent security review of the dev-certs tool, we observed that on export it would create a directo... — committed to dotnet/aspnetcore by github-actions[bot] 2 years ago
it can be fixed by calling mkdir manually:
@amcasey is there a suggested method/workaround we should use moving forward? is OP’s work around the most ideal?
@EdCharbeneau Which project template did you use? The React + ASP.NET Core one should be fixed in the next VS 2022 patch and I couldn’t find others that appeared to be affected, but please let me know if I missed one.
I ran into this bug as well. This thread helped me resolve it. Unfortunately, if this is the “new project” experience for someone evaluating .NET, it’s not pretty.
@seangwright @mderriey Thanks for the reports! The next patch should include a better error message.
@cgdallas I didn’t know there was a SPA template that depended on exporting the dev cert - I’ll give that a shot. The template may need to be updated to do the directory creation. It’s also possible we can change the error surfaced from node - I think
There was an error exporting the HTTPS developer certificate to a fileis verbatim fromdev-certs.In our case, we were using an out-of-the-box aspnet SPA template via
dotnet new reactthat was trying to generate a developer certificate during the build process and the Node build step is what was failing. However, the error from Node had nothing regarding a missing directory or anything on that front, just that it couldn’t create a certificate:So I don’t know how the dotnet tooling would have been able to surface something since the Node process is the one that ran into the issue. Had we seen an error similar to what Gregory mentioned above, that would have been way more clear as to what happened though - I’m just not sure its feasible.
I don’t think it was unclear. It looks like it took me between 6 and 22 minutes to fix the problem. The error
2.418 [26] An error has occurred while exporting the certificate: System.InvalidOperationException: The directory '/aspnet/https' does not exist. Choose permissions carefully when creating it.is very specific and provides enough information to code a fix for the issue without using-v.I opened an Issue because this is a change in behavior I didn’t expect, so I assumed it was a bug.
That was an intentional change, made to improve security. The reasoning was that, if the tool created a directory, it would have to choose file access permissions on the user’s behalf and that maximally conservative settings would break some apps. We decided instead to delegate that decision back to the user.
I’m sorry that you spent a bunch of time debugging this. My personal recommendation is to always pass
--verbosetodev-certs- the behavior is hard to reason about otherwise.dev-certs is a bundled global tool that comes into dotnet/installer. dev-certs comes from the aspnetcore repo so I am not sure the sdk repo is the best place for this issue…moving.