-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 support for certificates with client and server auth and URL SANs #166
Conversation
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.
If we are changing the default of mkcert -client
to client+server, we might as well not add the -server
flag, and make -client
mean client+server. I don't see that breaking anything.
Also, please split the URL support into a separate commit (or PR).
Thanks for the feedback! |
@FiloSottile I updated the PR according to your requests: It consists of 2 commits now, the first only adds support for URLs as SANs, the second adds the extended key usage server auth for client certs. |
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.
Thanks! The second commit looks good, made a couple comments about the first.
main.go
Outdated
@@ -194,6 +195,9 @@ func (m *mkcert) Run(args []string) { | |||
if email, err := mail.ParseAddress(name); err == nil && email.Address == name { | |||
continue | |||
} | |||
if _, err := url.Parse(name); err == nil { | |||
continue | |||
} | |||
punycode, err := idna.ToASCII(name) | |||
if err != nil { | |||
log.Fatalf("ERROR: %q is not a valid hostname, IP, or email: %s", name, err) |
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.
Here and below, update the error.
main.go
Outdated
@@ -194,6 +195,9 @@ func (m *mkcert) Run(args []string) { | |||
if email, err := mail.ParseAddress(name); err == nil && email.Address == name { | |||
continue | |||
} | |||
if _, err := url.Parse(name); err == nil { |
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.
This is missing the extra validation that happens in cert.go
.
cert.go
Outdated
@@ -70,13 +71,15 @@ func (m *mkcert) makeCert(hosts []string) { | |||
tpl.IPAddresses = append(tpl.IPAddresses, ip) | |||
} else if email, err := mail.ParseAddress(h); err == nil && email.Address == h { | |||
tpl.EmailAddresses = append(tpl.EmailAddresses, h) | |||
} else if uriName, err := url.Parse(h); err == nil && uriName.Scheme != "" { |
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.
I'm a bit worried this will catch things some people want as hostnames. Anything with a :
will parse as an URI with Scheme != ""
, and sometimes people use :
in hostnames, for example.
Are there other filters we can apply while still working for your use case?
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.
For my concrete use case I want Spiffe URIs, so checking for value URLs plus the prefix spiffe://
would be fine too (for me)
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.
I'll update the PR to require the scheme spiffe
.
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.
No need to make it Spiffe specific. Looks like those are URLs with the full ://
, so we can just check Scheme != "" && Host != ""
(because without ://
only Scheme and Opaque get populated).
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.
Thanks! Just updated the PR with this check.
Just updated the PR by fixing the error message and only supporting spiffe URIs for now. |
LGTM with a minor nit (see suggestions). |
Co-Authored-By: Filippo Valsorda <[email protected]>
Co-Authored-By: Filippo Valsorda <[email protected]>
Thank you! Sorry for forgetting about this. |
Thank you for this awesome tool! :-)
I wanted to use it to create certificates for a Service Mesh, that is for using Istio with mTLS without using Citadel.
Therefore I needed to create certificates that have an extended key usage of client and server auth.
I also needed to have Spiffe URIs in the Subject Alternate Names.
Therefore I did the following changes:
-server
which is enabled by default. If set tofalse
and setting-client=true
a client-only certificate would be generated, with-client=true
and-server=true
(the default) a client and server certificate would be created.