-
Notifications
You must be signed in to change notification settings - Fork 44
Rebase to Amazon Linux 2023 and enable FIPS #125
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
base: develop
Are you sure you want to change the base?
Changes from all commits
5c48a4b
3043588
e331812
b053194
0b10ea1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| # https://ftp.gnu.org/gnu/bash/bash-5.1.16.tar.gz | ||
| SHA512 (bash-5.1.16.tar.gz) = a32a343b6dde9a18eb6217602655f72c4098b0d90f04cf4e686fb21b81fc4ef26ade30f7226929fbb7c207cde34617dbad2c44f6103161d1141122bb31dc6c80 | ||
| # https://ftp.gnu.org/gnu/bash/bash-5.2.15.tar.gz | ||
| SHA512 (bash-5.2.15.tar.gz) = 08a67f6da4af7a75ff2b2d5a9eb8fc46d8c6e9ae80ccaf73b51736d6609916861b1f3fced938ce3ea16d014edb324e1a3d8e03f4917f68dc56ffb665316f26c7 | ||
|
Contributor
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. Same here, you are missing a newline |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,9 @@ declare -r SSH_HOST_KEY_DIR="${PERSISTENT_STORAGE_BASE_DIR}/etc/ssh" | |
| declare -r USER_DATA="${PERSISTENT_STORAGE_BASE_DIR}/user-data" | ||
| declare -r HOST_CERTS="/.bottlerocket/certs" | ||
|
|
||
| #shellcheck disable=SC2155 # If not set then we'll treat it as 0 | ||
| declare -r FIPS_MODE_FLAG=$(cat '/proc/sys/crypto/fips_enabled' 2>/dev/null || echo 0) | ||
|
|
||
| if [ ! -s "${USER_DATA}" ]; then | ||
| log "Admin host-container user-data is empty, going to sleep forever" | ||
| exec sleep infinity | ||
|
|
@@ -45,6 +48,16 @@ link_host_certs() { | |
| update-ca-trust | ||
| } | ||
|
|
||
| # Update crypto policies to FIPS if FIPS is enabled | ||
| if [[ ${FIPS_MODE_FLAG} -eq 1 ]]; then | ||
| update-crypto-policies --set FIPS 2>/dev/null | ||
| if [[ "$(cat '/etc/crypto-policies/config')" != "FIPS" ]]; then | ||
| log "Failed to validate FIPS configuration" | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
|
|
||
| get_user_data_keys() { | ||
| # Extract the keys from user-data json | ||
| local raw_keys | ||
|
|
@@ -207,7 +220,13 @@ fi | |
|
|
||
| # Generate the server keys | ||
| mkdir -p "${SSH_HOST_KEY_DIR}" | ||
| for key_alg in rsa ecdsa ed25519; do | ||
| # Skip ED25519 in FIPS mode as it's not allowed | ||
| key_algorithms=(rsa ecdsa) | ||
|
Contributor
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. What's the default size of the RSA key? It must be >= 2048 bits. And for ECDSA, make sure you use FIPS curve.
Member
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. Looks like for RSA its 3072 bits (changed from 2048 in OpenSSH 8.2). ECSDA defaults to P-256 which is a FIPS curve. Of course if we wanted to be extra sure we could set these explicitly to avoid changes in behavior. |
||
| if [[ "${FIPS_MODE_FLAG}" -ne 1 ]]; then | ||
| key_algorithms+=(ed25519) | ||
| fi | ||
|
|
||
| for key_alg in "${key_algorithms[@]}"; do | ||
| # If both of the keys exist, don't overwrite them | ||
| if [[ -s "${SSH_HOST_KEY_DIR}/ssh_host_${key_alg}_key" ]] \ | ||
| && [[ -s "${SSH_HOST_KEY_DIR}/ssh_host_${key_alg}_key.pub" ]]; then | ||
|
|
@@ -228,6 +247,15 @@ for key_alg in rsa ecdsa ed25519; do | |
| fi | ||
| done | ||
|
|
||
| readonly host_cgroup="/.bottlerocket/rootfs/sys/fs/cgroup" | ||
|
|
||
| cgroup_fstype=$(findmnt -n -o FSTYPE "${host_cgroup}" || true) | ||
| if [[ "${cgroup_fstype}" == tmpfs ]]; then | ||
| # Host uses cgroup v1, so use cgroup v1 in container too | ||
| ln -sf "${host_cgroup}" /sys/fs/cgroup | ||
| log "cgroup v1 enabled in admin container to match host" | ||
| fi | ||
|
|
||
| install_proxy_profile | ||
|
|
||
| enable_systemd_services | ||
|
|
@@ -236,32 +264,7 @@ enable_systemd_services | |
|
|
||
| systemd_options=() | ||
|
|
||
| # cgroup v2 compatibility crimes: systemd 219 in the admin container only | ||
| # supports cgroup v1. | ||
| if [[ $(findmnt -n -o FSTYPE /sys/fs/cgroup) = cgroup2 ]]; then | ||
| # Mount an extra cgroup v1 hierarchy for use by systemd in the admin | ||
| # container. Vanilla systemd is hard-wired to look for it at /sys/fs/cgroup | ||
| # but that path is already taken by the host's proper cgroup hierarchy. | ||
| # Mounting a cgroup v1 hierarchy here might confuse the host and the systemd | ||
| # documentation advises against manually interfering with anything in that | ||
| # path. Therefore, mount the extra hierarchy elsewhere and tell systemd in | ||
| # the admin container where to look. Requirements: | ||
| # | ||
| # 1. The base must be a mount point. | ||
| # 2. The base must contain another mounted cgroup file system named "systemd". | ||
| # | ||
| # In either case there is no need to populate the file systems with any | ||
| # actual cgroup controllers, since the host is expected to manage processes. | ||
| readonly cgroup_base=/.bottlerocket/admin-container-cgroup | ||
| mkdir -p "${cgroup_base}" | ||
| mount -t tmpfs -o nosuid,nodev,noexec tmpfs "${cgroup_base}" | ||
| mkdir -p "${cgroup_base}"/systemd | ||
| mount -o remount,ro "${cgroup_base}" | ||
| mount -t cgroup -o none,name=systemd cgroup "${cgroup_base}"/systemd | ||
| systemd_options+=( --cgroup-base "${cgroup_base}" ) | ||
| fi | ||
|
|
||
| # Persuade systemd that it's OK to run as a user manager. | ||
| export XDG_RUNTIME_DIR="/run/user/${UID}" | ||
| mkdir -p /run/systemd/system "${XDG_RUNTIME_DIR}" | ||
| exec /usr/lib/systemd/systemd "${systemd_options[@]}" --user --unit=admin.target | ||
| exec /usr/lib/systemd/systemd "${systemd_options[@]}" --user --unit=admin.target | ||
|
Contributor
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. You are missing a new line at the end of this file. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for your commit messages please break lines at 75 characters