Skip to content

Commit

Permalink
server: add FIPS mode statistic indicating FIPS compliance (#14719)
Browse files Browse the repository at this point in the history
Signed-off-by: Ravindra Akella <rakella@rakella-ltm.internal.salesforce.com>
  • Loading branch information
raakella authored Jan 21, 2021
1 parent 8de5ad9 commit 62f1c83
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/root/configuration/observability/statistics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ Server related statistics are rooted at *server.* with following statistics:
static_unknown_fields, Counter, Number of messages in static configuration with unknown fields
dynamic_unknown_fields, Counter, Number of messages in dynamic configuration with unknown fields

Server Compilation Settings
---------------------------

Server Compilation Settings related statistics are rooted at *server.compilation_settings.* with following statistics:

.. csv-table::
:header: Name, Type, Description
:widths: 1, 1, 2

fips_mode, Gauge, Integer representing whether the envoy build is FIPS compliant or not
1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ New Features
* dispatcher: supports a stack of `Envoy::ScopeTrackedObject` instead of a single tracked object. This will allow Envoy to dump more debug information on crash.
* http: added support for :ref:`:ref:`preconnecting <envoy_v3_api_msg_config.cluster.v3.Cluster.PreconnectPolicy>`. Preconnecting is off by default, but recommended for clusters serving latency-sensitive traffic, especially if using HTTP/1.1.
* http: change frame flood and abuse checks to the upstream HTTP/2 codec to ON by default. It can be disabled by setting the `envoy.reloadable_features.upstream_http2_flood_checks` runtime key to false.
* server: added :ref:`fips_mode <statistics>` statistic.
* tcp_proxy: add support for converting raw TCP streams into HTTP/1.1 CONNECT requests. See :ref:`upgrade documentation <tunneling-tcp-over-http>` for details.

Deprecated
Expand Down
8 changes: 8 additions & 0 deletions source/common/version/version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ const envoy::config::core::v3::BuildVersion& VersionInfo::buildVersion() {
return *result;
}

bool VersionInfo::sslFipsCompliant() {
bool fipsCompliant = false;
#ifdef BORINGSSL_FIPS
fipsCompliant = true;
#endif
return fipsCompliant;
}

const std::string& VersionInfo::buildType() {
#ifdef NDEBUG
static const std::string release_type = "RELEASE";
Expand Down
2 changes: 2 additions & 0 deletions source/common/version/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class VersionInfo {
static const std::string& revisionStatus();
// Repository information and build type.
static const std::string& version();
// FIPS Compliance of envoy build
static bool sslFipsCompliant();

static const envoy::config::core::v3::BuildVersion& buildVersion();

Expand Down
10 changes: 10 additions & 0 deletions source/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,17 @@ void InstanceImpl::initialize(const Options& options,
stats_store_.setHistogramSettings(Config::Utility::createHistogramSettings(bootstrap_));

const std::string server_stats_prefix = "server.";
const std::string server_compilation_settings_stats_prefix = "server.compilation_settings";
server_stats_ = std::make_unique<ServerStats>(
ServerStats{ALL_SERVER_STATS(POOL_COUNTER_PREFIX(stats_store_, server_stats_prefix),
POOL_GAUGE_PREFIX(stats_store_, server_stats_prefix),
POOL_HISTOGRAM_PREFIX(stats_store_, server_stats_prefix))});
server_compilation_settings_stats_ =
std::make_unique<CompilationSettings::ServerCompilationSettingsStats>(
CompilationSettings::ServerCompilationSettingsStats{ALL_SERVER_COMPILATION_SETTINGS_STATS(
POOL_COUNTER_PREFIX(stats_store_, server_compilation_settings_stats_prefix),
POOL_GAUGE_PREFIX(stats_store_, server_compilation_settings_stats_prefix),
POOL_HISTOGRAM_PREFIX(stats_store_, server_compilation_settings_stats_prefix))});
validation_context_.staticWarningValidationVisitor().setUnknownCounter(
server_stats_->static_unknown_fields_);
validation_context_.dynamicWarningValidationVisitor().setUnknownCounter(
Expand Down Expand Up @@ -388,6 +395,9 @@ void InstanceImpl::initialize(const Options& options,
}
}
server_stats_->version_.set(version_int);
if (VersionInfo::sslFipsCompliant()) {
server_compilation_settings_stats_->fips_mode_.set(1);
}

bootstrap_.mutable_node()->set_hidden_envoy_deprecated_build_version(VersionInfo::version());
bootstrap_.mutable_node()->set_user_agent_name("envoy");
Expand Down
14 changes: 14 additions & 0 deletions source/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@

namespace Envoy {
namespace Server {
namespace CompilationSettings {
/**
* All server compilation settings stats. @see stats_macros.h
*/
#define ALL_SERVER_COMPILATION_SETTINGS_STATS(COUNTER, GAUGE, HISTOGRAM) \
GAUGE(fips_mode, NeverImport)

struct ServerCompilationSettingsStats {
ALL_SERVER_COMPILATION_SETTINGS_STATS(GENERATE_COUNTER_STRUCT, GENERATE_GAUGE_STRUCT,
GENERATE_HISTOGRAM_STRUCT)
};
} // namespace CompilationSettings

/**
* All server wide stats. @see stats_macros.h
Expand Down Expand Up @@ -322,6 +334,8 @@ class InstanceImpl final : Logger::Loggable<Logger::Id::main>,
time_t original_start_time_;
Stats::StoreRoot& stats_store_;
std::unique_ptr<ServerStats> server_stats_;
std::unique_ptr<CompilationSettings::ServerCompilationSettingsStats>
server_compilation_settings_stats_;
Assert::ActionRegistrationPtr assert_action_registration_;
Assert::ActionRegistrationPtr envoy_bug_action_registration_;
ThreadLocal::Instance& thread_local_;
Expand Down
17 changes: 17 additions & 0 deletions test/server/server_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,23 @@ TEST_P(ServerInstanceImplTest, ProxyVersionOveridesFromBootstrap) {
server_thread->join();
}

// Validates that the "server.fips_mode" stat indicates the FIPS compliance from the Envoy Build
TEST_P(ServerInstanceImplTest, ValidateFIPSModeStat) {
auto server_thread =
startTestServer("test/server/test_data/server/proxy_version_bootstrap.yaml", true);

if (VersionInfo::sslFipsCompliant()) {
EXPECT_EQ(
1L, TestUtility::findGauge(stats_store_, "server.compilation_settings.fips_mode")->value());
} else {
EXPECT_EQ(
0L, TestUtility::findGauge(stats_store_, "server.compilation_settings.fips_mode")->value());
}

server_->dispatcher().post([&] { server_->shutdown(); });
server_thread->join();
}

TEST_P(ServerInstanceImplTest, EmptyShutdownLifecycleNotifications) {
auto server_thread = startTestServer("test/server/test_data/server/node_bootstrap.yaml", false);
server_->dispatcher().post([&] { server_->shutdown(); });
Expand Down

0 comments on commit 62f1c83

Please sign in to comment.