mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
refactor(iam): match S3 requests on the routed path, as every scope is (#9164)
The registry matched an S3 request's route on the path as sent and every other scope's on the path the router dispatched on. S3 needs no exception: S3SlashOnlyKeyFilter rewrites a key of slashes alone escaped (PUT /bucket// is /bucket/%2F), which the routed path keeps as the filter wrote it, and the object a request names comes from S3's own reading of its key (RequestPathLabels), which keeps the slashes it was sent with. The routed path is also the one the router dispatched on, so a path it normalizes, such as /bucket/.., is checked as the operation that runs. A new integration test checks a key of slashes alone under IAM enforcement.
This commit is contained in:
1 parent
5a912d5263
commit
ce7f1ab185
3 files changed
+23
-6
No files matched your search
@@ -626,9 +626,10 @@ public class IamActionRegistry {
|
||||
*/
|
||||
public String resolveRoute(String credentialScope, ContainerRequestContext ctx) {
|
||||
String method = ctx.getMethod().toUpperCase();
|
||||
// An S3 key may end in a slash, and one of slashes alone arrives escaped as S3SlashOnlyKeyFilter rewrites
|
||||
// it (PUT /bucket// writes the key "/"), so an S3 path is matched as sent, not decoded.
|
||||
String path = "s3".equals(credentialScope) ? sentPath(ctx.getUriInfo()) : routedPath(ctx);
|
||||
// Matched on the path the router dispatched on, as every scope is: S3 too, whose key of slashes alone
|
||||
// S3SlashOnlyKeyFilter rewrites escaped (PUT /bucket// writes the key "/"), and whose own reading of a key,
|
||||
// which keeps the slashes it was sent with, names the object (RequestPathLabels).
|
||||
String path = routedPath(ctx);
|
||||
|
||||
for (ActionRule rule : RULES) {
|
||||
if (rule.matches(credentialScope, method, path, ctx)) {
|
||||
@@ -736,7 +737,7 @@ public class IamActionRegistry {
|
||||
|| ctx.getUriInfo().getRequestUri() == null) {
|
||||
return false;
|
||||
}
|
||||
String path = "s3".equals(credentialScope) ? sentPath(ctx.getUriInfo()) : routedPath(ctx);
|
||||
String path = routedPath(ctx);
|
||||
return IamRestRoutes.vendored().ambiguous(credentialScope, ctx.getMethod().toUpperCase(),
|
||||
withoutInternalPrefix(ctx, path), ctx.getUriInfo().getQueryParameters(), movedUnderPrefix(ctx),
|
||||
ctx.getHeaders());
|
||||
|
||||
@@ -637,8 +637,8 @@ class IamActionRegistryTest {
|
||||
@Test
|
||||
void aTrailingSlashIsCheckedAsTheRouteWithoutIt() {
|
||||
// The router matches /clusters/ as /clusters, so the rule ending at the route's last segment covers it.
|
||||
// An S3 path is matched as sent: a key may end in a slash, and one of slashes alone arrives as
|
||||
// S3SlashOnlyKeyFilter rewrites it, escaped.
|
||||
// An S3 key may end in a slash, and one of slashes alone arrives as S3SlashOnlyKeyFilter rewrites it,
|
||||
// escaped.
|
||||
String[][] routes = {
|
||||
{"eks", "POST", "/clusters/", "eks:CreateCluster"},
|
||||
{"eks", "GET", "/clusters/c/node-groups/ng/", "eks:DescribeNodegroup"},
|
||||
|
||||
+16
@@ -272,6 +272,22 @@ class S3ObjectOperationsIamEnforcementIntegrationTest {
|
||||
.when().delete(f.path("a/governed")).then().statusCode(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* A key of slashes alone, "/" sent as "/bucket//", is that object, checked as the object operation on it, not as
|
||||
* the bucket its path would name without them.
|
||||
*/
|
||||
@Test
|
||||
void aKeyOfOnlySlashesIsCheckedAsThatObject() {
|
||||
Fixture f = new Fixture("slash-only", false);
|
||||
f.policy(f.allow("s3:PutObject", "s3:GetObject", "s3:DeleteObject"));
|
||||
HttpResponse<String> put = f.raw("PUT", "/", null, f.accessKeyId, Map.of(), "one slash");
|
||||
assertEquals(200, put.statusCode(), put.body());
|
||||
HttpResponse<String> get = f.raw("GET", "/", null, f.accessKeyId, Map.of(), null);
|
||||
assertEquals(200, get.statusCode(), get.body());
|
||||
assertEquals("one slash", get.body());
|
||||
assertEquals(204, f.raw("DELETE", "/", null, f.accessKeyId, Map.of(), null).statusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theBypassIsDecidedOnTheKeyARequestNamesEvenWithALeadingSlash() {
|
||||
// A key that starts with "/" travels as "//" after the bucket, which JAX-RS collapses to the
|
||||
|
||||
Reference in new issue
Block a user