Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security Plugin cannot startup due to AccessControlException: access denied #3317

Closed
wants to merge 1 commit into from

Conversation

reta
Copy link
Collaborator

@reta reta commented Sep 5, 2023

Description

Fixing AccessControlException after opensearch-project/OpenSearch#9289, we have 2 options here:

  1. since the bcprov moved to core, it will be loaded by core, the plugin should not try to enforce it
  2. plugin may try to enforce it but the core security policy should be extended to allow that
grant codeBase "${codebase.bcprov-jdk15to18}" {
  permission java.security.SecurityPermission "putProviderProperty.BC";
  permission java.security.SecurityPermission "insertProvider.BC";
  permission java.security.SecurityPermission "removeProviderProperty.BC";
};
  • Category (Enhancement, New feature, Bug fix, Test fix, Refactoring, Maintenance, Documentation)
  • Why these changes are required?
  • What is the old behavior before changes and new behavior after changes?

Issues Resolved

Closes #3309

Is this a backport? If so, please add backport PR # and/or commits #

Testing

Covered by existing tests

Check List

  • New functionality includes testing
  • New functionality has been documented
  • Commits are signed per the DCO using --signoff

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.

@codecov
Copy link

codecov bot commented Sep 5, 2023

Codecov Report

Merging #3317 (366ecfd) into main (fd3a143) will increase coverage by 0.00%.
Report is 1 commits behind head on main.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##               main    #3317   +/-   ##
=========================================
  Coverage     63.24%   63.25%           
+ Complexity     3450     3449    -1     
=========================================
  Files           263      263           
  Lines         20040    20036    -4     
  Branches       3344     3343    -1     
=========================================
- Hits          12674    12673    -1     
+ Misses         5739     5736    -3     
  Partials       1627     1627           
Files Changed Coverage Δ
.../opensearch/security/OpenSearchSecurityPlugin.java 84.43% <ø> (-0.10%) ⬇️

... and 4 files with indirect coverage changes

@willyborankin
Copy link
Collaborator

willyborankin commented Sep 5, 2023

@reta we had more settings:

  permission java.security.SecurityPermission "putProviderProperty.BC";
  permission java.security.SecurityPermission "insertProvider.BC";
  permission java.security.SecurityPermission "removeProviderProperty.BC";
  permission java.util.PropertyPermission "*", "write";

add @cwperks aded this fix: #3289. So all of them need to be added to the the SDK now? If yes this is a partial fix :-(

@reta
Copy link
Collaborator Author

reta commented Sep 5, 2023

permission java.util.PropertyPermission "*", "write";

