Skip to content

Fix library cache deletion after SECURITY-2586 #148

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

Merged
merged 5 commits into from
May 13, 2022

Conversation

dwnusbaum
Copy link
Member

@dwnusbaum dwnusbaum commented Mar 18, 2022

The security fixes related to the cache feature in ace0de3 broke LibraryCachingCleanup (cleans up unused cache directories) and LibraryCachingConfiguration.doClearCache (allows admins to manually delete all cached versions of a specific library). This went unnoticed because neither piece of functionality had any test coverage.

This PR fixes the issues with library cache deletion after SECURITY-2586 and adds relevant test coverage.

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

Sorry, something went wrong.

} else {
listener.getLogger().println("Caching library " + name + "@" + version);
versionCacheDir.mkdirs();
retrieveLockFile.touch(System.currentTimeMillis());
retriever.retrieve(name, version, changelog, versionCacheDir, run, listener);
retrieveLockFile.delete();
}
lastReadFile.touch(System.currentTimeMillis());
Copy link
Member Author

Choose a reason for hiding this comment

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

Now we write this even when creating the cache directory for the first time, so that it will eventually be deleted even if it was only used once.

} else {
listener.getLogger().println("Caching library " + name + "@" + version);
versionCacheDir.mkdirs();
retrieveLockFile.touch(System.currentTimeMillis());
retriever.retrieve(name, version, changelog, versionCacheDir, run, listener);
retrieveLockFile.delete();
}
lastReadFile.touch(System.currentTimeMillis());
versionCacheDir.withSuffix("-name.txt").write(name, "UTF-8");
Copy link
Member Author

Choose a reason for hiding this comment

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

We write this every time rather than just when the cache is first created to handle caches created after the security fix but before this PR.

Comment on lines -17 to -18
recurrencePeriod = Long.getLong("jenkins.workflow-libs.cacheCleanupPeriodDays", TimeUnit.DAYS.toMillis(7));
unreadCacheClearTime = Long.getLong("jenkins.workflow-libs.unreadCacheClearDays", TimeUnit.DAYS.toMillis(7));
Copy link
Member Author

Choose a reason for hiding this comment

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

These did not follow standard Jenkins system property naming conventions, and I did not see any documentation related to them, so I created a new EXPIRE_AFTER_READ_DAYS property that follows the normal Jenkins style.

}

@Override public long getRecurrencePeriod() {
return recurrencePeriod;
return TimeUnit.HOURS.toMillis(12);
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously this was 7 days, which combined with unreadCacheClearTime being 7 days meant that in the worst case a library could go almost 2 weeks without being cleaned up, and if Jenkins restarts in that time frame, the timer would start all over again.

Since the check is not that expensive, I think it is fine to run it twice a day.

Comment on lines +34 to +36
<j:if test="${h.hasPermission(app.ADMINISTER)}">
<f:validateButton title="${%Clear cache}" progress="${%Clearing...}" method="clearCache" with="name" />
</j:if>
Copy link
Member Author

Choose a reason for hiding this comment

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

The backend has always required ADMINISTER permission, but we used to show this button on folder-level libraries to anyone with Job/Configure permission, which is just confusing.

@dwnusbaum dwnusbaum marked this pull request as ready for review March 18, 2022 21:20
@mawinter69
Copy link

Any idea when this will get merged?
I need this for my fix in #151

@dwnusbaum dwnusbaum merged commit e633085 into jenkinsci:master May 13, 2022
@dwnusbaum dwnusbaum deleted the fix-cache-deletion branch May 13, 2022 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants