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

[SUREFIRE-2109] Add suffix derived from current user to Surefire temp directory name #554

Merged
merged 1 commit into from
Jan 4, 2023
Merged

Conversation

spannm
Copy link
Contributor

@spannm spannm commented Jul 10, 2022

This pull request offers a fix for bug [SUREFIRE-2109].

Following this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SUREFIRE-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace SUREFIRE-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean install).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@olamy olamy added the bug label Jul 24, 2022
Copy link
Member

@olamy olamy left a comment

Choose a reason for hiding this comment

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

LGTM

@spannm
Copy link
Contributor Author

spannm commented Aug 29, 2022

Hi @olamy is there anything left to do for me, or is this pr ready to be merged?

@@ -180,6 +180,8 @@ public synchronized File createTempFile( String prefix, String suffix )
throw new UncheckedIOException( new IOException(
"Unable to create temporary directory " + tempDir.getAbsolutePath() ) );
}
// try to make temp file directory writable for all
tempDir.setWritable( true, false );

Choose a reason for hiding this comment

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

Security-wise, I don't think it's a good idea to have a shared directory with other users. Why would you need this? Also, why not use java.nio.file.Files.createTempDirectory() and specify 'surefire-' + the username as prefix?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand the "writable for all" part of the change either. If the temp directory name is user-specific, why would anyone else need to have write access?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The aim of the original PR was to stop Surefire from bloating the system temp directory by instead having it write into a subdirectory 'surefire'. The subdirectory was only writeable by the user that created it. So Surefire would fail if another user ran tests on the same machine (before reboot or otherwise cleaning up temp). Thus the user suffix is introduced by this PR. As user names may contain characters illegal in directory names, there is a risk, even though small or theoretic, that two users have identically names temp subdirectories. By making the directory writeable for all, this risk is eliminated.
Until very recently Surefire wrote to system temp which by definition is shared by all users and was never a security concern to anyone. This PR leaves this semantic untouched.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation.

I understand the rationale now, but what about the scenario that java.io.tmpdir is set to a user-specific location in an otherwise protected area? I still think there should be a difference in scrutiny applied between writing to a destination that is already world-writable by design and explicitly making the destination world-writable.

How about passing the username through URLEncoder#encode instead of removing special characters? That is guaranteed to create a directory name that is collision-free and valid on all file systems. It also handles the issue immediately at the code location where it arises rather than working around it somewhere else in a manner that is not particularly easy to grasp.

Copy link

@cpfeiffer cpfeiffer Dec 31, 2022

Choose a reason for hiding this comment

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

If you only want to avoid clashes between multiple users, Files.createTempDirectory("surefire-") would create the unique, collision-free directory for you.

Copy link
Contributor

Choose a reason for hiding this comment

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

That would bloat the system temp directory again, so it would run counter to the motivation for the original change as described in SUREFIRE-2086.

As @sman-81 said: The aim of the original PR was to stop Surefire from bloating the system temp directory by instead having it create the new directory in a fixed subdirectory of the system temp directory, not the system temp directory itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your input!
I'll amend and rebase the PR early next week.
Until then: Happy New Year!

Copy link
Contributor Author

@spannm spannm Jan 2, 2023

Choose a reason for hiding this comment

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

I've removed the "writable for all" part. The chance of two similar user names - working on the same machine! - resulting in identical sub directory names is theoretic at best. Having the user name as part of the directory name is helpful to quickly spot one's own directory. We are good leaving this part of the code as-is IMO. I look forward to your feedback.

@spannm spannm changed the title [SUREFIRE-2109] Add suffix derived from current user to Surefire temp directory name and make directory writable for all [SUREFIRE-2109] Add suffix derived from current user to Surefire temp directory name Jan 2, 2023
@spannm spannm requested review from cpfeiffer and andpab and removed request for cpfeiffer and andpab January 2, 2023 07:05
Copy link
Contributor

@andpab andpab left a comment

Choose a reason for hiding this comment

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

Fine with me. 👍

For the record: The URLEncoder approach would also have kept the username unchanged for the character set you have in your regex. From the javadoc:

  • The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
  • The special characters ".", "-", "*", and "_" remain the same.

@spannm
Copy link
Contributor Author

spannm commented Jan 3, 2023

This is ready to ship now.
Who can merge this PR?

@andpab
Copy link
Contributor

andpab commented Jan 3, 2023

@olamy Can you merge this PR?

@slawekjaranowski
Copy link
Member

Looks good enough ...
I see one another issue - what when JVM not exit immediately ... like in mvnd - classes are loaded once and can be reused. But it can be next issue ...

@slawekjaranowski slawekjaranowski self-assigned this Jan 3, 2023
@slawekjaranowski slawekjaranowski merged commit c068b12 into apache:master Jan 4, 2023
@spannm spannm deleted the sman-81-SUREFIRE-2109 branch January 17, 2023 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants