Skip to content

Commit

Permalink
Merge pull request #118 from smallstep/iid-common-names
Browse files Browse the repository at this point in the history
Add subject to the list of SANs in cloud providers
  • Loading branch information
maraino authored Jul 20, 2019
2 parents 3e723c6 + 1cb595b commit 94ae060
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ required = [
[[constraint]]
branch = "master"
name = "github.com/smallstep/certinfo"

[[constraint]]
branch = "master"
name = "github.com/smallstep/zcrypto"
5 changes: 5 additions & 0 deletions command/ca/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import (
"github.com/urfave/cli"
)

// sharedContext is used to share information between commands.
var sharedContext = struct {
DisableCustomSANs bool
}{}

// init creates and registers the ca command
func init() {
cmd := cli.Command{
Expand Down
30 changes: 22 additions & 8 deletions command/ca/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,22 +352,36 @@ func (f *certificateFlow) CreateSignRequest(tok, subject string, sans []string)
case token.AWS:
doc := jwt.Payload.Amazon.InstanceIdentityDocument
if len(ips) == 0 && len(dnsNames) == 0 {
ips = append(ips, net.ParseIP(doc.PrivateIP))
dnsNames = append(dnsNames,
defaultSANs := []string{
doc.PrivateIP,
fmt.Sprintf("ip-%s.%s.compute.internal", strings.Replace(doc.PrivateIP, ".", "-", -1), doc.Region),
)
}
if !sharedContext.DisableCustomSANs {
defaultSANs = append(defaultSANs, subject)
}
dnsNames, ips = splitSANs(defaultSANs)
}
case token.GCP:
ce := jwt.Payload.Google.ComputeEngine
if len(dnsNames) == 0 {
dnsNames = append(dnsNames,
if len(ips) == 0 && len(dnsNames) == 0 {
defaultSANs := []string{
fmt.Sprintf("%s.c.%s.internal", ce.InstanceName, ce.ProjectID),
fmt.Sprintf("%s.%s.c.%s.internal", ce.InstanceName, ce.Zone, ce.ProjectID),
)
}
if !sharedContext.DisableCustomSANs {
defaultSANs = append(defaultSANs, subject)
}
dnsNames, ips = splitSANs(defaultSANs)
}
case token.Azure:
if len(dnsNames) == 0 {
dnsNames = append(dnsNames, jwt.Payload.Azure.VirtualMachine)
if len(ips) == 0 && len(dnsNames) == 0 {
defaultSANs := []string{
jwt.Payload.Azure.VirtualMachine,
}
if !sharedContext.DisableCustomSANs {
defaultSANs = append(defaultSANs, subject)
}
dnsNames, ips = splitSANs(defaultSANs)
}
default: // Use common name in the token
subject = jwt.Payload.Subject
Expand Down
3 changes: 3 additions & 0 deletions command/ca/offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,13 @@ func (c *offlineCA) GenerateToken(ctx *cli.Context, typ int, subject string, san
}
return strings.TrimSpace(string(out)), nil
case *provisioner.GCP: // Do the identity request to get the token
sharedContext.DisableCustomSANs = p.DisableCustomSANs
return p.GetIdentityToken(subject, c.CaURL())
case *provisioner.AWS: // Do the identity request to get the token
sharedContext.DisableCustomSANs = p.DisableCustomSANs
return p.GetIdentityToken(subject, c.CaURL())
case *provisioner.Azure: // Do the identity request to get the token
sharedContext.DisableCustomSANs = p.DisableCustomSANs
return p.GetIdentityToken(subject, c.CaURL())
}

Expand Down
3 changes: 3 additions & 0 deletions command/ca/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,13 @@ func newTokenFlow(ctx *cli.Context, typ int, subject string, sans []string, caUR
}
return strings.TrimSpace(string(out)), nil
case *provisioner.GCP: // Do the identity request to get the token
sharedContext.DisableCustomSANs = p.DisableCustomSANs
return p.GetIdentityToken(subject, caURL)
case *provisioner.AWS: // Do the identity request to get the token
sharedContext.DisableCustomSANs = p.DisableCustomSANs
return p.GetIdentityToken(subject, caURL)
case *provisioner.Azure: // Do the identity request to get the token
sharedContext.DisableCustomSANs = p.DisableCustomSANs
return p.GetIdentityToken(subject, caURL)
}

Expand Down

0 comments on commit 94ae060

Please sign in to comment.