@@ -63,10 +63,14 @@ func createRotateTLSServerCertificatePlan(log zerolog.Logger, spec api.Deploymen
63
63
Msg ("Failed to get TLS secret" )
64
64
continue
65
65
}
66
- renewalNeeded := tlsKeyfileNeedsRenewal (log , keyfile )
66
+ tlsSpec := spec .TLS
67
+ if group .IsArangosync () {
68
+ tlsSpec = spec .Sync .TLS
69
+ }
70
+ renewalNeeded , reason := tlsKeyfileNeedsRenewal (log , keyfile , tlsSpec )
67
71
if renewalNeeded {
68
72
plan = append (append (plan ,
69
- api .NewAction (api .ActionTypeRenewTLSCertificate , group , m .ID )),
73
+ api .NewAction (api .ActionTypeRenewTLSCertificate , group , m .ID , reason )),
70
74
createRotateMemberPlan (log , m , group , "TLS certificate renewal" )... ,
71
75
)
72
76
}
@@ -133,8 +137,32 @@ func createRotateTLSCAPlan(log zerolog.Logger, apiObject k8sutil.APIObject,
133
137
134
138
// tlsKeyfileNeedsRenewal decides if the certificate in the given keyfile
135
139
// should be renewed.
136
- func tlsKeyfileNeedsRenewal (log zerolog.Logger , keyfile string ) bool {
140
+ func tlsKeyfileNeedsRenewal (log zerolog.Logger , keyfile string , spec api. TLSSpec ) ( bool , string ) {
137
141
raw := []byte (keyfile )
142
+ // containsAll returns true when all elements in the expected list
143
+ // are in the actual list.
144
+ containsAll := func (actual []string , expected []string ) bool {
145
+ for _ , x := range expected {
146
+ found := false
147
+ for _ , y := range actual {
148
+ if x == y {
149
+ found = true
150
+ break
151
+ }
152
+ }
153
+ if ! found {
154
+ return false
155
+ }
156
+ }
157
+ return true
158
+ }
159
+ ipsToStringSlice := func (list []net.IP ) []string {
160
+ result := make ([]string , len (list ))
161
+ for i , x := range list {
162
+ result [i ] = x .String ()
163
+ }
164
+ return result
165
+ }
138
166
for {
139
167
var derBlock * pem.Block
140
168
derBlock , raw = pem .Decode (raw )
@@ -146,7 +174,7 @@ func tlsKeyfileNeedsRenewal(log zerolog.Logger, keyfile string) bool {
146
174
if err != nil {
147
175
// We do not understand the certificate, let's renew it
148
176
log .Warn ().Err (err ).Msg ("Failed to parse x509 certificate. Renewing it" )
149
- return true
177
+ return true , "Cannot parse x509 certificate: " + err . Error ()
150
178
}
151
179
if cert .IsCA {
152
180
// Only look at the server certificate, not CA or intermediate
@@ -162,42 +190,31 @@ func tlsKeyfileNeedsRenewal(log zerolog.Logger, keyfile string) bool {
162
190
Str ("not-after" , cert .NotAfter .String ()).
163
191
Str ("expiration-date" , expirationDate .String ()).
164
192
Msg ("TLS certificate renewal needed" )
165
- return true
193
+ return true , "Server certificate about to expire"
194
+ }
195
+ // Check alternate names against spec
196
+ dnsNames , ipAddresses , emailAddress , err := spec .GetParsedAltNames ()
197
+ if err == nil {
198
+ if ! containsAll (cert .DNSNames , dnsNames ) {
199
+ return true , "Some alternate DNS names are missing"
200
+ }
201
+ if ! containsAll (ipsToStringSlice (cert .IPAddresses ), ipAddresses ) {
202
+ return true , "Some alternate IP addresses are missing"
203
+ }
204
+ if ! containsAll (cert .EmailAddresses , emailAddress ) {
205
+ return true , "Some alternate email addresses are missing"
206
+ }
166
207
}
167
208
}
168
209
}
169
- return false
210
+ return false , ""
170
211
}
171
212
172
213
// tlsCANeedsRenewal decides if the given CA certificate
173
214
// should be renewed.
174
215
// Returns: shouldRenew, reason
175
216
func tlsCANeedsRenewal (log zerolog.Logger , cert string , spec api.TLSSpec ) (bool , string ) {
176
217
raw := []byte (cert )
177
- // containsAll returns true when all elements in the expected list
178
- // are in the actual list.
179
- containsAll := func (actual []string , expected []string ) bool {
180
- for _ , x := range expected {
181
- found := false
182
- for _ , y := range actual {
183
- if x == y {
184
- found = true
185
- break
186
- }
187
- }
188
- if ! found {
189
- return false
190
- }
191
- }
192
- return true
193
- }
194
- ipsToStringSlice := func (list []net.IP ) []string {
195
- result := make ([]string , len (list ))
196
- for i , x := range list {
197
- result [i ] = x .String ()
198
- }
199
- return result
200
- }
201
218
for {
202
219
var derBlock * pem.Block
203
220
derBlock , raw = pem .Decode (raw )
@@ -227,19 +244,6 @@ func tlsCANeedsRenewal(log zerolog.Logger, cert string, spec api.TLSSpec) (bool,
227
244
Msg ("TLS CA certificate renewal needed" )
228
245
return true , "CA Certificate about to expire"
229
246
}
230
- // Check alternate names against spec
231
- dnsNames , ipAddresses , emailAddress , err := spec .GetParsedAltNames ()
232
- if err == nil {
233
- if ! containsAll (cert .DNSNames , dnsNames ) {
234
- return true , "Some alternate DNS names are missing"
235
- }
236
- if ! containsAll (ipsToStringSlice (cert .IPAddresses ), ipAddresses ) {
237
- return true , "Some alternate IP addresses are missing"
238
- }
239
- if ! containsAll (cert .EmailAddresses , emailAddress ) {
240
- return true , "Some alternate email addresses are missing"
241
- }
242
- }
243
247
}
244
248
}
245
249
return false , ""
0 commit comments