Skip to content

Commit 139e6bc

Browse files
committed
Conditionally install bcfips jars when building for observabilitySRE
This commit implements a pattern for performing specific gradle tasks based on a newly named "fedrampHighMode" option. This option is used to configure tests to run with additional configuration specific to the observabilitySRE use case. Similarly the additional jar dependencies for bouncycastle fips providers are conditionally installed gated on the "fedrampHighMode" option. In order to ensure the the "fedrampHighMode" option persists through the layers of sub-processes spawned between gradle and rake we store and respect an environment variable FEDRAMP_HIGH_MODE. This may be useful generally in building the docker image. Try codereview suggestion
1 parent c8992ce commit 139e6bc

8 files changed

Lines changed: 44 additions & 17 deletions

File tree

.buildkite/pull_request_pipeline.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ steps:
5454
set -euo pipefail
5555
5656
docker build -t test-runner-image -f x-pack/distributions/internal/observabilitySRE/docker/Dockerfile .
57-
docker run test-runner-image ./gradlew --info --stacktrace -PrunTestsInFIPSMode=true rubyTests
57+
docker run test-runner-image ./gradlew --info --stacktrace -PfedrampHighMode=true rubyTests
5858
artifact_paths:
5959
- "coverage/coverage.json"
6060

@@ -96,7 +96,7 @@ steps:
9696
set -euo pipefail
9797
9898
docker build -t test-runner-image -f x-pack/distributions/internal/observabilitySRE/docker/Dockerfile .
99-
docker run test-runner-image ./gradlew --info --stacktrace -PrunTestsInFIPSMode=true javaTests
99+
docker run test-runner-image ./gradlew --info --stacktrace -PfedrampHighMode=true javaTests
100100
artifact_paths:
101101
- "**/build/test-results/javaTests/TEST-*.xml"
102102
- "**/jacocoTestReport.xml"
@@ -139,7 +139,7 @@ steps:
139139
source .buildkite/scripts/common/vm-agent.sh
140140
# TODO: Use https://github.com/elastic/logstash/pull/17311 to compute QUALIFIED_VERSION once merged
141141
QUALIFIED_VERSION="8.19.0-SNAPSHOT"
142-
./gradlew --stacktrace artifactDockerObservabilitySRE
142+
./gradlew --stacktrace artifactDockerObservabilitySRE -PfedrampHighMode=true
143143
docker run docker.elastic.co/logstash/logstash-observability-sre:$${QUALIFIED_VERSION} \
144144
logstash -e 'input { generator { count => 3 } } output { stdout { codec => rubydebug } }'
145145

ci/run-fips-integration-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
half_number=$1
77
source ci/get-test-half.sh
88
specs=$(get_test_half "$half_number")
9-
./gradlew --info --stacktrace -PrunTestsInFIPSMode=true runIntegrationTests -PrubyIntegrationSpecs="$specs"
9+
./gradlew --info --stacktrace -PfedrampHighMode=true runIntegrationTests -PrubyIntegrationSpecs="$specs"

