Skip to content

NoSQL: Limit inline policy mapping value size#4545

Merged
snazy merged 2 commits into
apache:mainfrom
snazy:nosql-policy-mapping-value-size
May 28, 2026
Merged

NoSQL: Limit inline policy mapping value size#4545
snazy merged 2 commits into
apache:mainfrom
snazy:nosql-policy-mapping-value-size

Conversation

@snazy
Copy link
Copy Markdown
Member

@snazy snazy commented May 26, 2026

Put a hard cap on the inline NoSQL policy-mapping value size.

That value sits directly in the shared policy-mappings index, so leaving it unbounded lets one attachment bloat commit size and maintenance work for no real gain.

Polaris still accepts client-supplied policy-mapping parameters on the attach-policy request and persists them inline in the NoSQL policy-mappings index. I could not find any in-tree first-party caller that intentionally sets up a non-empty parameter bag itself, but the field is still live API surface, so the cap belongs in the NoSQL write path as a defensive bound on that inline index value.

Put a hard cap on the inline NoSQL policy-mapping value size.

That value sits directly in the shared policy-mappings index, so leaving it unbounded lets one attachment bloat commit size and maintenance work for no real gain.

Polaris still accepts client-supplied policy-mapping parameters on the attach-policy request and persists them inline in the NoSQL policy-mappings index.
I could not find any in-tree first-party caller that intentionally sets up a non-empty parameter bag itself, but the field is still live API surface, so the cap belongs in the NoSQL write path as a defensive bound on that inline index value.
if (serializedPolicyMappingSize > MAX_POLICY_MAPPING_INDEX_VALUE_SIZE) {
return state.noCommit(
new PolicyAttachmentResult(
UNEXPECTED_ERROR_SIGNALED,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we use a better error code for this client input validation failure?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ideally yes. I just could not find a legitimate reason why the limit would ever be exceeded. So I think that the accompanying error message should be okay.

long targetId,
boolean doAttach,
@NonNull Map<String, String> parameters) {
private static final int MAX_POLICY_MAPPING_INDEX_VALUE_SIZE = 384;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why 384?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also should this be public? (and reused in tests)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a comment and updated the tests.

@github-project-automation github-project-automation Bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board May 27, 2026
* separate new {@link Obj}ect.
* </ul>
*/
public static final int MAX_POLICY_MAPPING_INDEX_VALUE_SIZE = 384;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How was 384 picked? The javadoc explains how to evolve it but not the rationale , a short note (typical param-bag size + headroom, or measured serialized size of expected real-world entries) would help a future reviewer judge whether a bump is safe.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There isn't really a deeper policy-level reason for 384. The policy mapping parameters are an opaque property bag here, and AFAICT the policy design does not define what is supposed to go into it or what a reasonable size would be.

So this is mostly a NoSQL-storage guardrail. The mapping value is stored inline in the index, and index values are serialized as-is. 384 is intentionally conservative: large enough for the small parameter bags we currently support/test, but small enough that one mapping cannot take a noticeable chunk of the embedded index.

If we ever find a real use case that needs substantially more data in the mapping, I don't think we should keep bumping this forever. Then the payload should probably move into a separate object and the index should only keep the lookup data / reference.

@snazy snazy merged commit 1370c09 into apache:main May 28, 2026
23 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to merge to Done in Basic Kanban Board May 28, 2026
@snazy snazy deleted the nosql-policy-mapping-value-size branch May 28, 2026 05:43
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.

4 participants