fix(s3api): complete bucket-listing IAM condition handling (#12699)

* fix(s3api): complete bucket-listing IAM condition handling

Populate s3:delimiter and s3:max-keys for bucket. Add regression tests for listing conditions and variants.

Assisted-by: gpt-6.1-sol, deepseek-v4.1-flash

* fix(s3api): ignore max-keys for multipart listing policies

Assisted-by: GPT-6.1 Terra

* s3api: drop max-keys from multipart-upload listing policy conditions

Bucket policies and embedded IAM policies read condition values through
ExtractConditionValuesFromRequest, which still exposed max-keys on ?uploads
listings. Those page by max-uploads, so an unused max-keys parameter could
satisfy an s3:max-keys condition. Match the advanced IAM path and leave the
key absent there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-11-17 17:05:00 -08:00
1 parent 5681be241e
commit 1d30b0de21
4 files changed
+142 -9

No files matched your search

+17
View File
@@ -4,6 +4,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"slices"
"strings"
"testing"
@@ -419,6 +420,22 @@ func TestExtractConditionValuesFromRequest(t *testing.T) {
}
}
func TestExtractConditionValuesFromRequestMaxKeys(t *testing.T) {
for _, tt := range []struct {
query string
want []string
}{
{"list-type=2&max-keys=5", []string{"5"}},
{"versions&max-keys=5", []string{"5"}},
{"uploads&max-uploads=1000&max-keys=5", nil},
} {
req := &http.Request{Method: "GET", URL: &url.URL{Path: "/test-bucket", RawQuery: tt.query}, RemoteAddr: "10.0.0.5:54321"}
if got := NewPolicyEngine().ExtractConditionValuesFromRequest(req)["s3:max-keys"]; !slices.Equal(got, tt.want) {
t.Errorf("%s: s3:max-keys = %v, want %v", tt.query, got, tt.want)
}
}
}
func TestExtractConditionValuesFromRequestSourceIPPrecedence(t *testing.T) {
tests := []struct {
name string