搜索

1.3. 为旧 HTTPS 证书扫描 RHOSP 端点

download PDF

从 OpenShift Container Platform 4.10 开始,HTTPS 证书必须包含主题替代名称(SAN)字段。运行以下脚本,为仅包含 CommonName 字段的传统证书在 Red Hat OpenStack Platform(RHOSP)目录中扫描每个 HTTPS 端点。

重要

OpenShift Container Platform 在安装或升级前不会检查底层 RHOSP 基础架构是否有旧证书。使用提供的脚本来自行检查这些证书。在安装或升级集群前无法更新旧证书将导致集群无法正常工作。

先决条件

流程

  1. 将以下脚本保存到机器中:

    #!/usr/bin/env bash
    
    set -Eeuo pipefail
    
    declare catalog san
    catalog="$(mktemp)"
    san="$(mktemp)"
    readonly catalog san
    
    declare invalid=0
    
    openstack catalog list --format json --column Name --column Endpoints \
    	| jq -r '.[] | .Name as $name | .Endpoints[] | select(.interface=="public") | [$name, .interface, .url] | join(" ")' \
    	| sort \
    	> "$catalog"
    
    while read -r name interface url; do
    	# Ignore HTTP
    	if [[ ${url#"http://"} != "$url" ]]; then
    		continue
    	fi
    
    	# Remove the schema from the URL
    	noschema=${url#"https://"}
    
    	# If the schema was not HTTPS, error
    	if [[ "$noschema" == "$url" ]]; then
    		echo "ERROR (unknown schema): $name $interface $url"
    		exit 2
    	fi
    
    	# Remove the path and only keep host and port
    	noschema="${noschema%%/*}"
    	host="${noschema%%:*}"
    	port="${noschema##*:}"
    
    	# Add the port if was implicit
    	if [[ "$port" == "$host" ]]; then
    		port='443'
    	fi
    
    	# Get the SAN fields
    	openssl s_client -showcerts -servername "$host" -connect "$host:$port" </dev/null 2>/dev/null \
    		| openssl x509 -noout -ext subjectAltName \
    		> "$san"
    
    	# openssl returns the empty string if no SAN is found.
    	# If a SAN is found, openssl is expected to return something like:
    	#
    	#    X509v3 Subject Alternative Name:
    	#        DNS:standalone, DNS:osp1, IP Address:192.168.2.1, IP Address:10.254.1.2
    	if [[ "$(grep -c "Subject Alternative Name" "$san" || true)" -gt 0 ]]; then
    		echo "PASS: $name $interface $url"
    	else
    		invalid=$((invalid+1))
    		echo "INVALID: $name $interface $url"
    	fi
    done < "$catalog"
    
    # clean up temporary files
    rm "$catalog" "$san"
    
    if [[ $invalid -gt 0 ]]; then
    	echo "${invalid} legacy certificates were detected. Update your certificates to include a SAN field."
    	exit 1
    else
    	echo "All HTTPS certificates for this cloud are valid."
    fi
  2. 运行脚本。
  3. 将脚本报告为 INVALID 的任何证书替换为包含 SAN 字段的证书。
重要

在安装 OpenShift Container Platform 4.10 之前,您必须替换所有旧的 HTTPS 证书,或将集群更新至该版本。旧证书将被拒绝,并显示以下信息:

x509: certificate relies on legacy Common Name field, use SANs instead

1.3.1. 手动为旧 HTTPS 证书扫描 RHOSP 端点

从 OpenShift Container Platform 4.10 开始,HTTPS 证书必须包含主题替代名称(SAN)字段。如果您无法访问 "Scanning RHOSP 端点用于旧 HTTPS 证书"中列出的预备工具,请执行以下步骤为仅包含 CommonName 字段的传统证书扫描 Red Hat OpenStack Platform (RHOSP)目录中的每个 HTTPS 端点。

重要

OpenShift Container Platform 在安装或升级前不会检查底层 RHOSP 基础架构是否有旧证书。使用以下步骤自己检查这些证书。在安装或升级集群前无法更新旧证书将导致集群无法正常工作。

流程

  1. 在命令行中运行以下命令查看 RHOSP 公共端点的 URL:

    $ openstack catalog list

    记录命令返回的每个 HTTPS 端点的 URL。

  2. 对于每个公共端点,请注意主机和端口。

    提示

    通过删除方案、端口和路径来确定端点的主机。

  3. 对于每个端点,运行以下命令来提取证书的 SAN 字段:

    1. 设置 host 变量:

      $ host=<host_name>
    2. 设置 port 变量:

      $ port=<port_number>

      如果端点的 URL 中没有包括端口,使用值 443

    3. 检索证书的 SAN 字段:

      $ openssl s_client -showcerts -servername "$host" -connect "$host:$port" </dev/null 2>/dev/null \
          | openssl x509 -noout -ext subjectAltName

      输出示例

      X509v3 Subject Alternative Name:
          DNS:your.host.example.net

      对于每个端点,查找类似于上例的输出。如果没有端点的输出,则该端点的证书无效,必须重新发布。

重要

在安装 OpenShift Container Platform 4.10 之前,您必须替换所有旧的 HTTPS 证书,或将集群更新至该版本。旧证书被拒绝,并显示以下信息:

x509: certificate relies on legacy Common Name field, use SANs instead
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.