mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(athena): give resource-tag conditions the tags of the workgroup or data catalog a request names (#8607)
The generated request resources give Athena's workgroup and data catalog types aws:ResourceTag/ keys, but AthenaStoredResourceArns did not answer storedTags, so a condition on their tags saw none. It now answers from AthenaService.storedTags, which reads the workgroup or the data catalog stored under the ARN in the account and Region it names, a pre-multi-account one of the default account in place, matched on the whole ARN; the built-in primary workgroup and AwsDataCatalog carry none. The tag lists are volatile, as tagging already replaces a list whole.
This commit is contained in:
1 parent
057684feac
commit
cf3d7e827c
8 files changed
+117
-9
No files matched your search
@@ -4,9 +4,11 @@ import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.athena.model.CreateWorkGroupRequest;
|
||||
import io.floci.aws.services.athena.model.QueryExecutionState;
|
||||
import io.floci.aws.services.athena.model.ResultConfiguration;
|
||||
import io.floci.aws.services.athena.model.ResultSet;
|
||||
import io.floci.aws.services.athena.model.WorkGroupTag;
|
||||
import io.floci.aws.services.floci.duck.FlociDuckClient;
|
||||
import io.floci.aws.services.glue.GlueService;
|
||||
import io.floci.aws.services.s3.S3Service;
|
||||
@@ -74,6 +76,25 @@ class AthenaServiceTest {
|
||||
vertx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void storedTagsReadTheWorkgroupOrTheDataCatalogTheArnNamesInItsAccountAndRegion() {
|
||||
CreateWorkGroupRequest request = new CreateWorkGroupRequest();
|
||||
request.setName("analytics");
|
||||
request.setTags(List.of(new WorkGroupTag("team", "data")));
|
||||
service.createWorkGroup(request, "us-east-1");
|
||||
service.createDataCatalog("us-east-1", "lake", "LAMBDA", null, null, List.of(new WorkGroupTag("team", "lake")));
|
||||
String arn = "arn:aws:athena:us-east-1:000000000000:";
|
||||
|
||||
assertEquals(Map.of("team", "data"), service.storedTags(arn + "workgroup/analytics"));
|
||||
assertEquals(Map.of("team", "lake"), service.storedTags(arn + "datacatalog/lake"));
|
||||
assertEquals(Map.of(), service.storedTags(arn + "workgroup/primary"));
|
||||
assertEquals(Map.of(), service.storedTags(arn + "datacatalog/AwsDataCatalog"));
|
||||
assertEquals(Map.of(), service.storedTags(arn + "workgroup/analytics/session/s-1"));
|
||||
assertEquals(Map.of(), service.storedTags("arn:aws:athena:us-east-1:111111111111:workgroup/analytics"));
|
||||
assertEquals(Map.of(), service.storedTags("arn:aws:athena:us-west-2:000000000000:workgroup/analytics"));
|
||||
assertEquals(Map.of(), service.storedTags("arn:aws-cn:athena:us-east-1:000000000000:workgroup/analytics"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void stopDuringExecutionKeepsCancellationTerminal() throws Exception {
|
||||
CountDownLatch started = new CountDownLatch(1);
|
||||
|
||||
+39
@@ -992,6 +992,45 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
"athena:StartQueryExecution");
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@code aws:ResourceTag} condition reads the tags Athena holds on a workgroup and a data catalog, so an allow
|
||||
* on one team's tag lets the caller read that team's and not another's.
|
||||
*/
|
||||
@Test
|
||||
void anAthenaResourceTagConditionReadsTheTagsOfTheWorkgroupAndTheDataCatalog() {
|
||||
String workGroup = athenaTagged("CreateWorkGroup", "res-tag-wg-" + suffix(), "data");
|
||||
String otherWorkGroup = athenaTagged("CreateWorkGroup", "res-tag-wg-" + suffix(), "web");
|
||||
String catalog = athenaTagged("CreateDataCatalog", "res_tag_cat_" + suffix(), "data");
|
||||
String otherCatalog = athenaTagged("CreateDataCatalog", "res_tag_cat_" + suffix(), "web");
|
||||
|
||||
User user = user("res-athena-tags");
|
||||
user.policy("{\"Effect\":\"Allow\",\"Action\":[\"athena:GetWorkGroup\",\"athena:GetDataCatalog\"],"
|
||||
+ "\"Resource\":\"*\",\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
|
||||
send(user, "athena", "AmazonAthena.GetWorkGroup", "1.1", "{\"WorkGroup\":\"" + workGroup + "\"}")
|
||||
.statusCode(200);
|
||||
refusedJson(send(user, "athena", "AmazonAthena.GetWorkGroup", "1.1", "{\"WorkGroup\":\"" + otherWorkGroup
|
||||
+ "\"}"), "athena:GetWorkGroup");
|
||||
send(user, "athena", "AmazonAthena.GetDataCatalog", "1.1", "{\"Name\":\"" + catalog + "\"}").statusCode(200);
|
||||
refusedJson(send(user, "athena", "AmazonAthena.GetDataCatalog", "1.1", "{\"Name\":\"" + otherCatalog
|
||||
+ "\"}"), "athena:GetDataCatalog");
|
||||
}
|
||||
|
||||
/** An Athena workgroup or {@code LAMBDA} data catalog of the name, tagged with the team, deleted afterwards. */
|
||||
private String athenaTagged(String operation, String name, String team) {
|
||||
String body = "CreateWorkGroup".equals(operation) ? "{\"Name\":\"" + name + "\""
|
||||
: "{\"Name\":\"" + name + "\",\"Type\":\"LAMBDA\"";
|
||||
adminJson("athena", "AmazonAthena." + operation).body(body + ",\"Tags\":[{\"Key\":\"team\",\"Value\":\""
|
||||
+ team + "\"}]}").post("/").then().statusCode(200);
|
||||
if ("CreateWorkGroup".equals(operation)) {
|
||||
cleanup.register(() -> adminJson("athena", "AmazonAthena.DeleteWorkGroup")
|
||||
.body("{\"WorkGroup\":\"" + name + "\"}").post("/"));
|
||||
} else {
|
||||
cleanup.register(() -> adminJson("athena", "AmazonAthena.DeleteDataCatalog")
|
||||
.body("{\"Name\":\"" + name + "\"}").post("/"));
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* An Athena catalog read is checked on the catalog its {@code CatalogName} names, and Floci reads the metadata of
|
||||
* none but the account's Glue Data Catalog: a catalog of another type is refused, so a grant on it does not reach
|
||||
|
||||
Reference in new issue
Block a user