Skip to content

Execution with SecurityManager fails with 3.2.0-RC1 #38005

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

Closed
sdusart opened this issue Oct 24, 2023 · 2 comments
Closed

Execution with SecurityManager fails with 3.2.0-RC1 #38005

sdusart opened this issue Oct 24, 2023 · 2 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@sdusart
Copy link

sdusart commented Oct 24, 2023

Our application is composed by several executable jars produced by the spring-boot-maven-plugin.
We use the 21.0.1-zulu JVM with the security manager activated as we need to run user-defined scripts.

With springboot 3.2.0-M3 everything still works as expected; with 3.2.0-RC1 (after the reimplementation of the Nested Jar Support) the application fails to start.

Our policy file is :

// The application code gets all permissions (${app.dir} is the directory where the executable jars are)
grant codeBase "file:${app.dir}/*" {
  permission java.security.AllPermission;
};

// grants for specific codebase

// permissions given by default
grant {
  permission java.util.PropertyPermission "*", "read";
  permission java.lang.RuntimePermission "accessClassInPackage.sun.util.calendar";
};

With 3.2.0-RC1, the error is :

Exception in thread "main" java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:91)
	at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53)
	at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:54)
Caused by: java.lang.IllegalArgumentException: Unable to instantiate factory class [org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer] for factory type [org.springframework.context.ApplicationContextInitializer]
	at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$throwing$0(SpringFactoriesLoader.java:651)
	at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$handleMessage$3(SpringFactoriesLoader.java:675)
	at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:231)
	at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:206)
	at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:160)
	at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:477)
	at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:473)
	at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:282)
	at org.springframework.boot.builder.SpringApplicationBuilder.createSpringApplication(SpringApplicationBuilder.java:115)
	at org.springframework.boot.builder.SpringApplicationBuilder.<init>(SpringApplicationBuilder.java:102)
	at org.springframework.boot.builder.SpringApplicationBuilder.<init>(SpringApplicationBuilder.java:98)
	at com.alsyontech.thetys.ingestion.Ingestion.main(Ingestion.java:16)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	... 4 more
Caused by: java.security.AccessControlException: access denied ("java.lang.reflect.ReflectPermission" "suppressAccessChecks")
	at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:488)
	at java.base/java.security.AccessController.checkPermission(AccessController.java:1071)
	at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:411)
	at java.base/java.lang.reflect.AccessibleObject.checkPermission(AccessibleObject.java:92)
	at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:185)
	at org.springframework.util.ReflectionUtils.makeAccessible(ReflectionUtils.java:201)
	at org.springframework.core.io.support.SpringFactoriesLoader$FactoryInstantiator.<init>(SpringFactoriesLoader.java:373)
	at org.springframework.core.io.support.SpringFactoriesLoader$FactoryInstantiator.forClass(SpringFactoriesLoader.java:397)
	at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:227)
	... 14 more

With -Djava.security.debug=access,failure, I can see several denied accesses (see failure.log).

As indicated in https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2.0-RC1-Release-Notes , when I add <loaderImplementation>CLASSIC</loaderImplementation> to the spring-boot-maven-plugin configuration, everything works fine.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 24, 2023
@wilkinsona
Copy link
Member

Thanks for trying the release candidate. I can't explain why the loader implementation makes a difference here, but we haven't supported using the SecurityManager since Spring Boot 3.0. This change was motivated by its deprecation in the JDK and followed Spring Framework's lead.

You could continue with the classic loader implementation for now but you should move away from relying on the security manager as it isn't supported by Spring Boot or Spring Framework.

I'll leave this issue open for now as we should investigate to figure out why the behavior has changed. It may be that the security manager not working is a symptom of a broader problem and something that we do support is also affected.

@wilkinsona
Copy link
Member

I can't explain why the loader implementation makes a difference here

I think I can explain this now. When using the new loader implementation, the code source URLs change to jar:nested: URLs and they do not match the grants in the security.policy file. It may be possible to get this to work by changing the policy but, given that the security manager isn't support, I wouldn't recommend spending time doing so.

I don't think this change in behaviour is a symptom of a broader problem so I don't think there's any action for us to take here.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2023
@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants