@@ -30,6 +30,7 @@ import (
30
30
netutils "k8s.io/utils/net"
31
31
32
32
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
33
+ kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
33
34
certtestutil "k8s.io/kubernetes/cmd/kubeadm/app/util/certs"
34
35
"k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
35
36
testutil "k8s.io/kubernetes/cmd/kubeadm/test"
42
43
43
44
testCACert , testCAKey , _ = pkiutil .NewCertificateAuthority (testCACertCfg )
44
45
45
- testCertCfg = & pkiutil.CertConfig {
46
- Config : certutil.Config {
47
- CommonName : "test-common-name" ,
48
- Organization : []string {"sig-cluster-lifecycle" },
49
- AltNames : certutil.AltNames {
50
- IPs : []net.IP {netutils .ParseIPSloppy ("10.100.0.1" )},
51
- DNSNames : []string {"test-domain.space" },
52
- },
53
- Usages : []x509.ExtKeyUsage {x509 .ExtKeyUsageClientAuth },
54
- },
55
- }
46
+ testCertOrganization = []string {"sig-cluster-lifecycle" }
47
+
48
+ testCertCfg = makeTestCertConfig (testCertOrganization )
56
49
)
57
50
58
51
func TestNewManager (t * testing.T ) {
@@ -99,6 +92,11 @@ func TestRenewUsingLocalCA(t *testing.T) {
99
92
t .Fatalf ("couldn't write out CA certificate to %s" , dir )
100
93
}
101
94
95
+ etcdDir := filepath .Join (dir , "etcd" )
96
+ if err := pkiutil .WriteCertAndKey (etcdDir , "ca" , testCACert , testCAKey ); err != nil {
97
+ t .Fatalf ("couldn't write out CA certificate to %s" , etcdDir )
98
+ }
99
+
102
100
cfg := & kubeadmapi.ClusterConfiguration {
103
101
CertificatesDir : dir ,
104
102
}
@@ -108,23 +106,42 @@ func TestRenewUsingLocalCA(t *testing.T) {
108
106
}
109
107
110
108
tests := []struct {
111
- name string
112
- certName string
113
- createCertFunc func () * x509.Certificate
109
+ name string
110
+ certName string
111
+ createCertFunc func () * x509.Certificate
112
+ expectedOrganization []string
114
113
}{
115
114
{
116
115
name : "Certificate renewal for a PKI certificate" ,
117
116
certName : "apiserver" ,
118
117
createCertFunc : func () * x509.Certificate {
119
- return writeTestCertificate (t , dir , "apiserver" , testCACert , testCAKey )
118
+ return writeTestCertificate (t , dir , "apiserver" , testCACert , testCAKey , testCertOrganization )
120
119
},
120
+ expectedOrganization : testCertOrganization ,
121
121
},
122
122
{
123
123
name : "Certificate renewal for a certificate embedded in a kubeconfig file" ,
124
124
certName : "admin.conf" ,
125
125
createCertFunc : func () * x509.Certificate {
126
126
return writeTestKubeconfig (t , dir , "admin.conf" , testCACert , testCAKey )
127
127
},
128
+ expectedOrganization : testCertOrganization ,
129
+ },
130
+ {
131
+ name : "apiserver-etcd-client cert should not contain SystemPrivilegedGroup after renewal" ,
132
+ certName : "apiserver-etcd-client" ,
133
+ createCertFunc : func () * x509.Certificate {
134
+ return writeTestCertificate (t , dir , "apiserver-etcd-client" , testCACert , testCAKey , []string {kubeadmconstants .SystemPrivilegedGroup })
135
+ },
136
+ expectedOrganization : []string {},
137
+ },
138
+ {
139
+ name : "apiserver-kubelet-client cert should replace SystemPrivilegedGroup with ClusterAdminsGroup after renewal" ,
140
+ certName : "apiserver-kubelet-client" ,
141
+ createCertFunc : func () * x509.Certificate {
142
+ return writeTestCertificate (t , dir , "apiserver-kubelet-client" , testCACert , testCAKey , []string {kubeadmconstants .SystemPrivilegedGroup })
143
+ },
144
+ expectedOrganization : []string {kubeadmconstants .ClusterAdminsGroupAndClusterRoleBinding },
128
145
},
129
146
}
130
147
@@ -154,7 +171,7 @@ func TestRenewUsingLocalCA(t *testing.T) {
154
171
155
172
certtestutil .AssertCertificateIsSignedByCa (t , newCert , testCACert )
156
173
certtestutil .AssertCertificateHasClientAuthUsage (t , newCert )
157
- certtestutil .AssertCertificateHasOrganizations (t , newCert , testCertCfg . Organization ... )
174
+ certtestutil .AssertCertificateHasOrganizations (t , newCert , test . expectedOrganization ... )
158
175
certtestutil .AssertCertificateHasCommonName (t , newCert , testCertCfg .CommonName )
159
176
certtestutil .AssertCertificateHasDNSNames (t , newCert , testCertCfg .AltNames .DNSNames ... )
160
177
certtestutil .AssertCertificateHasIPAddresses (t , newCert , testCertCfg .AltNames .IPs ... )
@@ -193,7 +210,7 @@ func TestCreateRenewCSR(t *testing.T) {
193
210
name : "Creation of a CSR request for renewal of a PKI certificate" ,
194
211
certName : "apiserver" ,
195
212
createCertFunc : func () * x509.Certificate {
196
- return writeTestCertificate (t , dir , "apiserver" , testCACert , testCAKey )
213
+ return writeTestCertificate (t , dir , "apiserver" , testCACert , testCAKey , testCertOrganization )
197
214
},
198
215
},
199
216
{
@@ -233,7 +250,7 @@ func TestCreateRenewCSR(t *testing.T) {
233
250
func TestCertToConfig (t * testing.T ) {
234
251
expectedConfig := & certutil.Config {
235
252
CommonName : "test-common-name" ,
236
- Organization : [] string { "sig-cluster-lifecycle" } ,
253
+ Organization : testCertOrganization ,
237
254
AltNames : certutil.AltNames {
238
255
IPs : []net.IP {netutils .ParseIPSloppy ("10.100.0.1" )},
239
256
DNSNames : []string {"test-domain.space" },
@@ -244,7 +261,7 @@ func TestCertToConfig(t *testing.T) {
244
261
cert := & x509.Certificate {
245
262
Subject : pkix.Name {
246
263
CommonName : "test-common-name" ,
247
- Organization : [] string { "sig-cluster-lifecycle" } ,
264
+ Organization : testCertOrganization ,
248
265
},
249
266
ExtKeyUsage : []x509.ExtKeyUsage {x509 .ExtKeyUsageClientAuth },
250
267
DNSNames : []string {"test-domain.space" },
@@ -274,3 +291,17 @@ func TestCertToConfig(t *testing.T) {
274
291
t .Errorf ("expected SAN DNSNames %v, got %v" , expectedConfig .AltNames .DNSNames , cfg .AltNames .DNSNames )
275
292
}
276
293
}
294
+
295
+ func makeTestCertConfig (organization []string ) * pkiutil.CertConfig {
296
+ return & pkiutil.CertConfig {
297
+ Config : certutil.Config {
298
+ CommonName : "test-common-name" ,
299
+ Organization : organization ,
300
+ AltNames : certutil.AltNames {
301
+ IPs : []net.IP {netutils .ParseIPSloppy ("10.100.0.1" )},
302
+ DNSNames : []string {"test-domain.space" },
303
+ },
304
+ Usages : []x509.ExtKeyUsage {x509 .ExtKeyUsageClientAuth },
305
+ },
306
+ }
307
+ }
0 commit comments