Skip to content

Add host.docker.internal and host.containers.internal to the dev cert SAN #61265

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

benjaminpetit
Copy link
Member

@benjaminpetit benjaminpetit commented Apr 1, 2025

Add host.docker.internal and host.containers.internal to the dev cert SAN

Add necessary SAN for dev container scenario and add an easy to parse output to the dev-certs command.

Description

  • Add host.docker.internal and host.containers.internal to the dev cert SAN.
  • Bump the certificate version to 3
  • Decouple the notion of generated certificate number and minimum acceptable certificate version
  • Add new command similar to --check --trust but with json output: --check-json-output

The notion of minimum version is important if/when we backport this feature into dotnet 8 and 9: the runtime in 8 or 9 should be able to run perfectly fine without the new SAN in the cert.

Example of output for a v2 certificate (generated with .NET 9):

[
  {
    "Thumbprint": "D17F51D47E3D8A4FAB0A964B136BF677E469CFB8",
    "Subject": "CN=localhost",
    "X509SubjectAlternativeNameExtension": [
      "localhost"
    ],
    "Version": 2,
    "ValidityNotBefore": "2025-04-02T17:45:49+02:00",
    "ValidityNotAfter": "2026-04-02T17:45:49+02:00",
    "IsHttpsDevelopmentCertificate": true,
    "IsExportable": true,
    "TrustLevel": "Full"
  }
]

Example of output for a v3 certificate:

[
  {
    "Thumbprint": "4C743A4A6588E7C34BEC70DFF7E1A8605D3D68C9",
    "Subject": "CN=localhost",
    "X509SubjectAlternativeNameExtension": [
      "localhost",
      "host.docker.internal",
      "host.containers.internal"
    ],
    "Version": 3,
    "ValidityNotBefore": "2025-04-02T17:51:51+02:00",
    "ValidityNotAfter": "2026-04-02T17:51:51+02:00",
    "IsHttpsDevelopmentCertificate": true,
    "IsExportable": true,
    "TrustLevel": "Full"
  }
]

Fixes #61155

Add new SAN for dev cert + json output for the tool
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Apr 1, 2025
@adityamandaleeka
Copy link
Member

Looks good so far!

@benjaminpetit benjaminpetit marked this pull request as ready for review April 2, 2025 16:02
@benjaminpetit benjaminpetit requested a review from Copilot April 3, 2025 16:56
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the certificate generation functionality to include "host.docker.internal" and "host.containers.internal" in the SAN, bumps the certificate version to 3, and adds a new command for JSON output of certificate information.

  • Introduces the new --check-json-output option and its logic
  • Refactors certificate version handling by separating generated version and minimum acceptable version
  • Updates tests and adjusts access modifiers in platform-specific certificate managers

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

File Description
src/Tools/dotnet-dev-certs/src/Program.cs Adds new JSON output option and updates certificate filtering on OSX
src/Tools/FirstRunCertGenerator/test/CertificateManagerTests.cs Updates tests to use the new MinimumAspNetHttpsCertificateVersion property
src/Shared/CertificateGeneration/WindowsCertificateManager.cs, UnixCertificateManager.cs, MacOSCertificateManager.cs Adjusts access modifiers for the IsExportable method
src/Shared/CertificateGeneration/CertificateManager.cs Bumps certificate version constants, adds new SAN entries, and introduces the MinimumAspNetHttpsCertificateVersion property

@adityamandaleeka
Copy link
Member

Test failure is real.

@@ -110,6 +114,10 @@ public static int Main(string[] args)
"Display warnings and errors only.",
CommandOptionType.NoValue);

var checkJsonOutput = c.Option("--check-trust-machine-readable",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DamianEdwards is this good? Last chance to change it 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add host.docker.internal and host.containers.internal to the dev cert SAN
2 participants