mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -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
+48
@@ -94,6 +94,54 @@ class CloudFormationIamUserIntegrationTest {
|
||||
awaitStackStatus(newStackId, "DELETE_COMPLETE");
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteStackDeletesUserWithLoginProfileCreatedOutOfBand() throws InterruptedException {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String userName = "probe-profile-user-" + suffix;
|
||||
String stackName = "cfn-profile-stack-" + suffix;
|
||||
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"ProfileUser": {
|
||||
"Type": "AWS::IAM::User",
|
||||
"Properties": {
|
||||
"UserName": "%s"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".formatted(userName);
|
||||
|
||||
String stackId = createStack(stackName, template);
|
||||
awaitStackStatus(stackId, "CREATE_COMPLETE");
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", IAM_AUTH)
|
||||
.formParam("Action", "CreateLoginProfile")
|
||||
.formParam("UserName", userName)
|
||||
.formParam("Password", "Sup3r$ecret!")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
deleteStack(stackName);
|
||||
awaitStackStatus(stackId, "DELETE_COMPLETE");
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", IAM_AUTH)
|
||||
.formParam("Action", "GetUser")
|
||||
.formParam("UserName", userName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("NoSuchEntity"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteStackDeletesUserWithGeneratedName() throws InterruptedException {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
|
||||
+26
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.iam.IamService;
|
||||
import io.github.hectorvent.floci.services.iam.model.AccessKey;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamUser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -21,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -203,6 +205,30 @@ class IamUserCfnProvisionerTest {
|
||||
verify(iam).deleteUser("my-user");
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRemovesLoginProfileBeforeDeletingUser() {
|
||||
IamUser user = new IamUser("AIDAuser", "my-user", "/", "arn:aws:iam::" + ACCOUNT_ID + ":user/my-user");
|
||||
when(iam.getUser("my-user")).thenReturn(user);
|
||||
|
||||
provisioner.delete("AWS::IAM::User", "my-user", "us-east-1");
|
||||
|
||||
InOrder order = inOrder(iam);
|
||||
order.verify(iam).deleteLoginProfile("my-user");
|
||||
order.verify(iam).deleteUser("my-user");
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteToleratesUserWithoutLoginProfile() {
|
||||
IamUser user = new IamUser("AIDAuser", "my-user", "/", "arn:aws:iam::" + ACCOUNT_ID + ":user/my-user");
|
||||
when(iam.getUser("my-user")).thenReturn(user);
|
||||
doThrow(new AwsException("NoSuchEntity", "Login Profile for User my-user cannot be found.", 404))
|
||||
.when(iam).deleteLoginProfile("my-user");
|
||||
|
||||
provisioner.delete("AWS::IAM::User", "my-user", "us-east-1");
|
||||
|
||||
verify(iam).deleteUser("my-user");
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteToleratesAlreadyDeletedUser() {
|
||||
when(iam.getUser("already-gone"))
|
||||
|
||||
Reference in new issue
Block a user