test(cloudformation): pin account scoping of ListStacks and DescribeStackResources (#3475)

#2248 reports that ListStacks and DescribeStackResources ignored the
caller's account, so assumed-role credentials for a member account got the
management account's stacks from two of the three read APIs while
DescribeStacks scoped correctly. #3185 fixed that by routing every stack
read through the request-scoped account, but did not reference the issue
and did not test either operation: its test class never calls ListStacks
and only calls DescribeStackResources from the owning account. Removing the
account filter from either service method leaves every existing test green.

Add the two missing regression tests to
CloudFormationAccountOwnershipIntegrationTest. The first checks ListStacks
under two 12-digit access keys. The second follows the issue's scenario:
the management account creates a stack, assumes a role in the member
account, creates a stack with the temporary key, and both ListStacks and
DescribeStackResources must scope to the caller in each direction, with the
foreign stack reported as ValidationError "does not exist" as AWS does.

Both tests fail against the pre-#3185 shape of either method and pass on
main.

Closes #2248
This commit is contained in:
David authored and GitHub committed 2026-09-12 18:40:37 -05:00
1 parent cebb011a00
commit 99bc6c977d
1 file changed
+69 -3
@@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
@QuarkusTest
class CloudFormationAccountOwnershipIntegrationTest {
@@ -89,6 +90,60 @@ class CloudFormationAccountOwnershipIntegrationTest {
.body(not(containsString("Changed")));
}
@Test
void listStacksIsScopedToCallerAccount() {
createStack(ACCOUNT_1, US_EAST_1, "cfn-list-scope-account-1");
createStack(ACCOUNT_2, US_EAST_1, "cfn-list-scope-account-2");
listStacks(ACCOUNT_1, US_EAST_1)
.statusCode(200)
.body(containsString("<StackName>cfn-list-scope-account-1</StackName>"))
.body(not(containsString("<StackName>cfn-list-scope-account-2</StackName>")));
listStacks(ACCOUNT_2, US_EAST_1)
.statusCode(200)
.body(containsString("<StackName>cfn-list-scope-account-2</StackName>"))
.body(not(containsString("<StackName>cfn-list-scope-account-1</StackName>")));
}
@Test
void assumedRoleCredentialsScopeListStacksAndDescribeStackResources() {
createStack(ACCOUNT_1, US_EAST_1, "cfn-management-stack",
"{\"Resources\":{\"ManagementBucket\":{\"Type\":\"AWS::S3::Bucket\"}}}");
String memberAccessKeyId = given()
.header("Authorization", auth(ACCOUNT_1, US_EAST_1, "sts"))
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "AssumeRole")
.formParam("RoleArn", "arn:aws:iam::" + ACCOUNT_2 + ":role/cfn-member-deploy-role")
.formParam("RoleSessionName", "cfn-member-session")
.when().post("/").then()
.statusCode(200)
.body("AssumeRoleResponse.AssumeRoleResult.Credentials.AccessKeyId", startsWith("ASIA"))
.extract().path("AssumeRoleResponse.AssumeRoleResult.Credentials.AccessKeyId");
createStack(memberAccessKeyId, US_EAST_1, "cfn-member-stack",
"{\"Resources\":{\"MemberBucket\":{\"Type\":\"AWS::S3::Bucket\"}}}");
listStacks(memberAccessKeyId, US_EAST_1)
.statusCode(200)
.body(containsString("<StackName>cfn-member-stack</StackName>"))
.body(not(containsString("<StackName>cfn-management-stack</StackName>")));
listStacks(ACCOUNT_1, US_EAST_1)
.statusCode(200)
.body(containsString("<StackName>cfn-management-stack</StackName>"))
.body(not(containsString("<StackName>cfn-member-stack</StackName>")));
describeStackResources(memberAccessKeyId, US_EAST_1, "cfn-member-stack")
.statusCode(200)
.body(containsString("MemberBucket"));
describeStackResources(memberAccessKeyId, US_EAST_1, "cfn-management-stack")
.statusCode(400)
.body(containsString("does not exist"));
describeStackResources(ACCOUNT_1, US_EAST_1, "cfn-member-stack")
.statusCode(400)
.body(containsString("does not exist"));
}
private static String createStack(String account, String region, String name) {
return createStack(account, region, name, "{\"Resources\":{}}");
}
@@ -132,6 +187,13 @@ class CloudFormationAccountOwnershipIntegrationTest {
.when().post("/").then();
}
private static io.restassured.response.ValidatableResponse listStacks(String accessKeyId, String region) {
return given().header("Authorization", auth(accessKeyId, region))
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "ListStacks")
.when().post("/").then();
}
private static io.restassured.response.ValidatableResponse listExports(String account, String region) {
return given().header("Authorization", auth(account, region))
.contentType("application/x-www-form-urlencoded")
@@ -139,9 +201,13 @@ class CloudFormationAccountOwnershipIntegrationTest {
.when().post("/").then();
}
private static String auth(String account, String region) {
return "AWS4-HMAC-SHA256 Credential=" + account
+ "/20260907/" + region + "/cloudformation/aws4_request,"
private static String auth(String accessKeyId, String region) {
return auth(accessKeyId, region, "cloudformation");
}
private static String auth(String accessKeyId, String region, String service) {
return "AWS4-HMAC-SHA256 Credential=" + accessKeyId
+ "/20260907/" + region + "/" + service + "/aws4_request,"
+ " SignedHeaders=host, Signature=abc";
}
}