It seems like this one have to go to core :( I am still looking hence this pull request is in draft state

@willyborankin
Copy link
Collaborator

willyborankin commented Sep 5, 2023

permission java.util.PropertyPermission "*", "write";

It seems like this one have to go to core :( I am still looking hence this pull request is in draft state

ehhh "read,write" :-(

@willyborankin
Copy link
Collaborator

willyborankin commented Sep 5, 2023

@peternied, @cwperks and @reta I think this solution is ok for 2.10 but is not good in the future. Core should not provide such permissions, more important all plugin could add additional permissions.

@willyborankin
Copy link
Collaborator

@reta im wrong we have such login in the policy.

grant codeBase "${codebase.netty-common}" {
  permission java.lang.RuntimePermission "loadLibrary.*";
};

@@ -331,16 +331,6 @@ public OpenSearchSecurityPlugin(final Settings settings, final Path configPath)
sm.checkPermission(new SpecialPermission());
}

AccessController.doPrivileged(new PrivilegedAction<Object>() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@peternied @cwperks any reasons we need to explicitly add BouncyCastleProvider?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahhh it is historical. It was added this way.

Copy link
Member

Choose a reason for hiding this comment

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

From the javadoc for java.security.Security it is safe to call addProvider multiple times: https://docs.oracle.com/javase%2F7%2Fdocs%2Fapi%2F%2F/java/security/Security.html#addProvider(java.security.Provider)

the preference position in which the provider was added, or -1 if the provider was not added because it is already installed.

@reta
Copy link
Collaborator Author

reta commented Sep 5, 2023

@reta im wrong we have such login in the policy.

grant codeBase "${codebase.netty-common}" {
  permission java.lang.RuntimePermission "loadLibrary.*";
};

@willyborankin the ${codebase} placeholder is resolved relatively to plugin: /..../plugins/opensearch-security, there is no way to point to $OPENSEARCH/lib from there

@willyborankin
Copy link
Collaborator

@reta im wrong we have such login in the policy.

grant codeBase "${codebase.netty-common}" {
  permission java.lang.RuntimePermission "loadLibrary.*";
};

@willyborankin the ${codebase} placeholder is resolved relatively to plugin: /..../plugins/opensearch-security, there is no way to point to $OPENSEARCH/lib from there

got it

@cwperks
Copy link
Member

cwperks commented Sep 5, 2023

add @cwperks aded this fix: #3289. So all of them need to be added to the the SDK now? If yes this is a partial fix :-(

@willyborankin you are right that the permissions added in that PR would also need to be added to core since the dependency is now coming from core. I have a PR in core to add the existing bouncy castle permissions that the security plugin has into core opensearch-project/OpenSearch#9770 (Option 2 from this PR's description)

I am trying to figure out now the reasons why the security plugin calls on Security.addProvider, but from my own understanding bouncycastle is used to setup TLS (reading certs and keys) and is used for its implementation of BCrypt

@reta
Copy link
Collaborator Author

reta commented Sep 5, 2023

I am trying to figure out now the reasons why the security plugin calls on Security.addProvider, but from my own understanding bouncycastle is used to setup TLS (reading certs and keys) and is used for its implementation of BCrypt

We definitely need to add the BC provider, but since it is in core now, it should be done by core, that would also solve any issues with other plugins trying to add/remove BC.

@cwperks
Copy link
Member

cwperks commented Sep 5, 2023

@reta From the javadoc for java.security.Security it is safe to call addProvider multiple times: https://docs.oracle.com/javase%2F7%2Fdocs%2Fapi%2F%2F/java/security/Security.html#addProvider(java.security.Provider)

the preference position in which the provider was added, or -1 if the provider was not added because it is already installed.

@reta
Copy link
Collaborator Author

reta commented Sep 5, 2023

@reta From the javadoc for java.security.Security it is safe to call addProvider multiple times: https://docs.oracle.com/javase%2F7%2Fdocs%2Fapi%2F%2F/java/security/Security.html#addProvider(java.security.Provider)

@cwperks The problem is not how many times, the problem is who adds it first because that would impact the security policy to be taken into account (related to #3213 (comment)), and again - you need to grant the permissions to the plugin

@willyborankin
Copy link
Collaborator

willyborankin commented Sep 5, 2023

I am trying to figure out now the reasons why the security plugin calls on Security.addProvider, but from my own understanding bouncycastle is used to setup TLS (reading certs and keys) and is used for its implementation of BCrypt

We definitely need to add the BC provider, but since it is in core now, it should be done by core, that would also solve any issues with other plugins trying to add/remove BC.

If you set any security provider this way it means that in the list of sec providers JDK knows about it is in the first place.So you lets say can create a cipher this way:

Cipher cipher = Cipher.getInstance("DESede/CBC/NoPadding");

otherwise you need add a provider name:

Cipher cipher = Cipher.getInstance("DESede/CBC/NoPadding", BouncyCastleProvider.PROVIDER_NAME)

We can change it but it is not so fast as you could think.

@reta
Copy link
Collaborator Author

reta commented Sep 5, 2023

Closing in favor of opensearch-project/OpenSearch#9779

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.

Security Plugin cannot startup due to AccessControlException: access denied
3 participants