mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 23:29:28 -05:00
fix(secretsmanager): keep a version written under the rotation token during the test step (#7663)
This commit is contained in:
1 parent
c3058a8de4
commit
44565360e2
2 files changed
+67
-9
No files matched your search
+29
-9
@@ -1700,17 +1700,32 @@ public class SecretsManagerService implements ResourceProvider {
|
||||
invokeRotationLambda(secretArn, clientRequestToken, lambdaArn, "testSecret", region);
|
||||
} finally {
|
||||
if (staged) {
|
||||
removeVersion(secretArn, clientRequestToken, region);
|
||||
removeUntouchedPlaceholder(secretArn, clientRequestToken, region);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized (lockFor(secretArn)) {
|
||||
// Only this rotation's own version, or the current one a finished rotation left
|
||||
// AWSPENDING on: a version another rotation or client staged keeps its stage.
|
||||
Secret refreshed = resolveSecret(secretArn, region);
|
||||
SecretVersion pending = findVersionByStage(refreshed, "AWSPENDING");
|
||||
if (pending != null) {
|
||||
List<String> stages = new ArrayList<>(pending.getVersionStages());
|
||||
stages.remove("AWSPENDING");
|
||||
pending.setVersionStages(stages);
|
||||
List<SecretVersion> retirable = new ArrayList<>();
|
||||
if (refreshed.getVersions() != null && refreshed.getVersions().containsKey(clientRequestToken)) {
|
||||
retirable.add(refreshed.getVersions().get(clientRequestToken));
|
||||
}
|
||||
SecretVersion current = findVersionByStage(refreshed, AWSCURRENT);
|
||||
if (current != null) {
|
||||
retirable.add(current);
|
||||
}
|
||||
boolean retired = false;
|
||||
for (SecretVersion version : retirable) {
|
||||
if (version.getVersionStages() != null && version.getVersionStages().contains("AWSPENDING")) {
|
||||
List<String> stages = new ArrayList<>(version.getVersionStages());
|
||||
stages.remove("AWSPENDING");
|
||||
version.setVersionStages(stages);
|
||||
retired = true;
|
||||
}
|
||||
}
|
||||
if (retired) {
|
||||
persist(refreshed, region);
|
||||
}
|
||||
}
|
||||
@@ -1762,12 +1777,17 @@ public class SecretsManagerService implements ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private void removeVersion(String secretArn, String versionId, String region) {
|
||||
/** Removes the version {@link #stagePendingVersion} added, unless it has since gained a value or another stage. */
|
||||
private void removeUntouchedPlaceholder(String secretArn, String versionId, String region) {
|
||||
synchronized (lockFor(secretArn)) {
|
||||
Secret secret = resolveSecret(secretArn, region);
|
||||
if (secret.getVersions() != null && secret.getVersions().remove(versionId) != null) {
|
||||
persist(secret, region);
|
||||
SecretVersion version = secret.getVersions() == null ? null : secret.getVersions().get(versionId);
|
||||
if (version == null || version.getSecretString() != null || version.getSecretBinary() != null
|
||||
|| version.getVersionStages().stream().anyMatch(stage -> !"AWSPENDING".equals(stage))) {
|
||||
return;
|
||||
}
|
||||
secret.getVersions().remove(versionId);
|
||||
persist(secret, region);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user