-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
mcscertkey.go
77 lines (66 loc) · 2.67 KB
/
mcscertkey.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package tls
import (
"crypto/x509"
"crypto/x509/pkix"
"net"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
baremetaltypes "github.com/openshift/installer/pkg/types/baremetal"
kubevirttypes "github.com/openshift/installer/pkg/types/kubevirt"
openstacktypes "github.com/openshift/installer/pkg/types/openstack"
ovirttypes "github.com/openshift/installer/pkg/types/ovirt"
vspheretypes "github.com/openshift/installer/pkg/types/vsphere"
)
// MCSCertKey is the asset that generates the MCS key/cert pair.
type MCSCertKey struct {
SignedCertKey
}
var _ asset.Asset = (*MCSCertKey)(nil)
// Dependencies returns the dependency of the the cert/key pair, which includes
// the parent CA, and install config if it depends on the install config for
// DNS names, etc.
func (a *MCSCertKey) Dependencies() []asset.Asset {
return []asset.Asset{
&RootCA{},
&installconfig.InstallConfig{},
}
}
// Generate generates the cert/key pair based on its dependencies.
func (a *MCSCertKey) Generate(dependencies asset.Parents) error {
ca := &RootCA{}
installConfig := &installconfig.InstallConfig{}
dependencies.Get(ca, installConfig)
hostname := internalAPIAddress(installConfig.Config)
cfg := &CertCfg{
Subject: pkix.Name{CommonName: "system:machine-config-server"},
ExtKeyUsages: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
Validity: ValidityTenYears,
}
switch installConfig.Config.Platform.Name() {
case baremetaltypes.Name:
cfg.IPAddresses = []net.IP{net.ParseIP(installConfig.Config.BareMetal.APIVIP)}
cfg.DNSNames = []string{hostname, installConfig.Config.BareMetal.APIVIP}
case openstacktypes.Name:
cfg.IPAddresses = []net.IP{net.ParseIP(installConfig.Config.OpenStack.APIVIP)}
cfg.DNSNames = []string{hostname, installConfig.Config.OpenStack.APIVIP}
case ovirttypes.Name:
cfg.IPAddresses = []net.IP{net.ParseIP(installConfig.Config.Ovirt.APIVIP)}
cfg.DNSNames = []string{hostname, installConfig.Config.Ovirt.APIVIP}
case vspheretypes.Name:
cfg.DNSNames = []string{hostname}
if installConfig.Config.VSphere.APIVIP != "" {
cfg.IPAddresses = []net.IP{net.ParseIP(installConfig.Config.VSphere.APIVIP)}
cfg.DNSNames = append(cfg.DNSNames, installConfig.Config.VSphere.APIVIP)
}
case kubevirttypes.Name:
cfg.IPAddresses = []net.IP{net.ParseIP(installConfig.Config.Kubevirt.APIVIP)}
cfg.DNSNames = []string{hostname, installConfig.Config.Kubevirt.APIVIP}
default:
cfg.DNSNames = []string{hostname}
}
return a.SignedCertKey.Generate(cfg, ca, "machine-config-server", DoNotAppendParent)
}
// Name returns the human-friendly name of the asset.
func (a *MCSCertKey) Name() string {
return "Certificate (mcs)"
}