Skip to content

Commit 94ae060

Browse files
authored
Merge pull request #118 from smallstep/iid-common-names
Add subject to the list of SANs in cloud providers
2 parents 3e723c6 + 1cb595b commit 94ae060

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

Gopkg.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ required = [
7474
[[constraint]]
7575
branch = "master"
7676
name = "github.com/smallstep/certinfo"
77+
78+
[[constraint]]
79+
branch = "master"
80+
name = "github.com/smallstep/zcrypto"

command/ca/ca.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import (
1515
"github.com/urfave/cli"
1616
)
1717

18+
// sharedContext is used to share information between commands.
19+
var sharedContext = struct {
20+
DisableCustomSANs bool
21+
}{}
22+
1823
// init creates and registers the ca command
1924
func init() {
2025
cmd := cli.Command{

command/ca/certificate.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,22 +352,36 @@ func (f *certificateFlow) CreateSignRequest(tok, subject string, sans []string)
352352
case token.AWS:
353353
doc := jwt.Payload.Amazon.InstanceIdentityDocument
354354
if len(ips) == 0 && len(dnsNames) == 0 {
355-
ips = append(ips, net.ParseIP(doc.PrivateIP))
356-
dnsNames = append(dnsNames,
355+
defaultSANs := []string{
356+
doc.PrivateIP,
357357
fmt.Sprintf("ip-%s.%s.compute.internal", strings.Replace(doc.PrivateIP, ".", "-", -1), doc.Region),
358-
)
358+
}
359+
if !sharedContext.DisableCustomSANs {
360+
defaultSANs = append(defaultSANs, subject)
361+
}
362+
dnsNames, ips = splitSANs(defaultSANs)
359363
}
360364
case token.GCP:
361365
ce := jwt.Payload.Google.ComputeEngine
362-
if len(dnsNames) == 0 {
363-
dnsNames = append(dnsNames,
366+
if len(ips) == 0 && len(dnsNames) == 0 {
367+
defaultSANs := []string{
364368
fmt.Sprintf("%s.c.%s.internal", ce.InstanceName, ce.ProjectID),
365369
fmt.Sprintf("%s.%s.c.%s.internal", ce.InstanceName, ce.Zone, ce.ProjectID),
366-
)
370+
}
371+
if !sharedContext.DisableCustomSANs {
372+
defaultSANs = append(defaultSANs, subject)
373+
}
374+
dnsNames, ips = splitSANs(defaultSANs)
367375
}
368376
case token.Azure:
369-
if len(dnsNames) == 0 {
370-
dnsNames = append(dnsNames, jwt.Payload.Azure.VirtualMachine)
377+
if len(ips) == 0 && len(dnsNames) == 0 {
378+
defaultSANs := []string{
379+
jwt.Payload.Azure.VirtualMachine,
380+
}
381+
if !sharedContext.DisableCustomSANs {
382+
defaultSANs = append(defaultSANs, subject)
383+
}
384+
dnsNames, ips = splitSANs(defaultSANs)
371385
}
372386
default: // Use common name in the token
373387
subject = jwt.Payload.Subject

command/ca/offline.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,13 @@ func (c *offlineCA) GenerateToken(ctx *cli.Context, typ int, subject string, san
239239
}
240240
return strings.TrimSpace(string(out)), nil
241241
case *provisioner.GCP: // Do the identity request to get the token
242+
sharedContext.DisableCustomSANs = p.DisableCustomSANs
242243
return p.GetIdentityToken(subject, c.CaURL())
243244
case *provisioner.AWS: // Do the identity request to get the token
245+
sharedContext.DisableCustomSANs = p.DisableCustomSANs
244246
return p.GetIdentityToken(subject, c.CaURL())
245247
case *provisioner.Azure: // Do the identity request to get the token
248+
sharedContext.DisableCustomSANs = p.DisableCustomSANs
246249
return p.GetIdentityToken(subject, c.CaURL())
247250
}
248251

command/ca/token.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,13 @@ func newTokenFlow(ctx *cli.Context, typ int, subject string, sans []string, caUR
350350
}
351351
return strings.TrimSpace(string(out)), nil
352352
case *provisioner.GCP: // Do the identity request to get the token
353+
sharedContext.DisableCustomSANs = p.DisableCustomSANs
353354
return p.GetIdentityToken(subject, caURL)
354355
case *provisioner.AWS: // Do the identity request to get the token
356+
sharedContext.DisableCustomSANs = p.DisableCustomSANs
355357
return p.GetIdentityToken(subject, caURL)
356358
case *provisioner.Azure: // Do the identity request to get the token
359+
sharedContext.DisableCustomSANs = p.DisableCustomSANs
357360
return p.GetIdentityToken(subject, caURL)
358361
}
359362

0 commit comments

Comments
 (0)