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

Added a check for whether files can be created and executed within the configured tmp-dir #8951

Merged
merged 4 commits into from
Oct 18, 2024

Conversation

KevinCLydon
Copy link
Member

@KevinCLydon KevinCLydon commented Aug 13, 2024

Adds a couple warnings in case the user can write to the configured tmp-dir but can't set the files as executable or execute them, with the assumption in the latter case that the cause is likely that the directory is mounted using the "noexec" mount option.

I'm not sure if a test makes sense for this, because it would probably require mounting a directory for testing, and the user running the tests may not have permissions to do that. I think only root can mount with options in Ubuntu? Do we require root for other tests?

Fixes #8453

@gatk-bot
Copy link

gatk-bot commented Aug 13, 2024

Github actions tests reported job failures from actions build 10373907397
Failures in the following jobs:

Test Type JDK Job ID Logs
integration 17.0.6+10 10373907397.11 logs
integration 17.0.6+10 10373907397.0 logs

@jamesemery jamesemery self-assigned this Sep 23, 2024
Copy link
Member

@lbergelson lbergelson left a comment

Choose a reason for hiding this comment

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

@KevinCLydon I've reviewed this. I have a few comments. I like this approach, it seems practical and pretty robust. Have you tested that it actually warns on a system configured this way?


// Warn if there's anything that prevents execution in the tmp dir because some tools need that
// This test relies on the file system supporting posix file permissions
if(p.getFileSystem().supportedFileAttributeViews().contains("posix")) {
Copy link
Member

Choose a reason for hiding this comment

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

So I would pull this whole bit out into a new method called something stupid like "tryToWriteAnExecutableFileAndWarnOnFailure". There are multiple levels of try / catch here and it's kind of confusing at the moment.

Copy link
Member Author

@KevinCLydon KevinCLydon Oct 18, 2024

Choose a reason for hiding this comment

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

I'll move this into a separate function but I'm not sure there's a great way to fix the nested try / catch issue. I want the inner one because it specifically catches issues setting exec permissions on the temp file and I don't think that function throws granular-enough exceptions for me to easily be able to distinguish between an exception from that and an exception from like creating the file or getting the posix permissions. And I need the outer try / catch even in a new function so I can make sure the temp file gets deleted.

Copy link
Member

Choose a reason for hiding this comment

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

I see your point and it makes sense. I'm not sure we care that much about treating those cases differently though? Can we give meaningfully different advice if getting permissions failed vs if setting exec failed? Maybe can. If you think that's a useful distinction I'm not against having it split out. I do like it all encapsulated in a function that won't explode in any case though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think maybe it's not a worthwhile distinction


// Warn if there's anything that prevents execution in the tmp dir because some tools need that
// This test relies on the file system supporting posix file permissions
if(p.getFileSystem().supportedFileAttributeViews().contains("posix")) {
Copy link
Member

Choose a reason for hiding this comment

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

A small and annoying caveat here, the HttpFileSystem throw UnsupportedOperation if you ask it this. (Which it probably should and we should fix).

Copy link
Member Author

Choose a reason for hiding this comment

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

What should be the course of action if that happens? Catch it and move on?

Copy link
Member

Choose a reason for hiding this comment

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

Well, we won't even get to here in that case, since we've already exploded on the check above due to not supporting write access. Just a weird edge case.

Copy link
Member

Choose a reason for hiding this comment

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

I think catch and continue was the right choice.

}
}
catch(IOException e) {
logger.warn(
Copy link
Member

Choose a reason for hiding this comment

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

We should probably attach the exception here. Since we want a sane human readable warning we might want to put an additional logger.debug(e) beneath this instead of logging it with the user warning.

"directory using --tmp-dir"
);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I always prefer braces styled like

} catch () {
   ...
} finally { 

instead of

} 
catch () {
 ...
}
finally {

It's not big deal either way and we definitely have examples of both, but if you're not ideologically I'd say use braces on the same line.

// This test relies on the file system supporting posix file permissions
if(p.getFileSystem().supportedFileAttributeViews().contains("posix")) {
// Write an empty file to the tempdir
tempFilePath = Files.createTempFile(p, "gatk_exec_test", null);
Copy link
Member

Choose a reason for hiding this comment

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

Lets move this and the permissions getting into the try block. I think we don't want additional potential exceptions propagating up here. This is a warning only situation.

"This can cause issues for some GATK tools. You can specify a different directory using " +
"--tmp-dir"
);
}
Copy link
Member

Choose a reason for hiding this comment

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

Lets add a logger.debug() line in the case where posix permissions aren't available.

finally {
// Make sure we clean up the test file
try {
if (tempFilePath != null)
Copy link
Member

Choose a reason for hiding this comment

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

always {}

);
}
}
catch(IOException e) {
Copy link
Member

Choose a reason for hiding this comment

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

We might want to catch general "Exception" here. That's generally bad practice, but in this case we really want this to be only a warning I think and not crash GATK if something weird gets thrown.

@@ -177,6 +214,16 @@ public Object instanceMainPostParseArgs() {
// other exceptions with the tmp directory
throw new UserException.BadTempDir(p, e.getMessage(), e);
}
finally {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can move this finally block and attack it to the try where we are writing the file.

@KevinCLydon
Copy link
Member Author

@lbergelson Okay, I think I have a better version now that hopefully addresses all your comments 🤞

@lbergelson
Copy link
Member

@KevinCLydon Loos good to me. If you think we should have a different warning in the case where we get an error while checking permissions then I support that, but I'm not sure what we'd tell people exactly.

Good to either implement that or merge .

@KevinCLydon KevinCLydon merged commit c18f3e2 into master Oct 18, 2024
16 checks passed
@KevinCLydon KevinCLydon deleted the kl_noexec_tmp_warning_8453 branch October 18, 2024 17:50
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.

GATK should warn the user when the temp dir is "noexec"
4 participants