-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Closed
Labels
Milestone
Description
After update to guava 32.0.0
on Windows we start having such exception
Caused by: java.lang.UnsupportedOperationException: 'posix:permissions' not supported as initial attribute
at sun.nio.fs.WindowsSecurityDescriptor.fromAttribute(WindowsSecurityDescriptor.java:358)
at sun.nio.fs.WindowsFileSystemProvider.createDirectory(WindowsFileSystemProvider.java:492)
at java.nio.file.Files.createDirectory(Files.java:674)
at java.nio.file.TempFileHelper.create(TempFileHelper.java:136)
at java.nio.file.TempFileHelper.createTempDirectory(TempFileHelper.java:173)
at java.nio.file.Files.createTempDirectory(Files.java:950)
at com.google.common.io.TempFileCreator$JavaNioCreator.createTempDir(TempFileCreator.java:102)
at com.google.common.io.Files.createTempDir(Files.java:439)
seems it is related to
feb83a1
jbduncan
Activity
cpovirk commentedon Jun 5, 2023
Sorry about that. I was aware that some version of Windows had gotten some kind of POSIX support but probably also had heard enough during our jimfs work that I should have realized that that didn't solve this. A teammate ended thinking to test Windows after the release, at which point he confirmed that it didn't work. But all we've done so far is update the release notes, add a warning to the Javadoc at head, and try to read some about how to create the directory securely under Windows:
In response to a similar problem, the JUnit people took the position that
createTempDirectoryis secure by default, even if the caller doesn't pass any restrictions on permissions. So far, I haven't found any documentation that confirms that (and the first link above implies that opposite), though I can say that I haven't found a way to make it insecure on Linux, and the Windows behavior that my teammate saw looked secure, as well. We would really like to know for sure, though, given how much Guava users have already been through for this vulnerability....After some more searching around, I've come across https://codeql.github.com/codeql-query-help/java/java-local-temp-file-or-directory-information-disclosure/, which at least suggests that Windows is different than Unix. It says that Windows provides each app with its own temporary directory and so you don't have to worry about permissions there. But that source would be more reassuring if it didn't suggest that you can change the permissions of an existing directory and then rely on it to be secure... and probably also if it didn't assume that all non-POSIX systems have secure temporary directories.
I found some more information that I haven't confirmed on Stack Overflow. (And I found that the Javadoc for
java.io.Filestill suggests that the default is typically "C:\WINNT\TEMP"... :))I see from the Calcite issue you linked (thanks!) that this comes from a file in embedded-redis, a project that hasn't had a commit in over 4 years. So I assume it's not going to get fixed there.
I also see that you have a workaround. I'd be interested to hear:
basil commentedon Jun 6, 2023
See JENKINS-71375. There are about 21,984 installations (across all operating systems) of the Jenkins Artifactory plugin, which is subject to jfrog/build-info#737 on Windows. As a result, Jenkins Artifactory plugin users who are running Jenkins on Windows are impacted by this issue.
cpovirk commentedon Jun 7, 2023
Thanks, and sorry: That's pretty impressively bad. I'll see what I can do about this tomorrow.
If anyone else ends up here and has any implementation tips, let me know. I'm tentatively planning to try to set ACL permissions on the directory, even though it's probably already in a secure directory, just to be safe. (By the time I'm convinced that I can prove that the code is running on NTFS or similar, I'm hoping it's not much harder to set the permissions, too.)
basil commentedon Jun 7, 2023
I think we should only be setting POSIX attributes when FileSystem#supportedFileAttributeViews contains
posix. The default value ofjava.io.tmpdiron Windows is the return value ofGetTempPathW, which is defined to return the first of these paths:TMPenvironment variable.TEMPenvironment variable.USERPROFILEenvironment variable.(This blog post goes into the gory details regarding why both
TMPandTEMPare set.)My Windows 10 system had
TMPandTEMPdefined to%USERPROFILE%\AppData\Local\Temp, to which onlySYSTEM, the current user, and members of the Administrators group had permissions. My Windows 2000 system defined these variables to%USERPROFILE%\Local Settings\Tempwith the same permissions.So it appears that the common case is for the directory returned by
GetTempPathWto be secure, but one could imagine various corner cases:TMP/TEMP/USERPROFILEto allow broader accessTMP/TEMP/USERPROFILEorjava.io.tmpdirto a directory with broader accessTMP/TEMP/USERPROFILEorjava.io.tmpdirto a directory on a less secure filesystem, like FAT32OpenJDK itself does not attempt to deal with these corner cases. If this approach is good enough for OpenJDK, it might be good enough for Guava as well. If not, it might be best to simply fail fast with e.g.
UnsupportedOperationExceptionif we detect a corner case. An approach that correctly handles all of these corner cases sounds like it would be challenging to implement (and test).cpovirk commentedon Jun 7, 2023
Thanks, that's all reassuring! I think I have figured out how to create the file with the desired ACL in the first place (by implementing
FileAttributemyself with the name "acl:acl" and the value of the desired ACL). (And now that I know how to do it, I can find the ~2 total places on the Internet that it seems to be explained: 1, 2 :)) I have commandeered my wife's Windows machine to test it out. If it falls through, I'll be reasonably comfortable just callingcreateTempDirectory/createTempFilewith no attributes, as you suggest.Files.createTempDirandFileBackedOutputStreamunder Windows. #6539Fix `Files.createTempDir` and `FileBackedOutputStream` under Windows.
Fix `Files.createTempDir` and `FileBackedOutputStream` under Windows.
Files.createTempDirandFileBackedOutputStreamunder Windows. #6540cpovirk commentedon Jun 7, 2023
OK, I have pushed #6540 (but you should ignore the PR with the number just before that one...) with my attempt at a fix. If any Windows users are in a position to easily test whether it solves the problems of 32.0.0, please give it a shot. Otherwise, I will probably release 32.0.1 with that change and wait to hear comments after release :)
19 remaining items
Downgrade Truth library to 1.1.3 (#3733)
JLLeitschuh commentedon Jun 12, 2023
I wrote this documentation, and wrote the query, and I'm just going based upon what I heard from someone else. I've never actually confirmed this myself. I don't ever develop code on/for windows
cpovirk commentedon Jun 12, 2023
Small world :) Thanks.
radistao commentedon Sep 29, 2023
still reproduced for me on Windows with
guava32.1.2 😢Note: when roll-backed to 31.1 - works fine, but neither 32+ version works;
Env:
cpovirk commentedon Sep 29, 2023
Thanks, can you point the failure stack trace? I'm wondering if you're seeing #6634 (which I have a pending fix for) or some other issue.
radistao commentedon Sep 29, 2023
Unfortunately, the code is a bit more complex: there is a
staticblock inside classConfigurationFactory:and this class can't be loaded when first time referenced at runtime with the error:
I tried to reproduce with the bare code (see https://github.com/radistao/guava-createTempDir), where only 'ConfigurationFactory' with static block exists, but not reproducible.
Unfortunately i don't have an access to Windows environment to develop and debug (only build and run), otherwise i'd try to debug in the full project.
The only thing i can confirm: in our jar (we use fat jar with bundled spring boot application) only guava has different version, the rest of the code an dependencies remained the same:

If i have access to Windows development environment soon - i'll try to reproduce in debug mode.
radistao commentedon Oct 3, 2023
today i tried to debug in Intellij IDEA and it works successfully (team directory is created), but when i build to a fat jar and run as a spring boot application, i observe the following errors:
The trust relationship between this workstation and the primary domain failed.- this is something new
again: this happens when first time initializing class
ConfigurationFactorywhich has a static block withFiles.createTempDirYes, we use Windows Active Directory configuration, but currently i'm logged as non-domain user with admin privileges, and i run the application on behalf of the same user.
Maybe also worth to mention: we run the application using Windows Service Wrapper for .NET4 (https://github.com/winsw/winsw), and the application registered and executed as a Windows Service.
Hope this will shed some light on the issue.
cpovirk commentedon Oct 3, 2023
Thanks, that does sound likely to be the same problem as #6634. I have a fix out for review.
radistao commentedon Oct 3, 2023
ah, i missed that #6634 also refers to Windows Services. so yes, seems similar (at least now i was able to collect the logs to prove it)