Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 149 additions & 9 deletions .ci/pipelines/jobs/ocp-fips-helm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,23 @@ fips_deployment() {

namespace::configure "${NAME_SPACE}"

deploy_redis_cache "${NAME_SPACE}"
# Reuse the CI external PostgreSQL (TLS with a CI-generated CA)
log::section "Configuring external PostgreSQL with TLS"
namespace::configure "${NAME_SPACE_POSTGRES_DB}"
configure_external_postgres_db "${NAME_SPACE}" || return 1

# Deploy Redis with TLS using FIPS custom CA
log::section "Configuring Redis with FIPS custom CA and TLS"
fips_deploy_redis_with_tls "${NAME_SPACE}" || return 1

cd "${DIR}" || exit
local rhdh_base_url="https://${RELEASE_NAME}-developer-hub-${NAME_SPACE}.${K8S_CLUSTER_ROUTER_BASE}"
apply_yaml_files "${DIR}" "${NAME_SPACE}" "${rhdh_base_url}"

# FIPS-only app-config (Redis TLS cache), loaded after app-config-rhdh via extraAppConfig
common::create_configmap_from_file "app-config-rhdh-fips" "${NAME_SPACE}" \
"app-config-rhdh-fips.yaml" "${DIR}/resources/config_map/app-config-rhdh-fips.yaml"

# Merge base values with the FIPS environment overrides.
helm::merge_values "overwrite" \
"${DIR}/value_files/${HELM_CHART_VALUE_FILE_NAME}" \
Expand Down Expand Up @@ -105,10 +116,12 @@ run_standard_deployment_tests() {

# Setup Chromium NSS certificate database for Playwright
# This function configures the Chromium certificate store used by Playwright
# to trust the custom root CA certificate.
# to trust the custom root CA certificate, and makes the Node.js process running
# Playwright trust both the root CA and the external PostgreSQL CA.
#
# Required environment variables:
# FIPS_ROOT_CA_CERT - Base64-encoded root CA certificate (PEM format)
# NAME_SPACE - RHDH namespace (holds the PostgreSQL CA copied by configure_external_postgres_db)
#
# Returns:
# 0 - Success
Expand Down Expand Up @@ -151,8 +164,18 @@ fips_setup_chromium_cert_store() {
return 1
fi

# Trust the custom CA in the Node.js process running Playwright TLS tests.
export NODE_EXTRA_CA_CERTS="${root_ca_file}"
# Trust the custom CA and the external PostgreSQL CA (created by
# configure_external_postgres_db) in the Node.js process running Playwright TLS tests.
local pg_ca_file="${HOME}/.pki/postgresCA.crt"
local node_ca_bundle="${HOME}/.pki/node-ca-bundle.crt"
if ! oc get secret postgress-external-db-cluster-cert -n "${NAME_SPACE}" \
-o go-template='{{index .data "ca.crt" | base64decode}}' > "${pg_ca_file}" \
|| [[ ! -s "${pg_ca_file}" ]]; then
log::error "Failed to read the PostgreSQL CA from postgress-external-db-cluster-cert"
return 1
fi
cat "${root_ca_file}" "${pg_ca_file}" > "${node_ca_bundle}"
export NODE_EXTRA_CA_CERTS="${node_ca_bundle}"

# Add root CA certificate to NSS database (WITH sql: prefix for -A)
log::info "Adding root CA certificate to NSS database..."
Expand Down Expand Up @@ -197,8 +220,8 @@ fips_configure_custom_ca_ingress() {

# Verify required environment variables
if [[ -z "${FIPS_ROOT_CA_CERT:-}" ]] || [[ -z "${FIPS_ROOT_CA_KEY:-}" ]]; then
log::warning "FIPS_ROOT_CA_CERT or FIPS_ROOT_CA_KEY not set - skipping custom CA configuration"
return 0
log::error "FIPS_ROOT_CA_CERT or FIPS_ROOT_CA_KEY not set - required for FIPS job"
return 1
fi

if [[ -z "${K8S_CLUSTER_ROUTER_BASE:-}" ]]; then
Expand Down Expand Up @@ -279,9 +302,8 @@ EOF

log::success "✓ TLS secret '${secret_name}' created in namespace '${ingress_namespace}'"

# Clean up temporary files immediately
rm -rf "${tmpdir}"
unset FIPS_CERT_TMPDIR
# NOTE: tmpdir is preserved (FIPS_CERT_TMPDIR) for Redis cert generation
# It is removed by the cleanup EXIT trap (cleanup.sh)

# Patch the default IngressController to use the custom certificate
log::info "Patching default IngressController to use custom certificate..."
Expand Down Expand Up @@ -310,3 +332,121 @@ EOF
log::success "Custom CA ingress configuration completed successfully"
return 0
}

# Deploy Redis with TLS using FIPS custom CA-signed certificates
# This function generates Redis TLS certificate signed by the FIPS root CA,
# creates the required secrets, and deploys a TLS-enabled Redis instance.
#
# Prerequisites:
# - fips_configure_custom_ca_ingress() must be called first
# - FIPS_CERT_TMPDIR must be set with rootCA.crt and rootCA.key
#
# Required environment variables:
# REDIS_USERNAME - Redis username
# REDIS_PASSWORD - Redis password
#
# Returns:
# 0 - Success
# 1 - Failure (missing vars, cert generation failed, or deployment failed)
fips_deploy_redis_with_tls() {
local namespace=$1
local tmpdir="${FIPS_CERT_TMPDIR}"

log::info "Deploying Redis with FIPS custom CA-signed TLS certificates..."

# Verify prerequisites
if [[ -z "${tmpdir}" || ! -f "${tmpdir}/rootCA.crt" || ! -f "${tmpdir}/rootCA.key" ]]; then
log::error "FIPS CA not available - run fips_configure_custom_ca_ingress first"
return 1
fi

if [[ -z "${namespace}" ]]; then
log::error "Redis namespace not provided"
return 1
fi

if [[ -z "${REDIS_USERNAME}" || -z "${REDIS_PASSWORD}" ]]; then
log::error "REDIS_USERNAME or REDIS_PASSWORD not set"
return 1
fi

# Generate Redis server certificate
log::info "Generating Redis TLS certificate..."

openssl ecparam -name prime256v1 -genkey -noout -out "${tmpdir}/redis.key"

openssl req -new -key "${tmpdir}/redis.key" \
-out "${tmpdir}/redis.csr" \
-subj "/O=CI-FIPS-Testing/CN=redis.${namespace}.svc.cluster.local"

# Create extensions file for Redis certificate
cat > "${tmpdir}/redis_ext.cnf" << EOF
[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth
subjectKeyIdentifier = hash
authorityKeyIdentifier = issuer
subjectAltName = @alt_names

[ alt_names ]
DNS.1 = redis
DNS.2 = redis.${namespace}.svc
DNS.3 = redis.${namespace}.svc.cluster.local
EOF

openssl x509 -req -in "${tmpdir}/redis.csr" \
-CA "${tmpdir}/rootCA.crt" -CAkey "${tmpdir}/rootCA.key" -CAcreateserial \
-out "${tmpdir}/redis.crt" -days 30 -sha256 \
-extfile "${tmpdir}/redis_ext.cnf" -extensions v3_req

if [[ ! -f "${tmpdir}/redis.crt" ]]; then
log::error "Failed to generate Redis certificate"
return 1
fi

log::success "✓ Redis TLS certificate generated"

# Create Redis TLS secret
log::info "Creating Redis TLS secret in namespace '${namespace}'..."

oc create secret generic redis-certs \
-n "${namespace}" \
--from-file=ca.crt="${tmpdir}/rootCA.crt" \
--from-file=tls.crt="${tmpdir}/redis.crt" \
--from-file=tls.key="${tmpdir}/redis.key" \
--dry-run=client -o yaml | oc apply -f -

if [[ $? -ne 0 ]]; then
log::error "Failed to create redis-certs secret"
return 1
fi

log::success "✓ redis-certs secret created"

# Create Redis credentials secret
log::info "Creating Redis connection secret..."

# REDIS_USERNAME_ENCODED and REDIS_PASSWORD_ENCODED already set in env_variables.sh
envsubst < "${DIR}/resources/redis-cache/redis-secret.yaml" | oc apply --namespace="${namespace}" -f -

if [[ $? -ne 0 ]]; then
log::error "Failed to create Redis secret"
return 1
fi

log::success "✓ Redis secret created"

# Deploy TLS-enabled Redis
log::info "Deploying TLS-enabled Redis..."

if ! oc apply -f "${DIR}/resources/redis-cache/redis-deployment-tls.yaml" \
-f "${DIR}/resources/redis-cache/redis-service.yaml" --namespace="${namespace}"; then
log::error "Failed to deploy Redis"
return 1
fi

log::success "✓ Redis deployment created"
log::success "Redis TLS deployment completed successfully"
return 0
}
12 changes: 12 additions & 0 deletions .ci/pipelines/resources/config_map/app-config-rhdh-fips.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# FIPS-only app-config, listed in extraAppConfig AFTER app-config-rhdh.yaml
# so it overrides the plain redis:// connection defined there.
# The object form of `connection` is passed to the underlying node-redis client.
backend:
cache:
store: redis
connection:
url: rediss://${REDIS_USERNAME}:${REDIS_PASSWORD}@redis:6379
socket:
tls: true
ca:
$file: /opt/app-root/src/redis-ca.pem
70 changes: 70 additions & 0 deletions .ci/pipelines/resources/redis-cache/redis-deployment-tls.yaml
Comment thread
albarbaro marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
labels:
app: redis
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: registry.redhat.io/rhel9/redis-7:latest
ports:
- containerPort: 6379
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "256Mi"
cpu: "500m"
env:
- name: REDIS_USERNAME
valueFrom:
secretKeyRef:
name: redis-secret
key: REDIS_USERNAME
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redis-secret
key: REDIS_PASSWORD
command:
- /bin/sh
- -c
- |
# The RHEL image keeps protected mode on, which rejects remote clients while the
# default user has no password: disable the default user and allow remote clients.
# No RDB snapshots: the working dir is not writable and a failed save blocks writes.
echo "user default off" > /data/redis.conf
echo "user ${REDIS_USERNAME} on >${REDIS_PASSWORD} allcommands allkeys" >> /data/redis.conf
redis-server /data/redis.conf \
--protected-mode no \
--save "" \
--tls-port 6379 \
--port 0 \
--tls-cert-file /certs/tls.crt \
Comment thread
albarbaro marked this conversation as resolved.
Resolved
--tls-key-file /certs/tls.key \
--tls-ca-cert-file /certs/ca.crt \
--tls-auth-clients no
volumeMounts:
- name: redis-data
mountPath: /data
- name: redis-certs
mountPath: /certs
readOnly: true
volumes:
- name: redis-data
emptyDir: {}
- name: redis-certs
secret:
secretName: redis-certs
defaultMode: 0440
13 changes: 0 additions & 13 deletions .ci/pipelines/resources/redis-cache/redis-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,3 @@ spec:
volumes:
- name: redis-data
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: redis
labels:
app: redis
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
12 changes: 12 additions & 0 deletions .ci/pipelines/resources/redis-cache/redis-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: redis
labels:
app: redis
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
1 change: 1 addition & 0 deletions .ci/pipelines/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ deploy_redis_cache() {
local namespace=$1
envsubst < "$DIR/resources/redis-cache/redis-secret.yaml" | oc apply --namespace="${namespace}" -f -
oc apply -f "$DIR/resources/redis-cache/redis-deployment.yaml" --namespace="${namespace}"
oc apply -f "$DIR/resources/redis-cache/redis-service.yaml" --namespace="${namespace}"
}

# OLM Functions - Delegate to lib/operators.sh
Expand Down
Loading
Loading