Avoid Apache Commons IO utility methods when writing config files to JENKINS_HOME
to fix AccessDeniedException
in some cases
#436
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(I can file a Jira ticket if needed)
I recently investigated an issue reported by a user where Jenkins was working totally normally, but when they tried to change their security realm to SAML, they were unable to save the change. The issue seemed to be that they had JENKINS_HOME hard linked to an NFS mount point like
/my-mount
, and this broke the logic in the Apache Common IO utility methods that check for the existence of the file and create parent directories if needed. Here is the relevant part of the stack trace:Interactive testing in the script console showed that the
FileUtils.writeStringToFile
method really was uniquely causing the issue (I also checked whether the use ofgetAbsolutePath
in the config file path getter methods was a problem), andFiles.write
worked fine for the same files.In this plugin, we always use these methods to write files that are direct children of
JENKINS_HOME
, so there is no need tocheck for and create parent directories since we can assume that
JENKINS_HOME
exists, so this PR just switches to usingFiles.write
in all of the relevant cases.I did not find a way to reproduce the same
AccessDeniesException
reported by the user in a test to be able to create a regression test. The logic seems to be covered in at least basic ways by the existing tests though.Submitter checklist