mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(redshift): give resource-tag conditions the tags of the resource a request names (#8685)
The generated request resources give fifteen Redshift types the aws:ResourceTag/ key, but RedshiftStoredResourceArns answered only a snapshot's key, so a condition on a Redshift resource's tags saw none. It now answers from RedshiftService.storedTags, which reads the cluster, snapshot, parameter group, subnet group, snapshot copy grant, snapshot schedule, event subscription or integration stored under the ARN in the account and Region it names, in place, matched on the whole ARN; a snapshot is found as tagging finds it, the copy kept in the Region before the snapshot itself. CreateTags and DeleteTags already put a new map in place of the held one under the service's lock; the tag fields are now volatile, so the lookup reads one whole map.
This commit is contained in:
1 parent
bab6428f78
commit
d606843c49
15 files changed
+203
-13
No files matched your search
+32
@@ -1903,6 +1903,38 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
equalTo(arn));
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@code aws:ResourceTag} condition reads the tags Redshift holds on the parameter group a request names, so an
|
||||
* allow on one team's tag lets the caller read that team's group and not another's.
|
||||
*/
|
||||
@Test
|
||||
void aRedshiftResourceTagConditionReadsTheTagsOfTheParameterGroup() {
|
||||
String tagged = redshiftParameterGroup("res-tag-pg-" + suffix(), "data");
|
||||
String other = redshiftParameterGroup("res-tag-pg-" + suffix(), "web");
|
||||
|
||||
User user = user("res-redshift-tags");
|
||||
user.policy("{\"Effect\":\"Allow\",\"Action\":\"redshift:DescribeClusterParameters\",\"Resource\":\"*\","
|
||||
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
|
||||
describeClusterParameters(user, tagged).statusCode(200);
|
||||
refused(describeClusterParameters(user, other), "redshift:DescribeClusterParameters");
|
||||
}
|
||||
|
||||
/** A Redshift parameter group of the name, tagged with the team, deleted afterwards. */
|
||||
private String redshiftParameterGroup(String name, String team) {
|
||||
admin("redshift").formParam("Action", "CreateClusterParameterGroup").formParam("Version", "2012-12-01")
|
||||
.formParam("ParameterGroupName", name).formParam("ParameterGroupFamily", "redshift-1.0")
|
||||
.formParam("Description", "d").formParam("Tags.Tag.1.Key", "team").formParam("Tags.Tag.1.Value", team)
|
||||
.post("/").then().statusCode(200);
|
||||
cleanup.register(() -> admin("redshift").formParam("Action", "DeleteClusterParameterGroup")
|
||||
.formParam("Version", "2012-12-01").formParam("ParameterGroupName", name).post("/"));
|
||||
return name;
|
||||
}
|
||||
|
||||
private static ValidatableResponse describeClusterParameters(User user, String group) {
|
||||
return user.query("redshift", "DescribeClusterParameters").formParam("Version", "2012-12-01")
|
||||
.formParam("ParameterGroupName", group).post("/").then();
|
||||
}
|
||||
|
||||
/** A Redshift cluster is checked on {@code cluster:<identifier>}, before the cluster is looked up. */
|
||||
@Test
|
||||
void aRedshiftClusterIsCheckedOnItsIdentifier() {
|
||||
|
||||
@@ -594,6 +594,25 @@ class RedshiftEventServiceTest {
|
||||
List.of("team"), List.of("data"), null, null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void storedTagsAreTheTagsOfTheSubscriptionInTheAccountAndRegionGivenAndTaggingPutsANewMap() {
|
||||
service.createSubscription("watcher", TOPIC, null, List.of(), List.of(), null, null,
|
||||
Map.of("team", "data"), ALL_SOURCES_EXIST);
|
||||
RedshiftEventService west = new RedshiftEventService(factory, sns, authorizer,
|
||||
new RegionResolver("us-west-2", "000000000000"), objectMapper, clock);
|
||||
west.createSubscription("watcher", TOPIC, null, List.of(), List.of(), null, null,
|
||||
Map.of("team", "west"), ALL_SOURCES_EXIST);
|
||||
Map<String, String> held = service.storedTags("000000000000", "us-east-1", "watcher");
|
||||
|
||||
service.addSubscriptionTags("watcher", Map.of("env", "prod"));
|
||||
|
||||
assertEquals(Map.of("team", "data"), held);
|
||||
assertEquals(Map.of("team", "data", "env", "prod"), service.storedTags("000000000000", "us-east-1", "watcher"));
|
||||
assertEquals(Map.of("team", "west"), service.storedTags("000000000000", "us-west-2", "watcher"));
|
||||
assertNull(service.storedTags("111111111111", "us-east-1", "watcher"));
|
||||
assertNull(service.storedTags("000000000000", "us-east-1", "missing"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventHistoryAndSubscriptionNamesAreRegional() {
|
||||
create("watcher", null, List.of(), List.of(), null);
|
||||
|
||||
@@ -82,6 +82,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@@ -4106,6 +4107,61 @@ class RedshiftServiceTest {
|
||||
assertEquals(Map.of("team", "data"), cluster.getTags());
|
||||
}
|
||||
|
||||
@Test
|
||||
void storedTagsAreTheTagsOfTheResourceTheWholeArnNamesInItsAccountAndRegionAndTaggingPutsANewMap() {
|
||||
String account = "111111111111";
|
||||
Cluster cluster = storedCluster("warehouse", "us-east-1");
|
||||
cluster.setTags(new LinkedHashMap<>(Map.of("team", "data")));
|
||||
Snapshot snapshot = snapshotOf("nightly", "warehouse");
|
||||
snapshot.setSnapshotArn("arn:aws:redshift:us-east-1:111111111111:snapshot:warehouse/nightly");
|
||||
snapshot.setTags(new LinkedHashMap<>(Map.of("stage", "prod")));
|
||||
when(snapshotBackend.getForAccount(account, "nightly")).thenReturn(Optional.of(snapshot));
|
||||
ClusterParameterGroup ownGroup = new ClusterParameterGroup();
|
||||
ownGroup.setTags(new LinkedHashMap<>(Map.of("owner", "us")));
|
||||
when(parameterGroupBackend.getForAccount(account, regionalKey("tuned"))).thenReturn(Optional.of(ownGroup));
|
||||
ClusterParameterGroup otherGroup = new ClusterParameterGroup();
|
||||
otherGroup.setTags(new LinkedHashMap<>(Map.of("owner", "them")));
|
||||
when(parameterGroupBackend.getForAccount("222222222222", regionalKey("tuned")))
|
||||
.thenReturn(Optional.of(otherGroup));
|
||||
SnapshotSchedule schedule = new SnapshotSchedule();
|
||||
schedule.setTags(new LinkedHashMap<>(Map.of("cadence", "daily")));
|
||||
when(snapshotScheduleBackend.getForAccount(account, regionalKey("daily"))).thenReturn(Optional.of(schedule));
|
||||
Integration integration = new Integration();
|
||||
integration.setIntegrationArn("arn:aws:redshift:us-east-1:111111111111:integration:abc");
|
||||
integration.setTags(Map.of("feed", "orders"));
|
||||
when(integrationBackend.getForAccount(account, "abc")).thenReturn(Optional.of(integration));
|
||||
when(events.storedTags(account, "us-east-1", "alerts")).thenReturn(Map.of("route", "ops"));
|
||||
|
||||
assertEquals(Map.of("team", "data"),
|
||||
service.storedTags("arn:aws:redshift:us-east-1:111111111111:cluster:warehouse"));
|
||||
assertEquals(Map.of("stage", "prod"),
|
||||
service.storedTags("arn:aws:redshift:us-east-1:111111111111:snapshot:warehouse/nightly"));
|
||||
assertEquals(Map.of("owner", "us"),
|
||||
service.storedTags("arn:aws:redshift:us-east-1:111111111111:parametergroup:tuned"));
|
||||
assertEquals(Map.of("owner", "them"),
|
||||
service.storedTags("arn:aws:redshift:us-east-1:222222222222:parametergroup:tuned"));
|
||||
assertEquals(Map.of("cadence", "daily"),
|
||||
service.storedTags("arn:aws:redshift:us-east-1:111111111111:snapshotschedule:daily"));
|
||||
assertEquals(Map.of("feed", "orders"),
|
||||
service.storedTags("arn:aws:redshift:us-east-1:111111111111:integration:abc"));
|
||||
assertEquals(Map.of("route", "ops"),
|
||||
service.storedTags("arn:aws:redshift:us-east-1:111111111111:eventsubscription:alerts"));
|
||||
// Another Region's cluster of that name, another cluster's snapshot, an ARN whose partition is not its Region's
|
||||
// and a type Floci keeps no record of hold none.
|
||||
assertEquals(Map.of(), service.storedTags("arn:aws:redshift:eu-west-1:111111111111:cluster:warehouse"));
|
||||
assertEquals(Map.of(), service.storedTags("arn:aws:redshift:us-east-1:111111111111:snapshot:other/nightly"));
|
||||
assertEquals(Map.of(), service.storedTags("arn:aws-cn:redshift:us-east-1:111111111111:cluster:warehouse"));
|
||||
assertEquals(Map.of(), service.storedTags("arn:aws:redshift:us-east-1:111111111111:datashare:ns/share"));
|
||||
|
||||
Map<String, String> held = cluster.getTags();
|
||||
service.createTags("arn:aws:redshift:us-east-1:111111111111:cluster:warehouse", Map.of("env", "prod"));
|
||||
|
||||
assertNotSame(held, cluster.getTags());
|
||||
assertEquals(Map.of("team", "data"), held);
|
||||
assertEquals(Map.of("team", "data", "env", "prod"),
|
||||
service.storedTags("arn:aws:redshift:us-east-1:111111111111:cluster:warehouse"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTagsRejectsNonArnResourceName() {
|
||||
assertThrows(AwsException.class, () ->
|
||||
|
||||
Reference in new issue
Block a user