logstash-core/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,6 @@ dependencies {
235235
runtimeOnly 'commons-logging:commons-logging:1.3.1'
236236
// also handle libraries relying on log4j 1.x to redirect their logs
237237
runtimeOnly "org.apache.logging.log4j:log4j-1.2-api:${log4jVersion}"
238-
// FIPS deps. TODO: figure out how to actually manage these
239-
runtimeOnly("org.bouncycastle:bc-fips:2.0.0")
240-
runtimeOnly("org.bouncycastle:bcpkix-fips:2.0.7")
241-
runtimeOnly("org.bouncycastle:bctls-fips:2.0.19")
242-
runtimeOnly("org.bouncycastle:bcutil-fips:2.0.3")
243238
implementation('org.reflections:reflections:0.10.2') {
244239
exclude group: 'com.google.guava', module: 'guava'
245240
}

rubyUtils.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ Object executeJruby(File projectDir, File buildDir, Closure<?> /* Object*/ block
191191
env.put "GEM_HOME", gemDir
192192
env.put "GEM_SPEC_CACHE", "${buildDir}/cache".toString()
193193
env.put "GEM_PATH", gemDir
194+
// Pass through FEDRAMP_HIGH_MODE if it exists in the project properties
195+
if (project.hasProperty('fedrampHighMode') && project.property('fedrampHighMode').toBoolean()) {
196+
env.put "FEDRAMP_HIGH_MODE", "true"
197+
}
194198
try {
195199
block(jruby)
196200
} finally {

x-pack/ci/integration_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [ -n "$BUILD_JAVA_HOME" ]; then
1818
fi
1919

2020
if [ -n "$FIPS_MODE" ]; then
21-
./gradlew runXPackIntegrationTests -PrunTestsInFIPSMode=true
21+
./gradlew runXPackIntegrationTests -PfedrampHighMode=true
2222
else
2323
./gradlew runXPackIntegrationTests
2424
fi

x-pack/ci/unit_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if [ -n "$BUILD_JAVA_HOME" ]; then
1717
fi
1818

1919
if [ -n "$FIPS_MODE" ]; then
20-
./gradlew runXPackUnitTests -PrunTestsInFIPSMode=true
20+
./gradlew runXPackUnitTests -PfedrampHighMode=true
2121
else
2222
./gradlew runXPackUnitTests
2323
fi

x-pack/distributions/internal/observabilitySRE/build-ext.gradle

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
ext {
2-
runTestsInFIPSMode = project.hasProperty('runTestsInFIPSMode') ? project.property('runTestsInFIPSMode').toBoolean() : false
2+
fedrampHighMode = System.getenv('FEDRAMP_HIGH_MODE') == 'true' ||
3+
(project.hasProperty('fedrampHighMode') ? project.property('fedrampHighMode').toBoolean() : false)
34
}
45

56
subprojects {
67
ext {
7-
runTestsInFIPSMode = rootProject.runTestsInFIPSMode
8+
fedrampHighMode = rootProject.fedrampHighMode
89
}
910
}
1011

1112
allprojects {
1213
afterEvaluate {
14+
// Preserve fedrampHighMode option across subprocesses
15+
if (rootProject.fedrampHighMode) {
16+
tasks.withType(JavaExec).configureEach {
17+
environment("FEDRAMP_HIGH_MODE", "true")
18+
}
19+
20+
tasks.withType(Exec).configureEach {
21+
environment("FEDRAMP_HIGH_MODE", "true")
22+
}
23+
}
24+
1325
tasks.withType(Test) {
14-
if (runTestsInFIPSMode) {
26+
if (rootProject.fedrampHighMode) {
1527
logger.debug("configuring ${it} to run in FIPSMode ")
1628
systemProperty "java.security.properties", System.getenv("JAVA_SECURITY_PROPERTIES")
1729
systemProperty "javax.net.ssl.keyStore", "/etc/java/security/keystore.bcfks"
@@ -28,4 +40,20 @@ allprojects {
2840
}
2941
}
3042
}
31-
}
43+
}
44+
45+
project(':logstash-core') {
46+
afterEvaluate {
47+
if (rootProject.fedrampHighMode) {
48+
logger.lifecycle("Adding BouncyCastle FIPS dependencies to logstash-core")
49+
dependencies {
50+
// Add FIPS dependencies to the runtimeOnly configuration
51+
// This ensures they'll be included by the existing copyRuntimeLibs task
52+
runtimeOnly "org.bouncycastle:bc-fips:2.0.0"
53+
runtimeOnly "org.bouncycastle:bcpkix-fips:2.0.7"
54+
runtimeOnly "org.bouncycastle:bctls-fips:2.0.19"
55+
runtimeOnly "org.bouncycastle:bcutil-fips:2.0.3"
56+
}
57+
}
58+
}
59+
}

x-pack/distributions/internal/observabilitySRE/docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ENV JAVA_HOME=/usr/lib/jvm/java-21-openjdk
4343
ENV PATH="${JAVA_HOME}/bin:${PATH}"
4444

4545
# Initial build using JKS truststore
46-
RUN ./gradlew clean bootstrap assemble installDefaultGems
46+
RUN ./gradlew clean bootstrap assemble installDefaultGems -PfedrampHighMode=true
4747

4848
# Convert JKS to BCFKS for truststore and keystore
4949
RUN keytool -importkeystore \
@@ -87,4 +87,4 @@ ENV LS_JAVA_OPTS="\
8787
-Dorg.bouncycastle.fips.approved_only=true"
8888

8989
# Example test run, most use cases will override this
90-
CMD ["./gradlew", "--info", "--stacktrace", "-PrunTestsInFIPSMode=true", "runIntegrationTests"]
90+
CMD ["./gradlew", "--info", "--stacktrace", "-PfedrampHighMode=true", "runIntegrationTests"]

0 commit comments

Comments
 (0)