mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): honour 12-digit access key in IAM resource ARNs (#1017)
IamService constructed its accountId once at startup from config.defaultAccountId() (always '000000000000'), so every CreateRole, CreateUser, CreateGroup, CreatePolicy and CreateInstanceProfile call returned an ARN with the wrong account — identical to the STS bug fixed in #983. Inject RegionResolver and call regionResolver.getAccountId() per request inside iamArn(), so the ARN reflects the caller's account when a 12-digit AKID is used. Add integration tests iamCreateRoleHonoursTwelveDigitAccessKey and iamGetRoleHonoursTwelveDigitAccessKey to cover the fix. Co-authored-by: Simon B. Laursen <sls@bankdata.dk>
This commit is contained in:
1 parent
7e43b015e6
commit
9056f80028
4 files changed
+48
-13
No files matched your search
@@ -328,6 +328,42 @@ class IamIntegrationTest {
|
||||
equalTo("TestRole"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
void iamCreateRoleHonoursTwelveDigitAccessKey() {
|
||||
given()
|
||||
.formParam("Action", "CreateRole")
|
||||
.formParam("RoleName", "TenantRole")
|
||||
.formParam("Path", "/")
|
||||
.formParam("AssumeRolePolicyDocument", TRUST_POLICY)
|
||||
.header("Authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=123456789012/20260227/us-east-1/iam/aws4_request")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CreateRoleResponse.CreateRoleResult.Role.RoleName", equalTo("TenantRole"))
|
||||
.body("CreateRoleResponse.CreateRoleResult.Role.Arn",
|
||||
equalTo("arn:aws:iam::123456789012:role/TenantRole"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
void iamGetRoleHonoursTwelveDigitAccessKey() {
|
||||
given()
|
||||
.formParam("Action", "GetRole")
|
||||
.formParam("RoleName", "TenantRole")
|
||||
.header("Authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=123456789012/20260227/us-east-1/iam/aws4_request")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("GetRoleResponse.GetRoleResult.Role.RoleName", equalTo("TenantRole"))
|
||||
.body("GetRoleResponse.GetRoleResult.Role.Arn",
|
||||
equalTo("arn:aws:iam::123456789012:role/TenantRole"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Managed Policies
|
||||
// =========================================================================
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.iam.model.AccessKey;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamGroup;
|
||||
@@ -31,7 +32,7 @@ class IamServiceTest {
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
"000000000000"
|
||||
new RegionResolver("us-east-1", "000000000000")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.testutil;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.services.iam.IamService;
|
||||
@@ -23,7 +24,7 @@ public final class IamServiceTestHelper {
|
||||
StorageBackend.class,
|
||||
StorageBackend.class,
|
||||
StorageBackend.class,
|
||||
String.class
|
||||
RegionResolver.class
|
||||
);
|
||||
constructor.setAccessible(true);
|
||||
|
||||
@@ -38,7 +39,7 @@ public final class IamServiceTestHelper {
|
||||
accessKeys,
|
||||
null,
|
||||
null,
|
||||
"123456789012"
|
||||
new RegionResolver("us-east-1", "123456789012")
|
||||
);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new IllegalStateException("Failed to construct IamService test fixture", e);
|
||||
|
||||
Reference in new issue
Block a user