mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(glue): give resource-tag conditions the tags of the Glue resource a request names (#8582)
Since #8529 the generated request resources give Glue's types aws:ResourceTag/ keys, but no StoredResourceArns answered for the glue namespace, so a condition on a job's, a connection's or a registry's tags saw none. GlueStoredResourceArns now answers storedTags from GlueService.storedTags: a schema registry's or a schema's tags from the schema registry, any other resource's from the tags applied to its ARN, which Glue drops when it deletes the resource, each read in the account and Region the ARN names, a pre-multi-account entry of the default account in place, through AccountAwareStorageBackend.readInAccount. Only string values are taken, as TagResource keeps the request's map as given. Deleting a table or a user-defined function, directly or with its database, now drops the tags applied to its ARN as Glue's other deletes do, so one recreated under the same name starts with none. Tagging a resource through the shared tag store now puts a new tag map in place of the old one, so the lookup always copies one whole set.
This commit is contained in:
1 parent
6eb66cd6bf
commit
2842fe4eeb
12 files changed
+273
-16
No files matched your search
@@ -1660,6 +1660,68 @@ class GlueServiceTest {
|
||||
assertEquals("prod", crawlerTags.get("env"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void storedTagsAreTheStringTagsOfTheJobOrTheRegistryTheArnNames() {
|
||||
glueService.createJob(createValidJob("stored-tags-job"), Map.of("team", "data"), REGION);
|
||||
String jobArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":job/stored-tags-job";
|
||||
String registryArn = schemaRegistryService.createRegistry("stored-tags-registry", null,
|
||||
Map.of("team", "stream"), REGION).getRegistryArn();
|
||||
Map<String, String> mixed = (Map<String, String>) (Map<?, ?>) Map.of("owner", "ingest", "count", 5);
|
||||
glueService.tagResource(jobArn, mixed, REGION);
|
||||
|
||||
assertEquals(Map.of("team", "data", "owner", "ingest"), glueService.storedTags(jobArn));
|
||||
assertEquals(Map.of("team", "stream"), glueService.storedTags(registryArn));
|
||||
assertEquals(Map.of(), glueService.storedTags(jobArn.replace(ACCOUNT_ID, "111111111111")));
|
||||
assertEquals(Map.of(), glueService.storedTags(jobArn.replace(REGION, "us-west-2")));
|
||||
assertEquals(Map.of(), glueService.storedTags(registryArn.replace(REGION, "us-west-2")));
|
||||
assertEquals(Map.of(), glueService.storedTags(registryArn + "-missing"));
|
||||
|
||||
glueService.deleteJob("stored-tags-job", REGION);
|
||||
|
||||
assertEquals(Map.of(), glueService.storedTags(jobArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTablesAndAFunctionsTagsGoWhenTheyOrTheirDatabaseAreDeleted() {
|
||||
String tableArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":table/db1/tagged";
|
||||
String functionArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":userDefinedFunction/db1/tagged_fn";
|
||||
createTaggedTableAndFunction(tableArn, functionArn);
|
||||
assertEquals(Map.of("team", "data"), glueService.storedTags(tableArn));
|
||||
assertEquals(Map.of("team", "data"), glueService.storedTags(functionArn));
|
||||
|
||||
glueService.deleteTable("db1", "tagged");
|
||||
glueService.deleteUserDefinedFunction("db1", "tagged_fn");
|
||||
Table recreated = new Table();
|
||||
recreated.setName("tagged");
|
||||
glueService.createTable("db1", recreated);
|
||||
UserDefinedFunction function = new UserDefinedFunction();
|
||||
function.setFunctionName("tagged_fn");
|
||||
glueService.createUserDefinedFunction("db1", function);
|
||||
|
||||
assertEquals(Map.of(), glueService.storedTags(tableArn));
|
||||
assertEquals(Map.of(), glueService.storedTags(functionArn));
|
||||
|
||||
glueService.deleteTable("db1", "tagged");
|
||||
glueService.deleteUserDefinedFunction("db1", "tagged_fn");
|
||||
createTaggedTableAndFunction(tableArn, functionArn);
|
||||
glueService.deleteDatabase("db1", REGION);
|
||||
|
||||
assertEquals(Map.of(), glueService.storedTags(tableArn));
|
||||
assertEquals(Map.of(), glueService.storedTags(functionArn));
|
||||
}
|
||||
|
||||
private void createTaggedTableAndFunction(String tableArn, String functionArn) {
|
||||
Table table = new Table();
|
||||
table.setName("tagged");
|
||||
glueService.createTable("db1", table);
|
||||
UserDefinedFunction function = new UserDefinedFunction();
|
||||
function.setFunctionName("tagged_fn");
|
||||
glueService.createUserDefinedFunction("db1", function);
|
||||
glueService.tagResource(tableArn, Map.of("team", "data"), REGION);
|
||||
glueService.tagResource(functionArn, Map.of("team", "data"), REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void jobAndCrawlerRejectsDuplicateCreation() {
|
||||
Job job = createValidJob("dup-job");
|
||||
|
||||
+36
@@ -1912,6 +1912,42 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
refusedJson(send(user, "glue", "AWSGlue.GetJob", "1.1", "{\"JobName\":\"" + job + "-other\"}"), "glue:GetJob");
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@code aws:ResourceTag} condition reads the tags Glue holds on the resource a request names, a job's and a
|
||||
* schema registry's, so an allow on one team's tag lets the caller read that team's job and registry and not
|
||||
* another's.
|
||||
*/
|
||||
@Test
|
||||
void aGlueResourceTagConditionReadsTheTagsOfTheJobAndTheRegistry() {
|
||||
String tagged = "res-tag-job-" + suffix();
|
||||
String other = "res-tag-job-" + suffix();
|
||||
String jobRest = "\",\"Role\":\"arn:aws:iam::" + ACCOUNT + ":role/glue\","
|
||||
+ "\"Command\":{\"Name\":\"glueetl\",\"ScriptLocation\":\"s3://scripts/job.py\"}";
|
||||
glue("CreateJob", "{\"Name\":\"" + tagged + jobRest + ",\"Tags\":{\"team\":\"data\"}}").statusCode(200);
|
||||
cleanup.register(() -> glue("DeleteJob", "{\"JobName\":\"" + tagged + "\"}"));
|
||||
glue("CreateJob", "{\"Name\":\"" + other + jobRest + ",\"Tags\":{\"team\":\"web\"}}").statusCode(200);
|
||||
cleanup.register(() -> glue("DeleteJob", "{\"JobName\":\"" + other + "\"}"));
|
||||
String taggedRegistry = "res-tag-reg-" + suffix();
|
||||
String otherRegistry = "res-tag-reg-" + suffix();
|
||||
glue("CreateRegistry", "{\"RegistryName\":\"" + taggedRegistry + "\",\"Tags\":{\"team\":\"data\"}}")
|
||||
.statusCode(200);
|
||||
cleanup.register(() -> glue("DeleteRegistry", "{\"RegistryId\":{\"RegistryName\":\"" + taggedRegistry
|
||||
+ "\"}}"));
|
||||
glue("CreateRegistry", "{\"RegistryName\":\"" + otherRegistry + "\"}").statusCode(200);
|
||||
cleanup.register(() -> glue("DeleteRegistry", "{\"RegistryId\":{\"RegistryName\":\"" + otherRegistry
|
||||
+ "\"}}"));
|
||||
|
||||
User user = user("res-glue-tags");
|
||||
user.policy("{\"Effect\":\"Allow\",\"Action\":[\"glue:GetJob\",\"glue:GetRegistry\"],\"Resource\":\"*\","
|
||||
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
|
||||
send(user, "glue", "AWSGlue.GetJob", "1.1", "{\"JobName\":\"" + tagged + "\"}").statusCode(200);
|
||||
refusedJson(send(user, "glue", "AWSGlue.GetJob", "1.1", "{\"JobName\":\"" + other + "\"}"), "glue:GetJob");
|
||||
send(user, "glue", "AWSGlue.GetRegistry", "1.1", "{\"RegistryId\":{\"RegistryName\":\"" + taggedRegistry
|
||||
+ "\"}}").statusCode(200);
|
||||
refusedJson(send(user, "glue", "AWSGlue.GetRegistry", "1.1", "{\"RegistryId\":{\"RegistryName\":\""
|
||||
+ otherRegistry + "\"}}"), "glue:GetRegistry");
|
||||
}
|
||||
|
||||
/**
|
||||
* What Glue's batch deletes name, the tables of {@code TablesToDelete} and the connections of
|
||||
* {@code ConnectionNameList}, is checked one by one, so a deny scoped to one of them holds under an allow on
|
||||
|
||||
+26
@@ -6,6 +6,8 @@ import io.floci.aws.core.common.TagHandler;
|
||||
import io.floci.aws.core.resource.ExplorerResource;
|
||||
import io.floci.aws.core.resource.ResourceProvider;
|
||||
import io.floci.aws.core.resource.SupportedResourceType;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.resourcegroupstagging.model.ResourceTagMapping;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -25,6 +27,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class ResourceGroupsTaggingServiceTest {
|
||||
|
||||
@@ -47,6 +53,26 @@ class ResourceGroupsTaggingServiceTest {
|
||||
assertEquals("my-bucket", ResourceGroupsTaggingService.parsedType("my-bucket"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void storedTagsReadTheMappingOfTheAccountAndRegionAskedForAndTaggingReplacesIt() {
|
||||
StorageFactory storageFactory = mock(StorageFactory.class);
|
||||
when(storageFactory.create(anyString(), anyString(), any()))
|
||||
.thenAnswer(inv -> AccountAwareStorageBackend.inMemory(ACCOUNT));
|
||||
ResourceGroupsTaggingService service = new ResourceGroupsTaggingService(storageFactory, List.of(), List.of(),
|
||||
new RegionResolver(REGION, ACCOUNT));
|
||||
service.initializeStorage();
|
||||
service.tagResources(List.of(QUEUE_ARN), Map.of("team", "a"), REGION);
|
||||
Map<String, String> held = service.getTagsForResource(REGION, QUEUE_ARN);
|
||||
|
||||
service.tagResources(List.of(QUEUE_ARN), Map.of("stage", "prod"), REGION);
|
||||
service.untagResources(List.of(QUEUE_ARN), List.of("team"), REGION);
|
||||
|
||||
assertEquals(Map.of("stage", "prod"), service.storedTags(ACCOUNT, REGION, QUEUE_ARN));
|
||||
assertEquals(Map.of("team", "a"), held);
|
||||
assertEquals(Map.of(), service.storedTags("111111111111", REGION, QUEUE_ARN));
|
||||
assertEquals(Map.of(), service.storedTags(ACCOUNT, "us-west-2", QUEUE_ARN));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceTypeFilterMatchesProviderDeclaredType() {
|
||||
ResourceGroupsTaggingService service = service(List.of(
|
||||
|
||||
Reference in new issue
Block a user