mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam,lambda): return resource tags in Get and Create responses (#2262)
* fix(iam,lambda): return resource tags in Get and Create responses
IAM stored role, policy and user tags and served them through
ListRoleTags/ListPolicyTags/ListUserTags, but never serialized them into
the Create/Get responses. Lambda did the same with GetFunction. The AWS
SDKs and the Terraform provider read tags off those responses rather than
by calling List*Tags, so every tagged role, policy, user and function read
back untagged: apply succeeds and then plan never converges.
The inclusion is asymmetric, and getting that wrong deviates from AWS in
the opposite direction. IAM's resource-listing operations deliberately
return a subset of attributes:
ListRoles "does not return the following attributes, even though they
are an attribute of the returned object: PermissionsBoundary,
RoleLastUsed, Tags"
ListUsers same, for PermissionsBoundary and Tags
ListPolicies "this operation does not return tags"
roleXml, userXml and policyXml therefore take a detailed flag, following
the pattern #2155 established for the policy Description. Description on a
role stays unconditional: it is absent from the ListRoles exclusion list.
For policies one flag governs both Description and Tags, since ListPolicies
excludes them on identical grounds.
Detail call sites are CreateRole, GetRole, CreateServiceLinkedRole,
CreateUser, GetUser, CreatePolicy and GetPolicy. Listing call sites are
ListRoles, ListUsers, ListPolicies and GetGroup, plus the roles embedded in
an instance profile — GetInstanceProfile's own example response shows those
as a subset.
tagsElement emits nothing rather than an empty <Tags/> for an untagged
resource, which would otherwise read back as a tag set the caller never
configured.
Lambda needs no such gate: ListFunctions returns FunctionConfiguration,
which has no Tags field at all.
Closes #2199
* test(iam,lambda): cover the tag round trip and the listing-subset rule
Adds a GetFunction case to the Lambda tag test, ordered after the untag so
it also pins that a removed tag is reflected rather than served stale.
Adds a tagged role and a tagged policy to the Terraform compatibility
config, with cases for the positive round trip, the ListRoles/ListPolicies
subset negatives, and a clean second plan. The re-plan assertion is the one
that catches this drift class: tags that do not survive the round trip
apply cleanly and only show up later as perpetual drift.
This commit is contained in:
1 parent
c12f3fae7d
commit
b71bfc46b6
6 files changed
+459
-17
No files matched your search
+285
@@ -0,0 +1,285 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
* The AWS SDKs and the Terraform provider read a role's, policy's or user's tags off the
|
||||
* Create/Get response rather than by calling List*Tags. Tags were stored and were readable
|
||||
* through ListRoleTags, but never serialized into these responses, so every tagged resource
|
||||
* read back untagged and produced a permanent diff.
|
||||
*
|
||||
* <p>The inclusion is asymmetric, and the negative cases below pin that half: IAM's
|
||||
* resource-listing operations deliberately return a subset of attributes, so ListRoles,
|
||||
* ListUsers and ListPolicies must keep omitting tags.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class IamResourceTagsInResponseTest {
|
||||
|
||||
private static final String IAM_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260807/us-east-1/iam/aws4_request";
|
||||
|
||||
private static final String TRUST_POLICY =
|
||||
"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
|
||||
+ "\"Principal\":{\"Service\":\"ecs-tasks.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}";
|
||||
|
||||
private static final String POLICY_DOCUMENT =
|
||||
"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
|
||||
+ "\"Action\":\"s3:GetObject\",\"Resource\":\"*\"}]}";
|
||||
|
||||
private static io.restassured.specification.RequestSpecification iam(String action) {
|
||||
return given().header("Authorization", IAM_AUTH).formParam("Action", action);
|
||||
}
|
||||
|
||||
// ── Detail operations must return tags ────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void createAndGetRoleEchoTheirTags() {
|
||||
String role = "TagEchoRole";
|
||||
|
||||
iam("CreateRole")
|
||||
.formParam("RoleName", role)
|
||||
.formParam("Path", "/")
|
||||
.formParam("AssumeRolePolicyDocument", TRUST_POLICY)
|
||||
.formParam("Tags.member.1.Key", "Environment")
|
||||
.formParam("Tags.member.1.Value", "dev")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Tags>"))
|
||||
.body(containsString("<Key>Environment</Key>"))
|
||||
.body(containsString("<Value>dev</Value>"));
|
||||
|
||||
iam("GetRole")
|
||||
.formParam("RoleName", role)
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Key>Environment</Key>"))
|
||||
.body(containsString("<Value>dev</Value>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRoleOmitsTheTagsElementEntirelyWhenUntagged() {
|
||||
String role = "UntaggedEchoRole";
|
||||
|
||||
iam("CreateRole")
|
||||
.formParam("RoleName", role)
|
||||
.formParam("Path", "/")
|
||||
.formParam("AssumeRolePolicyDocument", TRUST_POLICY)
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
// An empty <Tags/> would read back as a tag set the caller never configured.
|
||||
iam("GetRole")
|
||||
.formParam("RoleName", role)
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(not(containsString("<Tags>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagsAddedAfterCreationAppearOnGetRole() {
|
||||
String role = "LaterTaggedRole";
|
||||
|
||||
iam("CreateRole")
|
||||
.formParam("RoleName", role)
|
||||
.formParam("Path", "/")
|
||||
.formParam("AssumeRolePolicyDocument", TRUST_POLICY)
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
iam("TagRole")
|
||||
.formParam("RoleName", role)
|
||||
.formParam("Tags.member.1.Key", "Team")
|
||||
.formParam("Tags.member.1.Value", "platform")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
iam("GetRole")
|
||||
.formParam("RoleName", role)
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Key>Team</Key>"))
|
||||
.body(containsString("<Value>platform</Value>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createServiceLinkedRoleEchoesNoTagsButStillSerializesTheRole() {
|
||||
iam("CreateServiceLinkedRole")
|
||||
.formParam("AWSServiceName", "elasticache.amazonaws.com")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<RoleName>"))
|
||||
.body(not(containsString("<Tags>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAndGetPolicyEchoTheirTags() {
|
||||
String policyName = "TagEchoPolicy";
|
||||
|
||||
String arn = iam("CreatePolicy")
|
||||
.formParam("PolicyName", policyName)
|
||||
.formParam("PolicyDocument", POLICY_DOCUMENT)
|
||||
.formParam("Tags.member.1.Key", "Owner")
|
||||
.formParam("Tags.member.1.Value", "data")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Key>Owner</Key>"))
|
||||
.extract().path("CreatePolicyResponse.CreatePolicyResult.Policy.Arn");
|
||||
|
||||
iam("GetPolicy")
|
||||
.formParam("PolicyArn", arn)
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Key>Owner</Key>"))
|
||||
.body(containsString("<Value>data</Value>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAndGetUserEchoTheirTags() {
|
||||
String user = "TagEchoUser";
|
||||
|
||||
iam("CreateUser")
|
||||
.formParam("UserName", user)
|
||||
.formParam("Tags.member.1.Key", "CostCenter")
|
||||
.formParam("Tags.member.1.Value", "1234")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Key>CostCenter</Key>"));
|
||||
|
||||
iam("GetUser")
|
||||
.formParam("UserName", user)
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Key>CostCenter</Key>"))
|
||||
.body(containsString("<Value>1234</Value>"));
|
||||
}
|
||||
|
||||
// ── Listing operations must keep omitting tags ────────────────────────────
|
||||
|
||||
@Test
|
||||
void listRolesOmitsTagsEvenForATaggedRole() {
|
||||
iam("CreateRole")
|
||||
.formParam("RoleName", "ListSubsetRole")
|
||||
.formParam("Path", "/")
|
||||
.formParam("AssumeRolePolicyDocument", TRUST_POLICY)
|
||||
.formParam("Tags.member.1.Key", "ListRolesMarker")
|
||||
.formParam("Tags.member.1.Value", "must-not-be-listed")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
// "IAM resource-listing operations return a subset of the available attributes for the
|
||||
// resource. This operation does not return the following attributes, even though they
|
||||
// are an attribute of the returned object: PermissionsBoundary, RoleLastUsed, Tags."
|
||||
iam("ListRoles")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<RoleName>ListSubsetRole</RoleName>"))
|
||||
.body(not(containsString("<Tags>")))
|
||||
.body(not(containsString("must-not-be-listed")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listRolesStillReturnsDescriptionWhichIsNotInTheExcludedSet() {
|
||||
iam("CreateRole")
|
||||
.formParam("RoleName", "DescribedListRole")
|
||||
.formParam("Path", "/")
|
||||
.formParam("AssumeRolePolicyDocument", TRUST_POLICY)
|
||||
.formParam("Description", "kept-in-listings")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
iam("ListRoles")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("kept-in-listings"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listUsersOmitsTagsEvenForATaggedUser() {
|
||||
iam("CreateUser")
|
||||
.formParam("UserName", "ListSubsetUser")
|
||||
.formParam("Tags.member.1.Key", "ListUsersMarker")
|
||||
.formParam("Tags.member.1.Value", "user-must-not-be-listed")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
iam("ListUsers")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<UserName>ListSubsetUser</UserName>"))
|
||||
.body(not(containsString("<Tags>")))
|
||||
.body(not(containsString("user-must-not-be-listed")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listPoliciesOmitsTagsAndDescriptionEvenForATaggedPolicy() {
|
||||
iam("CreatePolicy")
|
||||
.formParam("PolicyName", "ListSubsetPolicy")
|
||||
.formParam("PolicyDocument", POLICY_DOCUMENT)
|
||||
.formParam("Description", "policy-description-must-not-be-listed")
|
||||
.formParam("Tags.member.1.Key", "ListPoliciesMarker")
|
||||
.formParam("Tags.member.1.Value", "policy-must-not-be-listed")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
iam("ListPolicies")
|
||||
.formParam("Scope", "Local")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<PolicyName>ListSubsetPolicy</PolicyName>"))
|
||||
.body(not(containsString("<Tags>")))
|
||||
.body(not(containsString("policy-must-not-be-listed")))
|
||||
.body(not(containsString("policy-description-must-not-be-listed")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getGroupListsItsMembersWithoutTags() {
|
||||
iam("CreateUser")
|
||||
.formParam("UserName", "GroupMemberUser")
|
||||
.formParam("Tags.member.1.Key", "GroupMarker")
|
||||
.formParam("Tags.member.1.Value", "group-must-not-be-listed")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
iam("CreateGroup").formParam("GroupName", "TagSubsetGroup")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
iam("AddUserToGroup")
|
||||
.formParam("GroupName", "TagSubsetGroup")
|
||||
.formParam("UserName", "GroupMemberUser")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
iam("GetGroup")
|
||||
.formParam("GroupName", "TagSubsetGroup")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<UserName>GroupMemberUser</UserName>"))
|
||||
.body(not(containsString("<Tags>")))
|
||||
.body(not(containsString("group-must-not-be-listed")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getInstanceProfileEmbedsItsRoleWithoutTags() {
|
||||
iam("CreateRole")
|
||||
.formParam("RoleName", "ProfileEmbeddedRole")
|
||||
.formParam("Path", "/")
|
||||
.formParam("AssumeRolePolicyDocument", TRUST_POLICY)
|
||||
.formParam("Tags.member.1.Key", "ProfileMarker")
|
||||
.formParam("Tags.member.1.Value", "profile-must-not-be-listed")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
iam("CreateInstanceProfile")
|
||||
.formParam("InstanceProfileName", "TagSubsetProfile")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
iam("AddRoleToInstanceProfile")
|
||||
.formParam("InstanceProfileName", "TagSubsetProfile")
|
||||
.formParam("RoleName", "ProfileEmbeddedRole")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
// GetInstanceProfile's own example response shows the embedded role as a subset.
|
||||
iam("GetInstanceProfile")
|
||||
.formParam("InstanceProfileName", "TagSubsetProfile")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<RoleName>ProfileEmbeddedRole</RoleName>"))
|
||||
.body(not(containsString("<Tags>")))
|
||||
.body(not(containsString("profile-must-not-be-listed")));
|
||||
}
|
||||
}
|
||||
+20
@@ -297,6 +297,26 @@ class LambdaPermissionTagLayerIntegrationTest {
|
||||
.body("LayerVersions", empty());
|
||||
}
|
||||
|
||||
// ── GetFunction tags ──────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* The Terraform provider and the SDKs read a function's tags from GetFunction rather than by
|
||||
* calling ListTags, so omitting the field made a tagged function read back untagged and diff
|
||||
* on every plan. Runs after the untag above, so it also pins that GetFunction reflects a
|
||||
* removed tag rather than serving a stale set.
|
||||
*/
|
||||
@Test
|
||||
@Order(19)
|
||||
void getFunction_includesTags() {
|
||||
given()
|
||||
.when()
|
||||
.get("/2015-03-31/functions/" + FN)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags.team", equalTo("platform"))
|
||||
.body("Tags.env", nullValue());
|
||||
}
|
||||
|
||||
// ── cleanup ───────────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user