Skip to content

Commit

Permalink
Merge pull request #9812 from justinsb/write_full_certificate_chain
Browse files Browse the repository at this point in the history
Support writing a full certificate chain
  • Loading branch information
k8s-ci-robot authored Aug 26, 2020
2 parents 5b80bb8 + 2be2156 commit f8a89b5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 0 additions & 1 deletion nodeup/pkg/model/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ func (c *NodeupModelContext) BuildCertificateTask(ctx *fi.ModelBuilderContext, n
if err != nil {
return err
}

p := filename
if !filepath.IsAbs(p) {
p = filepath.Join(c.PathSrvKubernetes(), filename)
Expand Down
4 changes: 4 additions & 0 deletions nodeup/pkg/model/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (b *SecretBuilder) Build(c *fi.ModelBuilderContext) error {
Subject: nodetasks.PKIXName{CommonName: "kubernetes-master"},
AlternateNames: alternateNames,
}

// Including the CA certificate is more correct, and is needed for e.g. AWS WebIdentity federation
issueCert.IncludeRootCertificate = true

c.AddTask(issueCert)
err := issueCert.AddFileTasks(c, b.PathSrvKubernetes(), "server", "", nil)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions nodeup/pkg/model/tests/golden/minimal/tasks-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ contents:
- api.internal.minimal.example.com
- 100.64.0.1
- 127.0.0.1
includeRootCertificate: true
signer: ca
subject:
CommonName: kubernetes-master
Expand All @@ -90,6 +91,7 @@ contents:
- api.internal.minimal.example.com
- 100.64.0.1
- 127.0.0.1
includeRootCertificate: true
signer: ca
subject:
CommonName: kubernetes-master
Expand Down Expand Up @@ -146,6 +148,7 @@ alternateNames:
- api.internal.minimal.example.com
- 100.64.0.1
- 127.0.0.1
includeRootCertificate: true
signer: ca
subject:
CommonName: kubernetes-master
Expand Down
15 changes: 15 additions & 0 deletions upup/pkg/fi/nodeup/nodetasks/issue_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ type IssueCert struct {
Subject PKIXName `json:"subject"`
AlternateNames []string `json:"alternateNames,omitempty"`

// IncludeRootCertificate will force the certificate data to include the full chain, not just the leaf
IncludeRootCertificate bool `json:"includeRootCertificate,omitempty"`

cert *fi.TaskDependentResource
key *fi.TaskDependentResource
ca *fi.TaskDependentResource
Expand Down Expand Up @@ -160,6 +163,18 @@ func (e *IssueCert) Run(c *fi.Context) error {
keyResource.Resource = &asBytesResource{privateKey}
caResource.Resource = &asBytesResource{caCertificate}

if e.IncludeRootCertificate {
var b bytes.Buffer
if _, err := certificate.WriteTo(&b); err != nil {
return err
}
b.WriteString("\n")
if _, err := caCertificate.WriteTo(&b); err != nil {
return err
}
certResource.Resource = fi.NewBytesResource(b.Bytes())
}

return nil
}

Expand Down

0 comments on commit f8a89b5

Please sign in to comment.