-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
connect: strip port from DNS SANs for ingress gateway leaf cert #15320
Conversation
85156b9
to
fbefbcc
Compare
@kyhavlov : Thanks! A few follow-up questions:
|
|
77fee06
to
331312f
Compare
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.
@kyhavlov: I think I spotted something that can quickly be fixed.
agent/connect/csr.go
Outdated
formattedDNSNames := make([]string, 0) | ||
for _, host := range dnsNames { | ||
hostSegments := strings.Split(host, ":") | ||
formattedHost := hostSegments[0] |
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.
Should we confirm that len(hostSegments) > 0
here before accessing the 0th element, to ensure we don't have an out-of-bounds access?
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.
To test this edge case, I guess you could add a host ""
to the array in your test
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 should be okay. strings.Split
only returns an empty list when both arguments are empty.
formattedHost
could be empty here, but that would only occur if the one of dnsNames
had no hostname, like :8080
.
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.
We wouldn't want a bad configuration (like ":8080
") to cause a panic though, right?
agent/connect/csr.go
Outdated
continue | ||
} | ||
|
||
if len(hostSegments) >= 1 { |
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 check seems to be ineffective in its current position, because we're already assuming that hostSegments
has at least 1 element by accessing its 0th element without a guard.
agent/connect/csr.go
Outdated
formattedDNSNames := make([]string, 0) | ||
for _, host := range dnsNames { | ||
hostSegments := strings.Split(host, ":") | ||
formattedHost := hostSegments[0] |
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 should be okay. strings.Split
only returns an empty list when both arguments are empty.
formattedHost
could be empty here, but that would only occur if the one of dnsNames
had no hostname, like :8080
.
ceed3ce
to
2251d55
Compare
2251d55
to
a24eaf3
Compare
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.
LGTM!
Closes #11092 - currently we're passing along whatever's in the
Hosts
field verbatim to construct the list of SANs. This PR changes that to strip the:
and everything after it from eachHost
string so that it's in the format Vault expects when signing the leaf cert.