diff --git a/.github/workflows/iam-data-drift.yml b/.github/workflows/iam-data-drift.yml
index 6700ceeb2f..c3329ba5d9 100644
--- a/.github/workflows/iam-data-drift.yml
+++ b/.github/workflows/iam-data-drift.yml
@@ -1,12 +1,12 @@
name: IAM Data Drift
-# Checks the seven vendored files that come from AWS's live service reference rather than from a
+# Checks the eight vendored files that come from AWS's live service reference rather than from a
# pinned dependency: the IAM service namespace list, the map of which resource each IAM action is
# authorized against, the map of operations AWS authorizes as an action of another name, the
# table of the operations that pass a role and the services they pass it to, the table of the
# operations that pass a Lambda network connector, the table of the
# tagging actions operations that tag what they create need, and the table of the resources each
-# operation's request names. That
+# operation's request names, and the DynamoDB condition key table. That
# needs the live service reference index, so unlike every other check here it can
# fail without anything in the repository having changed: an AWS outage, or a namespace AWS has
# retired. It therefore runs on its own, never as part of a job that ordinary changes trigger.
@@ -55,6 +55,11 @@ on:
- 'src/main/resources/aws/iam-request-resources.json'
- 'tools/aws/regen_iam_request_resources.py'
- 'tools/aws/test_regen_iam_request_resources.py'
+ - 'src/main/resources/aws/dynamodb-condition-keys.json'
+ - 'tools/aws/regen_dynamodb_condition_keys.py'
+ - 'tools/aws/test_regen_dynamodb_condition_keys.py'
+ - 'tools/aws/regen_partitions.py'
+ - 'tools/aws/regen_query_services.py'
- '.github/workflows/iam-data-drift.yml'
schedule:
# Mondays at 06:00 UTC, before the working week rather than during it.
diff --git a/.github/workflows/partition-literals.yml b/.github/workflows/partition-literals.yml
index b24f1485bd..54a6012664 100644
--- a/.github/workflows/partition-literals.yml
+++ b/.github/workflows/partition-literals.yml
@@ -100,6 +100,9 @@ jobs:
- name: Run generator tests
run: make aws-data-test
+ - name: Check DynamoDB condition request members
+ run: make dynamodb-condition-keys-check
+
- name: Check partitions.json against a fresh generation
run: make aws-data-check
diff --git a/Makefile b/Makefile
index 2da6cbdda9..4e0bfebf32 100644
--- a/Makefile
+++ b/Makefile
@@ -419,6 +419,9 @@ IAM_PASSED_NETWORK_CONNECTORS_PATHS := src/main/resources/aws/iam-passed-network
tools/aws/test_regen_iam_passed_network_connectors.py
IAM_TAG_ON_CREATE_PATHS := src/main/resources/aws/iam-tag-on-create.json tools/aws/regen_iam_tag_on_create.py \
$(IAM_PASSED_ROLES_GENERATOR) tools/aws/test_regen_iam_tag_on_create.py
+DYNAMODB_CONDITION_KEYS_PATHS := src/main/resources/aws/dynamodb-condition-keys.json \
+ tools/aws/regen_dynamodb_condition_keys.py tools/aws/test_regen_dynamodb_condition_keys.py \
+ tools/aws/regen_partitions.py tools/aws/regen_query_services.py
IAM_REQUEST_RESOURCES_PATHS := src/main/resources/aws/iam-request-resources.json \
tools/aws/regen_iam_request_resources.py $(IAM_PASSED_ROLES_GENERATOR) \
tools/aws/test_regen_iam_request_resources.py
@@ -427,7 +430,7 @@ iam-data-verify: ## CI gate (online): every vendored IAM file must still match A
@# Every check runs even when an earlier one fails, so one file's drift cannot hide another's
@# state. Sequential steps in CI stop at the first failure, which once left the action
@# resource gate unexercised while the namespace list was stale.
- @namespaces=0; actions=0; authorized=0; passed=0; connectors=0; tagged=0; requested=0; \
+ @namespaces=0; actions=0; authorized=0; passed=0; connectors=0; tagged=0; requested=0; dynamodb=0; \
covers() { \
[ -z "$(strip $(CHANGED))" ] && return 0; \
for path in $(CHANGED); do case " $$1 " in *" $$path "*) return 0;; esac; done; \
@@ -455,8 +458,11 @@ iam-data-verify: ## CI gate (online): every vendored IAM file must still match A
if covers "$(IAM_REQUEST_RESOURCES_PATHS)" "the table of the resources requests name"; then \
$(MAKE) --no-print-directory iam-request-resources-verify || requested=$$?; \
fi; \
+ if covers "$(DYNAMODB_CONDITION_KEYS_PATHS)" "the DynamoDB condition key table"; then \
+ $(MAKE) --no-print-directory dynamodb-condition-keys-verify || dynamodb=$$?; \
+ fi; \
if [ $$namespaces -ne 0 ] || [ $$actions -ne 0 ] || [ $$authorized -ne 0 ] || [ $$passed -ne 0 ] \
- || [ $$connectors -ne 0 ] || [ $$tagged -ne 0 ] || [ $$requested -ne 0 ]; then \
+ || [ $$connectors -ne 0 ] || [ $$tagged -ne 0 ] || [ $$requested -ne 0 ] || [ $$dynamodb -ne 0 ]; then \
echo ""; \
echo "error: vendored IAM data does not match upstream:"; \
if [ $$namespaces -ne 0 ]; then \
@@ -480,6 +486,7 @@ iam-data-verify: ## CI gate (online): every vendored IAM file must still match A
if [ $$requested -ne 0 ]; then \
echo " the table of the resources requests name, see its message above"; \
fi; \
+ if [ $$dynamodb -ne 0 ]; then echo " the DynamoDB condition key table"; fi; \
exit 1; \
fi
@@ -649,3 +656,11 @@ cfn-property-types-verify: ## CI gate (online): the vendored CloudFormation prop
cfn-property-types-test: ## Run the CloudFormation property type generator's unit tests
$(PYTHON) -m pytest tools/aws/test_regen_cfn_property_types.py -q
+
+.PHONY: dynamodb-condition-keys-sync dynamodb-condition-keys-check dynamodb-condition-keys-verify
+dynamodb-condition-keys-sync: ## Regenerate DynamoDB IAM condition keys from AWS and botocore
+ $(PYTHON) tools/aws/regen_dynamodb_condition_keys.py
+dynamodb-condition-keys-check: ## Check DynamoDB condition request members against pinned botocore
+ $(PYTHON) tools/aws/regen_dynamodb_condition_keys.py --check
+dynamodb-condition-keys-verify: ## Check DynamoDB condition action keys against AWS
+ $(PYTHON) tools/aws/regen_dynamodb_condition_keys.py --verify
diff --git a/compatibility-tests/sdk-test-python/iam/README.md b/compatibility-tests/sdk-test-python/iam/README.md
new file mode 100644
index 0000000000..cb8348837b
--- /dev/null
+++ b/compatibility-tests/sdk-test-python/iam/README.md
@@ -0,0 +1,15 @@
+# IAM-enabled compatibility cases
+
+These cases require Floci with `floci.services.iam.enforcement-enabled=true` and
+administrative test credentials. They are separate from the default `tests/`
+suite, which runs with IAM enforcement disabled.
+
+From `compatibility-tests/sdk-test-python`, run:
+
+```sh
+FLOCI_ENDPOINT=http://localhost:4566 pytest -q iam/test_dynamodb_select_defaults.py
+```
+
+The DynamoDB selection cases create disposable tables and roles, use scoped STS
+sessions, and delete their resources in reverse dependency order. They verify
+Query/Scan table and index defaults and explicit projection policies.
diff --git a/compatibility-tests/sdk-test-python/iam/test_dynamodb_select_defaults.py b/compatibility-tests/sdk-test-python/iam/test_dynamodb_select_defaults.py
new file mode 100644
index 0000000000..4c8b0d084e
--- /dev/null
+++ b/compatibility-tests/sdk-test-python/iam/test_dynamodb_select_defaults.py
@@ -0,0 +1,94 @@
+"""Query/Scan Select defaults with IAM enforcement enabled."""
+
+from contextlib import ExitStack
+import json
+
+import boto3
+import pytest
+from botocore.exceptions import ClientError
+
+
+@pytest.mark.parametrize("action", ["query", "scan"])
+@pytest.mark.parametrize("index", [False, True])
+def test_select_defaults_require_projection(
+ dynamodb_client, iam_client, sts_client, aws_config, unique_name, action, index
+):
+ table = f"select-{unique_name}"
+ role_name = f"select-{unique_name}"
+ with ExitStack() as cleanup:
+ dynamodb_client.create_table(
+ TableName=table,
+ KeySchema=[{"AttributeName": "pk", "KeyType": "HASH"}],
+ AttributeDefinitions=[
+ {"AttributeName": "pk", "AttributeType": "S"},
+ {"AttributeName": "group_key", "AttributeType": "S"},
+ ],
+ GlobalSecondaryIndexes=[{
+ "IndexName": "by-group",
+ "KeySchema": [{"AttributeName": "group_key", "KeyType": "HASH"}],
+ "Projection": {"ProjectionType": "KEYS_ONLY"},
+ }],
+ BillingMode="PAY_PER_REQUEST",
+ )
+ cleanup.callback(dynamodb_client.delete_table, TableName=table)
+ dynamodb_client.get_waiter("table_exists").wait(TableName=table)
+ dynamodb_client.put_item(TableName=table, Item={
+ "pk": {"S": "one"}, "group_key": {"S": "group"}, "extra": {"S": "visible"}
+ })
+ role = iam_client.create_role(
+ RoleName=role_name,
+ AssumeRolePolicyDocument=json.dumps({
+ "Version": "2012-10-17", "Statement": [{
+ "Effect": "Allow", "Principal": {"AWS": "*"}, "Action": "sts:AssumeRole"
+ }]
+ }),
+ )["Role"]
+ cleanup.callback(iam_client.delete_role, RoleName=role_name)
+ iam_client.put_role_policy(RoleName=role_name, PolicyName="read", PolicyDocument=json.dumps({
+ "Version": "2012-10-17", "Statement": [{
+ "Effect": "Allow", "Action": "dynamodb:*", "Resource": "*"
+ }]
+ }))
+ cleanup.callback(iam_client.delete_role_policy, RoleName=role_name, PolicyName="read")
+
+ def scoped_client(selection, operator):
+ credentials = sts_client.assume_role(
+ RoleArn=role["Arn"], RoleSessionName="select-test",
+ Policy=json.dumps({"Version": "2012-10-17", "Statement": [{
+ "Effect": "Allow", "Action": ["dynamodb:Query", "dynamodb:Scan"],
+ "Resource": "*", "Condition": {operator: {"dynamodb:Select": selection}}
+ }]}),
+ )["Credentials"]
+ client = boto3.client(
+ "dynamodb", endpoint_url=aws_config["endpoint_url"],
+ region_name=aws_config["region_name"],
+ aws_access_key_id=credentials["AccessKeyId"],
+ aws_secret_access_key=credentials["SecretAccessKey"],
+ aws_session_token=credentials["SessionToken"],
+ )
+ cleanup.callback(client.close)
+ return client
+
+ request = {"TableName": table}
+ if index:
+ request["IndexName"] = "by-group"
+ if action == "query":
+ request.update(
+ KeyConditionExpression="#key = :v",
+ ExpressionAttributeNames={"#key": "group_key" if index else "pk"},
+ ExpressionAttributeValues={":v": {"S": "group" if index else "one"}},
+ )
+ restricted = scoped_client("SPECIFIC_ATTRIBUTES", "StringEqualsIfExists")
+ with pytest.raises(ClientError) as error:
+ getattr(restricted, action)(**request)
+ assert error.value.response["Error"]["Code"] == "AccessDeniedException"
+ projected = getattr(restricted, action)(**request, ProjectionExpression="pk")
+ assert projected["Items"] == [{"pk": {"S": "one"}}]
+ allowed = scoped_client(
+ "ALL_PROJECTED_ATTRIBUTES" if index else "ALL_ATTRIBUTES", "StringEquals"
+ )
+ result = getattr(allowed, action)(**request)
+ expected = {"pk": {"S": "one"}, "group_key": {"S": "group"}}
+ if not index:
+ expected["extra"] = {"S": "visible"}
+ assert result["Items"] == [expected]
diff --git a/docs/services/dynamodb.md b/docs/services/dynamodb.md
index c020aa6228..aa85b58fac 100644
--- a/docs/services/dynamodb.md
+++ b/docs/services/dynamodb.md
@@ -68,6 +68,20 @@ the AWS [2011-12-05 DescribeTable](https://docs.aws.amazon.com/amazondynamodb/la
and [BatchWriteItem](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_BatchWriteItem_v20111205.html)
documentation.
+## Query and Scan IAM selection
+
+With IAM enforcement enabled, `dynamodb:Select` includes the effective selection
+for `Query` and `Scan`: `ALL_ATTRIBUTES` for an unprojected table read,
+`ALL_PROJECTED_ATTRIBUTES` for an unprojected index read, and
+`SPECIFIC_ATTRIBUTES` when a nonblank projection expression or a nonempty
+attribute list is supplied. Blank expressions and empty lists retain the table or
+index default for IAM evaluation. An explicit `Select` value
+is preserved. Legacy Query uses `Count` and `AttributesToGet` for the same purpose.
+
+`dynamodb:Attributes` still describes attributes named in the request, not all
+attributes returned. An attributes-only condition does not require a projection;
+use a `dynamodb:Select` condition when the policy must require specific attributes.
+
## Legacy conditional requests
The native backend accepts `KeyConditions` together with `FilterExpression`.
diff --git a/docs/services/iam.md b/docs/services/iam.md
index be048ba271..70dd701701 100644
--- a/docs/services/iam.md
+++ b/docs/services/iam.md
@@ -2354,6 +2354,9 @@ and requested attributes. `dynamodb:EnclosingOperation` identifies `TransactWrit
`TransactGetItems`; write items expose `ReturnValuesOnConditionCheckFailure` as
`dynamodb:ReturnValues` only when the request supplies a non-null value. An omitted value leaves
the condition key absent. Transaction API names alone do not grant item access.
+Transaction reads derive selection and requested attributes from the transaction `Get` shape:
+`ProjectionExpression`, its attribute-name aliases, and the key. Ignored `GetItem` fields such as
+`AttributesToGet` cannot satisfy a projected-read policy on `TransactGetItems`.
Transaction item authorization uses the effective local table ARN, matching execution.
A permission on a foreign account table cannot grant access to a same-named local table.
diff --git a/pom.xml b/pom.xml
index fc6aea2dcd..97e4db1717 100644
--- a/pom.xml
+++ b/pom.xml
@@ -330,6 +330,12 @@
+
+ software.amazon.awssdk
+ dynamodb
+ ${aws.sdk.version}
+ test
+
software.amazon.awssdk
sagemaker
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/IamConditionContextResolver.java b/src/main/java/io/github/hectorvent/floci/core/common/IamConditionContextResolver.java
index 326731c972..50d3f3ed49 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/IamConditionContextResolver.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/IamConditionContextResolver.java
@@ -821,8 +821,10 @@ public class IamConditionContextResolver {
// Execution resolves ARN inputs within the request account; authorize that same table.
String executionTable = DynamoDbTableNames.resolveWithRegion(tableName, region).name();
String itemAction = "dynamodb:" + operation + "Item";
- DynamoDbConditionKeys.Result keys = DynamoDbConditionKeys.extract(
- itemAction, request, describeTargetTable(executionTable));
+ TableDefinition table = describeTargetTable(executionTable);
+ DynamoDbConditionKeys.Result keys = read
+ ? DynamoDbConditionKeys.extractTransactionGet(request, table)
+ : DynamoDbConditionKeys.extract(itemAction, request, table);
Map> context = new LinkedHashMap<>();
context.put("dynamodb:EnclosingOperation", List.of(read ? "TransactGetItems" : "TransactWriteItems"));
if (!keys.leadingKeys().isEmpty()) {
@@ -831,6 +833,9 @@ public class IamConditionContextResolver {
if (!keys.attributes().isEmpty()) {
context.put("dynamodb:Attributes", keys.attributes());
}
+ if (keys.select() != null) {
+ context.put("dynamodb:Select", List.of(keys.select()));
+ }
if (!read && request.hasNonNull("ReturnValuesOnConditionCheckFailure")) {
context.put("dynamodb:ReturnValues",
List.of(request.path("ReturnValuesOnConditionCheckFailure").asText()));
@@ -842,20 +847,32 @@ public class IamConditionContextResolver {
return checks;
}
- /** Resolves each batch entry with its own schema, optionally restricted to one resource. */
+ /** Request-wide context for callers that do not yet have a resolved resource. */
Map> dynamoDbBatchConditionContext(String action, ContainerRequestContext ctx,
String resourceArn) {
+ List