-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Record an informative stack trace & telemetry whenever
FilePath
age…
…nt-to-controller access is permitted (#5890) * Record an informative stack trace whenever `SlaveToMasterFileCallable` is permitted * Also record telemetry as `SlaveToMasterFileCallableUsage` * Deduplicate stack traces, and verify in test * Push out end date to 2022-03-01 * `noopener noreferrer` needed on external links Co-authored-by: Daniel Beck <1831569+daniel-beck@users.noreply.github.com> * s/should/does/ in help Co-authored-by: Daniel Beck <1831569+daniel-beck@users.noreply.github.com> * Link to redirect w/ more info Co-authored-by: Daniel Beck <1831569+daniel-beck@users.noreply.github.com> * `mvn spotless:apply` Co-authored-by: Daniel Beck <1831569+daniel-beck@users.noreply.github.com>
- Loading branch information
1 parent
65b9f1c
commit 55c31c8
Showing
4 changed files
with
118 additions
and
0 deletions.
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
75 changes: 75 additions & 0 deletions
75
core/src/main/java/jenkins/telemetry/impl/SlaveToMasterFileCallableUsage.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,75 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2021 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.telemetry.impl; | ||
|
||
import hudson.Extension; | ||
import hudson.Functions; | ||
import java.time.LocalDate; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
import jenkins.SlaveToMasterFileCallable; | ||
import jenkins.security.s2m.DefaultFilePathFilter; | ||
import jenkins.telemetry.Telemetry; | ||
import net.sf.json.JSONObject; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
/** | ||
* Records when {@link DefaultFilePathFilter} found {@link SlaveToMasterFileCallable} or similar being used. | ||
*/ | ||
@Extension | ||
@Restricted(NoExternalUse.class) | ||
public class SlaveToMasterFileCallableUsage extends Telemetry { | ||
|
||
private Set<String> traces = new TreeSet<>(); | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Access to files on controllers from code running on an agent"; | ||
} | ||
|
||
@Override | ||
public LocalDate getStart() { | ||
return LocalDate.of(2021, 11, 4); // https://www.jenkins.io/security/advisory/2021-11-04/ | ||
} | ||
|
||
@Override | ||
public LocalDate getEnd() { | ||
return LocalDate.of(2022, 3, 1); | ||
} | ||
|
||
@Override | ||
public synchronized JSONObject createContent() { | ||
JSONObject json = JSONObject.fromObject(Collections.singletonMap("traces", traces)); | ||
traces.clear(); | ||
return json; | ||
} | ||
|
||
public synchronized void recordTrace(Throwable trace) { | ||
traces.add(Functions.printThrowable(trace).replaceAll("@[a-f0-9]+", "@…")); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...rc/main/resources/jenkins/telemetry/impl/SlaveToMasterFileCallableUsage/description.jelly
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,13 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core"> | ||
Jenkins controllers construct a remote-procedure-call (RPC) channel to agents to instruct them to perform work. | ||
This channel is bidirectional and in a handful of cases agents made requests of the controller. | ||
This was always tricky to secure, | ||
and <a href="https://www.jenkins.io/security/advisory/2021-11-04/" target="_blank" rel="noopener noreferrer">recently</a> | ||
the category of usages which involved access to files was more tightly restricted than before; | ||
Jenkins developers are considering disabling this kind of usage entirely. | ||
Since it is difficult to determine via static analysis or even manual code inspection which plugins are using this system, | ||
we are collecting information on how widely it is used. | ||
The data includes names of Java classes mainly in Jenkins core and plugins as well as method names and line numbers. | ||
It does not include the names of files being accessed or anything else not determined by versions of software components in use. | ||
</j:jelly> |
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