/
etcd.go
172 lines (139 loc) · 5.01 KB
/
etcd.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package tls
import (
"crypto/x509"
"crypto/x509/pkix"
"github.com/openshift/installer/pkg/asset"
)
// EtcdCA is the asset that generates the etcd-ca key/cert pair.
// [DEPRECATED]
type EtcdCA struct {
SelfSignedCertKey
}
var _ asset.Asset = (*EtcdCA)(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 *EtcdCA) Dependencies() []asset.Asset {
return []asset.Asset{}
}
// Generate generates the cert/key pair based on its dependencies.
func (a *EtcdCA) Generate(dependencies asset.Parents) error {
cfg := &CertCfg{
Subject: pkix.Name{CommonName: "etcd", OrganizationalUnit: []string{"etcd"}},
KeyUsages: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
Validity: ValidityTenYears,
IsCA: true,
}
return a.SelfSignedCertKey.Generate(cfg, "etcd-client-ca")
}
// Name returns the human-friendly name of the asset.
func (a *EtcdCA) Name() string {
return "Certificate (etcd)"
}
// EtcdClientCertKey is the asset that generates the etcd client key/cert pair.
// [DEPRECATED]
type EtcdClientCertKey struct {
SignedCertKey
}
var _ asset.Asset = (*EtcdClientCertKey)(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 *EtcdClientCertKey) Dependencies() []asset.Asset {
return []asset.Asset{
&EtcdCA{},
}
}
// Generate generates the cert/key pair based on its dependencies.
func (a *EtcdClientCertKey) Generate(dependencies asset.Parents) error {
etcdCA := &EtcdCA{}
dependencies.Get(etcdCA)
cfg := &CertCfg{
Subject: pkix.Name{CommonName: "etcd", OrganizationalUnit: []string{"etcd"}},
KeyUsages: x509.KeyUsageKeyEncipherment,
ExtKeyUsages: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth},
Validity: ValidityTenYears,
}
return a.SignedCertKey.Generate(cfg, etcdCA, "etcd-client", DoNotAppendParent)
}
// Name returns the human-friendly name of the asset.
func (a *EtcdClientCertKey) Name() string {
return "Certificate (etcd)"
}
// EtcdSignerCertKey is a key/cert pair that signs the etcd client and peer certs.
type EtcdSignerCertKey struct {
SelfSignedCertKey
}
var _ asset.WritableAsset = (*EtcdSignerCertKey)(nil)
// Dependencies returns the dependency of the root-ca, which is empty.
func (c *EtcdSignerCertKey) Dependencies() []asset.Asset {
return []asset.Asset{}
}
// Generate generates the root-ca key and cert pair.
func (c *EtcdSignerCertKey) Generate(parents asset.Parents) error {
cfg := &CertCfg{
Subject: pkix.Name{CommonName: "etcd-signer", OrganizationalUnit: []string{"openshift"}},
KeyUsages: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
Validity: ValidityTenYears,
IsCA: true,
}
return c.SelfSignedCertKey.Generate(cfg, "etcd-signer")
}
// Name returns the human-friendly name of the asset.
func (c *EtcdSignerCertKey) Name() string {
return "Certificate (etcd-signer)"
}
// EtcdCABundle is the asset the generates the etcd-ca-bundle,
// which contains all the individual client CAs.
type EtcdCABundle struct {
CertBundle
}
var _ asset.Asset = (*EtcdCABundle)(nil)
// Dependencies returns the dependency of the cert bundle.
func (a *EtcdCABundle) Dependencies() []asset.Asset {
return []asset.Asset{
&EtcdSignerCertKey{},
}
}
// Generate generates the cert bundle based on its dependencies.
func (a *EtcdCABundle) Generate(deps asset.Parents) error {
var certs []CertInterface
for _, asset := range a.Dependencies() {
deps.Get(asset)
certs = append(certs, asset.(CertInterface))
}
return a.CertBundle.Generate("etcd-ca-bundle", certs...)
}
// Name returns the human-friendly name of the asset.
func (a *EtcdCABundle) Name() string {
return "Certificate (etcd-ca-bundle)"
}
// EtcdSignerClientCertKey is the asset that generates the etcd client key/cert pair.
type EtcdSignerClientCertKey struct {
SignedCertKey
}
var _ asset.Asset = (*EtcdSignerClientCertKey)(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 *EtcdSignerClientCertKey) Dependencies() []asset.Asset {
return []asset.Asset{
&EtcdSignerCertKey{},
}
}
// Generate generates the cert/key pair based on its dependencies.
func (a *EtcdSignerClientCertKey) Generate(dependencies asset.Parents) error {
ca := &EtcdSignerCertKey{}
dependencies.Get(ca)
cfg := &CertCfg{
Subject: pkix.Name{CommonName: "etcd", OrganizationalUnit: []string{"etcd"}},
KeyUsages: x509.KeyUsageKeyEncipherment,
ExtKeyUsages: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth},
Validity: ValidityTenYears,
}
return a.SignedCertKey.Generate(cfg, ca, "etcd-signer-client", DoNotAppendParent)
}
// Name returns the human-friendly name of the asset.
func (a *EtcdSignerClientCertKey) Name() string {
return "Certificate (etcd-signer-client)"
}