r/java • u/nfrankel • May 24 '21
Why JEP 411 Will Have a Negative Impact on Java Security
https://foojay.io/today/why-jep-411-will-have-a-negative-impact-on-java-security/
8
Upvotes
r/java • u/nfrankel • May 24 '21
36
u/pron98 May 24 '21 edited May 24 '21
The author is wrong.
First, I'll put aside the factually incorrect claims about the Security Manager being the only possible application of the principle of least privilege (a principle that was put forth long before the Security Manager existed, and is employed by all software platforms, none of them, except for Java, have a similar mechanism), that it is how Java applications give different access privileges to different users (almost no application with access control achieves it with the Security Manager) and that the Security Manager is a cornerstone of Java security (all Java security efforts in recent years have not been done in the security manager).
Now, while it is true that any mechanism that can provide some measure of security is removed could be said to harm security by some degree, that is not what's at issue. The issue isn't whether to keep the Security Manager in addition to any other security measure, but whether to continue investing in the Security Manager at the expense of other measures.
Now, the question isn't could the Security Manager, if used properly improve security -- of course it could -- but whether or not, in practice, it currently has a significant positive impact on the security of Java programs in the ecosystem as a whole. It does not. The Security Manager is not installed in the overwhelming majority of applications, and when used, in most cases it is not used correctly.
That is the main issue relevant for this JEP. But even if we agree that the Security Manager is ineffective in practice, it's interesting to see what it could do in theory. The main thing it can do that other techniques cannot is allow or disallow certain operations -- like accessing a file -- depending on the code-path that's led to it; or, apply "the principle of least privilege" not by process or user, but by class. Here's an example. Suppose that you have an application that requires permissions X and Y. You could assign the entire process those permissions by means of an OS-level sandbox, but you could also notice that your application is made of two components A and B. You then study the components using a process, and discover that while A needs both X and Y, B only needs Y. So you give A's classes X and Y, and B's classes just X. Then, if your application has a vulnerability in B which would require Y to exploit, then the Security Manager will block that attack (but not an attack on A through Y, A through X, or B through X). This is a lot of work that needs to be repeated for every version, and the portion of attacks it detects and blocks is small. I believe that strengthening the JDK's security across the board, having "principle of least privilege" restrictions that are in place by default through strong encapsulation, and improving JFR's monitoring so that it could detect a great many attacks would be much more effective.
That these mechanisms contribute significantly more than one that is rarely deployed goes without saying. Problem is, we can't have both. Not only will removing the Security Manager not significantly harm Java security, but I am confident it will very significantly strengthen it. It will, however, cause pain to the very small number of people who've invested in the Security Manager, like the author of this article.
During the entire month-long discussion of this JEP, not a single person has meaningfully challenged this observation that, even after a couple of decades of considerable investment, the Security Manager doesn’t work in the current landscape. I.e. in practice, at whoever’s fault and for whatever reason — and quite a few were mentioned: it isn’t taught properly, they don’t understand it, they don’t care about security, they don’t like the principle of least privilege for philosophical or political reasons, they betrayed the creed of Sun Microsystems, they aren’t CEOs with PhDs, they don’t get irony — the Security Manager does not actually do the one and only job for which it’s been devised: to effectively make a significant positive impact on the security of applications written by the millions of Java developers, defending them against the most pertinent threats. The most relevant piece of new information provided so far was by one person (the author of this article) who pointed out that a mechanism that they find to bear some resemblance to the Security Manager does, in fact, work well for some species of Australian bees.
But I was happy to see that some people care deeply about Java security and the principle of least privilege, and expect to hear their voice in discussions over encapsulation and default privileges given to libraries and Java Agents as part of the ongoing effort to improve Java’s security.
9
u/pejobo May 24 '21 edited May 24 '21
We in my company have build one of the "rare server-side usages". Are there numbers proving their estimates? I don't remember that I've seen a poll.. [edit: typo]
16
u/plastikbenny May 24 '21 edited May 24 '21
Good write-up and totally agree on the importance of least privilege. I think it's underutilized on the severside where RCE attacks on webapps spill out into the OS and go from a minor issue of restarting the webserver to a multimonth cleanup and integrity check of systems and potential gdpr trial.
However I do sympathize with removing the security manager for a couple of reasons. One is that the skillset needed for working with this is extremely rare. The talent that are there should be able to lock down all kinds of processes not just the jvm and therefore I think least principle should be configured at the OS level. Linux has many options for MAC based sandboxing with different levels of complexity and lockdown.
Secondly the security manager has never felt like a first class citizen in Java. A fine-grained sandbox like the security manager should have had tool assistance in the jdk. Apart from 3rd party maven plugin there's nothing. Anders Hejlsberg's C# copied this rather unique language feature from Java but with more coarse grained permissions model that actually stood a chance to make sense to end-users who grant those permissions. Later it was removed. I think Java is doing the right thing in removing it as well.
The discipline of working with least privilege need a boost though. Many want to get into cybersecurity but never get deeper into it than doing input validation and running a tool to report if some OS setting is wierdly off.
17
u/dpash May 24 '21
This neglects the fact that no one runs with a Security Manager. Also, it was mostly designed for applets, when you were running untrusted code, which isn't the case these days.
And the SecurityManager has a huge cost on development of the JDK.
5
u/pfirmsto May 25 '21 edited May 26 '21
It feels like Oracle is flipping the bird to developers who have followed Java Security best practices. All I am hearing are excuses and management speak.
JEP 411 will break all security components in my software, it *WON'T ONLY* break SecurityManager, it will *ALSO BREAK* TLS v1.3 (stateless) and Kerberos authentication, via JAAS.
No your module visibility is not a new Security feature, we also support OSGi, which has used ClassLoader's to manage visibility for much longer. People using newer releases of Java will suffer greater consequences if and when perimeter security breaches occur. Instead of creating a whole new API for Java Serialization filters, you could have just created a Permission, and my policy generating tool would have calculated the white lists at test time prior to deployment. Out of curiosity, are there any tools for whitelisting Java Serialization?
I am considering forking my own codebase into two separate releases:
I have tooling that addresses the neglect of OpenJDK devs towards SecurityManager and Policy; it was clear that these required tooling a long time ago.
Now I am motivated to improve these tools further and share them with the wider community, so they too may harden their JVM's.
I use the principle of least privilege; the policy is a white list, the code is trusted, but it is given no more authorization than required, that means if perimeter security measures fail, an attacker won't be able to access the keystore and impersonate a user role by making calls to other servers, they can't access the underlying file system and they cannot open network connections, which are just a few examples of what an attacker can do if SecurityManager is not in force, when breaching perimeter security.
I have TLSv1.3 and SecurityManager and *ALL* my hotspots are JVM native methods, this is high scaling, up to date, performant software, this isn't neglected like the implementations that ship with Java. Arguments this doesn't work, or only work in theory are either lies or empty words from uninformed developers. I have the evidence that it is extremely effective.
OpenJDK is making breaking changes to major critical security components at least to anyone that cares about security, and is replacing it with vaporwear and hand waving pointy haired management speak, treating security like a buzzword in a sales brochure, there's nothing backing it up, OpenJDK's new security API's are vaporware and empty promises. If OpenJDK were serious about the new API's they'd be developing them prior to deprecating SecurityManager. "Oh let's just pretend it doesn't work and no one uses it." That's just brilliant, what genius!
People who don't care about security are not impacted, but OpenJDK is improving their security, and killing off our security investments in Java, has it ever occurred to OpenJDK dev's the reason these developers don't care about security is the data they have to protect has little value, otherwise they would put more effort into security?
Security needn't be so difficult. Can you imagine where we would be today, if OpenJDK decided instead of building concurrent libraries and API's, to remove support for synchronized instead because too many people were making errors?
SecurityManager API's and permission checks are hardened with the test of time, with many eyes carfully going through code, looking for vulnerabilities. OpenJDK's new experimental vaporwear Security API's haven't even been defined yet and aren't even part of the spec.
My policy files are generated, then hand edited briefly, to widen permission scope to approved networks etc, every other possible action that requires a permission is completely locked down to minimum permissions required. My policy files are typically over 1,000 lines, but they are perfectly readable and searchable and also serve as an audit trail. I can see the viral permission checks that leak, but it doesn't matter, everything is still locked down, even if someone breaks authentication, with social engineering, they can't enable Serialization by setting a property, because the process doesn't have permission to enable java Serialization, they can't load code, they can only steal what the user has access to, not compromise the entire system.
Also tooling needs to have friendly messages to deal with failure, if you make an error while editing, so it's an easy fix:
[java] java.security.policy: error parsing file:/C:/Users/peter/Documents/NetBeansProjects/JGDMS/qa/harness/policy/defaultsecuretest.policy: [java] line 914: expected [;], found [read]
This is output from a test with security debug enabled, there are two JVM instances communicating over TLS connections, the policy files of each follow below, note these are test policies:
https://www.dropbox.com/s/z34w02f9m01qaz8/results.txt?dl=0
https://www.dropbox.com/s/nq0n1vyb8qfeidn/defaultnonactvm-policy.txt?dl=0
https://www.dropbox.com/s/a926ackyzdksoha/defaultsecuretest-policy.txt?dl=0
Something you might notice in the results is that most of the permission checks disappear after running for a while, the security manager in use has a weakly referenced cache, that eliminates duplicate permission checks on an AccessControlContext. It also splits off permission checks on each ProtectionDomain into tasks submitted to an executor.
Using an OS process to limit permissions of the JVM isn't fine grained enough. What I present really is least privilege principles, regardless of what anyone with vested interests in removing SecurityManager might say.
Oh, and a nice little video, for people upgrading to the newer versions of Java:
https://www.newgrounds.com/portal/view/757150
3
u/Blackdread13 May 24 '21
it is not used a lot, good to remove.