Skip to content

Conversation

@ywangd
Copy link
Member

@ywangd ywangd commented Dec 9, 2025

Add general support for index and project exclusions for the CPS index resolution process. Exclusion follows the same flat-world resolution model so that an expression such as -foo exclude foo from matching projects.

Note it currently throws exception on following cases:

  1. Double exclusion on project and index expression (new rule)
  2. Unmatched project in both exclusion and inclusion (new and existing rule)
  3. Excluding a project without including it first (existing rule)
  4. Project exclusion results into empty (existing rule)
  5. Project exclusion with index expression other than * (existing rule)

Other than the first case, we might want to discuss relaxing other cases in the future.

Relates: ES-12692

@ywangd ywangd added >non-issue :Security/Security Security issues without another label v9.3.0 labels Dec 9, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Security Meta label for security team label Dec 9, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

Comment on lines -53 to -54
// TODO remove me: only used in tests
public static Map<String, IndexRewriteResult> rewriteIndexExpressions(
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this method to the corresponding test since it's test only.

@elasticsearchmachine elasticsearchmachine added the serverless-linked Added by automation, don't add manually label Dec 9, 2025
// Cannot apply exclusion for both the project and the index
expectThrows(IllegalArgumentException.class, () -> rewriteIndexExpressions(origin, linked, "-_origin:-metrics*"));
expectThrows(IllegalArgumentException.class, () -> rewriteIndexExpressions(origin, linked, "-P0:-metrics*"));
expectThrows(IllegalArgumentException.class, () -> rewriteIndexExpressions(origin, linked, "-P1:-metrics*"));
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: Consider using org.elasticsearch.test.ESTestCase#expectThrows that can assert error message as well

Copy link
Member Author

Choose a reason for hiding this comment

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

TIL. Pushed 78d2d86

@idegtiarenko
Copy link
Contributor

Is this updating only CPS resolvedTo data structure?

@ywangd
Copy link
Member Author

ywangd commented Dec 9, 2025

Is this updating only CPS resolvedTo data structure?

It should be reflected in both IndicesRequest#indices() and Replaceable#getResolvedIndexExpressions(). I believe the later is what you referred as resolvedTo for FieldCaps.

@idegtiarenko
Copy link
Contributor

Is this updating only CPS resolvedTo data structure?

It should be reflected in both IndicesRequest#indices() and Replaceable#getResolvedIndexExpressions(). I believe the later is what you referred as resolvedTo for FieldCaps.

Is it going to be reflected when running in non CPS mode?

@ywangd
Copy link
Member Author

ywangd commented Dec 11, 2025

Is it going to be reflected when running in non CPS mode?

If CPS is disabled, ResolvedIndexExpressions won't be populated and is always null. It might change in future. But we haven't decided on that yet. It will always be reflected in IndicesRequest#indices() regardless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :Security/Security Security issues without another label serverless-linked Added by automation, don't add manually Team:Security Meta label for security team v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants