Skip to content

Commit b053194

Browse files
committed
crypto: implement FIPS 140-2 compliance support
Add FIPS 140-2 cryptographic module support to ensure compliance with federal security standards. The change includes FIPS-approved algorithms and proper key management to meet certification requirements. Signed-off-by: Maher Homsi <[email protected]>
1 parent e331812 commit b053194

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ LABEL "org.opencontainers.image.version"="$IMAGE_VERSION"
7070

7171
RUN dnf update -y \
7272
&& dnf install -y \
73+
crypto-policies-scripts \
7374
ec2-instance-connect \
7475
jq \
7576
openssh-server \

start_admin.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ declare -r SSH_HOST_KEY_DIR="${PERSISTENT_STORAGE_BASE_DIR}/etc/ssh"
1111
declare -r USER_DATA="${PERSISTENT_STORAGE_BASE_DIR}/user-data"
1212
declare -r HOST_CERTS="/.bottlerocket/certs"
1313

14+
#shellcheck disable=SC2155 # If not set then we'll treat it as 0
15+
declare -r FIPS_MODE_FLAG=$(cat '/proc/sys/crypto/fips_enabled' 2>/dev/null || echo 0)
16+
1417
if [ ! -s "${USER_DATA}" ]; then
1518
log "Admin host-container user-data is empty, going to sleep forever"
1619
exec sleep infinity
@@ -45,6 +48,16 @@ link_host_certs() {
4548
update-ca-trust
4649
}
4750

51+
# Update crypto policies to FIPS if FIPS is enabled
52+
if [[ ${FIPS_MODE_FLAG} -eq 1 ]]; then
53+
update-crypto-policies --set FIPS 2>/dev/null
54+
if [[ "$(cat '/etc/crypto-policies/config')" != "FIPS" ]]; then
55+
log "Failed to validate FIPS configuration"
56+
exit 1
57+
fi
58+
fi
59+
60+
4861
get_user_data_keys() {
4962
# Extract the keys from user-data json
5063
local raw_keys
@@ -207,7 +220,13 @@ fi
207220

208221
# Generate the server keys
209222
mkdir -p "${SSH_HOST_KEY_DIR}"
210-
for key_alg in rsa ecdsa ed25519; do
223+
# Skip ED25519 in FIPS mode as it's not allowed
224+
key_algorithms=(rsa ecdsa)
225+
if [[ "${FIPS_MODE_FLAG}" -ne 1 ]]; then
226+
key_algorithms+=(ed25519)
227+
fi
228+
229+
for key_alg in "${key_algorithms[@]}"; do
211230
# If both of the keys exist, don't overwrite them
212231
if [[ -s "${SSH_HOST_KEY_DIR}/ssh_host_${key_alg}_key" ]] \
213232
&& [[ -s "${SSH_HOST_KEY_DIR}/ssh_host_${key_alg}_key.pub" ]]; then

0 commit comments

Comments
 (0)