-
Notifications
You must be signed in to change notification settings - Fork 3.5k
x-pack: add fips validation plugin from x-pack #16940
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
Merged
yaauie
merged 9 commits into
elastic:feature/fedramp-high-8.x
from
yaauie:fips-validation-extension
Apr 8, 2025
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3549844
x-pack: add fips_validation plugin to be included in fips builds
yaauie 55df118
fips validation: ensure BCFIPS,BCJSSE,SUN are first 3 security providers
yaauie 681a856
remove re-injection of BCFIPS jars
yaauie de41bc4
Update lib/bootstrap/rubygems.rb
yaauie 0ee498f
Merge branch 'feature/fedramp-high-8.x' into fips-validation-extension
yaauie 6623cb1
add integration spec for fips_validation plugin
yaauie e07dc8a
add missing logstash_plugin helper
yaauie b1089bf
fixup
yaauie a8011ba
skip non-fips spec on fips-configured artifact, add spec details
yaauie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
2 changes: 2 additions & 0 deletions
2
...ibutions/internal/observabilitySRE/plugin/logstash-integration-fips_validation/.gitignore
This file contains hidden or 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,2 @@ | ||
*.gem | ||
VERSION |
99 changes: 99 additions & 0 deletions
99
...ervabilitySRE/plugin/logstash-integration-fips_validation/lib/logstash/fips_validation.rb
This file contains hidden or 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,99 @@ | ||
|
||
require "logstash/environment" | ||
|
||
require "logstash/plugins/registry" | ||
|
||
module LogStash | ||
class FipsValidation < LogStash::UniversalPlugin | ||
|
||
include LogStash::Util::Loggable | ||
|
||
require 'java' | ||
java_import org.jruby.util.SafePropertyAccessor | ||
|
||
def register_hooks(hooks) | ||
logger.debug("registering hooks") | ||
require 'logstash/runner' | ||
hooks.register_hooks(LogStash::Runner, self) | ||
end | ||
|
||
def before_bootstrap_checks(runner) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be any of the hooks that are fired by the |
||
logger.debug("running before_bootstrap_checks") | ||
accumulator = Accumulator.new(self) | ||
|
||
# naive security provider check: specific three in specific order before any others | ||
observed_security_providers = ::Java::java.security.Security.getProviders.map(&:name) | ||
expected_security_providers = %w(BCFIPS BCJSSE SUN) | ||
if observed_security_providers.first(3) == expected_security_providers | ||
accumulator.success "Java security providers are properly configured (observed `#{observed_security_providers}`)" | ||
else | ||
accumulator.failure "Java security providers are misconfigured (expected `#{expected_security_providers}` to be first 3, observed `#{observed_security_providers}`)" | ||
end | ||
|
||
# naive secure-random provider check: | ||
observed_random_provider = ::Java::java.security.SecureRandom.new.getProvider.getName | ||
expected_random_provider = "BCFIPS" | ||
if observed_random_provider != expected_random_provider | ||
accumulator.failure "Java SecureRandom provider is misconfigured (expected `#{expected_random_provider}`; observed `#{observed_random_provider}`)" | ||
else | ||
accumulator.success "Java SecureRandom provider is properly configured (observed `#{observed_random_provider}`)" | ||
end | ||
|
||
# ensure Bouncycastle is configured and ready | ||
begin | ||
if Java::org.bouncycastle.crypto.CryptoServicesRegistrar.isInApprovedOnlyMode | ||
accumulator.success "Bouncycastle Crytpo is in `approved-only` mode" | ||
else | ||
accumulator.failure "Bouncycastle Crypto is not in 'approved-only' mode" | ||
end | ||
|
||
if ::Java::org.bouncycastle.crypto.fips.FipsStatus.isReady | ||
accumulator.success "Bouncycastle Crypto is fips-ready" | ||
else | ||
accumulator.failure "Bouncycastle Crypto is not fips-ready" | ||
end | ||
rescue => ex | ||
accumulator.failure "Bouncycastle Crypto unavailable: (#{ex.class}) #{ex.message}" | ||
end | ||
|
||
# ensure non-compliant jruby openssl provider isn't registered or eligible for later registration | ||
if org.jruby.ext.openssl.SecurityHelper.isProviderRegistered | ||
accumulator.failure "non-compliant Jruby OpenSSL security helper is registered" | ||
elsif org.jruby.util.SafePropertyAccessor.getBoolean("jruby.openssl.provider.register") != false | ||
accumulator.failure "non-compliant Jruby OpenSSL security helper is eligible to be registered" | ||
else | ||
accumulator.success "non-compliant Jruby OpenSSL security helper is correctly not registered" | ||
end | ||
|
||
# hard-exit if there were _any_ failures | ||
if accumulator.failure? | ||
logger.fatal "Logstash is not configured in a FIPS-compliant manner" | ||
exit 1 | ||
end | ||
|
||
logger.info("FIPS OK") | ||
end | ||
|
||
class Accumulator | ||
def initialize(logger_context) | ||
@logger = logger_context.logger | ||
@success = [] | ||
@failure = [] | ||
end | ||
|
||
def success(message) | ||
@success << message | ||
@logger.info(message) | ||
end | ||
|
||
def failure(message) | ||
@failure << message | ||
@logger.error(message) | ||
end | ||
|
||
def failure? | ||
@failure.any? | ||
end | ||
end | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
...nal/observabilitySRE/plugin/logstash-integration-fips_validation/lib/logstash_registry.rb
This file contains hidden or 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,4 @@ | ||
|
||
require_relative "logstash/fips_validation" | ||
|
||
LogStash::PLUGIN_REGISTRY.add(:universal, "fips_validation", LogStash::FipsValidation) |
38 changes: 38 additions & 0 deletions
38
.../plugin/logstash-integration-fips_validation/logstash-integration-fips_validation.gemspec
This file contains hidden or 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,38 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
gem_version_file = File.expand_path("GEM_BUILD_VERSION", __dir__) | ||
unless File.exist?(gem_version_file) | ||
File.write(gem_version_file, ENV.fetch("GEM_BUILD_VERSION")) | ||
end | ||
|
||
Gem::Specification.new do |s| | ||
s.name = File.basename(__FILE__, ".gemspec") | ||
s.version = File.read(gem_version_file).chomp | ||
s.licenses = ['Elastic-2.0'] | ||
s.summary = "A logstash plugin that ensures FIPS 140-3 compliance" | ||
s.description = <<~DESC | ||
This plugin is to be included in Logstash distributions that need FedRAMP HIGH | ||
FIPS 140-3 compliance; its hooks run before pipelines are loaded to ensure that | ||
the process is running with the correct settings for cryptography. | ||
DESC | ||
s.authors = ["Elasticsearch"] | ||
s.email = '[email protected]' | ||
s.homepage = "http://www.elasticsearch.org/guide/en/logstash/current/index.html" | ||
|
||
s.require_paths = ["lib"] | ||
|
||
# Files | ||
s.files = Dir::glob("lib/**/*.rb") | | ||
Dir::glob("*.gemspec") | | ||
Dir.glob("VERSION") | ||
|
||
# Special flag to let us know this is actually a logstash plugin | ||
s.metadata = { | ||
"logstash_plugin" => "true", | ||
"logstash_group" => "integration", | ||
"integration_plugins" => "", # empty; no config-accessible plugins | ||
} | ||
|
||
# Gem dependencies | ||
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99" | ||
end |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.