forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiservercertkey.go
63 lines (52 loc) · 1.88 KB
/
apiservercertkey.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
package tls
import (
"crypto/x509"
"crypto/x509/pkix"
"net"
"github.com/pkg/errors"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
)
// APIServerCertKey is the asset that generates the API server key/cert pair.
type APIServerCertKey struct {
CertKey
}
var _ asset.Asset = (*APIServerCertKey)(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 *APIServerCertKey) Dependencies() []asset.Asset {
return []asset.Asset{
&KubeCA{},
&installconfig.InstallConfig{},
}
}
// Generate generates the cert/key pair based on its dependencies.
func (a *APIServerCertKey) Generate(dependencies asset.Parents) error {
kubeCA := &KubeCA{}
installConfig := &installconfig.InstallConfig{}
dependencies.Get(kubeCA, installConfig)
apiServerAddress, err := cidrhost(installConfig.Config.Networking.ServiceCIDR.IPNet, 1)
if err != nil {
return errors.Wrap(err, "failed to get API Server address from InstallConfig")
}
cfg := &CertCfg{
Subject: pkix.Name{CommonName: "system:kube-apiserver", Organization: []string{"kube-master"}},
KeyUsages: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsages: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
Validity: ValidityTenYears,
DNSNames: []string{
apiAddress(installConfig.Config),
"kubernetes", "kubernetes.default",
"kubernetes.default.svc",
"kubernetes.default.svc.cluster.local",
"localhost",
},
IPAddresses: []net.IP{net.ParseIP(apiServerAddress), net.ParseIP("127.0.0.1")},
}
return a.CertKey.Generate(cfg, kubeCA, "apiserver", AppendParent)
}
// Name returns the human-friendly name of the asset.
func (a *APIServerCertKey) Name() string {
return "Certificate (kube-apiaserver)"
}