Skip to content
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

x-pack: add fips validation plugin from x-pack #16940

Draft
wants to merge 2 commits into
base: feature/fedramp-high-8.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions logstash-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ idea {
}

dependencies {
runtimeOnly("org.bouncycastle:bc-fips:2.0.0")
runtimeOnly("org.bouncycastle:bcpkix-fips:2.0.7")
runtimeOnly("org.bouncycastle:bctls-fips:2.0.19")
runtimeOnly("org.bouncycastle:bcutil-fips:2.0.3")
api(files("../vendor/jruby/lib/jruby.jar") { // jruby-core.jar
builtBy ':downloadAndInstallJRuby'
}) { because "DEPENDENCY: org.jruby:jruby-core:${jrubyVersion}" } // meta-data for generateLicenseReport
Expand Down
62 changes: 62 additions & 0 deletions x-pack/lib/fips_validation/extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

require "logstash/environment"

require "logstash/plugins/registry"

module LogStash
module FipsValidation
class Extension < LogStash::UniversalPlugin

LogStash::PLUGIN_REGISTRY.add(:universal, "fips_validation", self)

include LogStash::Util::Loggable

def register_hooks(hooks)
require 'logstash/runner'
hooks.register_hooks(LogStash::Runner, self)
end

def before_bootstrap_checks(runner)
return unless ENV['ENFORCE_FIPS_140_3']

issues = []

# naive security provider check: specific three in specific order
observed_security_providers = ::Java::java.security.Security.getProviders.map(&:name)
expected_security_providers = %w(BCFIPS BCJSSE SUN)
if observed_security_providers != expected_security_providers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if observed_security_providers != expected_security_providers
if observed_security_providers[..2] != expected_security_providers

In the container env these are the first three (in that order) but there are more:

[2025-01-24T22:56:53,562][FATAL][logstash.runner          ] An unexpected error occurred! {:error=>#<LogStash::ConfigurationError: FIPS compliance issues: ["Java security providers are misconfigured (expected `[\"BCFIPS\", \"BCJSSE\", \"SUN\"]`, observed `[\"BCFIPS\", \"BCJSSE\", \"SUN\", \"SunJSSE\", \"SunJCE\", \"SunJGSS\", \"SunSASL\", \"XMLDSig\", \"SunPCSC\", \"JdkLDAP\", \"JdkSASL\", \"SunPKCS11\"]`)"]>, :backtrace=>["/logstash/x-pack/lib/fips_validation/extension.rb:55:in `before_bootstrap_checks'", "org/logstash/execution/EventDispatcherExt.java:94:in `execute'", "/logstash/logstash-core/lib/logstash/runner.rb:363:in `execute'", "/logstash/vendor/bundle/jruby/3.1.0/gems/clamp-1.3.2/lib/clamp/command.rb:66:in `run'", "/logstash/logstash-core/lib/logstash/runner.rb:298:in `run'", "/logstash/vendor/bundle/jruby/3.1.0/gems/clamp-1.3.2/lib/clamp/command.rb:140:in `run'", "/logstash/lib/bootstrap/environment.rb:89:in `<main>'"]}
[2025-01-24T22:56:53,564][FATAL][org.logstash.Logstash    ] Logstash stopped processing because of an error: (SystemExit) exit
org.jruby.exceptions.SystemExit: (SystemExit) exit
	at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:924) ~[jruby.jar:?]
	at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:883) ~[jruby.jar:?]
	at logstash.lib.bootstrap.environment.<main>(/logstash/lib/bootstrap/environment.rb:90) ~[?:?]

issues << "Java security providers are misconfigured (expected `#{expected_security_providers}`, observed `#{observed_security_providers}`)"
end

# naive secure-random provider check:
observed_random_provider = ::Java::java.security.SecureRandom.new.getProvider.getName
expected_random_provider = "BCFIPS"
unless observed_random_provider == expected_random_provider
issues << "Java SecureRandom provider is misconfigured (expected `#{expected_random_provider}`; observed `#{observed_random_provider}`)"
end

# ensure Bouncycastle is configured and ready
begin
unless Java::org.bouncycastle.crypto.CryptoServicesRegistrar.isInApprovedOnlyMode
issues << "Bouncycastle Crypto is not in 'approved-only' mode"
end

unless ::Java::org.bouncycastle.crypto.fips.FipsStatus.isReady
issues << "Bouncycastle Crypto is not fips-ready"
end
rescue => ex
issues << "Bouncycastle Crypto unavailable: (#{ex.class}) #{ex.message}"
end

# ensure non-compliant jruby openssl provider isn't registered
if org.jruby.ext.openssl.SecurityHelper.isProviderRegistered
issues << "non-compliant Jruby OpenSSL security helper is registered"
end

if issues.any?
fail LogStash::ConfigurationError, "FIPS compliance issues: #{issues}"
end
end
end
end
end
2 changes: 2 additions & 0 deletions x-pack/lib/x-pack/logstash_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
xpack_modules.each do |name|
$LOAD_PATH << File.join(LogStash::XPACK_PATH, "modules", name, "lib")
end

require "logstash/plugins/registry"
require "logstash/modules/util"
require "fips_validation/extension" if File.exist?(File.join(LogStash::XPACK_PATH, "lib/fips_validation/extension.rb"))
require "monitoring/monitoring"
require "monitoring/inputs/metrics"
require "monitoring/outputs/elasticsearch_monitoring"
Expand Down
Loading