mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): check Glue requests on the resources they name (#8529)
Glue was one of the namespaces the table of request resources did not read yet, so under enforcement every Glue request was checked on *: a grant scoped to one database or table could not allow anything, and a deny scoped to one did not hold. - Glue moves from NOT_COVERED to NAMESPACES and the generator reads all 314 of its operations. A table operation is checked on the account's Data Catalog, the database and the table, the three types the Service Reference gives glue:GetTable and its kin; a database operation on the catalog and the database; jobs, crawlers, triggers, workflows and connections on the ARNs Glue mints for them. - Where a Glue request names its resources in ways the generator did not read yet, its rules read a little further, each from botocore alone: Input and List drop from a member's stem as Config and plurals do (DatabaseInput.Name, ConnectionNameList); a list whose own list shape is named for the type's names fills it (BatchDeleteTable's TablesToDelete, a BatchDeleteTableNameList); "being" ends a type's name in documentation (GetWorkflowRun's Name, "name of the workflow being run"); a type of no variables of its own, the account's catalog, is no longer dropped as an alternative to the unnamed type a create makes; and a create whose request carries tags and whose action acts on other types alone tags the resource it makes when the request names it in full (CreateConnection's tags on connection/<ConnectionInput.Name>), which the table reader now accepts. - Outside Glue those rules change four entries: Redshift's BatchModifyClusterSnapshots is checked on the snapshots its SnapshotIdentifierList names instead of *, and EventBridge's CreateEventSource and QuickSight's CreateDataSet and CreateTopic gain a makes that changes nothing at runtime. Every other entry is unchanged. - What the table does not read stays as the metadata gives it: a CatalogId is not read, so another account's or a federated catalog is checked on the caller's account's ARNs, and a schema named by its registry and name on schema/<SchemaName>, the Service Reference's format, whose botocore pattern takes no slash. IamRequestResourceEnforcementIntegrationTest checks a table on the catalog, its database and itself, a database and a job on the ARNs Glue gives them, a deny on one table or connection holding inside a batch delete, a database's creation on its DatabaseInput.Name, a connection's tags on its ConnectionInput.Name, and a workflow run on its workflow. The generator's tests cover each rule; iam.md says so.
This commit is contained in:
1 parent
b0625347d8
commit
e6f57d849d
8 files changed
+614
-43
No files matched your search
@@ -418,6 +418,12 @@ class RequestResourceMembersTest {
|
||||
Map.of(), Map.of(), null, Map.of(), false, null)),
|
||||
parseUnchecked("{\"namespaces\":{\"a\":[]}," + formats + ",\"operations\":{\"a:Op\":{\"types\":[],"
|
||||
+ "\"resources\":[]," + makes + "}}}").makes().get("a:Op"));
|
||||
// So does a create acting on other types alone (Glue's CreateConnection, on its connection type).
|
||||
String kinds = "\"arnFormats\":{\"a\":{\"thing\":\"arn:${Partition}:a:${Region}:${Account}:thing/${ThingName}\","
|
||||
+ "\"kind\":\"arn:${Partition}:a:${Region}:${Account}:kind/${KindName}\"}}";
|
||||
assertEquals(List.of("thing"), parseUnchecked("{\"namespaces\":{\"a\":[]}," + kinds
|
||||
+ ",\"operations\":{\"a:Op\":{\"types\":[\"kind\"],\"resources\":[]," + makes + "}}}")
|
||||
.makes().get("a:Op").getFirst().types());
|
||||
for (String bad : List.of("\"types\":[\"thing\"],\"resources\":[]," + makes, "\"types\":[],\"resources\":[],"
|
||||
+ "\"makes\":[{\"type\":\"thing\",\"fill\":{},\"made\":true}]", "\"types\":[],\"resources\":[],"
|
||||
+ "\"makes\":[{\"types\":[\"thing\"],\"arn\":\"ThingArn\"}]")) {
|
||||
@@ -546,11 +552,11 @@ class RequestResourceMembersTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Each resource a create whose action acts on no type makes, from a request naming it, is where its tags go, and
|
||||
* the create itself names none.
|
||||
* Each resource a create whose action acts on no type, or on other types alone, makes, from a request naming it,
|
||||
* is where its tags go, and a create acting on no type names nothing itself.
|
||||
*/
|
||||
@TestFactory
|
||||
Stream<DynamicTest> everyResourceACreateActingOnNoTypeMakesIsWhereItsTagsGo() {
|
||||
Stream<DynamicTest> everyResourceACreateMakesIsWhereItsTagsGo() {
|
||||
RequestResourceMembers.Table table = RequestResourceMembers.table();
|
||||
return table.makes().entrySet().stream().map(operation -> DynamicTest.dynamicTest(operation.getKey(), () -> {
|
||||
String namespace = operation.getKey().substring(0, operation.getKey().indexOf(':'));
|
||||
@@ -570,8 +576,10 @@ class RequestResourceMembersTest {
|
||||
"000000000000");
|
||||
assertEquals(List.of(expected), RequestResources.created(operation.getKey(), null, json(body.toString()),
|
||||
"aws", "us-east-1", "000000000000", labels), body + " " + labels);
|
||||
assertEquals(List.of(), RequestResources.of(operation.getKey(), json(body.toString()), "aws",
|
||||
"us-east-1", "000000000000", null, labels));
|
||||
if (table.types().getOrDefault(operation.getKey(), List.of()).isEmpty()) {
|
||||
assertEquals(List.of(), RequestResources.of(operation.getKey(), json(body.toString()), "aws",
|
||||
"us-east-1", "000000000000", null, labels));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
+131
@@ -1860,6 +1860,137 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
}
|
||||
|
||||
/** The user's JSON-protocol request to the target, {@code <prefix>.<operation>}, with the body. */
|
||||
/**
|
||||
* A Glue table is checked on the account's catalog, its database and itself, the types AWS gives
|
||||
* {@code glue:GetTable}, so a grant on all three allows it, the same grant refuses another table of the database,
|
||||
* a grant leaving out the catalog refuses it, and a deny scoped to the table holds under an allow on everything.
|
||||
*/
|
||||
@Test
|
||||
void aGlueTableIsCheckedOnTheCatalogItsDatabaseAndItself() {
|
||||
String database = "res_db_" + suffix();
|
||||
String glueArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT + ":";
|
||||
glue("CreateDatabase", "{\"DatabaseInput\":{\"Name\":\"" + database + "\"}}").statusCode(200);
|
||||
cleanup.register(() -> glue("DeleteDatabase", "{\"Name\":\"" + database + "\"}"));
|
||||
glue("CreateTable", "{\"DatabaseName\":\"" + database + "\",\"TableInput\":{\"Name\":\"orders\"}}")
|
||||
.statusCode(200);
|
||||
cleanup.register(() -> glue("DeleteTable", "{\"DatabaseName\":\"" + database + "\",\"Name\":\"orders\"}"));
|
||||
String catalog = allowOn("glue:GetTable", glueArn + "catalog");
|
||||
String scoped = allowOn("glue:GetTable", glueArn + "database/" + database) + ","
|
||||
+ allowOn("glue:GetTable", glueArn + "table/" + database + "/orders");
|
||||
|
||||
User user = user("res-glue-table");
|
||||
user.policy(catalog + "," + scoped);
|
||||
getTable(user, database, "orders").statusCode(200);
|
||||
refusedJson(getTable(user, database, "other"), "glue:GetTable");
|
||||
user.policy(scoped);
|
||||
refusedJson(getTable(user, database, "orders"), "glue:GetTable");
|
||||
user.policy(allowOn("glue:GetTable", "*") + ",{\"Effect\":\"Deny\",\"Action\":\"glue:GetTable\",\"Resource\":\""
|
||||
+ glueArn + "table/" + database + "/orders\"}");
|
||||
refusedJson(getTable(user, database, "orders"), "glue:GetTable");
|
||||
}
|
||||
|
||||
/** A Glue database is checked on the catalog and {@code database/<name>}, and a job on {@code job/<name>}. */
|
||||
@Test
|
||||
void aGlueDatabaseAndAJobAreCheckedOnTheArnsGlueGivesThem() {
|
||||
String database = "res_db_" + suffix();
|
||||
String job = "res-job-" + suffix();
|
||||
String glueArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT + ":";
|
||||
glue("CreateDatabase", "{\"DatabaseInput\":{\"Name\":\"" + database + "\"}}").statusCode(200);
|
||||
cleanup.register(() -> glue("DeleteDatabase", "{\"Name\":\"" + database + "\"}"));
|
||||
glue("CreateJob", "{\"Name\":\"" + job + "\",\"Role\":\"arn:aws:iam::" + ACCOUNT + ":role/glue\","
|
||||
+ "\"Command\":{\"Name\":\"glueetl\",\"ScriptLocation\":\"s3://scripts/job.py\"}}").statusCode(200);
|
||||
cleanup.register(() -> glue("DeleteJob", "{\"JobName\":\"" + job + "\"}"));
|
||||
|
||||
User user = user("res-glue-db");
|
||||
user.policy(allowOn("glue:GetDatabase", glueArn + "catalog") + ","
|
||||
+ allowOn("glue:GetDatabase", glueArn + "database/" + database) + ","
|
||||
+ allowOn("glue:GetJob", glueArn + "job/" + job));
|
||||
send(user, "glue", "AWSGlue.GetDatabase", "1.1", "{\"Name\":\"" + database + "\"}").statusCode(200);
|
||||
refusedJson(send(user, "glue", "AWSGlue.GetDatabase", "1.1", "{\"Name\":\"" + database + "_other\"}"),
|
||||
"glue:GetDatabase");
|
||||
send(user, "glue", "AWSGlue.GetJob", "1.1", "{\"JobName\":\"" + job + "\"}").statusCode(200);
|
||||
refusedJson(send(user, "glue", "AWSGlue.GetJob", "1.1", "{\"JobName\":\"" + job + "-other\"}"), "glue:GetJob");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* everything.
|
||||
*/
|
||||
@Test
|
||||
void aGlueBatchDeleteIsCheckedOnEachTableAndConnectionItNames() {
|
||||
String database = "res_db_" + suffix();
|
||||
String glueArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT + ":";
|
||||
glue("CreateDatabase", "{\"DatabaseInput\":{\"Name\":\"" + database + "\"}}").statusCode(200);
|
||||
cleanup.register(() -> glue("DeleteDatabase", "{\"Name\":\"" + database + "\"}"));
|
||||
|
||||
User user = user("res-glue-batch");
|
||||
user.policy(allowOn("glue:*", "*") + ",{\"Effect\":\"Deny\",\"Action\":[\"glue:BatchDeleteTable\","
|
||||
+ "\"glue:BatchDeleteConnection\"],\"Resource\":[\"" + glueArn + "table/" + database + "/kept\",\""
|
||||
+ glueArn + "connection/kept-" + database + "\"]}");
|
||||
refusedJson(send(user, "glue", "AWSGlue.BatchDeleteTable", "1.1", "{\"DatabaseName\":\"" + database
|
||||
+ "\",\"TablesToDelete\":[\"gone\",\"kept\"]}"), "glue:BatchDeleteTable");
|
||||
send(user, "glue", "AWSGlue.BatchDeleteTable", "1.1", "{\"DatabaseName\":\"" + database
|
||||
+ "\",\"TablesToDelete\":[\"gone\"]}").statusCode(200);
|
||||
refusedJson(send(user, "glue", "AWSGlue.BatchDeleteConnection", "1.1", "{\"ConnectionNameList\":[\"gone-"
|
||||
+ database + "\",\"kept-" + database + "\"]}"), "glue:BatchDeleteConnection");
|
||||
send(user, "glue", "AWSGlue.BatchDeleteConnection", "1.1", "{\"ConnectionNameList\":[\"gone-" + database
|
||||
+ "\"]}").statusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Glue database's creation is checked on the catalog and the database its {@code DatabaseInput.Name} names, and
|
||||
* a connection's tags on the connection its {@code ConnectionInput.Name} names, the resource they go on.
|
||||
*/
|
||||
@Test
|
||||
void aGlueCreateIsCheckedOnWhatItsInputNames() {
|
||||
String database = "res_db_" + suffix();
|
||||
String connection = "res-conn-" + suffix();
|
||||
String glueArn = "arn:aws:glue:" + REGION + ":" + ACCOUNT + ":";
|
||||
cleanup.register(() -> glue("DeleteDatabase", "{\"Name\":\"" + database + "\"}"));
|
||||
cleanup.register(() -> glue("DeleteConnection", "{\"ConnectionName\":\"" + connection + "\"}"));
|
||||
|
||||
User user = user("res-glue-create");
|
||||
user.policy(allowOn("glue:CreateDatabase", glueArn + "catalog") + ","
|
||||
+ allowOn("glue:CreateDatabase", glueArn + "database/" + database));
|
||||
refusedJson(send(user, "glue", "AWSGlue.CreateDatabase", "1.1",
|
||||
"{\"DatabaseInput\":{\"Name\":\"" + database + "_other\"}}"), "glue:CreateDatabase");
|
||||
send(user, "glue", "AWSGlue.CreateDatabase", "1.1", "{\"DatabaseInput\":{\"Name\":\"" + database + "\"}}")
|
||||
.statusCode(200);
|
||||
|
||||
String create = "{\"ConnectionInput\":{\"Name\":\"" + connection + "\",\"ConnectionType\":\"JDBC\","
|
||||
+ "\"ConnectionProperties\":{\"JDBC_CONNECTION_URL\":\"jdbc:postgresql://db:5432/app\"}},"
|
||||
+ "\"Tags\":{\"team\":\"data\"}}";
|
||||
user.policy(allowOn("glue:CreateConnection", "*") + "," + allowOn("glue:TagResource", "*")
|
||||
+ ",{\"Effect\":\"Deny\",\"Action\":\"glue:TagResource\",\"Resource\":\"" + glueArn + "connection/"
|
||||
+ connection + "\"}");
|
||||
refusedJson(send(user, "glue", "AWSGlue.CreateConnection", "1.1", create), "glue:TagResource");
|
||||
user.policy(allowOn("glue:CreateConnection", "*") + ","
|
||||
+ allowOn("glue:TagResource", glueArn + "connection/" + connection));
|
||||
send(user, "glue", "AWSGlue.CreateConnection", "1.1", create).statusCode(200);
|
||||
}
|
||||
|
||||
/** A Glue workflow run is checked on the workflow its {@code Name} names. */
|
||||
@Test
|
||||
void aGlueWorkflowRunIsCheckedOnItsWorkflow() {
|
||||
String workflow = "res-wf-" + suffix();
|
||||
User user = user("res-glue-run");
|
||||
user.policy(allowOn("glue:GetWorkflowRun", "arn:aws:glue:" + REGION + ":" + ACCOUNT + ":workflow/" + workflow));
|
||||
refusedJson(send(user, "glue", "AWSGlue.GetWorkflowRun", "1.1",
|
||||
"{\"Name\":\"" + workflow + "-other\",\"RunId\":\"wr_0\"}"), "glue:GetWorkflowRun");
|
||||
send(user, "glue", "AWSGlue.GetWorkflowRun", "1.1", "{\"Name\":\"" + workflow + "\",\"RunId\":\"wr_0\"}")
|
||||
.body(not(containsString("AccessDeniedException")));
|
||||
}
|
||||
|
||||
private static ValidatableResponse glue(String operation, String body) {
|
||||
return adminJson("glue", "AWSGlue." + operation).body(body).post("/").then();
|
||||
}
|
||||
|
||||
private static ValidatableResponse getTable(User user, String database, String table) {
|
||||
return send(user, "glue", "AWSGlue.GetTable", "1.1",
|
||||
"{\"DatabaseName\":\"" + database + "\",\"Name\":\"" + table + "\"}");
|
||||
}
|
||||
|
||||
private static ValidatableResponse send(User user, String service, String target, String version, String body) {
|
||||
return user.json(service, target, version).body(body).post("/").then();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user