Skip to content

Commit 6bc80a2

Browse files
aniketpalucursoragent
authored andcommitted
fix: configure FIPS-compliant gRPC cipher suites for offline server
Signed-off-by: Aniket Paluska <[email protected]> Co-authored-by: Cursor <[email protected]> Signed-off-by: Aniket Paluskar <[email protected]>
1 parent 1cb23fd commit 6bc80a2

2 files changed

Lines changed: 79 additions & 2 deletions

File tree

‎sdk/python/feast/offline_server.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,31 @@
3838
logger = logging.getLogger(__name__)
3939
logger.setLevel(logging.INFO)
4040

41+
_FIPS_CIPHER_SUITES = ":".join(
42+
[
43+
"ECDHE-RSA-AES128-GCM-SHA256",
44+
"ECDHE-RSA-AES256-GCM-SHA384",
45+
"ECDHE-ECDSA-AES128-GCM-SHA256",
46+
"ECDHE-ECDSA-AES256-GCM-SHA384",
47+
"AES128-GCM-SHA256",
48+
"AES256-GCM-SHA384",
49+
]
50+
)
51+
52+
53+
def _is_fips_enabled() -> bool:
54+
try:
55+
with open("/proc/sys/crypto/fips_enabled") as f:
56+
return f.read().strip() == "1"
57+
except (FileNotFoundError, PermissionError, OSError):
58+
return False
59+
60+
61+
def _configure_grpc_fips() -> None:
62+
if _is_fips_enabled() and "GRPC_SSL_CIPHER_SUITES" not in os.environ:
63+
os.environ["GRPC_SSL_CIPHER_SUITES"] = _FIPS_CIPHER_SUITES
64+
logger.info("FIPS mode detected, configured FIPS-compliant gRPC cipher suites.")
65+
4166

4267
class OfflineServer(fl.FlightServerBase):
4368
def __init__(
@@ -596,6 +621,7 @@ def start_server(
596621
tls_cert_path: str = "",
597622
):
598623
_init_auth_manager(store)
624+
_configure_grpc_fips()
599625

600626
tls_certificates = []
601627
scheme = "grpc+tcp"

‎sdk/python/tests/unit/test_offline_server.py‎

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from unittest.mock import MagicMock, patch
1+
import os
2+
from unittest.mock import MagicMock, mock_open, patch
23

34
import assertpy
45

@@ -7,7 +8,11 @@
78
RemoteOfflineStoreConfig,
89
_create_retrieval_metadata,
910
)
10-
from feast.offline_server import OfflineServer
11+
from feast.offline_server import (
12+
OfflineServer,
13+
_configure_grpc_fips,
14+
_is_fips_enabled,
15+
)
1116

1217

1318
def test_create_retrieval_metadata_with_sql_string():
@@ -86,3 +91,49 @@ def test_offline_server_get_historical_features_passes_sql_to_store():
8691
assertpy.assert_that(result).is_equal_to(mock_job)
8792
_, kwargs = mock_offline_store.get_historical_features.call_args
8893
assertpy.assert_that(kwargs["entity_df"]).is_equal_to(sql)
94+
95+
96+
def test_is_fips_enabled_returns_true():
97+
with patch("builtins.open", mock_open(read_data="1\n")):
98+
assert _is_fips_enabled() is True
99+
100+
101+
def test_is_fips_enabled_returns_false():
102+
with patch("builtins.open", mock_open(read_data="0\n")):
103+
assert _is_fips_enabled() is False
104+
105+
106+
def test_is_fips_enabled_missing_file():
107+
with patch("builtins.open", side_effect=FileNotFoundError):
108+
assert _is_fips_enabled() is False
109+
110+
111+
def test_configure_grpc_fips_sets_cipher_suites():
112+
with (
113+
patch("feast.offline_server._is_fips_enabled", return_value=True),
114+
patch.dict(os.environ, {}, clear=False),
115+
):
116+
os.environ.pop("GRPC_SSL_CIPHER_SUITES", None)
117+
_configure_grpc_fips()
118+
assert "GRPC_SSL_CIPHER_SUITES" in os.environ
119+
assert "AES128-GCM-SHA256" in os.environ["GRPC_SSL_CIPHER_SUITES"]
120+
del os.environ["GRPC_SSL_CIPHER_SUITES"]
121+
122+
123+
def test_configure_grpc_fips_respects_existing_env():
124+
with (
125+
patch("feast.offline_server._is_fips_enabled", return_value=True),
126+
patch.dict(os.environ, {"GRPC_SSL_CIPHER_SUITES": "custom"}, clear=False),
127+
):
128+
_configure_grpc_fips()
129+
assert os.environ["GRPC_SSL_CIPHER_SUITES"] == "custom"
130+
131+
132+
def test_configure_grpc_fips_noop_without_fips():
133+
with (
134+
patch("feast.offline_server._is_fips_enabled", return_value=False),
135+
patch.dict(os.environ, {}, clear=False),
136+
):
137+
os.environ.pop("GRPC_SSL_CIPHER_SUITES", None)
138+
_configure_grpc_fips()
139+
assert "GRPC_SSL_CIPHER_SUITES" not in os.environ

0 commit comments

Comments
 (0)