mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(cloudformation): remove the login profile when deleting an IAM user (#3975)
Since login profiles became real state, DeleteUser returns DeleteConflict while one exists, so deleting a stack whose AWS::IAM::User was given a password out of band ended in DELETE_FAILED. The provisioner now deletes the login profile before the user, tolerating a user that has none. The resource-type table notes that the template LoginProfile and PermissionsBoundary properties are ignored.
This commit is contained in:
1 parent
b1e0751764
commit
8af15a71c4
6 files changed
+120
-1
No files matched your search
+41
@@ -12,6 +12,8 @@ import software.amazon.awssdk.services.cloudformation.model.DescribeStacksReques
|
||||
import software.amazon.awssdk.services.cloudformation.model.Output;
|
||||
import software.amazon.awssdk.services.cloudformation.model.Stack;
|
||||
import software.amazon.awssdk.services.iam.IamClient;
|
||||
import software.amazon.awssdk.services.iam.model.CreateLoginProfileRequest;
|
||||
import software.amazon.awssdk.services.iam.model.DeleteLoginProfileRequest;
|
||||
import software.amazon.awssdk.services.iam.model.DeleteUserRequest;
|
||||
import software.amazon.awssdk.services.iam.model.GetUserRequest;
|
||||
import software.amazon.awssdk.services.iam.model.GetUserResponse;
|
||||
@@ -110,6 +112,45 @@ class CloudFormationIamUserTest {
|
||||
.isInstanceOf(NoSuchEntityException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Deleting a stack removes a user whose login profile was created through the IAM API")
|
||||
void deleteStackRemovesUserWithLoginProfile() throws InterruptedException {
|
||||
String profileStackName = TestFixtures.uniqueName("compat-cfn-iam-profile");
|
||||
String profileUserName = TestFixtures.uniqueName("compat-profile-user");
|
||||
try {
|
||||
cloudFormation.createStack(CreateStackRequest.builder()
|
||||
.stackName(profileStackName)
|
||||
.templateBody(template(profileUserName, "/"))
|
||||
.build());
|
||||
assertThat(waitForTerminal(profileStackName, 30)).isEqualTo("CREATE_COMPLETE");
|
||||
|
||||
iam.createLoginProfile(CreateLoginProfileRequest.builder()
|
||||
.userName(profileUserName).password("Sdk-Test-P4ssword!").build());
|
||||
|
||||
cloudFormation.deleteStack(DeleteStackRequest.builder().stackName(profileStackName).build());
|
||||
waitForDeleted(profileStackName, 30);
|
||||
|
||||
assertThatThrownBy(() -> iam.getUser(GetUserRequest.builder().userName(profileUserName).build()))
|
||||
.isInstanceOf(NoSuchEntityException.class);
|
||||
} finally {
|
||||
try {
|
||||
cloudFormation.deleteStack(DeleteStackRequest.builder().stackName(profileStackName).build());
|
||||
} catch (Exception e) {
|
||||
LOG.log(Level.WARNING, "Failed to delete CloudFormation stack during cleanup: " + profileStackName, e);
|
||||
}
|
||||
try {
|
||||
iam.deleteLoginProfile(DeleteLoginProfileRequest.builder().userName(profileUserName).build());
|
||||
} catch (Exception ignored) {
|
||||
// The stack delete normally removes the profile with the user, so this is only a fallback.
|
||||
}
|
||||
try {
|
||||
iam.deleteUser(DeleteUserRequest.builder().userName(profileUserName).build());
|
||||
} catch (Exception ignored) {
|
||||
// The stack delete normally removes the user, so this is only a fallback.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String template(String name, String path) {
|
||||
return """
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user