-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add -dev-tls-san flag #22657
Merged
Merged
Add -dev-tls-san flag #22657
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
command/server: add `-dev-tls-san` flag to configure subject alternative names for the certificate generated when using `-dev-tls`. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package server | ||
|
||
import ( | ||
"crypto/x509" | ||
"encoding/pem" | ||
"testing" | ||
|
||
"github.com/hashicorp/go-secure-stdlib/strutil" | ||
) | ||
|
||
// TestGenerateCertExtraSans ensures the implementation backing the flag | ||
// -dev-tls-san populates alternate DNS and IP address names in the generated | ||
// certificate as expected. | ||
func TestGenerateCertExtraSans(t *testing.T) { | ||
ca, err := GenerateCA() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
for name, tc := range map[string]struct { | ||
extraSans []string | ||
expectedDNSNames []string | ||
expectedIPAddresses []string | ||
}{ | ||
"empty": {}, | ||
"DNS names": { | ||
extraSans: []string{"foo", "foo.bar"}, | ||
expectedDNSNames: []string{"foo", "foo.bar"}, | ||
}, | ||
"IP addresses": { | ||
extraSans: []string{"0.0.0.0", "::1"}, | ||
expectedIPAddresses: []string{"0.0.0.0", "::1"}, | ||
}, | ||
"mixed": { | ||
extraSans: []string{"bar", "0.0.0.0", "::1"}, | ||
expectedDNSNames: []string{"bar"}, | ||
expectedIPAddresses: []string{"0.0.0.0", "::1"}, | ||
}, | ||
} { | ||
t.Run(name, func(t *testing.T) { | ||
certStr, _, err := generateCert(ca.Template, ca.Signer, tc.extraSans) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
block, _ := pem.Decode([]byte(certStr)) | ||
cert, err := x509.ParseCertificate(block.Bytes) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
expectedDNSNamesLen := len(tc.expectedDNSNames) + 5 | ||
if len(cert.DNSNames) != expectedDNSNamesLen { | ||
t.Errorf("Wrong number of DNS names, expected %d but got %v", expectedDNSNamesLen, cert.DNSNames) | ||
} | ||
expectedIPAddrLen := len(tc.expectedIPAddresses) + 1 | ||
if len(cert.IPAddresses) != expectedIPAddrLen { | ||
t.Errorf("Wrong number of IP addresses, expected %d but got %v", expectedIPAddrLen, cert.IPAddresses) | ||
} | ||
|
||
for _, expected := range tc.expectedDNSNames { | ||
if !strutil.StrListContains(cert.DNSNames, expected) { | ||
t.Errorf("Missing DNS name %s", expected) | ||
} | ||
} | ||
for _, expected := range tc.expectedIPAddresses { | ||
var found bool | ||
for _, ip := range cert.IPAddresses { | ||
if ip.String() == expected { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
t.Errorf("Missing IP address %s", expected) | ||
} | ||
} | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment if you've got a minute: do you want to add the listen address here as well? I think it'd help close #18259, though we could always require the explicit SAN if we preferred... Just thinking the UX might be nice of the address+dev-tls (without dev-tls-san), but my 2c. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea! Added in 3deacb8