mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(organizations): start a new root with no policy types enabled (#4756)
CreateOrganization (and EnableAllFeatures) seeded the root with SERVICE_CONTROL_POLICY already ENABLED, so the first EnablePolicyType a caller issues was rejected with PolicyTypeAlreadyEnabledException. That is exactly what Terraform's aws_organizations_organization does with enabled_policy_types right after CreateOrganization, so the common "create the org and turn on SCPs" configuration failed at its first resource. On AWS a new root has an empty PolicyTypes list: the provider's acceptance test for a plain organization asserts roots.0.policy_types is empty, and its enabled_policy_types test enables SCPs on a fresh organization successfully. DescribeOrganization's AvailablePolicyTypes used to read the root's list, which is what the seed was standing in for. It is now reported separately and, as AWS documents for the deprecated field, lists only SERVICE_CONTROL_POLICY for an ALL organization. Tests that relied on the seed now call EnablePolicyType first, as a real caller must. The CloudFormation test creates the stack without its SCP, enables the type, then adds the SCP by UpdateStack, because no CloudFormation resource enables a policy type.
This commit is contained in:
1 parent
b5c428319f
commit
18128b432a
9 files changed
+92
-18
No files matched your search
+25
-2
@@ -1,5 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
@@ -11,6 +13,7 @@ import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
@@ -178,12 +181,32 @@ class OrganizationsCfnIntegrationTest {
|
||||
"DescribeStacksResponse.DescribeStacksResult.Stacks.member.StackStatus")));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link #TEMPLATE} without the SCP. A new root has no policy types enabled and CloudFormation
|
||||
* has no resource that enables one, so a template cannot create an organization and an SCP in
|
||||
* the same operation: the SCP arrives in an update once EnablePolicyType has run.
|
||||
*/
|
||||
private static String templateWithoutScp() throws Exception {
|
||||
ObjectNode template = (ObjectNode) new ObjectMapper().readTree(TEMPLATE);
|
||||
((ObjectNode) template.get("Resources")).remove("Scp");
|
||||
((ObjectNode) template.get("Outputs")).remove(List.of("PolicyId", "PolicyArn", "PolicyAwsManaged"));
|
||||
return template.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createStackProvisionsEveryOrganizationsResourceType() {
|
||||
cloudFormation("CreateStack", "StackName", STACK_NAME, "TemplateBody", TEMPLATE)
|
||||
void createStackProvisionsEveryOrganizationsResourceType() throws Exception {
|
||||
cloudFormation("CreateStack", "StackName", STACK_NAME, "TemplateBody", templateWithoutScp())
|
||||
.then().statusCode(200);
|
||||
awaitStackStatus("CREATE_COMPLETE");
|
||||
|
||||
organizations("EnablePolicyType", "{\"RootId\":\"" + output(describeStacks(), "RootId")
|
||||
+ "\",\"PolicyType\":\"SERVICE_CONTROL_POLICY\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
cloudFormation("UpdateStack", "StackName", STACK_NAME, "TemplateBody", TEMPLATE)
|
||||
.then().statusCode(200);
|
||||
awaitStackStatus("UPDATE_COMPLETE");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+5
-2
@@ -45,9 +45,12 @@ class ScpEnforcementLeaveOrganizationIntegrationTest {
|
||||
// --- management sets up the organization -----------------------------------------------
|
||||
org(MGMT, "CreateOrganization", "{\"FeatureSet\":\"ALL\"}").then().statusCode(200);
|
||||
|
||||
// FeatureSet=ALL already enables the SERVICE_CONTROL_POLICY type on the root and seeds
|
||||
// FullAWSAccess, so no explicit EnablePolicyType is needed for SCPs to participate.
|
||||
// A new root has no policy types enabled; SCPs only participate once EnablePolicyType
|
||||
// turns them on. FullAWSAccess is already attached, so enabling them denies nothing alone.
|
||||
String rootId = JsonPath.from(org(MGMT, "ListRoots", "{}").asString()).getString("Roots[0].Id");
|
||||
org(MGMT, "EnablePolicyType",
|
||||
"{\"RootId\":\"" + rootId + "\",\"PolicyType\":\"SERVICE_CONTROL_POLICY\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
String policyId = JsonPath.from(org(MGMT, "CreatePolicy",
|
||||
"{\"Name\":\"deny-leave-" + suffix + "\",\"Type\":\"SERVICE_CONTROL_POLICY\","
|
||||
|
||||
+8
@@ -95,6 +95,14 @@ class OrganizationsFeatureSetIntegrationTest {
|
||||
.statusCode(200)
|
||||
.body("Organization.FeatureSet", equalTo("ALL"))
|
||||
.body("Organization.AvailablePolicyTypes.Type", hasItem("SERVICE_CONTROL_POLICY"));
|
||||
|
||||
// Upgrading makes policy types available; it does not enable any of them on the root.
|
||||
organizations("ListRoots", "{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Roots[0].PolicyTypes", empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+24
-3
@@ -12,6 +12,7 @@ import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
@@ -108,7 +109,9 @@ class OrganizationsIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void listRootsReturnsRootWithServiceControlPolicyEnabled() {
|
||||
void listRootsReturnsRootWithNoPolicyTypesEnabled() {
|
||||
// AvailablePolicyTypes above lists SCPs for an all-features organization, but that is not
|
||||
// the same as the root having them enabled: a new root starts with none.
|
||||
rootId = organizations("ListRoots", "{}")
|
||||
.when()
|
||||
.post("/")
|
||||
@@ -118,13 +121,31 @@ class OrganizationsIntegrationTest {
|
||||
.body("Roots[0].Id", matchesPattern("r-[a-z0-9]{4}"))
|
||||
.body("Roots[0].Name", equalTo("Root"))
|
||||
.body("Roots[0].Arn", startsWith("arn:aws:organizations::000000000000:root/" + organizationId))
|
||||
.body("Roots[0].PolicyTypes.Type", hasItem("SERVICE_CONTROL_POLICY"))
|
||||
.body("Roots[0].PolicyTypes.Status", hasItem("ENABLED"))
|
||||
.body("Roots[0].PolicyTypes", empty())
|
||||
.extract().jsonPath().getString("Roots[0].Id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void serviceControlPoliciesCanBeEnabledOnTheNewRoot() {
|
||||
organizations("EnablePolicyType", "{\"RootId\":\"" + rootId + "\",\"PolicyType\":\"SERVICE_CONTROL_POLICY\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Root.PolicyTypes.Type", contains("SERVICE_CONTROL_POLICY"));
|
||||
|
||||
organizations("ListRoots", "{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Roots[0].PolicyTypes.Type", contains("SERVICE_CONTROL_POLICY"))
|
||||
.body("Roots[0].PolicyTypes.Status", contains("ENABLED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void fullAwsAccessIsAttachedToTheRoot() {
|
||||
organizations("ListPoliciesForTarget",
|
||||
"{\"TargetId\":\"" + rootId + "\",\"Filter\":\"SERVICE_CONTROL_POLICY\"}")
|
||||
|
||||
+10
-2
@@ -63,6 +63,7 @@ class OrganizationsServiceTest {
|
||||
service.createOrganizationalUnit(MANAGEMENT_ACCOUNT, organization.getRoot().getId(), "Unit", null);
|
||||
assertTrue(unit.getId().matches("ou-" + rootSuffix + "-[a-z0-9]{8}"), unit.getId());
|
||||
|
||||
service.enablePolicyType(MANAGEMENT_ACCOUNT, organization.getRoot().getId(), "SERVICE_CONTROL_POLICY");
|
||||
OrganizationPolicy policy = service.createPolicy(MANAGEMENT_ACCOUNT, "{}", null, "Policy",
|
||||
"SERVICE_CONTROL_POLICY", null);
|
||||
assertTrue(policy.getId().matches("p-[a-z0-9]{8}"), policy.getId());
|
||||
@@ -216,6 +217,7 @@ class OrganizationsServiceTest {
|
||||
Organization organization = service.createOrganization(MANAGEMENT_ACCOUNT, "ALL");
|
||||
String rootId = organization.getRoot().getId();
|
||||
OrganizationalUnit unit = service.createOrganizationalUnit(MANAGEMENT_ACCOUNT, rootId, "Unit", null);
|
||||
service.enablePolicyType(MANAGEMENT_ACCOUNT, rootId, "SERVICE_CONTROL_POLICY");
|
||||
OrganizationPolicy policy = service.createPolicy(MANAGEMENT_ACCOUNT, "{}", null, "Policy",
|
||||
"SERVICE_CONTROL_POLICY", null);
|
||||
|
||||
@@ -293,6 +295,7 @@ class OrganizationsServiceTest {
|
||||
String member = service.createAccount(MANAGEMENT_ACCOUNT, "member@example.com", "Member", null, false)
|
||||
.getAccountId();
|
||||
service.moveAccount(MANAGEMENT_ACCOUNT, member, rootId, ouId);
|
||||
service.enablePolicyType(MANAGEMENT_ACCOUNT, rootId, "SERVICE_CONTROL_POLICY");
|
||||
|
||||
// FullAWSAccess sits on root, OU, and account: three levels.
|
||||
List<List<String>> levels = service.effectiveScpLevels(member);
|
||||
@@ -309,7 +312,8 @@ class OrganizationsServiceTest {
|
||||
|
||||
@Test
|
||||
void theManagementAccountIsExemptFromScps() {
|
||||
service.createOrganization(MANAGEMENT_ACCOUNT, "ALL");
|
||||
Organization organization = service.createOrganization(MANAGEMENT_ACCOUNT, "ALL");
|
||||
service.enablePolicyType(MANAGEMENT_ACCOUNT, organization.getRoot().getId(), "SERVICE_CONTROL_POLICY");
|
||||
String member = service.createAccount(MANAGEMENT_ACCOUNT, "member@example.com", "Member", null, false)
|
||||
.getAccountId();
|
||||
|
||||
@@ -326,10 +330,14 @@ class OrganizationsServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void disablingTheScpPolicyTypeOnTheRootRemovesTheCeiling() {
|
||||
void scpsBindOnlyWhileTheirPolicyTypeIsEnabledOnTheRoot() {
|
||||
Organization organization = service.createOrganization(MANAGEMENT_ACCOUNT, "ALL");
|
||||
String member = service.createAccount(MANAGEMENT_ACCOUNT, "member@example.com", "Member", null, false)
|
||||
.getAccountId();
|
||||
// A new root has no policy types enabled, so there is no ceiling until SCPs are turned on.
|
||||
assertNull(service.effectiveScpLevels(member));
|
||||
|
||||
service.enablePolicyType(MANAGEMENT_ACCOUNT, organization.getRoot().getId(), "SERVICE_CONTROL_POLICY");
|
||||
assertNotNull(service.effectiveScpLevels(member));
|
||||
|
||||
service.disablePolicyType(MANAGEMENT_ACCOUNT, organization.getRoot().getId(), "SERVICE_CONTROL_POLICY");
|
||||
|
||||
Reference in new issue
Block a user