-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use Mariner 2 in FIPS test --------- Co-authored-by: narrieta <narrieta>
- Loading branch information
Showing
4 changed files
with
126 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,10 +1,16 @@ | ||
# | ||
# FIPS should not affect extension processing. The test enables FIPS and then executes an extension. | ||
# | ||
# NOTE: Enabling FIPS is very specific to the distro. This test is only executed on RHEL 9.0. | ||
# NOTE: Enabling FIPS is very specific to the distro. This test is only executed on Mariner 2. | ||
# | ||
# TODO: Add other distros. | ||
# | ||
# NOTE: FIPS can be enabled on RHEL9 using these instructions: see https://access.redhat.com/solutions/137833#rhel9), | ||
# but extensions with protected settings do not work end-to-end, since the Agent can't decrypt the tenant | ||
# certificate. | ||
# | ||
name: "FIPS" | ||
tests: | ||
- source: "fips/fips.py" | ||
images: "rhel_90" | ||
images: "mariner_2" | ||
owns_vm: true |
This file contains 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 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,56 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Microsoft Azure Linux Agent | ||
# | ||
# Copyright 2018 Microsoft Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# | ||
# Verifies whether FIPS is enabled on Mariner 2.0 | ||
# | ||
|
||
set -euo pipefail | ||
|
||
# Check if FIPS mode is enabled by the kernel (returns 1 if enabled) | ||
fips_enabled=$(sudo cat /proc/sys/crypto/fips_enabled) | ||
if [ "$fips_enabled" != "1" ]; then | ||
echo "FIPS is not enabled by the kernel: $fips_enabled" | ||
exit 1 | ||
fi | ||
|
||
# Check if sysctl is configured (returns crypto.fips_enabled = 1 if enabled) | ||
sysctl_configured=$(sudo sysctl crypto.fips_enabled) | ||
if [ "$sysctl_configured" != "crypto.fips_enabled = 1" ]; then | ||
echo "sysctl is not configured for FIPS: $sysctl_configured" | ||
exit 1 | ||
fi | ||
|
||
# Check if openssl library is running in FIPS mode | ||
# MD5 should fail; the command's output should be similar to: | ||
# Error setting digest | ||
# 131590634539840:error:060800C8:digital envelope routines:EVP_DigestInit_ex:disabled for FIPS:crypto/evp/digest.c:135: | ||
openssl=$(openssl md5 < /dev/null 2>&1 || true) | ||
if [[ "$openssl" != *"disabled for FIPS"* ]]; then | ||
echo "openssl is not running in FIPS mode: $openssl" | ||
exit 1 | ||
fi | ||
|
||
# Check if dracut-fips is installed (returns dracut-fips-<version>) | ||
dracut_fips=$( (rpm -qa | grep dracut-fips) || true ) | ||
if [[ "$dracut_fips" != *"dracut-fips"* ]]; then | ||
echo "dracut-fips is not installed: $dracut_fips" | ||
exit 1 | ||
fi | ||
|
||
echo "FIPS mode is enabled." |
This file contains 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,53 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Microsoft Azure Linux Agent | ||
# | ||
# Copyright 2018 Microsoft Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# | ||
# Enables FIPS on Mariner 2.0 | ||
# | ||
|
||
set -euo pipefail | ||
|
||
echo "Installing packages required packages to enable FIPS..." | ||
sudo tdnf install -y grubby dracut-fips | ||
|
||
# | ||
# Set boot_uuid variable for the boot partition if different from the root | ||
# | ||
boot_dev="$(df /boot/ | tail -1 | cut -d' ' -f1)" | ||
echo "Boot partition: $boot_dev" | ||
|
||
root_dev="$(df / | tail -1 | cut -d' ' -f1)" | ||
echo "Root partition: $root_dev" | ||
|
||
boot_uuid="" | ||
if [ "$boot_dev" != "$root_dev" ]; then | ||
boot_uuid="boot=UUID=$(blkid $boot_dev -s UUID -o value)" | ||
echo "Boot UUID: $boot_uuid" | ||
fi | ||
|
||
# | ||
# Enable FIPS and set boot= parameter | ||
# | ||
echo "Enabling FIPS..." | ||
if sudo grub2-editenv - list | grep -q kernelopts; then | ||
set -x | ||
sudo grub2-editenv - set "$(sudo grub2-editenv - list | grep kernelopts) fips=1 $boot_uuid" | ||
else | ||
set -x | ||
sudo grubby --update-kernel=ALL --args="fips=1 $boot_uuid" | ||
fi |