mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(cloudformation): apply AWS::IAM::AccessKey Status (#4060)
IamAccessKeyCfnProvisioner ignored the Status property, so an access key declared Inactive was created Active. Resolve Status and apply it: a new key is deactivated when the template asks for Inactive, and on an unchanged update the mutable Status is reconciled in place. Status is validated up front (Active/Inactive), before any key is created, so a bad value cannot create a key and then fail (a user is capped at two keys). The update path reconciles Status only when the template declares it, so an unrelated update does not reactivate a key deactivated out of band, matching AWS's apply-only-declared-properties update semantics. Refs #3933
This commit is contained in:
1 parent
e1334cb512
commit
78c046b883
2 files changed
+73
-7
No files matched your search
+48
@@ -78,6 +78,54 @@ class IamAccessKeyCfnProvisionerTest {
|
||||
verify(iam, never()).createAccessKey(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWithInactiveStatusDeactivatesTheKey() throws Exception {
|
||||
AccessKey key = new AccessKey();
|
||||
key.setAccessKeyId("AKIA1");
|
||||
key.setSecretAccessKey("secret-1");
|
||||
when(iam.createAccessKey("alice")).thenReturn(key);
|
||||
|
||||
provisioner.provision(resource(), props("{\"UserName\": \"alice\", \"Status\": \"Inactive\"}"), ctx(null));
|
||||
|
||||
verify(iam).createAccessKey("alice");
|
||||
verify(iam).updateAccessKey("alice", "AKIA1", "Inactive");
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnchangedUpdateReconcilesStatus() throws Exception {
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId("AKIA1");
|
||||
r.getAttributes().put(SERIAL_ATTR, "");
|
||||
when(iam.findUserNameByAccessKeyId("AKIA1")).thenReturn(Optional.of("alice"));
|
||||
|
||||
provisioner.provision(r, props("{\"UserName\": \"alice\", \"Status\": \"Inactive\"}"), ctx("AKIA1"));
|
||||
|
||||
verify(iam, never()).createAccessKey(anyString());
|
||||
verify(iam).updateAccessKey("alice", "AKIA1", "Inactive");
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUpdateThatOmitsStatusLeavesItAlone() throws Exception {
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId("AKIA1");
|
||||
r.getAttributes().put(SERIAL_ATTR, "");
|
||||
when(iam.findUserNameByAccessKeyId("AKIA1")).thenReturn(Optional.of("alice"));
|
||||
|
||||
provisioner.provision(r, props("{\"UserName\": \"alice\"}"), ctx("AKIA1"));
|
||||
|
||||
verify(iam, never()).createAccessKey(anyString());
|
||||
verify(iam, never()).updateAccessKey(anyString(), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aBogusStatusIsRejectedBeforeCreatingAKey() {
|
||||
AwsException e = assertThrows(AwsException.class, () -> provisioner.provision(
|
||||
resource(), props("{\"UserName\": \"alice\", \"Status\": \"Bogus\"}"), ctx(null)));
|
||||
|
||||
assertEquals("ValidationError", e.getErrorCode());
|
||||
verify(iam, never()).createAccessKey(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void bumpingSerialOnUpdateRotatesTheKey() throws Exception {
|
||||
StackResource r = resource();
|
||||
|
||||
Reference in new issue
Block a user