-
Notifications
You must be signed in to change notification settings - Fork 190
[rhcos-4.18] tests: add fips.enable.tls
#4491
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| FROM registry.redhat.io/rhel10/nginx-126:10.1 | ||
|
|
||
| ADD nginx.conf "${NGINX_CONF_PATH}" | ||
|
|
||
| COPY index.html /usr/share/nginx/html/index.html | ||
|
|
||
| # TLS material | ||
| USER 0 | ||
| COPY tls/ /etc/nginx/tls/ | ||
| RUN chown -R 1001:0 /etc/nginx/tls | ||
| USER 1001 | ||
|
|
||
| CMD ["nginx", "-g", "daemon off;"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # fips-nginx Container | ||
|
|
||
| This is used by the `fips.enable.https` test to verify that using | ||
|
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. |
||
| TLS works in FIPS mode by having Ignition fetch a remote resource | ||
| over HTTPS with FIPS compatible algorithms. | ||
|
|
||
| See https://catalog.redhat.com/en/software/containers/rhel10/nginx-126/677d3718e58b5a1ae5598058#overview | ||
|
|
||
| To build the container using command: | ||
| `./build.sh <IP>` | ||
|
|
||
| To run the container image using command: | ||
| `podman run -d -p 8443:8443 --name fips-nginx fips-nginx` | ||
|
|
||
| Remember to create firewall-rules to allow port 8443: | ||
| ``` | ||
| gcloud compute firewall-rules create allow-nginx-fips-8443 \ | ||
| --action ALLOW \ | ||
| --direction INGRESS \ | ||
| --rules tcp:8443 \ | ||
| --source-ranges 0.0.0.0/0 \ | ||
| --target-tags nginx-fips-server \ | ||
| --description "Allow FIPS test access to nginx on port 8443" | ||
|
|
||
| gcloud compute instances add-tags rhcos-fips-test \ | ||
| --zone us-central1-a \ | ||
| --tags nginx-fips-server | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,107 @@ | ||||||
| #!/usr/bin/env bash | ||||||
|
|
||||||
| # Run the image using command: | ||||||
| # podman run -d --name fips-nginx -p 8443:8443 fips-nginx | ||||||
| set -euo pipefail | ||||||
|
|
||||||
| # Check if argument is provided | ||||||
| if [ $# -eq 0 ]; then | ||||||
| echo "Error: Missing IP address argument" | ||||||
| echo "Usage: $0 <ip-address>" | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| ip="$1" | ||||||
|
|
||||||
| tmpdir="$(mktemp -d)" | ||||||
|
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. |
||||||
| cp Containerfile ${tmpdir} | ||||||
|
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. The script assumes it is run from the directory where
Suggested change
|
||||||
| cd ${tmpdir} | ||||||
|
|
||||||
| # Prepare index.html | ||||||
| cat <<EOF > index.html | ||||||
| This file was served from an RHCOS FIPS-hardened server. | ||||||
| EOF | ||||||
|
|
||||||
| # Prepare nginx.conf | ||||||
| cat <<EOF > nginx.conf | ||||||
| events {} | ||||||
|
|
||||||
| http { | ||||||
| server { | ||||||
| listen 8443 ssl; | ||||||
| server_name _; | ||||||
|
|
||||||
| # ---- FIPS-only TLS ---- | ||||||
| ssl_protocols TLSv1.2; | ||||||
| ssl_prefer_server_ciphers on; | ||||||
|
|
||||||
| ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256; | ||||||
|
|
||||||
| ssl_certificate /etc/nginx/tls/fips-server.crt; | ||||||
| ssl_certificate_key /etc/nginx/tls/fips-server.key; | ||||||
|
|
||||||
| location / { | ||||||
| root /usr/share/nginx/html; | ||||||
| index index.html; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| EOF | ||||||
|
|
||||||
| mkdir -p tls | ||||||
| pushd tls/ | ||||||
| # Prepare openssl.cnf | ||||||
| # The IP must point to an nginx server configured with FIPS-compliant ciphers | ||||||
| cat <<SSLEOF > openssl.cnf | ||||||
| [ req ] | ||||||
| default_bits = 3072 | ||||||
| distinguished_name = dn | ||||||
| prompt = no | ||||||
| string_mask = utf8only | ||||||
| req_extensions = req_ext | ||||||
|
|
||||||
| [ dn ] | ||||||
| CN = FIPS TLS Test Server | ||||||
|
|
||||||
| [ req_ext ] | ||||||
| keyUsage = critical, digitalSignature, keyEncipherment | ||||||
| extendedKeyUsage = critical, serverAuth | ||||||
| subjectAltName = @alt_names | ||||||
|
|
||||||
| [ alt_names ] | ||||||
| IP.1 = ${ip} | ||||||
| SSLEOF | ||||||
|
|
||||||
| # Prepare key and crt | ||||||
| ## Generate the private key (FIPS-approved) | ||||||
| openssl genpkey \ | ||||||
| -algorithm RSA \ | ||||||
| -pkeyopt rsa_keygen_bits:3072 \ | ||||||
| -out fips-server.key | ||||||
|
|
||||||
| ## Generate CSR (still FIPS-only) | ||||||
| openssl req -new -key fips-server.key -out fips-server.csr -config openssl.cnf | ||||||
|
|
||||||
| ## Self-sign the certificate (TLS-compatible + FIPS) | ||||||
| openssl x509 -req \ | ||||||
| -in fips-server.csr \ | ||||||
| -signkey fips-server.key \ | ||||||
| -out fips-server.crt \ | ||||||
| -days 3650 \ | ||||||
| -sha256 \ | ||||||
| -extfile openssl.cnf \ | ||||||
| -extensions req_ext | ||||||
|
|
||||||
| # Verify SAN present | ||||||
| openssl x509 -in fips-server.crt -noout -text | grep -A2 "Subject Alternative Name" | ||||||
|
|
||||||
| openssl verify \ | ||||||
| -provider fips \ | ||||||
| -CAfile fips-server.crt \ | ||||||
| fips-server.crt | ||||||
|
|
||||||
| rm fips-server.csr openssl.cnf | ||||||
|
|
||||||
| popd | ||||||
|
|
||||||
| podman build -t fips-nginx . | ||||||
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.
The test uses a hardcoded IP address
34.172.244.189to fetch a resource. This makes the test fragile and dependent on an external service that might not be available or could change, leading to flaky tests and maintenance overhead.It would be better to either: