Skip to content

Commit 52f0a2d

Browse files
authored
Add Snyk (#312)
* 🚧 snyk config * 👷 add snyk CI step * 🔒 upgrade auto-service, retain annotations only at compile time * :arrow_up upgrade protpbuf-java-util to resolve guava dependency vulnerability * 🔒 exclude netty from being available at runtime * 🔒 exclude apache from being available at runtime * 🔒 upgrade jetty for tests * 🔒 exclude apache library from runtime classpath * 🐛 fix library conifguration for apache httpclient * 🐛 fix library configuraton for netty-4.1 * 🔒 💩 ignore vulns * 🐛 fix bug where testRuntimeClasspath was also being considered for dependency scan in CI * 🔊 add debugging info * 🔒 exclude vertx from runtime classpath * 🐛 used named rather than class literal when specifying transformers * ♻️ refactor library configuration into shared plugin * ⏪ revert changes to jetty-server version that are not needed * ♻️ refactor testing-common to use test-fixtures plugin * 🔥 delete snyk policy * 🐛 fix projects depending on new test-fixtures project * ♻️ simplify checked cast of ProjectDependency * ⬆️ complete uprade of protobuf * 💡 document the new library configuration
1 parent b8e63cf commit 52f0a2d

File tree

34 files changed

+144
-60
lines changed

34 files changed

+144
-60
lines changed

.github/workflows/build.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,20 @@ jobs:
6464
env:
6565
JVM_OPTS: -Xmx1g
6666
TERM: dumb
67+
68+
snyk-scan:
69+
runs-on: ubuntu-20.04
70+
steps:
71+
# Set fetch-depth: 0 to fetch commit history and tags for use in version calculation
72+
- name: Check out code
73+
uses: actions/[email protected]
74+
with:
75+
fetch-depth: 0
76+
submodules: true
77+
- name: Setup snyk
78+
uses: snyk/actions/[email protected]
79+
- name: Snyk test
80+
run: snyk test -d --all-sub-projects --org=hypertrace --severity-threshold=low --configuration-matching="^runtimeClasspath$"
81+
env:
82+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
83+
GRADLE_OPTS: -Dorg.gradle.workers.max=1

buildSrc/src/main/java/io/opentelemetry/instrumentation/gradle/AutoInstrumentationPlugin.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.util.Arrays;
1010
import org.gradle.api.Plugin;
1111
import org.gradle.api.Project;
12+
import org.gradle.api.artifacts.Configuration;
13+
import org.gradle.api.artifacts.Dependency;
1214
import org.gradle.api.plugins.JavaLibraryPlugin;
1315
import org.gradle.api.tasks.Internal;
1416
import org.gradle.api.tasks.testing.Test;
@@ -24,6 +26,7 @@ public class AutoInstrumentationPlugin implements Plugin<Project> {
2426
@Override
2527
public void apply(Project project) {
2628
project.getPlugins().apply(JavaLibraryPlugin.class);
29+
createLibraryConfiguration(project);
2730
project
2831
.getTasks()
2932
.withType(
@@ -40,7 +43,56 @@ public void apply(Project project) {
4043
});
4144
}
4245

46+
/**
47+
* Creates a custom dependency configuration called {@code library} inspired by the <a
48+
* href="https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/0b0516bd1a0599c8f536cc6b2151782000681f39/gradle/instrumentation-common.gradle#L8">opentelemetry-java-instrumentation</a>.
49+
* Namely, this instructs Gradle to include the classes from the dependency on the {@code
50+
* compileClasspath} and the {@code testRuntimeClasspath} but not the {@code runtimeClasspath}.
51+
* This makes the scope of the dependency clear to all consumers of this project and gives
52+
* stronger guarantees that we won't accidentally include libraries targeted for instrumentation
53+
* in the published Hypertrace javaagent JAR.
54+
*
55+
* <p> Example usage:
56+
* <pre>
57+
* dependencies {
58+
* library("org.apache.httpcomponents:httpclient:4.0")
59+
* }
60+
* </pre>
61+
*
62+
* <p> This above snippet is functionally equivalent to:
63+
* <pre>
64+
* dependencies {
65+
* compileOnly("org.apache.httpcomponents:httpclient:4.0")
66+
* testImplementation("org.apache.httpcomponents:httpclient:4.0")
67+
* }
68+
* </pre>
69+
*
70+
*
71+
* <p>This change was first introduced to help our dependency scanning tool, Snyk, understand
72+
* that certain dependencies are not going to be included in the published artifact and therefore
73+
* do not represent security vulnerabilities
74+
*
75+
* @param project to create the configuration in
76+
*/
77+
private void createLibraryConfiguration(Project project) {
78+
final Configuration libraryConfiguration = project.getConfigurations()
79+
.create("library", files -> {
80+
files.setCanBeConsumed(false);
81+
files.setCanBeResolved(false);
82+
});
83+
// here, we manually copy dependencies added with the library configuration and add them to the
84+
// testImplementation DependencySet as well. Inspired by https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/0b0516bd1a0599c8f536cc6b2151782000681f39/gradle/instrumentation-common.gradle#L46
85+
libraryConfiguration.getDependencies().whenObjectAdded(
86+
dependency -> {
87+
final Dependency copy = dependency.copy();
88+
project.getConfigurations().named("testImplementation").get().getDependencies().add(copy);
89+
}
90+
);
91+
project.getConfigurations().named("compileOnly").get().extendsFrom(libraryConfiguration);
92+
}
93+
4394
private static class InstrumentationTestArgs implements CommandLineArgumentProvider {
95+
4496
private final File bootstrapJar;
4597

4698
@Internal

filter-api/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ val versions: Map<String, String> by extra
88
dependencies {
99
api("io.opentelemetry:opentelemetry-api:${versions["opentelemetry"]}")
1010
api(project(":javaagent-core"))
11-
implementation("com.google.auto.service:auto-service:1.0-rc7")
11+
compileOnly("com.google.auto.service:auto-service-annotations:1.0")
1212
implementation("org.slf4j:slf4j-api:${versions["slf4j"]}")
13-
annotationProcessor("com.google.auto.service:auto-service:1.0-rc7")
13+
annotationProcessor("com.google.auto.service:auto-service:1.0")
1414
}

instrumentation/apache-httpasyncclient-4.1/build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ dependencies {
3232

3333
api("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-apache-httpasyncclient-4.1:${versions["opentelemetry_java_agent"]}")
3434

35-
implementation("org.apache.httpcomponents:httpasyncclient:4.1")
36-
37-
testImplementation(project(":testing-common"))
35+
library("org.apache.httpcomponents:httpasyncclient:4.1")
36+
testImplementation(testFixtures(project(":testing-common")))
3837
}
3938

instrumentation/apache-httpclient-4.0/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies {
4242
api(project(":instrumentation:java-streams"))
4343
api("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-apache-httpclient-4.0:${versions["opentelemetry_java_agent"]}")
4444

45-
implementation("org.apache.httpcomponents:httpclient:4.0")
45+
library("org.apache.httpcomponents:httpclient:4.0")
4646

47-
testImplementation(project(":testing-common"))
47+
testImplementation(testFixtures(project(":testing-common")))
4848
}

instrumentation/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ val versions: Map<String, String> by extra
88
subprojects {
99
dependencies {
1010
implementation("org.slf4j:slf4j-api:1.7.30")
11-
implementation("com.google.auto.service:auto-service:1.0-rc7")
12-
annotationProcessor("com.google.auto.service:auto-service:1.0-rc7")
11+
compileOnly("com.google.auto.service:auto-service-annotations:1.0")
12+
annotationProcessor("com.google.auto.service:auto-service:1.0")
1313
implementation("net.bytebuddy:byte-buddy:${versions["byte_buddy"]}")
1414

1515
implementation("io.opentelemetry:opentelemetry-api:${versions["opentelemetry"]}")

instrumentation/grpc-1.5/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ dependencies {
6868

6969
implementation("javax.annotation:javax.annotation-api:1.3.2")
7070

71-
testImplementation(project(":testing-common"))
71+
testImplementation(testFixtures(project(":testing-common")))
7272
testImplementation("io.grpc:grpc-core:${grpcVersion}") {
7373
version {
7474
strictly(grpcVersion)

instrumentation/java-streams/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ afterEvaluate{
2020
}
2121

2222
dependencies {
23-
testImplementation(project(":testing-common"))
23+
testImplementation(testFixtures(project(":testing-common")))
2424
}

instrumentation/jaxrs-client-2.0/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies {
3737

3838
compileOnly("javax.ws.rs:javax.ws.rs-api:2.0.1")
3939

40-
testImplementation(project(":testing-common"))
40+
testImplementation(testFixtures(project(":testing-common")))
4141
testImplementation("org.glassfish.jersey.core:jersey-client:2.27")
4242
testImplementation("org.glassfish.jersey.inject:jersey-hk2:2.27")
4343
}

instrumentation/micronaut-1.0/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies {
1111
implementation(project(":instrumentation:netty:netty-4.1"))
1212
implementation("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-netty-4.1:${versions["opentelemetry_java_agent"]}")
1313

14-
testImplementation(project(":testing-common"))
14+
testImplementation(testFixtures(project(":testing-common")))
1515
testImplementation("io.micronaut.test:micronaut-test-junit5:${micronautTestVersion}")
1616
testImplementation("io.micronaut:micronaut-http-server-netty:${micronautVersion}")
1717
testImplementation("io.micronaut:micronaut-runtime:${micronautVersion}")
@@ -27,7 +27,7 @@ for (version in listOf(micronaut2Version)) {
2727
extendsFrom(configurations.runtimeClasspath.get())
2828
}
2929
dependencies {
30-
versionedConfiguration(project(":testing-common"))
30+
versionedConfiguration(testFixtures(project(":testing-common")))
3131
versionedConfiguration("io.micronaut.test:micronaut-test-junit5:${micronautTestVersion}")
3232
versionedConfiguration("io.micronaut:micronaut-http-server-netty:${version}")
3333
versionedConfiguration("io.micronaut:micronaut-http-client:${version}")

0 commit comments

Comments
 (0)