From c597c4aa000827eb95576856cb71c8373a065cb9 Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Wed, 7 Aug 2024 18:19:11 +0200 Subject: [PATCH] Drop support for remoting releases before 2024-08 --- core/pom.xml | 2 +- core/src/main/java/hudson/PluginManager.java | 16 -- .../security/s2m/JarURLValidatorImpl.java | 104 ----------- pom.xml | 3 +- test/pom.xml | 10 +- .../jenkins/security/Security3430Test.java | 161 +++--------------- war/pom.xml | 2 +- 7 files changed, 33 insertions(+), 265 deletions(-) delete mode 100644 core/src/main/java/jenkins/security/s2m/JarURLValidatorImpl.java diff --git a/core/pom.xml b/core/pom.xml index 8e30ae211ed7..63d789788369 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -41,7 +41,7 @@ THE SOFTWARE. 2.10.0 - 3107.v665000b_51092 + 3256.3258.v858f3c9a_f69d diff --git a/core/src/main/java/hudson/PluginManager.java b/core/src/main/java/hudson/PluginManager.java index 16c22e9ca90c..75dd52c4d7b7 100644 --- a/core/src/main/java/hudson/PluginManager.java +++ b/core/src/main/java/hudson/PluginManager.java @@ -2417,22 +2417,6 @@ public String toString() { // only for debugging purpose return "classLoader " + getClass().getName(); } - - // TODO Remove this once we require post 2024-07 remoting minimum version and deleted ClassLoaderProxy#fetchJar(URL) - @SuppressFBWarnings( - value = "DMI_COLLECTION_OF_URLS", - justification = "All URLs point to local files, so no DNS lookup.") - @Restricted(NoExternalUse.class) - public boolean isPluginJar(URL jarUrl) { - for (PluginWrapper plugin : activePlugins) { - if (plugin.classLoader instanceof URLClassLoader) { - if (Set.of(((URLClassLoader) plugin.classLoader).getURLs()).contains(jarUrl)) { - return true; - } - } - } - return false; - } } @SuppressFBWarnings(value = "MS_SHOULD_BE_FINAL", justification = "for script console") diff --git a/core/src/main/java/jenkins/security/s2m/JarURLValidatorImpl.java b/core/src/main/java/jenkins/security/s2m/JarURLValidatorImpl.java deleted file mode 100644 index 7fafcea946d5..000000000000 --- a/core/src/main/java/jenkins/security/s2m/JarURLValidatorImpl.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 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 jenkins.security.s2m; - -import edu.umd.cs.findbugs.annotations.Nullable; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import hudson.Extension; -import hudson.PluginManager; -import hudson.remoting.Channel; -import hudson.remoting.ChannelBuilder; -import hudson.remoting.JarURLValidator; -import java.io.IOException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; -import jenkins.model.Jenkins; -import jenkins.security.ChannelConfigurator; -import jenkins.util.SystemProperties; -import org.kohsuke.accmod.Restricted; -import org.kohsuke.accmod.restrictions.NoExternalUse; - -@Restricted(NoExternalUse.class) -@Deprecated -@Extension -public class JarURLValidatorImpl extends ChannelConfigurator implements JarURLValidator { - - public static final Logger LOGGER = Logger.getLogger(JarURLValidatorImpl.class.getName()); - - @Override - public void onChannelBuilding(ChannelBuilder builder, @Nullable Object context) { - LOGGER.log(Level.CONFIG, () -> "Setting up JarURLValidatorImpl for context: " + context); - builder.withProperty(JarURLValidator.class, this); - } - - @Override - public void validate(URL url) throws IOException { - final String rejectAllProp = JarURLValidatorImpl.class.getName() + ".REJECT_ALL"; - if (SystemProperties.getBoolean(rejectAllProp)) { - LOGGER.log(Level.FINE, () -> "Rejecting URL due to configuration: " + url); - throw new IOException("The system property '" + rejectAllProp + "' has been set, so all attempts by agents to load jars from the controller are rejected." - + " Update the agent.jar of the affected agent to a version released in August 2024 or later to prevent this error."); // TODO better version spec - } - final String allowAllProp = Channel.class.getName() + ".DISABLE_JAR_URL_VALIDATOR"; - if (SystemProperties.getBoolean(allowAllProp)) { - LOGGER.log(Level.FINE, () -> "Allowing URL due to configuration: " + url); - return; - } - if (!isAllowedJar(url)) { - LOGGER.log(Level.FINE, () -> "Rejecting URL: " + url); - throw new IOException("This URL does not point to a jar file allowed to be requested by agents: " + url + "." - + " Update the agent.jar of the affected agent to a version released in August 2024 or later to prevent this error." - + " Alternatively, set the system property '" + allowAllProp + "' to 'true' if all the code built by Jenkins is as trusted as an administrator."); - } else { - LOGGER.log(Level.FINE, () -> "Allowing URL: " + url); - } - } - @SuppressFBWarnings( - value = "DMI_COLLECTION_OF_URLS", - justification = "All URLs point to local files, so no DNS lookup.") - private static boolean isAllowedJar(URL url) { - final ClassLoader classLoader = Jenkins.get().getPluginManager().uberClassLoader; - if (classLoader instanceof PluginManager.UberClassLoader uberClassLoader) { - if (uberClassLoader.isPluginJar(url)) { - LOGGER.log(Level.FINER, () -> "Determined to be plugin jar: " + url); - return true; - } - } - - final ClassLoader coreClassLoader = Jenkins.class.getClassLoader(); - if (coreClassLoader instanceof URLClassLoader urlClassLoader) { - if (Set.of(urlClassLoader.getURLs()).contains(url)) { - LOGGER.log(Level.FINER, () -> "Determined to be core jar: " + url); - return true; - } - } - - LOGGER.log(Level.FINER, () -> "Neither core nor plugin jar: " + url); - return false; - } -} diff --git a/pom.xml b/pom.xml index a0673a9c6cc1..f6229f33af46 100644 --- a/pom.xml +++ b/pom.xml @@ -87,7 +87,8 @@ THE SOFTWARE. https://www.jenkins.io/changelog - 3256.3258.v858f3c9a_f69d + + 3262.v48cc7b_a_2fee8 Max Medium diff --git a/test/pom.xml b/test/pom.xml index 7b0a43d7c4a1..3f1d1ff9f144 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -39,7 +39,7 @@ THE SOFTWARE. false - 3107.v665000b_51092 + 3256.3258.v858f3c9a_f69d - 3107.v665000b_51092 + 3256.3258.v858f3c9a_f69d 20.16.0 1.22.19