Skip to content

Replace usages of ThreadContext.stashContext with pluginSubject.runAs#715

Merged
heemin32 merged 19 commits intoopensearch-project:mainfrom
cwperks:remove-stash-context
Jul 24, 2025
Merged

Replace usages of ThreadContext.stashContext with pluginSubject.runAs#715
heemin32 merged 19 commits intoopensearch-project:mainfrom
cwperks:remove-stash-context

Conversation

@cwperks
Copy link
Copy Markdown
Member

@cwperks cwperks commented Jan 28, 2025

Description

This PR replaces usages of ThreadContext.stashContext with a replacement that enforces stricter ownership over system indices. Plugins can use this replacement for system index access and the advantage of this replacement is that it provides context into which plugin is performing privileged actions like system index access.

Related Issues

Resolves opensearch-project/opensearch-plugins#238

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
@yizheliu-amazon
Copy link
Copy Markdown
Contributor

Hi @cwperks , should this change be included in 2.19 release? The code freeze for 2.19 starts at Jan 28th as per: https://opensearch.org/releases.html

@cwperks
Copy link
Copy Markdown
Member Author

cwperks commented Jan 31, 2025

Hi @cwperks , should this change be included in 2.19 release? The code freeze for 2.19 starts at Jan 28th as per: https://opensearch.org/releases.html

No this does not need to be included. This is part of a larger effort across plugins. I initially looked at geospatial since it was one of the plugins that creates an instance of JobScheduler's LockService and I wanted to demonstrate how to use the instance of LockService provided by job scheduler instead of creating a separate instance. Eventually, I want to remove the public constructor for LockService to enforce that plugins use the instance provided by job scheduler.

The reason for this is a new model for access to system indices instead of the current model of wrapping with ThreadContext.stashContext.

In the current model there are not authz checks that are run in that block so a plugin can perform any action w/o restriction.

In the new model (utilizing pluginSubject.runAs) it provides information at runtime about which plugin is running the action and security uses that information to allow it to access its own system indices, but can forbid other actions.

@yizheliu-amazon
Copy link
Copy Markdown
Contributor

I see. Thank you for the information.

cwperks added 7 commits June 23, 2025 09:21
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
…troller

Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
@cwperks
Copy link
Copy Markdown
Member Author

cwperks commented Jul 24, 2025

Unrelated to the changes in this PR, but I'll see about fixing these:

> Task :compileTestJava
D:\a\geospatial\geospatial\src\test\java\org\opensearch\geospatial\index\mapper\xypoint\XYPointFieldMapperTests.java:61: error: ignoreMalformed() has protected access in AbstractGeometryFieldMapper
                assertTrue("param [ ignore_malformed ] is not updated", xyPointFieldMapper.ignoreMalformed().value());
                                                                                          ^
D:\a\geospatial\geospatial\src\test\java\org\opensearch\geospatial\index\mapper\xypoint\XYPointFieldMapperTests.java:122: error: ignoreMalformed() has protected access in AbstractGeometryFieldMapper
        assertEquals("param [ ignore_malformed ] default value should be false", xyPointFieldMapper.ignoreMalformed().value(), false);
                                                                                                   ^
D:\a\geospatial\geospatial\src\test\java\org\opensearch\geospatial\index\mapper\xyshape\XYShapeFieldMapperTests.java:66: error: ignoreMalformed() has protected access in AbstractGeometryFieldMapper
                assertTrue("param [ ignore_malformed ] is not updated", XYShapeFieldMapper.ignoreMalformed().value());
                                                                                          ^
D:\a\geospatial\geospatial\src\test\java\org\opensearch\geospatial\index\mapper\xyshape\XYShapeFieldMapperTests.java:137: error: ignoreMalformed() has protected access in AbstractGeometryFieldMapper
        assertEquals("param [ ignore_malformed ] default value should be false", XYShapeFieldMapper.ignoreMalformed().value(), false);

@cwperks
Copy link
Copy Markdown
Member Author

cwperks commented Jul 24, 2025

Checks are failing due to this change in core: opensearch-project/OpenSearch#18706

access modifier for ignoreMalformed() changed from public to protected.

cwperks added 2 commits July 24, 2025 11:12
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
@cwperks
Copy link
Copy Markdown
Member Author

cwperks commented Jul 24, 2025

Fixed the errors due to the breaking change from core.

I added a public shouldIgnoreMalformed to XYShapeFieldMapper and XYPointFieldMapper that can be called in the tests.

@heemin32 heemin32 merged commit e7ecd51 into opensearch-project:main Jul 24, 2025
13 checks passed
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.

[META] Remove usages of ThreadContext.stashContext and adopt new mechanism for System Index access

4 participants