Changing opensearch.cgroups.hierarchy.override causes java.lang.SecurityException exception#20565
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
📝 WalkthroughWalkthroughThis change introduces support for a new system property placeholder Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
|
❗ AI-powered Code-Diff-Analyzer found issues on commit 75aa263.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@libs/agent-sm/agent-policy/src/test/java/org/opensearch/secure_sm/policy/PolicyFileTests.java`:
- Around line 32-35: The test currently asserts an exact total count on
filePermissions (assertThat(filePermissions, hasSize(3))), which is brittle;
remove that exact size assertion and instead assert presence of the expected
entries only (use the existing checks on
filePermissions.stream().filter(...).count() or anyMatch to verify
"/sys/fs/cgroup/memory" and "/lib/security/cacerts" exist) so the test relies on
presence rather than an exact total; update PolicyFileTests.java to stop
asserting filePermissions size and keep/adjust the filtering assertions on
filePermissions to check existence (>=1) only.
🧹 Nitpick comments (1)
libs/agent-sm/agent-policy/src/main/java/org/opensearch/secure_sm/policy/PolicyFile.java (1)
146-163: Guard against unmatched placeholder patterns.If a policy uses
${opensearch.cgroups.hierarchy.override}without both surrounding separators,indexbecomes -1 and the substring will throw. Consider an early guard or a more flexible replacement to avoidStringIndexOutOfBoundsException.♻️ Suggested defensive guard
- final int index = value.indexOf(separator + "${" + property + "}" + separator); + final String token = separator + "${" + property + "}" + separator; + final int index = value.indexOf(token); + if (index < 0) { + return value; + }Also applies to: 175-180
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
CHANGELOG.mdlibs/agent-sm/agent-policy/src/main/java/org/opensearch/secure_sm/policy/PolicyFile.javalibs/agent-sm/agent-policy/src/test/java/org/opensearch/secure_sm/policy/PolicyFileTests.javalibs/agent-sm/agent-policy/src/test/resources/test.policyserver/src/main/resources/org/opensearch/bootstrap/security.policy
🧰 Additional context used
🧬 Code graph analysis (1)
libs/agent-sm/agent-policy/src/test/java/org/opensearch/secure_sm/policy/PolicyFileTests.java (1)
libs/agent-sm/agent-policy/src/main/java/org/opensearch/secure_sm/policy/PolicyFile.java (1)
SuppressWarnings(43-393)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
- GitHub Check: gradle-check
- GitHub Check: Analyze (java)
- GitHub Check: assemble (21, ubuntu-24.04-arm)
- GitHub Check: assemble (25, windows-latest)
- GitHub Check: precommit (25, ubuntu-latest)
- GitHub Check: precommit (21, ubuntu-latest)
- GitHub Check: precommit (25, ubuntu-24.04-arm)
- GitHub Check: precommit (21, macos-15)
- GitHub Check: precommit (21, ubuntu-24.04-arm)
- GitHub Check: precommit (25, windows-latest)
- GitHub Check: precommit (21, windows-2025, true)
- GitHub Check: precommit (25, macos-15-intel)
- GitHub Check: precommit (21, windows-latest)
- GitHub Check: assemble (21, windows-latest)
- GitHub Check: assemble (25, ubuntu-latest)
- GitHub Check: precommit (25, macos-15)
- GitHub Check: assemble (21, ubuntu-latest)
- GitHub Check: precommit (21, macos-15-intel)
- GitHub Check: assemble (25, ubuntu-24.04-arm)
🔇 Additional comments (5)
CHANGELOG.md (1)
18-18: Changelog entry looks good.Clear and appropriately placed under “Fixed.”
libs/agent-sm/agent-policy/src/test/resources/test.policy (1)
9-12: Looks good.The policy entries align with the new placeholder expansion behavior.
libs/agent-sm/agent-policy/src/main/java/org/opensearch/secure_sm/policy/PolicyFile.java (1)
132-139: Good change using the correct path separator.Using File.separator here fixes cross-platform path handling.
server/src/main/resources/org/opensearch/bootstrap/security.policy (1)
255-260: Looks good.The new permissions correctly cover the override hierarchy paths.
libs/agent-sm/agent-policy/src/test/java/org/opensearch/secure_sm/policy/PolicyFileTests.java (1)
28-31: No action needed. The code is compatible with the project's target JDK version (Java 21). ThePermissionCollection#elementsAsStream()method has been available since Java 9, and is therefore fully supported in Java 21.Likely an incorrect or invalid review comment.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
libs/agent-sm/agent-policy/src/test/java/org/opensearch/secure_sm/policy/PolicyFileTests.java
Outdated
Show resolved
Hide resolved
|
❌ Gradle check result for b99e737: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
…ityException exception Signed-off-by: Andriy Redko <drreta@gmail.com>
libs/agent-sm/agent-policy/src/main/java/org/opensearch/secure_sm/policy/PolicyFile.java
Show resolved
Hide resolved
|
❌ Gradle check result for d08131a: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20565 +/- ##
============================================
+ Coverage 73.25% 73.27% +0.02%
+ Complexity 72103 72064 -39
============================================
Files 5798 5798
Lines 329732 329748 +16
Branches 47519 47523 +4
============================================
+ Hits 241554 241633 +79
+ Misses 68805 68732 -73
- Partials 19373 19383 +10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @reta do we need to update anything in https://github.com/peterzhuamazon/OpenSearch/blob/main/distribution/packages/src/common/systemd/opensearch.service ? Thanks. |
Thanks @peterzhuamazon , I believe manual changes will be needed there, since this is really a JVM property that we cannot use for systemd hardening, what do you think? The reporter on the issue mentioned it:
|
Signed-off-by: Andriy Redko <drreta@gmail.com>
|
Hi @reta do we have any defaults for For deb/rpm it is not as flexible as tar, so I think we can hardcode the default into systemd file for now. |
@peterzhuamazon Yes, default is |
…ityException exception (opensearch-project#20565) * Changing opensearch.cgroups.hierarchy.override causes java.lang.SecurityException exception Signed-off-by: Andriy Redko <drreta@gmail.com> * Address code review comments Signed-off-by: Andriy Redko <drreta@gmail.com> --------- Signed-off-by: Andriy Redko <drreta@gmail.com>
…ityException exception (opensearch-project#20565) * Changing opensearch.cgroups.hierarchy.override causes java.lang.SecurityException exception Signed-off-by: Andriy Redko <drreta@gmail.com> * Address code review comments Signed-off-by: Andriy Redko <drreta@gmail.com> --------- Signed-off-by: Andriy Redko <drreta@gmail.com>
Description
At the moment, the permissions we grant by default apply to root of
cgroupthe hierarchy:The
opensearch.cgroups.hierarchy.overridemay change that and in general, the permissions become dynamic, based on the<cgroup name>name (whateveropensearch.cgroups.hierarchy.overridepoints to):The suggested fix it to support
opensearch.cgroups.hierarchy.overrideexpansion in policy files, so for exampleopensearch.cgroups.hierarchy.override=/testwould translate to:How to test / reproduce:
sudo mkdir /sys/fs/cgroup/testsudo chmod --recursive o+rw /sys/fs/cgroup/testOPENSEARCH_JAVA_OPTS="-Dopensearch.cgroups.hierarchy.override=/test" cgexec -g memory:test ./bin/opensearchRelated Issues
Resolves #20522
Check List
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.