Fix secret rotation on expired leases.
Handling for expired leases now considers the appropriate exception type. See gh-319 gh-321.
This commit is contained in:
@@ -572,6 +572,16 @@ public class SecretLeaseContainer extends SecretLeaseEventPublisher implements
|
||||
|
||||
return renewed;
|
||||
}
|
||||
catch (VaultException e) {
|
||||
|
||||
// Workaround as there is no HttpStatusCodeException attached.
|
||||
if (e.getMessage().contains("Status 400")) {
|
||||
onLeaseExpired(requestedSecret, lease);
|
||||
}
|
||||
|
||||
onError(requestedSecret, lease,
|
||||
new VaultException(String.format("Cannot renew lease: %s", e)));
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
|
||||
if (e.getStatusCode() == HttpStatus.BAD_REQUEST) {
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.vault.VaultException;
|
||||
import org.springframework.vault.client.VaultResponses;
|
||||
import org.springframework.vault.core.RestOperationsCallback;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
import org.springframework.vault.core.lease.domain.Lease;
|
||||
@@ -500,6 +501,23 @@ public class SecretLeaseContainerUnitTests {
|
||||
any(AfterSecretLeaseRevocationEvent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expiredLeaseShouldRenew() {
|
||||
|
||||
prepareRenewal();
|
||||
|
||||
VaultException exception = VaultResponses
|
||||
.buildException(new HttpClientErrorException(HttpStatus.BAD_REQUEST));
|
||||
|
||||
when(vaultOperations.doWithSession(any(RestOperationsCallback.class))).thenThrow(
|
||||
exception);
|
||||
|
||||
secretLeaseContainer.doRenewLease(requestedSecret, Lease.of("foo", 1, true));
|
||||
|
||||
verify(leaseListenerAdapter).onLeaseEvent(any(SecretLeaseExpiredEvent.class));
|
||||
verify(vaultOperations).doWithSession(any(RestOperationsCallback.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotRevokeSecretsWithoutLease() throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user