-
Notifications
You must be signed in to change notification settings - Fork 30
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-40533] Allow definition of sandboxed libraries at global scope #129
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
669afe2
[JENKINS-40533] Allow definition of sandboxed libraries at global scope
Vlatombe 6d0bb7f
Move isTrusted to the concrete class
Vlatombe 443a6bd
Fix message
Vlatombe 98322fb
Namespace libraries per source to avoid naming clashes
Vlatombe fcd5409
Retain old behaviour for GlobalLibraries
Vlatombe 6654038
Merge branch 'master' into JENKINS-40533
Vlatombe 39fb0fc
make it abstract
Vlatombe f79a32c
Simplify
Vlatombe fcd2360
Add missing spotbugs annotations
Vlatombe 218384f
And yet a few more
Vlatombe 94f0443
Put untrusted libraries just after trusted ones
Vlatombe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/main/java/org/jenkinsci/plugins/workflow/libs/AbstractGlobalLibraries.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2024 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.jenkinsci.plugins.workflow.libs; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.model.ItemGroup; | ||
import hudson.model.Job; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import jenkins.model.GlobalConfiguration; | ||
import jenkins.model.Jenkins; | ||
import net.sf.json.JSONObject; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
/** | ||
* Common code between {@link GlobalLibraries} and {@link GlobalUntrustedLibraries}. | ||
*/ | ||
public abstract class AbstractGlobalLibraries extends GlobalConfiguration { | ||
private List<LibraryConfiguration> libraries = new ArrayList<>(); | ||
|
||
protected AbstractGlobalLibraries() { | ||
load(); | ||
} | ||
|
||
public abstract String getDescription(); | ||
|
||
public List<LibraryConfiguration> getLibraries() { | ||
return libraries; | ||
} | ||
|
||
public void setLibraries(List<LibraryConfiguration> libraries) { | ||
this.libraries = libraries; | ||
save(); | ||
} | ||
|
||
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { | ||
if (Jenkins.get().hasPermission(getRequiredGlobalConfigPagePermission())) { | ||
setLibraries(Collections.emptyList()); // allow last library to be deleted | ||
return super.configure(req, json); | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
abstract static class AbstractForJob extends LibraryResolver { | ||
protected abstract AbstractGlobalLibraries getConfiguration(); | ||
|
||
@NonNull @Override public final Collection<LibraryConfiguration> forJob(@NonNull Job<?,?> job, @NonNull Map<String,String> libraryVersions) { | ||
return getLibraries(); | ||
} | ||
|
||
@NonNull @Override public final Collection<LibraryConfiguration> fromConfiguration(@NonNull StaplerRequest request) { | ||
AbstractGlobalLibraries abstractGlobalLibraries = getConfiguration(); | ||
if (Jenkins.get().hasPermission(abstractGlobalLibraries.getRequiredGlobalConfigPagePermission())) { | ||
return getLibraries(); | ||
} | ||
return Collections.emptySet(); | ||
} | ||
|
||
@NonNull @Override public final Collection<LibraryConfiguration> suggestedConfigurations(@NonNull ItemGroup<?> group) { | ||
return getLibraries(); | ||
} | ||
|
||
private List<LibraryConfiguration> getLibraries() { | ||
return getConfiguration().getLibraries(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/org/jenkinsci/plugins/workflow/libs/GlobalUntrustedLibraries.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2024 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package org.jenkinsci.plugins.workflow.libs; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.Extension; | ||
import hudson.ExtensionList; | ||
import hudson.security.Permission; | ||
import jenkins.model.Jenkins; | ||
|
||
/** | ||
* Manages untrusted libraries available to any job in the system. | ||
*/ | ||
@Extension public class GlobalUntrustedLibraries extends AbstractGlobalLibraries { | ||
|
||
public GlobalUntrustedLibraries() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return Messages.GlobalUntrustedLibraries_Description(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String getDisplayName() { | ||
return Messages.GlobalUntrustedLibraries_DisplayName(); | ||
} | ||
|
||
public static @NonNull GlobalUntrustedLibraries get() { | ||
return ExtensionList.lookupSingleton(GlobalUntrustedLibraries.class); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Permission getRequiredGlobalConfigPagePermission() { | ||
return Jenkins.MANAGE; | ||
} | ||
|
||
@Extension(ordinal=0) public static class ForJob extends AbstractForJob { | ||
protected GlobalUntrustedLibraries getConfiguration() { | ||
return get(); | ||
} | ||
|
||
@Override | ||
public boolean isTrusted() { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
src/main/resources/org/jenkinsci/plugins/workflow/libs/GlobalLibraries/config.properties
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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 think this implementation needs to wrap the returned libraries in
ResolvedLibraryConfiguration
likeFolderLibraries.ForJob
to avoid introducing a new security issue like what was fixed by ace0de3.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.
Maybe the trust flag is enough though, I am not sure. Either way I would look at old security fixes here carefully to see if anything extra needs to be done to separate the two global configurations in all contexts.
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.
Indeed, this is addressed in 98322fb
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.
Looking at the old fix in more detail, I think it was probably fine as you had it originally because of this line:
pipeline-groovy-lib-plugin/src/main/java/org/jenkinsci/plugins/workflow/libs/LibraryAdder.java
Line 132 in b98828a
I think folder-based libraries just needed special treatment to distinguish between folders with the same name defined at different levels since they use the same
LibraryResolver
class. Since the new untrusted global libraries use a distinct resolver class and only exist in a single place, things should be fine without wrappingLibraryConfiguration
s. Your changes usegetClass().getName()
anyway so the behavior should be identical. I didn't try testing it though.