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
[JENKINS-59775] Ensure that PluginManager.start runs as SYSTEM #4320
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks promising to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amends #4124 FTR.
String pluginShortName = "require-system-during-load"; | ||
dynamicLoad(pluginShortName + ".hpi"); | ||
try (ACLContext context = ACL.as(User.getOrCreateByIdOrFullName("underprivileged").impersonate())) { | ||
r.jenkins.pluginManager.start(Collections.singletonList(r.jenkins.pluginManager.getPlugin(pluginShortName))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in what way does this fail with src/main/
reverted? Since it is not obvious to at least me as a reviewer, best to show the stack trace of the test failure in the PR description or a line comment or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stacktrace is in the JIRA. Here is what happens in that test without the fix:
hudson.security.AccessDeniedException2: underprivileged is missing the Overall/Administer permission
at hudson.security.ACL.checkPermission(ACL.java:73)
at hudson.security.AccessControlled.checkPermission(AccessControlled.java:47)
at test.ThePlugin.postInitialize(ThePlugin.java:10)
at hudson.PluginManager.start(PluginManager.java:955)
at hudson.PluginManagerTest.requireSystemDuringStart(PluginManagerTest.java:474)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.jvnet.hudson.test.JenkinsRule$1.evaluate(JenkinsRule.java:600)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
@@ -948,49 +948,51 @@ public void dynamicLoad(File arc, boolean removeExisting, @CheckForNull List<Plu | |||
|
|||
@Restricted(NoExternalUse.class) | |||
public void start(List<PluginWrapper> plugins) throws Exception { | |||
Jenkins.get().refreshExtensions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have to Hide whitespace changes to see what is happening here. Risk of merge conflicts, git blame
issues, etc. For cases like this I tend to recommend either leaving the original code at its original indentation (despite looking ugly), or introducing a helper method:
public void start(List<PluginWrapper> plugins) throws Exception {
try (ACLContext context = ACL.as(ACL.SYSTEM)) {
doStart(plugins);
}
}
private void doStart(List<PluginWrapper> plugins) throws Exception {
// as before…
}
to minimize the diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I'll work with the indentation.
Co-Authored-By: Jesse Glick <jglick@cloudbees.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks right. I plan to merge it tomorrow if no negative feedback.
See JENKINS-59775.
Proposed changelog entries
Submitter checklist
Desired reviewers
@jglick @reviewbybees