Skip to content

Commit

Permalink
server: added utility function for bundling init certs
Browse files Browse the repository at this point in the history
Part of #60632

Release note: None
  • Loading branch information
Aaron Blum authored and itsbilal committed Feb 19, 2021
1 parent 5c2c112 commit 41ee1c2
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/server/auto_tls_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (b *CertificateBundle) InitializeFromConfig(c base.Config) (err error) {
// First check to see if host cert is already present
// if it is, we should fail to initialize.
if _, err = os.Stat(cl.NodeCertPath()); !os.IsNotExist(err) {
err = errors.New("InterNodeHost certificate already present")
err = errors.New("interNodeHost certificate already present")
return
}

Expand Down Expand Up @@ -337,3 +337,22 @@ func (b *CertificateBundle) InitializeFromConfig(c base.Config) (err error) {

return
}

// copyOnlyCAs is a helper function to only populate the CA portion of
// a ServiceCertificateBundle
func (sb *ServiceCertificateBundle) copyOnlyCAs(destBundle *ServiceCertificateBundle) {
destBundle.CACertificate = sb.CACertificate
destBundle.CAKey = sb.CAKey
}

// ToPeerInitBundle populates a bundle of initialization certificate CAs (only).
// This function is expected to serve any node providing a init bundle to a
// joining or starting peer.
func (b *CertificateBundle) ToPeerInitBundle() (pb CertificateBundle) {
b.InterNode.copyOnlyCAs(&pb.InterNode)
b.UserAuth.copyOnlyCAs(&pb.UserAuth)
b.SQLService.copyOnlyCAs(&pb.SQLService)
b.RPCService.copyOnlyCAs(&pb.RPCService)
b.AdminUIService.copyOnlyCAs(&pb.AdminUIService)
return
}

0 comments on commit 41ee1c2

Please sign in to comment.