Skip to content

fix: reduce AWS STS inline policy size by merging read+write actions#4228

Open
yushesp wants to merge 1 commit intoapache:mainfrom
yushesp:fix/sts-policy-size
Open

fix: reduce AWS STS inline policy size by merging read+write actions#4228
yushesp wants to merge 1 commit intoapache:mainfrom
yushesp:fix/sts-policy-size

Conversation

@yushesp
Copy link
Copy Markdown
Contributor

@yushesp yushesp commented Apr 16, 2026

Writable locations previously appeared in two separate statements:

  1. Read statement covering every location
  2. Write statement covering only writable ones.

This listed the resource ARN twice for every writable location, which pushed deeply nested namespace paths past the 2048-character STS policy limit.

This change emits a single combined statement granting both read and write actions for writable locations, and keep the read-only statement only for locations not already covered.

Also wraps the assumeRole call to rewrap PackedPolicyTooLargeException with a descriptive error msg.

Example:

Before (2 statements, ARN duplicated):

  {"Action": ["s3:GetObject", "s3:GetObjectVersion"],
   "Resource": ["...bucket/path/*"]}
  {"Action": ["s3:PutObject", "s3:DeleteObject"],
   "Resource": ["...bucket/path/*"]}

After (1 statement):

  {"Action": ["s3:GetObject", "s3:GetObjectVersion",
              "s3:PutObject", "s3:DeleteObject"],
   "Resource": ["...bucket/path/*"]}

Fixes #3243

Checklist

  • 🛡️ Don't disclose security issues! (contact security@apache.org)
  • 🔗 Clearly explained why the changes are needed, or linked related issues: Fixes #
  • 🧪 Added/updated tests with good coverage, or manually tested (and explained how)
  • 💡 Added comments for complex logic
  • 🧾 Updated CHANGELOG.md (if needed)
  • 📚 Updated documentation in site/content/in-dev/unreleased (if needed)

Writable locations previously appeared in two separate statements:
1. Read statement covering every location
2. Write statement covering only writable ones.

This listed the resource ARN twice for every writable location,
which pushed deeply nested namespace paths past the 2048-character
STS policy limit.

This change emits a single combined statement granting both read and write actions
for writable locations, and keep the read-only statement only for
locations not already covered.

Also wraps the assumeRole call to rewrap PackedPolicyTooLargeException
with a descriptive error msg.

Example:

Before (2 statements, ARN duplicated):
  {"Action": ["s3:GetObject", "s3:GetObjectVersion"],
   "Resource": ["...bucket/path/*"]}
  {"Action": ["s3:PutObject", "s3:DeleteObject"],
   "Resource": ["...bucket/path/*"]}

After (1 statement):
  {"Action": ["s3:GetObject", "s3:GetObjectVersion",
              "s3:PutObject", "s3:DeleteObject"],
   "Resource": ["...bucket/path/*"]}

Fixes apache#3243
Copy link
Copy Markdown
Member

@jbonofre jbonofre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

try {
response = stsClient.assumeRole(request.build());
} catch (PackedPolicyTooLargeException e) {
throw new RuntimeException(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I would expect some more specific than RuntimeException here but as the rest of the storage layer is also using RuntimeException, it's consistent and make sense 😄

response = stsClient.assumeRole(request.build());
} catch (PackedPolicyTooLargeException e) {
throw new RuntimeException(
"AWS STS rejected the session policy: it exceeds the 2048-character packed-policy"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused when I saw the corresponding testDeepNestedNamespaceStaysWithinPackedPolicyLimit as the assert is on the raw JSON length, not the packed size.

But it's actually correct. I was misleaded by the comment and naming.

@github-project-automation github-project-automation bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Polaris fails to create a Table because of an STS policy size limit

2 participants