mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(iam): read DynamoDB from the generated tables, its statement and item permissions from the developer guide (#9235)
DynamoDB is read from iam-request-resources.json now, and
ResourceArnBuilder's DynamoDB branch, the registry's PartiQL action,
the condition resolver's mapping of transaction items and statements to
actions and Step Functions' copy of all three are gone, leaving iam in
HAND_BUILT.
Which action each transaction item and each PartiQL statement is
checked as comes from the developer guide, vendored by
fetch_dynamodb_permissions.py into
tools/aws/sources/dynamodb-permissions.json and read under
PERMISSION_SOURCES: the PartiQL IAM page's required permissions and the
transactions page's paragraph on each kind of item.
- Each transaction item is checked as the action of its kind on the
table its TableName names (TransactItems[].Put.TableName as
dynamodb:PutItem), each PartiQL statement as the action of its verb on
the table or index it names, an EXISTS statement as the SELECT it
evaluates, which DynamoDB's own parser reads through the new
StoredResourceArns.statement hook before it binds the request's
parameters. A request naming nothing is checked as its own action on
*; a state machine's task naming nothing is left to DynamoDB, as
before.
- RequestResources.targets replaces checkedAs: each element of a list is
read apart and returned with its check, so the condition resolver
still gives each item or statement its own keys and
dynamodb:EnclosingOperation.
- BatchGetItem and BatchWriteItem name their tables by the keys of
RequestItems, which the generator reads from botocore (RequestItems{}).
- RequestResourceMembers reads Name{}, Name[].Item.Field and statement
rows (statement, verb, names).
This commit is contained in:
1 parent
4d481ebccb
commit
3a1ea212f0
27 files changed
+1298
-661
No files matched your search
@@ -952,8 +952,8 @@ class IamConditionContextResolverTest {
|
||||
+ "\"Key\":{\"PK\":{\"S\":\"USER_alice\"}}," + extra + "}}]}");
|
||||
JsonNode original = body.deepCopy();
|
||||
when(request.getProperty("floci.bufferedJsonBody")).thenReturn(body);
|
||||
Map<String, List<String>> context = resolver.dynamoDbTransactionItems("dynamodb:TransactGetItems",
|
||||
request, "us-east-1", "000000000000").getFirst().context();
|
||||
Map<String, List<String>> context = resolver.resolvePart("dynamodb", "dynamodb:GetItem",
|
||||
"dynamodb:TransactGetItems", request, body.path("TransactItems").path(0).path("Get"), "us-east-1");
|
||||
assertEquals(List.of("ALL_ATTRIBUTES"), context.get("dynamodb:Select"));
|
||||
assertEquals(List.of("PK"), context.get("dynamodb:Attributes"));
|
||||
assertEquals(List.of("USER_alice"), context.get("dynamodb:LeadingKeys"));
|
||||
|
||||
@@ -234,13 +234,11 @@ class RequestResourceMembersTest {
|
||||
assertTrue(table.namespaces().contains("lambda"));
|
||||
assertFalse(table.handBuilt().contains("lambda"));
|
||||
assertFalse(table.handBuilt().contains("logs"));
|
||||
assertEquals(Set.of("dynamodb"), table.namespaces().stream().filter(table.handBuilt()::contains)
|
||||
assertEquals(Set.of(), table.namespaces().stream().filter(table.handBuilt()::contains)
|
||||
.collect(Collectors.toSet()));
|
||||
// What AWS was measured to check where the Service Reference lists no resource type (MEASURED).
|
||||
assertEquals(Set.of("dynamodb:ListTables"), table.operations().keySet().stream()
|
||||
assertEquals(Set.of(), table.operations().keySet().stream()
|
||||
.filter(operation -> table.handBuilt().contains(operation.substring(0, operation.indexOf(':'))))
|
||||
.collect(Collectors.toSet()),
|
||||
"only what MEASURED gives is read in a hand-built namespace");
|
||||
.collect(Collectors.toSet()), "nothing is read in a hand-built namespace");
|
||||
assertTrue(table.namespaces().stream().noneMatch(table.notCovered()::contains));
|
||||
assertTrue(table.operations().containsKey("rds:CreateDBParameterGroup"));
|
||||
assertTrue(table.operations().containsKey("rds:CreateDBProxy"));
|
||||
@@ -371,9 +369,10 @@ class RequestResourceMembersTest {
|
||||
+ "{\"resources\":[],\"creates\":[{\"type\":\"part\",\"parent\":\"thing\",\"arn\":\"ThingArn\"}]}}}"),
|
||||
part);
|
||||
}
|
||||
// A member past one structure, or filling a variable from a list in a list.
|
||||
// An ARN member past one structure, a member filling a variable past two, or one filling it from a list in a
|
||||
// list.
|
||||
assertThrows(IllegalStateException.class, () -> parse(document(formats, "{\"types\":[\"thing\"],\"arn\":\"A[].B.ThingArn\"}")));
|
||||
for (String bad : List.of("A.Names[]", "A[].Names[]", "A[].B.Name")) {
|
||||
for (String bad : List.of("A.Names[]", "A[].Names[]", "A[].B.C.Name")) {
|
||||
assertThrows(IllegalStateException.class, () -> parse(document(formats,
|
||||
"{\"type\":\"thing\",\"fill\":{\"ThingName\":\"" + bad + "\"}}")), bad);
|
||||
}
|
||||
@@ -782,7 +781,9 @@ class RequestResourceMembersTest {
|
||||
/** The value at the member's path in a body: in its list's first element, and in its field's structure. */
|
||||
private static void put(ObjectNode body, Member member, String value) {
|
||||
if (member.field() == null) {
|
||||
if (member.list()) {
|
||||
if (member.map()) {
|
||||
body.putObject(member.name()).putObject(value);
|
||||
} else if (member.list()) {
|
||||
body.putArray(member.name()).add(value);
|
||||
} else {
|
||||
body.put(member.name(), value);
|
||||
|
||||
@@ -280,7 +280,8 @@ class RequestResourcesTest {
|
||||
@Test
|
||||
void listTablesIsCheckedOnTheTableCollectionAwsWasMeasuredToCheck() {
|
||||
assertTrue(RequestResources.reads("dynamodb:ListTables"));
|
||||
assertFalse(RequestResources.reads("dynamodb:DescribeLimits"));
|
||||
assertEquals(List.of(), RequestResources.of("dynamodb:DescribeLimits", json("{}"), "aws-us-gov",
|
||||
"us-gov-west-1", "111122223333"));
|
||||
for (String body : List.of("{}", "{\"TableName\":\"ignored\",\"ExclusiveStartTableName\":\"cursor\"}")) {
|
||||
assertEquals(List.of("arn:aws-us-gov:dynamodb:us-gov-west-1:111122223333:table/*"),
|
||||
RequestResources.of("dynamodb:ListTables", json(body), "aws-us-gov", "us-gov-west-1",
|
||||
|
||||
@@ -482,28 +482,11 @@ class DynamoDbConditionKeysTest {
|
||||
assertTrue(result.attributes().contains("inStock"), result.attributes().toString());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"BatchExecuteStatement, Statements", "ExecuteTransaction, TransactStatements"})
|
||||
void partiQLStatementRequestsFollowTheRecordedMemberPaths(String operation, String member) {
|
||||
JsonNode body = json("{\"" + member + "\":[{\"Statement\":\"SELECT * FROM a\"},"
|
||||
+ "{\"Statement\":\"DELETE FROM b WHERE PK = ?\",\"Parameters\":[{\"S\":\"k\"}]},"
|
||||
+ "\"not-an-object\"]}");
|
||||
|
||||
List<JsonNode> requests = DynamoDbConditionKeys.partiQLStatementRequests(operation, body);
|
||||
|
||||
assertEquals(3, requests.size());
|
||||
assertEquals("SELECT * FROM a", DynamoDbConditionKeys.partiQLStatement(requests.get(0)));
|
||||
assertEquals("DELETE FROM b WHERE PK = ?", DynamoDbConditionKeys.partiQLStatement(requests.get(1)));
|
||||
assertEquals("k", requests.get(1).path("Parameters").path(0).path("S").asText());
|
||||
assertNull(DynamoDbConditionKeys.partiQLStatement(requests.get(2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void partiQLStatementRequestsIgnoreTheOtherOperationsMember() {
|
||||
JsonNode body = json("{\"Statements\":[{\"Statement\":\"SELECT * FROM a\"}]}");
|
||||
|
||||
assertTrue(DynamoDbConditionKeys.partiQLStatementRequests("ExecuteTransaction", body).isEmpty());
|
||||
assertTrue(DynamoDbConditionKeys.partiQLStatementRequests("BatchExecuteStatement", null).isEmpty());
|
||||
void partiQLStatementReadsTheTextOfOneStatementRequest() {
|
||||
assertEquals("DELETE FROM b WHERE PK = ?", DynamoDbConditionKeys.partiQLStatement(
|
||||
json("{\"Statement\":\"DELETE FROM b WHERE PK = ?\",\"Parameters\":[{\"S\":\"k\"}]}")));
|
||||
assertNull(DynamoDbConditionKeys.partiQLStatement(json("{\"Statement\":1}")));
|
||||
assertNull(DynamoDbConditionKeys.partiQLStatement(json("\"not-an-object\"")));
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import org.junit.jupiter.params.provider.ValueSource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
@@ -205,7 +206,32 @@ class DynamoDbPartiQLParserTest {
|
||||
assertEquals(2, update.sets().size());
|
||||
assertEquals("b", update.removes().getFirst().root());
|
||||
assertEquals(DynamoDbPartiQLParser.Returning.ALL_NEW, update.returning());
|
||||
assertEquals("dynamodb:PartiQLUpdate", DynamoDbPartiQLParser.iamAction("FROM \"t\" WHERE pk = 'p' SET c = 1"));
|
||||
assertEquals(Optional.of(new DynamoDbPartiQLParser.StatementTarget("UPDATE", "t", null)),
|
||||
DynamoDbPartiQLParser.target("FROM \"t\" WHERE pk = 'p' SET c = 1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A statement's verb and the table and index it names, as IAM checks it, an EXISTS statement's those of the SELECT
|
||||
* it evaluates; none for a statement of another verb.
|
||||
*/
|
||||
@Test
|
||||
void aStatementsTargetIsItsVerbTableAndIndex() {
|
||||
assertEquals(Optional.of(new DynamoDbPartiQLParser.StatementTarget("SELECT", "t", "byName")),
|
||||
DynamoDbPartiQLParser.target("SELECT * FROM \"t\".\"byName\" WHERE pk = 'p'"));
|
||||
assertEquals(Optional.of(new DynamoDbPartiQLParser.StatementTarget("SELECT", "t", "byName")),
|
||||
DynamoDbPartiQLParser.target("SELECT * FROM \"t\".\"byName\" WHERE pk = ?"));
|
||||
assertEquals(Optional.of(new DynamoDbPartiQLParser.StatementTarget("DELETE", "t", null)),
|
||||
DynamoDbPartiQLParser.target("DELETE FROM \"t\" WHERE pk = ? AND sk = ?"));
|
||||
assertEquals(Optional.of(new DynamoDbPartiQLParser.StatementTarget("SELECT", "t", null)),
|
||||
DynamoDbPartiQLParser.target("EXISTS(SELECT * FROM \"t\" WHERE pk = 'p' AND v = 1)"));
|
||||
assertEquals(Optional.of(new DynamoDbPartiQLParser.StatementTarget("SELECT", "t", null)),
|
||||
DynamoDbPartiQLParser.target("SELECT * FROM \"t\" WHERE pk = 'p'"));
|
||||
assertEquals(Optional.of(new DynamoDbPartiQLParser.StatementTarget("INSERT", "t", null)),
|
||||
DynamoDbPartiQLParser.target("INSERT INTO \"t\" VALUE {'pk': 'p'}"));
|
||||
assertEquals(Optional.of(new DynamoDbPartiQLParser.StatementTarget("DELETE", "t", null)),
|
||||
DynamoDbPartiQLParser.target("DELETE FROM \"t\" WHERE pk = 'p'"));
|
||||
assertEquals(Optional.empty(), DynamoDbPartiQLParser.target("not a statement \""));
|
||||
assertEquals(Optional.empty(), DynamoDbPartiQLParser.target(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.floci.aws.core.common.ProtocolClaim;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.RequestContext;
|
||||
import io.floci.aws.core.common.RequestPathLabels;
|
||||
import io.floci.aws.core.common.RequestResources;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import io.floci.aws.core.common.WireProtocol;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
@@ -15,6 +16,8 @@ import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.services.cloudwatch.logs.CloudWatchLogsDeliveryService;
|
||||
import io.floci.aws.services.cloudwatch.logs.CloudWatchLogsStoredResourceArns;
|
||||
import io.floci.aws.services.cloudwatch.logs.model.Delivery;
|
||||
import io.floci.aws.services.dynamodb.DynamoDbStoredResourceArns;
|
||||
import io.floci.aws.services.dynamodb.backend.DynamoDbTableAccess;
|
||||
import io.floci.aws.services.eks.EksService;
|
||||
import io.floci.aws.services.eks.EksStoredResourceArns;
|
||||
import io.floci.aws.services.iam.model.AccessKey;
|
||||
@@ -55,6 +58,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -1135,183 +1139,148 @@ class ResourceArnBuilderTest {
|
||||
ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
}
|
||||
|
||||
private static final String DDB = "arn:aws:dynamodb:us-east-1:000000000000:table/";
|
||||
|
||||
/** The resources a DynamoDB request is checked on, as the table reads {@code operation}. */
|
||||
private List<String> dynamoDb(String operation) {
|
||||
return builder.buildResources("dynamodb", "dynamodb:" + operation, ctx, "us-east-1", ACCOUNT, "aws");
|
||||
}
|
||||
|
||||
/** The checks of a DynamoDB request checked by its parts, each statement parsed as DynamoDB parses it. */
|
||||
private List<RequestResources.Target> dynamoDbTargets(String operation) {
|
||||
return reading(new DynamoDbStoredResourceArns(mock(DynamoDbTableAccess.class)))
|
||||
.targets("dynamodb", "dynamodb:" + operation, ctx, "us-east-1", ACCOUNT, "aws");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbBuildsArnFromShortTableName() {
|
||||
void dynamoDbChecksTheTableItsRequestNames() {
|
||||
setJsonBody("{\"TableName\":\"FgacTable\"}");
|
||||
String arn = builder.build("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals("arn:aws:dynamodb:us-east-1:000000000000:table/FgacTable", arn);
|
||||
assertEquals(List.of(DDB + "FgacTable"), dynamoDb("GetItem"));
|
||||
// A bare name that merely looks ARN-ish is still a name, not an ARN.
|
||||
setJsonBody("{\"TableName\":\"arn:aws:dynamodb:us-east-1\"}");
|
||||
assertEquals(List.of(DDB + "arn:aws:dynamodb:us-east-1"), dynamoDb("GetItem"));
|
||||
setJsonBody("{\"TableName\":\"" + DDB + "FgacTable\"}");
|
||||
assertEquals(List.of(DDB + "FgacTable"), dynamoDb("GetItem"));
|
||||
setJsonBody("{\"TableCreationParameters\":{\"TableName\":\"ImportTarget\"},\"InputFormat\":\"DYNAMODB_JSON\"}");
|
||||
assertEquals(List.of(DDB + "ImportTarget"), dynamoDb("ImportTable"));
|
||||
setJsonBody("{}");
|
||||
assertEquals(List.of("*"), dynamoDb("GetItem"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass-through used to be a {@code startsWith("arn:aws:dynamodb:")} probe, so a table ARN from
|
||||
* any other partition was not recognised as an ARN at all and got rebuilt as
|
||||
* {@code table/arn:aws-cn:dynamodb:...}, a resource name that matches no policy.
|
||||
* A table ARN of any partition is checked as given, and as the caller's table of that name, which DynamoDB acts on:
|
||||
* a {@code startsWith("arn:aws:dynamodb:")} probe once rebuilt another partition's ARN as {@code table/arn:...}.
|
||||
*/
|
||||
@Test
|
||||
void dynamoDbReturnsExactArnForAnyPartition() {
|
||||
for (String fullArn : List.of(
|
||||
"arn:aws-us-gov:dynamodb:us-gov-west-1:000000000000:table/FgacTable",
|
||||
void dynamoDbChecksATableArnOfAnyPartitionAsGiven() {
|
||||
for (String fullArn : List.of("arn:aws-us-gov:dynamodb:us-gov-west-1:000000000000:table/FgacTable",
|
||||
"arn:aws-cn:dynamodb:cn-north-1:000000000000:table/FgacTable")) {
|
||||
setJsonBody("{\"TableName\":\"" + fullArn + "\"}");
|
||||
assertEquals(fullArn, builder.build("dynamodb", ctx, "us-east-1", "000000000000"));
|
||||
List<String> checked = dynamoDb("GetItem");
|
||||
assertEquals(fullArn, checked.getFirst());
|
||||
assertTrue(checked.contains(DDB + "FgacTable"), checked.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/** A bare name that merely looks ARN-ish is still a name, not an ARN. */
|
||||
@Test
|
||||
void dynamoDbTreatsAnIncompleteArnAsATableName() {
|
||||
setJsonBody("{\"TableName\":\"arn:aws:dynamodb:us-east-1\"}");
|
||||
assertEquals("arn:aws:dynamodb:us-east-1:000000000000:table/arn:aws:dynamodb:us-east-1",
|
||||
builder.build("dynamodb", ctx, "us-east-1", "000000000000"));
|
||||
void dynamoDbChecksTheResourceAnArnMemberHolds() {
|
||||
setJsonBody("{\"ResourceArn\":\"" + DDB + "FgacTable\",\"Tags\":[{\"Key\":\"env\",\"Value\":\"dev\"}]}");
|
||||
assertEquals(List.of(DDB + "FgacTable"), dynamoDb("TagResource"));
|
||||
setJsonBody("{\"TableArn\":\"" + DDB + "ExportTable\",\"S3Bucket\":\"my-bucket\"}");
|
||||
assertEquals(List.of(DDB + "ExportTable"), dynamoDb("ExportTableToPointInTime"));
|
||||
String stream = DDB + "FgacTable/stream/2026-09-01T00:00:00.000";
|
||||
setJsonBody("{\"StreamArn\":\"" + stream + "\"}");
|
||||
assertEquals(List.of(stream), dynamoDb("DescribeStream"));
|
||||
String export = DDB + "FgacTable/export/01693526400000-abcd";
|
||||
setJsonBody("{\"ExportArn\":\"" + export + "\"}");
|
||||
assertEquals(List.of(export), dynamoDb("DescribeExport"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbReturnsExactArnIfTableNameIsAlreadyArn() {
|
||||
String fullArn = "arn:aws:dynamodb:us-east-1:000000000000:table/FgacTable";
|
||||
setJsonBody("{\"TableName\":\"" + fullArn + "\"}");
|
||||
String arn = builder.build("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(fullArn, arn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbBuildsArnFromResourceArn() {
|
||||
String tagArn = "arn:aws:dynamodb:us-east-1:000000000000:table/FgacTable";
|
||||
setJsonBody("{\"ResourceArn\":\"" + tagArn + "\",\"Tags\":[{\"Key\":\"env\",\"Value\":\"dev\"}]}");
|
||||
String arn = builder.build("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(tagArn, arn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbBuildsArnFromTableArn() {
|
||||
String exportArn = "arn:aws:dynamodb:us-east-1:000000000000:table/ExportTable";
|
||||
setJsonBody("{\"TableArn\":\"" + exportArn + "\",\"S3Bucket\":\"my-bucket\"}");
|
||||
String arn = builder.build("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(exportArn, arn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbBuildsArnFromStreamArn() {
|
||||
String streamArn = "arn:aws:dynamodb:us-east-1:000000000000:table/FgacTable/stream/2026-09-01T00:00:00.000";
|
||||
setJsonBody("{\"StreamArn\":\"" + streamArn + "\"}");
|
||||
String arn = builder.build("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(streamArn, arn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbBuildsArnFromExportArn() {
|
||||
String exportArn = "arn:aws:dynamodb:us-east-1:000000000000:table/FgacTable/export/01693526400000-abcd";
|
||||
setJsonBody("{\"ExportArn\":\"" + exportArn + "\"}");
|
||||
String arn = builder.build("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(exportArn, arn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbBuildsArnFromTheSourceOfAPointInTimeRestore() {
|
||||
void dynamoDbChecksThePointInTimeRestoreOnItsSourceTable() {
|
||||
setJsonBody("{\"SourceTableName\":\"Music\",\"TargetTableName\":\"MusicCopy\"}");
|
||||
assertEquals("arn:aws:dynamodb:us-east-1:000000000000:table/Music",
|
||||
builder.build("dynamodb", ctx, "us-east-1", "000000000000"));
|
||||
String sourceArn = "arn:aws:dynamodb:eu-west-2:000000000000:table/Music";
|
||||
setJsonBody("{\"SourceTableArn\":\"" + sourceArn + "\",\"TargetTableName\":\"MusicCopy\"}");
|
||||
assertEquals(sourceArn, builder.build("dynamodb", ctx, "us-east-1", "000000000000"));
|
||||
assertEquals(List.of(DDB + "Music"), dynamoDb("RestoreTableToPointInTime"));
|
||||
String source = "arn:aws:dynamodb:eu-west-2:000000000000:table/Music";
|
||||
setJsonBody("{\"SourceTableArn\":\"" + source + "\",\"TargetTableName\":\"MusicCopy\"}");
|
||||
assertEquals(source, dynamoDb("RestoreTableToPointInTime").getFirst());
|
||||
}
|
||||
|
||||
/** A batch's tables are the keys of its RequestItems, which botocore keys by the shape a table's name has. */
|
||||
@Test
|
||||
void dynamoDbBuildsArnFromSingleTableBatchRequest() {
|
||||
void dynamoDbChecksABatchOnEveryTableItsRequestItemsKey() {
|
||||
setJsonBody("{\"RequestItems\":{\"MyTable\":{\"Keys\":[]}}}");
|
||||
String arn = builder.build("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals("arn:aws:dynamodb:us-east-1:000000000000:table/MyTable", arn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbBuildsArnsFromMultiTableBatchRequest() {
|
||||
assertEquals(List.of(DDB + "MyTable"), dynamoDb("BatchGetItem"));
|
||||
setJsonBody("{\"RequestItems\":{\"TableA\":{\"Keys\":[]},\"TableB\":{\"Keys\":[]}}}");
|
||||
List<String> arns = builder.buildResources("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(List.of(
|
||||
"arn:aws:dynamodb:us-east-1:000000000000:table/TableA",
|
||||
"arn:aws:dynamodb:us-east-1:000000000000:table/TableB"
|
||||
), arns);
|
||||
assertEquals(List.of(DDB + "TableA", DDB + "TableB"), dynamoDb("BatchGetItem"));
|
||||
assertEquals(List.of(DDB + "TableA", DDB + "TableB"), dynamoDb("BatchWriteItem"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Each of a transaction's items is checked as the action the developer guide gives its kind, on its own table,
|
||||
* with the item it comes from: {@code Put} as {@code dynamodb:PutItem}, {@code ConditionCheck} as
|
||||
* {@code dynamodb:ConditionCheckItem}, {@code Get} as {@code dynamodb:GetItem}; the transaction's own action never.
|
||||
*/
|
||||
@Test
|
||||
void dynamoDbBuildsArnFromSingleTableTransactRequest() {
|
||||
setJsonBody("{\"TransactItems\":[{\"Put\":{\"TableName\":\"MyTable\"}},{\"Delete\":{\"TableName\":\"MyTable\"}}]}");
|
||||
String arn = builder.build("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals("arn:aws:dynamodb:us-east-1:000000000000:table/MyTable", arn);
|
||||
void dynamoDbChecksEachTransactionItemAsItsKindsAction() {
|
||||
setJsonBody("{\"TransactItems\":[{\"Put\":{\"TableName\":\"TableA\"}},"
|
||||
+ "{\"ConditionCheck\":{\"TableName\":\"TableB\"}},{\"Delete\":{\"TableName\":\"TableA\"}}]}");
|
||||
assertTrue(RequestResources.checkedByParts("dynamodb:TransactWriteItems"));
|
||||
List<RequestResources.Target> targets = dynamoDbTargets("TransactWriteItems");
|
||||
assertEquals(List.of("dynamodb:ConditionCheckItem", "dynamodb:PutItem", "dynamodb:DeleteItem"),
|
||||
targets.stream().map(RequestResources.Target::action).toList());
|
||||
assertEquals(List.of(List.of(DDB + "TableB"), List.of(DDB + "TableA"), List.of(DDB + "TableA")),
|
||||
targets.stream().map(RequestResources.Target::resources).toList());
|
||||
assertEquals("TableB", targets.getFirst().element().path("TableName").asText());
|
||||
setJsonBody("{\"TransactItems\":[{\"Get\":{\"TableName\":\"MyTable\"}}]}");
|
||||
assertEquals(List.of(new RequestResources.Target("dynamodb:GetItem", List.of(DDB + "MyTable"),
|
||||
dynamoDbTargets("TransactGetItems").getFirst().element())),
|
||||
dynamoDbTargets("TransactGetItems"));
|
||||
assertEquals(List.of(), dynamoDbTargets("GetItem"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A PartiQL statement is checked as the action the developer guide gives its verb, on the table or index it names,
|
||||
* as DynamoDB parses it, a quoted keyword or name included; each statement of a batch or transaction apart.
|
||||
*/
|
||||
@Test
|
||||
void dynamoDbBuildsArnsFromMultiTableTransactRequest() {
|
||||
setJsonBody("{\"TransactItems\":[{\"Put\":{\"TableName\":\"TableA\"}},{\"Delete\":{\"TableName\":\"TableB\"}},{\"Get\":{\"TableName\":\"TableA\"}}]}");
|
||||
List<String> arns = builder.buildResources("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(List.of(
|
||||
"arn:aws:dynamodb:us-east-1:000000000000:table/TableA",
|
||||
"arn:aws:dynamodb:us-east-1:000000000000:table/TableB"
|
||||
), arns);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbBuildsArnFromPartiQLStatement() {
|
||||
setJsonBody("{\"Statement\":\"SELECT * FROM \\\"UsersTable\\\" WHERE id = '1'\"}");
|
||||
List<String> arns = builder.buildResources("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(List.of("arn:aws:dynamodb:us-east-1:000000000000:table/UsersTable"), arns);
|
||||
|
||||
setJsonBody("{\"Statement\":\"INSERT INTO OrdersTable VALUE {'id': '1'}\"}");
|
||||
arns = builder.buildResources("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(List.of("arn:aws:dynamodb:us-east-1:000000000000:table/OrdersTable"), arns);
|
||||
|
||||
setJsonBody("{\"Statement\":\"UPDATE \\\"ProductsTable\\\" SET price=10 WHERE id='1'\"}");
|
||||
arns = builder.buildResources("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(List.of("arn:aws:dynamodb:us-east-1:000000000000:table/ProductsTable"), arns);
|
||||
|
||||
setJsonBody("{\"Statement\":\"DELETE FROM \\\"LogsTable\\\" WHERE id='1'\"}");
|
||||
arns = builder.buildResources("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(List.of("arn:aws:dynamodb:us-east-1:000000000000:table/LogsTable"), arns);
|
||||
|
||||
setJsonBody("{\"Statement\":\"SELECT * FROM \\\"Table With Spaces & Special:Chars\\\" WHERE id = '1'\"}");
|
||||
arns = builder.buildResources("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(List.of("arn:aws:dynamodb:us-east-1:000000000000:table/Table With Spaces & Special:Chars"), arns);
|
||||
|
||||
setJsonBody("{\"Statement\":\"SELECT * FROM 'Table.With.Single.Quotes#1' WHERE id = '1'\"}");
|
||||
arns = builder.buildResources("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(List.of("arn:aws:dynamodb:us-east-1:000000000000:table/Table.With.Single.Quotes#1"), arns);
|
||||
|
||||
setJsonBody("{\"Statement\":\"SELECT \\\"FROM TableEvil\\\" FROM \\\"TableA\\\" WHERE pk = 1\"}");
|
||||
arns = builder.buildResources("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(List.of("arn:aws:dynamodb:us-east-1:000000000000:table/TableA"), arns);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbBuildsArnsFromPartiQLBatchStatements() {
|
||||
setJsonBody("{\"Statements\":[{\"Statement\":\"SELECT * FROM \\\"TableA\\\" WHERE id = '1'\"},{\"Statement\":\"SELECT * FROM TableB WHERE id = '2'\"}]}");
|
||||
List<String> arns = builder.buildResources("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(List.of(
|
||||
"arn:aws:dynamodb:us-east-1:000000000000:table/TableA",
|
||||
"arn:aws:dynamodb:us-east-1:000000000000:table/TableB"
|
||||
), arns);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbBuildsArnsFromPartiQLTransactStatements() {
|
||||
setJsonBody("{\"TransactStatements\":[{\"Statement\":\"INSERT INTO \\\"TableA\\\" VALUE {'id': '1'}\"},{\"Statement\":\"UPDATE \\\"TableB\\\" SET x=1 WHERE id='2'\"}]}");
|
||||
List<String> arns = builder.buildResources("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(List.of(
|
||||
"arn:aws:dynamodb:us-east-1:000000000000:table/TableA",
|
||||
"arn:aws:dynamodb:us-east-1:000000000000:table/TableB"
|
||||
), arns);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbBuildsArnFromTableCreationParameters() {
|
||||
setJsonBody("{\"TableCreationParameters\":{\"TableName\":\"ImportTarget\"},\"InputFormat\":\"DYNAMODB_JSON\"}");
|
||||
String arn = builder.build("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals("arn:aws:dynamodb:us-east-1:000000000000:table/ImportTarget", arn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dynamoDbReturnsWildcardWhenNoTableSpecified() {
|
||||
setJsonBody("{}");
|
||||
String arn = builder.build("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals("*", arn);
|
||||
void dynamoDbChecksEachPartiQLStatementAsItsVerbsAction() {
|
||||
Map<String, String> statements = new LinkedHashMap<>();
|
||||
statements.put("SELECT * FROM \\\"UsersTable\\\" WHERE id = '1'", "dynamodb:PartiQLSelect UsersTable");
|
||||
statements.put("INSERT INTO OrdersTable VALUE {'id': '1'}", "dynamodb:PartiQLInsert OrdersTable");
|
||||
statements.put("UPDATE \\\"ProductsTable\\\" SET price=10 WHERE id='1'",
|
||||
"dynamodb:PartiQLUpdate ProductsTable");
|
||||
statements.put("DELETE FROM \\\"LogsTable\\\" WHERE id='1'", "dynamodb:PartiQLDelete LogsTable");
|
||||
statements.put("SELECT * FROM \\\"Table With Spaces & Special:Chars\\\" WHERE id = '1'",
|
||||
"dynamodb:PartiQLSelect Table With Spaces & Special:Chars");
|
||||
statements.put("SELECT \\\"FROM TableEvil\\\" FROM \\\"TableA\\\" WHERE pk = 1",
|
||||
"dynamodb:PartiQLSelect TableA");
|
||||
statements.forEach((statement, expected) -> {
|
||||
setJsonBody("{\"Statement\":\"" + statement + "\"}");
|
||||
List<RequestResources.Target> targets = dynamoDbTargets("ExecuteStatement");
|
||||
String[] parts = expected.split(" ", 2);
|
||||
assertEquals(List.of(new RequestResources.Target(parts[0], List.of(DDB + parts[1]), null)), targets,
|
||||
statement);
|
||||
});
|
||||
setJsonBody("{\"Statement\":\"SELECT * FROM \\\"Music\\\".\\\"byArtist\\\" WHERE a = 'x'\"}");
|
||||
assertEquals(List.of(new RequestResources.Target("dynamodb:PartiQLSelect",
|
||||
List.of(DDB + "Music/index/byArtist"), null)), dynamoDbTargets("ExecuteStatement"));
|
||||
setJsonBody("{\"Statements\":[{\"Statement\":\"SELECT * FROM \\\"TableA\\\" WHERE id = '1'\"},"
|
||||
+ "{\"Statement\":\"DELETE FROM TableB WHERE id = '2'\"}]}");
|
||||
List<RequestResources.Target> batch = dynamoDbTargets("BatchExecuteStatement");
|
||||
assertEquals(List.of("dynamodb:PartiQLSelect TableA", "dynamodb:PartiQLDelete TableB"), batch.stream()
|
||||
.map(target -> target.action() + " " + target.resources().getFirst().substring(DDB.length())).toList());
|
||||
assertTrue(batch.getFirst().element().path("Statement").asText().contains("TableA"));
|
||||
setJsonBody("{\"TransactStatements\":[{\"Statement\":\"INSERT INTO \\\"TableA\\\" VALUE {'id': '1'}\"},"
|
||||
+ "{\"Statement\":\"UPDATE \\\"TableB\\\" SET x=1 WHERE id='2'\"}]}");
|
||||
assertEquals(List.of("dynamodb:PartiQLInsert", "dynamodb:PartiQLUpdate"),
|
||||
dynamoDbTargets("ExecuteTransaction").stream().map(RequestResources.Target::action).sorted().toList());
|
||||
setJsonBody("{\"TransactStatements\":[{\"Statement\":\"INSERT INTO \\\"TableA\\\" VALUE {'id': '1'}\"},"
|
||||
+ "{\"Statement\":\"EXISTS(SELECT * FROM \\\"TableB\\\" WHERE id = ? AND x = 1)\"}]}");
|
||||
assertEquals(List.of("dynamodb:PartiQLSelect TableB", "dynamodb:PartiQLInsert TableA"),
|
||||
dynamoDbTargets("ExecuteTransaction").stream().map(target -> target.action() + " "
|
||||
+ target.resources().getFirst().substring(DDB.length())).toList());
|
||||
setJsonBody("{\"Statements\":[{\"Statement\":\"-- nothing\"}]}");
|
||||
assertEquals(List.of(), dynamoDbTargets("BatchExecuteStatement"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1319,8 +1288,7 @@ class ResourceArnBuilderTest {
|
||||
String json = "{\"TableName\":\"FgacTable\",\"Item\":{\"PK\":{\"S\":\"USER_1\"}}}";
|
||||
setJsonBody(json);
|
||||
|
||||
String arn = builder.build("dynamodb", ctx, "us-east-1", "000000000000");
|
||||
assertEquals("arn:aws:dynamodb:us-east-1:000000000000:table/FgacTable", arn);
|
||||
assertEquals(List.of(DDB + "FgacTable"), dynamoDb("PutItem"));
|
||||
|
||||
InputStream entityStream = ctx.getEntityStream();
|
||||
assertNotNull(entityStream);
|
||||
@@ -1611,14 +1579,20 @@ class ResourceArnBuilderTest {
|
||||
ResourceArnBuilder backed = backedBy(kms);
|
||||
|
||||
setJsonBody("{\"CiphertextBlob\":\"" + encoded + "\",\"DestinationKeyId\":\"alias/destination\"}");
|
||||
assertEquals(Map.of("kms:ReEncryptFrom", List.of(KMS_OTHER_KEY_ARN), "kms:ReEncryptTo", List.of(KMS_KEY_ARN)),
|
||||
backed.checkedAs("kms", "kms:ReEncrypt", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
assertEquals(List.of(new RequestResources.Target("kms:ReEncryptFrom", List.of(KMS_OTHER_KEY_ARN), null),
|
||||
new RequestResources.Target("kms:ReEncryptTo", List.of(KMS_KEY_ARN), null)),
|
||||
backed.targets("kms", "kms:ReEncrypt", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
setJsonBody("{\"CiphertextBlob\":\"" + encoded + "\",\"SourceKeyId\":\"alias/source\","
|
||||
+ "\"DestinationKeyId\":\"alias/destination\"}");
|
||||
assertEquals(List.of("kms:ReEncryptFrom", "kms:ReEncryptTo"),
|
||||
List.copyOf(backed.checkedAs("kms", "kms:ReEncrypt", ctx, "us-east-1", ACCOUNT, "aws").keySet()));
|
||||
assertEquals(List.of(new RequestResources.Target("kms:ReEncryptFrom", List.of(KMS_OTHER_KEY_ARN), null),
|
||||
new RequestResources.Target("kms:ReEncryptTo", List.of(KMS_KEY_ARN), null)),
|
||||
backed.targets("kms", "kms:ReEncrypt", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
// A source no member names, nor the ciphertext, is not checked; the destination is.
|
||||
setJsonBody("{\"CiphertextBlob\":\"not base64!\",\"DestinationKeyId\":\"alias/destination\"}");
|
||||
assertEquals(List.of(new RequestResources.Target("kms:ReEncryptTo", List.of(KMS_KEY_ARN), null)),
|
||||
backed.targets("kms", "kms:ReEncrypt", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
assertEquals(List.of("*"), kms(backed, "ReEncrypt"));
|
||||
assertEquals(Map.of(), backed.checkedAs("kms", "kms:Encrypt", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
assertEquals(List.of(), backed.targets("kms", "kms:Encrypt", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1630,8 +1604,9 @@ class ResourceArnBuilderTest {
|
||||
KmsService kms = mock(KmsService.class);
|
||||
when(kms.findKeyArnOfAccount(KMS_KEY_ID, ACCOUNT, "us-east-1")).thenReturn(Optional.of(KMS_KEY_ARN));
|
||||
setJsonBody("{\"KeyId\":\"" + KMS_KEY_ID + "\",\"ReplicaRegion\":\"us-west-2\"}");
|
||||
assertEquals(Map.of("kms:ReplicateKey", List.of(KMS_KEY_ARN), "kms:CreateKey", List.of("*")),
|
||||
backedBy(kms).checkedAs("kms", "kms:ReplicateKey", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
assertEquals(List.of(new RequestResources.Target("kms:ReplicateKey", List.of(KMS_KEY_ARN), null),
|
||||
new RequestResources.Target("kms:CreateKey", List.of("*"), null)),
|
||||
backedBy(kms).targets("kms", "kms:ReplicateKey", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -205,13 +205,15 @@ class TaskPermissionsTest {
|
||||
assertEquals(Optional.empty(), TaskPermissions.of(integration("dynamodb:query"), json("{\"TableName\":\"t\"}"), machine("aws")));
|
||||
}
|
||||
|
||||
/** A table named by its ARN is checked as given and as the state machine's own, the table execution reaches. */
|
||||
@Test
|
||||
void aTableNamedByItsArnIsEvaluatedAsGiven() throws Exception {
|
||||
void aTableNamedByItsArnIsEvaluatedAsGivenAndAsTheMachinesOwn() throws Exception {
|
||||
String arn = "arn:aws:dynamodb:eu-west-1:444455556666:table/orders";
|
||||
assertEquals(List.of(new Permission("dynamodb:PutItem", arn)), sdkPermissions("putItem", "{\"TableName\":\"" + arn + "\"}"));
|
||||
assertEquals(List.of(new Permission("dynamodb:PutItem", arn)),
|
||||
TaskPermissions.of(integration("dynamodb:putItem"), json("{\"TableName\":\"" + arn + "\"}"), machine("aws"))
|
||||
.orElseThrow().permissions());
|
||||
List<Permission> both = List.of(new Permission("dynamodb:PutItem", arn),
|
||||
new Permission("dynamodb:PutItem", table("orders")));
|
||||
assertEquals(both, sdkPermissions("putItem", "{\"TableName\":\"" + arn + "\"}"));
|
||||
assertEquals(both, TaskPermissions.of(integration("dynamodb:putItem"), json("{\"TableName\":\"" + arn + "\"}"),
|
||||
machine("aws")).orElseThrow().permissions());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -233,10 +235,10 @@ class TaskPermissionsTest {
|
||||
@Test
|
||||
void aTransactWriteNeedsEachItemsOwnActionOnItsTable() throws Exception {
|
||||
Map<String, List<String>> enclosing = Map.of("dynamodb:EnclosingOperation", List.of("TransactWriteItems"));
|
||||
assertEquals(List.of(new Permission("dynamodb:PutItem", table("aaa"), enclosing),
|
||||
assertEquals(List.of(new Permission("dynamodb:ConditionCheckItem", table("ccc"), enclosing),
|
||||
new Permission("dynamodb:PutItem", table("aaa"), enclosing),
|
||||
new Permission("dynamodb:DeleteItem", table("bbb"), enclosing),
|
||||
new Permission("dynamodb:UpdateItem", table("aaa"), enclosing),
|
||||
new Permission("dynamodb:ConditionCheckItem", table("ccc"), enclosing)),
|
||||
new Permission("dynamodb:UpdateItem", table("aaa"), enclosing)),
|
||||
sdkPermissions("transactWriteItems", """
|
||||
{"TransactItems":[{"Put":{"TableName":"aaa"}},{"Delete":{"TableName":"bbb"}},
|
||||
{"Update":{"TableName":"aaa"}},{"ConditionCheck":{"TableName":"ccc"}}]}"""));
|
||||
@@ -250,22 +252,20 @@ class TaskPermissionsTest {
|
||||
sdkPermissions("transactGetItems", "{\"TransactItems\":[{\"Get\":{\"TableName\":\"aaa\"}},{\"Get\":{\"TableName\":\"bbb\"}}]}"));
|
||||
}
|
||||
|
||||
/** Execution resolves an ARN within the request's account, so that is the table the item is checked on. */
|
||||
/** Execution resolves an ARN within the request's account, so the item is checked on that table too. */
|
||||
@Test
|
||||
void aTransactItemNamedByAnArnIsTheTableItsExecutionReaches() throws Exception {
|
||||
assertEquals(List.of(new Permission("dynamodb:PutItem", table("aaa"),
|
||||
Map.of("dynamodb:EnclosingOperation", List.of("TransactWriteItems")))),
|
||||
void aTransactItemNamedByAnArnIsAlsoTheTableItsExecutionReaches() throws Exception {
|
||||
Map<String, List<String>> enclosing = Map.of("dynamodb:EnclosingOperation", List.of("TransactWriteItems"));
|
||||
assertEquals(List.of(new Permission("dynamodb:PutItem", "arn:aws:dynamodb:eu-west-1:444455556666:table/aaa",
|
||||
enclosing), new Permission("dynamodb:PutItem", table("aaa"), enclosing)),
|
||||
sdkPermissions("transactWriteItems", """
|
||||
{"TransactItems":[{"Put":{"TableName":"arn:aws:dynamodb:eu-west-1:444455556666:table/aaa"}}]}"""));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"{}", "{\"TransactItems\":\"x\"}", "{\"TransactItems\":[{\"Put\":{}}]}",
|
||||
"{\"TransactItems\":[{\"Get\":{\"TableName\":\"aaa\"}}]}",
|
||||
"{\"TransactItems\":[{\"Put\":{\"TableName\":\"arn:aws:dynamodb:ap-south-1:444455556666:table/aaa\"}}]}",
|
||||
"{\"TransactItems\":[{\"Put\":{\"TableName\":\"a\"}}]}",
|
||||
"{\"TransactItems\":[{\"Put\":{\"TableName\":\"arn:aws:s3:::aaa\"}}]}"})
|
||||
void aTransactionNamingNoTableItCanReachNeedsNoPermission(String request) throws Exception {
|
||||
"{\"TransactItems\":[{\"Get\":{\"TableName\":\"aaa\"}}]}"})
|
||||
void aTransactionNamingNoTableNeedsNoPermission(String request) throws Exception {
|
||||
assertEquals(List.of(), sdkPermissions("transactWriteItems", request));
|
||||
}
|
||||
|
||||
@@ -287,9 +287,40 @@ class TaskPermissionsTest {
|
||||
sdkPermissions("executeStatement", "{\"Statement\":\"INSERT INTO \\\"a\\\" VALUE {'pk':'x'}\"}"));
|
||||
}
|
||||
|
||||
/** Each statement of a batch or a transaction is checked apart, a transaction's as enclosed by it. */
|
||||
@Test
|
||||
void aResourceThatIsNotAnArnNeedsNoPermission() throws Exception {
|
||||
assertEquals(List.of(), sdkPermissions("tagResource", "{\"ResourceArn\":\"not-an-arn\"}"));
|
||||
void eachStatementOfABatchIsAuthorizedByWhatItDoesOnWhatItNames() throws Exception {
|
||||
assertEquals(List.of(new Permission("dynamodb:PartiQLSelect", table("a") + "/index/byName"),
|
||||
new Permission("dynamodb:PartiQLDelete", table("b"))),
|
||||
sdkPermissions("batchExecuteStatement", """
|
||||
{"Statements":[{"Statement":"DELETE FROM \\"b\\" WHERE pk = 'x'"},
|
||||
{"Statement":"SELECT * FROM \\"a\\".\\"byName\\" WHERE pk = 'x'"}]}"""));
|
||||
Map<String, List<String>> enclosing = Map.of("dynamodb:EnclosingOperation", List.of("ExecuteTransaction"));
|
||||
assertEquals(List.of(new Permission("dynamodb:PartiQLInsert", table("a"), enclosing),
|
||||
new Permission("dynamodb:PartiQLDelete", table("b"), enclosing)),
|
||||
sdkPermissions("executeTransaction", """
|
||||
{"TransactStatements":[{"Statement":"DELETE FROM \\"b\\" WHERE pk = 'x'"},
|
||||
{"Statement":"INSERT INTO \\"a\\" VALUE {'pk':'x'}"}]}"""));
|
||||
}
|
||||
|
||||
/** An EXISTS statement runs the SELECT it evaluates, so it needs PartiQLSelect on that SELECT's table. */
|
||||
@Test
|
||||
void anExistsStatementIsAuthorizedAsTheSelectItEvaluates() throws Exception {
|
||||
Map<String, List<String>> enclosing = Map.of("dynamodb:EnclosingOperation", List.of("ExecuteTransaction"));
|
||||
assertEquals(List.of(new Permission("dynamodb:PartiQLSelect", table("b"), enclosing),
|
||||
new Permission("dynamodb:PartiQLInsert", table("a"), enclosing)),
|
||||
sdkPermissions("executeTransaction", """
|
||||
{"TransactStatements":[{"Statement":"INSERT INTO \\"a\\" VALUE {'pk':'x'}"},
|
||||
{"Statement":"EXISTS(SELECT * FROM \\"b\\" WHERE pk = 'x' AND v = 1)"}]}"""));
|
||||
assertEquals(List.of(),
|
||||
sdkPermissions("executeTransaction", "{\"TransactStatements\":[{\"Statement\":\"-- nothing\"}]}"));
|
||||
}
|
||||
|
||||
/** A value naming no resource of the action's types names none, so the call is checked on any resource. */
|
||||
@Test
|
||||
void aResourceThatIsNotAnArnIsCheckedOnAnyResource() throws Exception {
|
||||
assertEquals(List.of(new Permission("dynamodb:TagResource", "*")),
|
||||
sdkPermissions("tagResource", "{\"ResourceArn\":\"not-an-arn\"}"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
||||
Reference in new issue
Block a user