@@ -63,10 +63,14 @@ func createRotateTLSServerCertificatePlan(log zerolog.Logger, spec api.Deploymen
6363 Msg ("Failed to get TLS secret" )
6464 continue
6565 }
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 )
6771 if renewalNeeded {
6872 plan = append (append (plan ,
69- api .NewAction (api .ActionTypeRenewTLSCertificate , group , m .ID )),
73+ api .NewAction (api .ActionTypeRenewTLSCertificate , group , m .ID , reason )),
7074 createRotateMemberPlan (log , m , group , "TLS certificate renewal" )... ,
7175 )
7276 }
@@ -133,8 +137,32 @@ func createRotateTLSCAPlan(log zerolog.Logger, apiObject k8sutil.APIObject,
133137
134138// tlsKeyfileNeedsRenewal decides if the certificate in the given keyfile
135139// 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 ) {
137141 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+ }
138166 for {
139167 var derBlock * pem.Block
140168 derBlock , raw = pem .Decode (raw )
@@ -146,7 +174,7 @@ func tlsKeyfileNeedsRenewal(log zerolog.Logger, keyfile string) bool {
146174 if err != nil {
147175 // We do not understand the certificate, let's renew it
148176 log .Warn ().Err (err ).Msg ("Failed to parse x509 certificate. Renewing it" )
149- return true
177+ return true , "Cannot parse x509 certificate: " + err . Error ()
150178 }
151179 if cert .IsCA {
152180 // Only look at the server certificate, not CA or intermediate
@@ -162,42 +190,31 @@ func tlsKeyfileNeedsRenewal(log zerolog.Logger, keyfile string) bool {
162190 Str ("not-after" , cert .NotAfter .String ()).
163191 Str ("expiration-date" , expirationDate .String ()).
164192 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+ }
166207 }
167208 }
168209 }
169- return false
210+ return false , ""
170211}
171212
172213// tlsCANeedsRenewal decides if the given CA certificate
173214// should be renewed.
174215// Returns: shouldRenew, reason
175216func tlsCANeedsRenewal (log zerolog.Logger , cert string , spec api.TLSSpec ) (bool , string ) {
176217 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- }
201218 for {
202219 var derBlock * pem.Block
203220 derBlock , raw = pem .Decode (raw )
@@ -227,19 +244,6 @@ func tlsCANeedsRenewal(log zerolog.Logger, cert string, spec api.TLSSpec) (bool,
227244 Msg ("TLS CA certificate renewal needed" )
228245 return true , "CA Certificate about to expire"
229246 }
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- }
243247 }
244248 }
245249 return false , ""
0 commit comments