@@ -62,10 +62,14 @@ func createRotateTLSServerCertificatePlan(log zerolog.Logger, spec api.Deploymen
6262 Msg ("Failed to get TLS secret" )
6363 continue
6464 }
65- renewalNeeded := tlsKeyfileNeedsRenewal (log , keyfile )
65+ tlsSpec := spec .TLS
66+ if group .IsArangosync () {
67+ tlsSpec = spec .Sync .TLS
68+ }
69+ renewalNeeded , reason := tlsKeyfileNeedsRenewal (log , keyfile , tlsSpec )
6670 if renewalNeeded {
6771 plan = append (append (plan ,
68- api .NewAction (api .ActionTypeRenewTLSCertificate , group , m .ID )),
72+ api .NewAction (api .ActionTypeRenewTLSCertificate , group , m .ID , reason )),
6973 createRotateMemberPlan (log , m , group , "TLS certificate renewal" )... ,
7074 )
7175 }
@@ -124,8 +128,32 @@ func createRotateTLSCAPlan(log zerolog.Logger, spec api.DeploymentSpec, status a
124128
125129// tlsKeyfileNeedsRenewal decides if the certificate in the given keyfile
126130// should be renewed.
127- func tlsKeyfileNeedsRenewal (log zerolog.Logger , keyfile string ) bool {
131+ func tlsKeyfileNeedsRenewal (log zerolog.Logger , keyfile string , spec api. TLSSpec ) ( bool , string ) {
128132 raw := []byte (keyfile )
133+ // containsAll returns true when all elements in the expected list
134+ // are in the actual list.
135+ containsAll := func (actual []string , expected []string ) bool {
136+ for _ , x := range expected {
137+ found := false
138+ for _ , y := range actual {
139+ if x == y {
140+ found = true
141+ break
142+ }
143+ }
144+ if ! found {
145+ return false
146+ }
147+ }
148+ return true
149+ }
150+ ipsToStringSlice := func (list []net.IP ) []string {
151+ result := make ([]string , len (list ))
152+ for i , x := range list {
153+ result [i ] = x .String ()
154+ }
155+ return result
156+ }
129157 for {
130158 var derBlock * pem.Block
131159 derBlock , raw = pem .Decode (raw )
@@ -137,7 +165,7 @@ func tlsKeyfileNeedsRenewal(log zerolog.Logger, keyfile string) bool {
137165 if err != nil {
138166 // We do not understand the certificate, let's renew it
139167 log .Warn ().Err (err ).Msg ("Failed to parse x509 certificate. Renewing it" )
140- return true
168+ return true , "Cannot parse x509 certificate: " + err . Error ()
141169 }
142170 if cert .IsCA {
143171 // Only look at the server certificate, not CA or intermediate
@@ -153,42 +181,31 @@ func tlsKeyfileNeedsRenewal(log zerolog.Logger, keyfile string) bool {
153181 Str ("not-after" , cert .NotAfter .String ()).
154182 Str ("expiration-date" , expirationDate .String ()).
155183 Msg ("TLS certificate renewal needed" )
156- return true
184+ return true , "Server certificate about to expire"
185+ }
186+ // Check alternate names against spec
187+ dnsNames , ipAddresses , emailAddress , err := spec .GetParsedAltNames ()
188+ if err == nil {
189+ if ! containsAll (cert .DNSNames , dnsNames ) {
190+ return true , "Some alternate DNS names are missing"
191+ }
192+ if ! containsAll (ipsToStringSlice (cert .IPAddresses ), ipAddresses ) {
193+ return true , "Some alternate IP addresses are missing"
194+ }
195+ if ! containsAll (cert .EmailAddresses , emailAddress ) {
196+ return true , "Some alternate email addresses are missing"
197+ }
157198 }
158199 }
159200 }
160- return false
201+ return false , ""
161202}
162203
163204// tlsCANeedsRenewal decides if the given CA certificate
164205// should be renewed.
165206// Returns: shouldRenew, reason
166207func tlsCANeedsRenewal (log zerolog.Logger , cert string , spec api.TLSSpec ) (bool , string ) {
167208 raw := []byte (cert )
168- // containsAll returns true when all elements in the expected list
169- // are in the actual list.
170- containsAll := func (actual []string , expected []string ) bool {
171- for _ , x := range expected {
172- found := false
173- for _ , y := range actual {
174- if x == y {
175- found = true
176- break
177- }
178- }
179- if ! found {
180- return false
181- }
182- }
183- return true
184- }
185- ipsToStringSlice := func (list []net.IP ) []string {
186- result := make ([]string , len (list ))
187- for i , x := range list {
188- result [i ] = x .String ()
189- }
190- return result
191- }
192209 for {
193210 var derBlock * pem.Block
194211 derBlock , raw = pem .Decode (raw )
@@ -218,19 +235,6 @@ func tlsCANeedsRenewal(log zerolog.Logger, cert string, spec api.TLSSpec) (bool,
218235 Msg ("TLS CA certificate renewal needed" )
219236 return true , "CA Certificate about to expire"
220237 }
221- // Check alternate names against spec
222- dnsNames , ipAddresses , emailAddress , err := spec .GetParsedAltNames ()
223- if err == nil {
224- if ! containsAll (cert .DNSNames , dnsNames ) {
225- return true , "Some alternate DNS names are missing"
226- }
227- if ! containsAll (ipsToStringSlice (cert .IPAddresses ), ipAddresses ) {
228- return true , "Some alternate IP addresses are missing"
229- }
230- if ! containsAll (cert .EmailAddresses , emailAddress ) {
231- return true , "Some alternate email addresses are missing"
232- }
233- }
234238 }
235239 }
236240 return false , ""
0 commit comments