mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3control): take TagResource and UntagResource tag condition keys from generated data (#6677)
The Service Authorization Reference lists aws:RequestTag/${TagKey} and
aws:TagKeys as condition keys for s3:TagResource, and aws:TagKeys for
s3:UntagResource. botocore's s3control model says where the request
carries them: TagResource's Tags list in the body, UntagResource's
TagKeys in the tagKeys query parameters.
With IAM enforcement on, Floci checked both S3 Control actions with no
request tag keys. A policy that allows TagResource only for certain tag
values, or UntagResource only for certain keys, matched no request, so
a request it allows was denied, and a ForAllValues condition on
aws:TagKeys allowed UntagResource whatever keys it named.
tools/aws/regen_s3control_tag_condition_keys.py now generates
s3control-tag-condition-keys.json from the two sources, as the DynamoDB
condition key table is generated: every s3 action the reference gives
either key, and every S3 Control operation's request members that feed
them, found as the tag-on-create table finds tag members.
IamConditionContextResolver reads it for a request on an S3 Control
route. The make targets check the members offline against the pinned
botocore in CI and the actions online against AWS in the IAM data drift
workflow. S3's own bucket and object tag keys stay as written, since
they were measured against AWS and do not all match the reference.
This commit is contained in:
1 parent
8ad890148a
commit
f926968167
11 files changed
+853
-9
No files matched your search
+68
@@ -503,6 +503,74 @@ class S3ControlIamEnforcementIntegrationTest {
|
||||
.body(containsString("<Code>NoSuchBucket</Code>"));
|
||||
}
|
||||
|
||||
/**
|
||||
* TagResource is checked with the tags it sends as {@code aws:RequestTag/<key>} and
|
||||
* {@code aws:TagKeys}, the condition keys the Service Authorization Reference lists for it.
|
||||
*/
|
||||
@Test
|
||||
void tagResourceIsCheckedAgainstTheTagsItsRequestSends() {
|
||||
String bucket = bucketWithTags("control-request-tag");
|
||||
String user = userWith("""
|
||||
{"Version":"2012-10-17","Statement":[
|
||||
{"Effect":"Allow","Action":"s3:TagResource","Resource":"arn:aws:s3:::%1$s",
|
||||
"Condition":{"StringEquals":{"aws:RequestTag/Owner":"team"}}}]}"""
|
||||
.formatted(bucket));
|
||||
|
||||
given()
|
||||
.header("Authorization", auth(user, "s3"))
|
||||
.header("x-amz-account-id", ACCOUNT)
|
||||
.contentType("application/xml")
|
||||
.body("<Tagging><Tags><Tag><Key>Owner</Key><Value>team</Value></Tag></Tags></Tagging>")
|
||||
.when()
|
||||
.post("/v20180820/tags/arn:aws:s3:::" + bucket)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
given()
|
||||
.header("Authorization", auth(user, "s3"))
|
||||
.header("x-amz-account-id", ACCOUNT)
|
||||
.contentType("application/xml")
|
||||
.body("<Tagging><Tags><Tag><Key>Owner</Key><Value>other</Value></Tag></Tags></Tagging>")
|
||||
.when()
|
||||
.post("/v20180820/tags/arn:aws:s3:::" + bucket)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("is not authorized to perform: s3:TagResource"));
|
||||
}
|
||||
|
||||
/**
|
||||
* UntagResource is checked with the keys it removes as {@code aws:TagKeys}, the condition key
|
||||
* the Service Authorization Reference lists for it.
|
||||
*/
|
||||
@Test
|
||||
void untagResourceIsCheckedAgainstTheKeysItsRequestNames() {
|
||||
String bucket = bucketWithTags("control-tag-keys");
|
||||
String user = userWith("""
|
||||
{"Version":"2012-10-17","Statement":[
|
||||
{"Effect":"Allow","Action":"s3:UntagResource","Resource":"arn:aws:s3:::%1$s",
|
||||
"Condition":{"ForAllValues:StringEquals":{"aws:TagKeys":["Env"]}}}]}"""
|
||||
.formatted(bucket));
|
||||
|
||||
given()
|
||||
.header("Authorization", auth(user, "s3"))
|
||||
.header("x-amz-account-id", ACCOUNT)
|
||||
.queryParam("tagKeys", "Env", "Owner")
|
||||
.when()
|
||||
.delete("/v20180820/tags/arn:aws:s3:::" + bucket)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("is not authorized to perform: s3:UntagResource"));
|
||||
|
||||
given()
|
||||
.header("Authorization", auth(user, "s3"))
|
||||
.header("x-amz-account-id", ACCOUNT)
|
||||
.queryParam("tagKeys", "Env")
|
||||
.when()
|
||||
.delete("/v20180820/tags/arn:aws:s3:::" + bucket)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
/** A bucket created by the root stand-in, tagged through the data plane, as Terraform reads it. */
|
||||
private String bucketWithTags(String prefix) {
|
||||
String bucket = prefix + "-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
class S3ControlTagConditionKeysTest {
|
||||
|
||||
private static final String TAGS = "<TagResourceRequest><Tags>"
|
||||
+ "<Tag><Key>Owner</Key><Value>team</Value></Tag>"
|
||||
+ "<Tag><Key>Env</Key><Value>dev</Value></Tag>"
|
||||
+ "</Tags></TagResourceRequest>";
|
||||
|
||||
@Test
|
||||
void tagResourceTakesEachTagOfItsBodyAndTheirKeys() {
|
||||
assertEquals(Map.of("aws:RequestTag/Owner", List.of("team"), "aws:RequestTag/Env", List.of("dev"),
|
||||
"aws:TagKeys", List.of("Owner", "Env")),
|
||||
S3ControlTagConditionKeys.conditions("s3:TagResource", () -> TAGS, new MultivaluedHashMap<>()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void untagResourceTakesTheKeysItsQueryNamesAndNoRequestTag() {
|
||||
MultivaluedMap<String, String> query = new MultivaluedHashMap<>();
|
||||
query.addAll("tagKeys", "Owner", "Env");
|
||||
assertEquals(Map.of("aws:TagKeys", List.of("Owner", "Env")),
|
||||
S3ControlTagConditionKeys.conditions("s3:UntagResource", () -> TAGS, query));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRequestCarryingNoTagsAndAnActionTakingNoKeyGetNothing() {
|
||||
assertNull(S3ControlTagConditionKeys.conditions("s3:TagResource", () -> "", new MultivaluedHashMap<>()));
|
||||
assertNull(S3ControlTagConditionKeys.conditions("s3:UntagResource", () -> "", new MultivaluedHashMap<>()));
|
||||
assertNull(S3ControlTagConditionKeys.conditions("s3:ListAccessPoints", () -> TAGS,
|
||||
new MultivaluedHashMap<>()));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user