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

[JENKINS-59775] Ensure that PluginManager.start runs as SYSTEM #4320

Merged
merged 4 commits into from Nov 2, 2019

Conversation

Dohbedoh
Copy link
Contributor

See JENKINS-59775.

Proposed changelog entries

  • Fix PluginManager dynamicLoad permissions

Submitter checklist

  • JIRA issue is well described
  • Changelog entry appropriate for the audience affected by the change (users or developer, depending on the change).
  • Appropriate autotests or explanation to why this change has no tests

Desired reviewers

@jglick @reviewbybees

Copy link
Member

@aheritier aheritier left a 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

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Amends #4124 FTR.

test/src/test/java/hudson/PluginManagerTest.java Outdated Show resolved Hide resolved
test/src/test/java/hudson/PluginManagerTest.java Outdated Show resolved Hide resolved
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)));
Copy link
Member

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.

Copy link
Contributor Author

@Dohbedoh Dohbedoh Oct 28, 2019

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();
Copy link
Member

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.

Copy link
Contributor Author

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.

Dohbedoh and others added 3 commits October 28, 2019 19:28
Copy link
Member

@oleg-nenashev oleg-nenashev left a 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.

@oleg-nenashev oleg-nenashev added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Oct 31, 2019
@oleg-nenashev oleg-nenashev merged commit e99c183 into jenkinsci:master Nov 2, 2019
@oleg-nenashev oleg-nenashev added the bug For changelog: Minor bug. Will be listed after features label Nov 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For changelog: Minor bug. Will be listed after features ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
4 participants